Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update bitmap #433

Merged
merged 4 commits into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bindings/bin/l1staking_deployed.hex

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion bindings/bindings/l1staking.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion bindings/bindings/l1staking_more.go

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion contracts/contracts/l1/staking/L1Staking.sol
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ contract L1Staking is IL1Staking, Staking, OwnableUpgradeable, ReentrancyGuardUp
/// @notice get staker bitmap
/// @param _staker the staker address
function getStakerBitmap(address _staker) external view returns (uint256 bitmap) {
require(isStaker(_staker), "invalid staker");
bitmap = 1 << stakerIndexes[_staker];
return bitmap;
}
Expand All @@ -348,7 +349,8 @@ contract L1Staking is IL1Staking, Staking, OwnableUpgradeable, ReentrancyGuardUp
/// @notice get stakers from bitmap
/// @param bitmap the stakers bitmap
function getStakersFromBitmap(uint256 bitmap) public view returns (address[] memory stakerAddrs) {
uint256 _bitmap = bitmap;
// skip first bit
uint256 _bitmap = bitmap >> 1;
uint256 stakersLength = 0;
while (_bitmap > 0) {
stakersLength = stakersLength + 1;
Expand Down
20 changes: 20 additions & 0 deletions contracts/contracts/test/Rollup.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ contract RollupCommitBatchTest is L1MessageBaseTest {
abi.encodeCall(IL1Staking.isStaker, (address(0))),
abi.encode(true)
);
hevm.mockCall(
address(rollup.l1StakingContract()),
abi.encodeCall(IL1Staking.getStakerBitmap, (address(0))),
abi.encode(2)
);
hevm.startPrank(address(0));
hevm.expectEmit(true, true, false, true);
emit IRollup.CommitBatch(1, bytes32(0xea8482fa5502100ff03f9329ad89519a3b4f4a6bbe9f7997508683195342f899));
Expand Down Expand Up @@ -243,6 +248,11 @@ contract RollupCommitBatchTest is L1MessageBaseTest {
abi.encodeCall(IL1Staking.isStaker, (address(0))),
abi.encode(true)
);
hevm.mockCall(
address(rollup.l1StakingContract()),
abi.encodeCall(IL1Staking.getStakerBitmap, (address(0))),
abi.encode(2)
);
hevm.startPrank(address(0));
hevm.expectRevert("too many txs in one chunk");

Expand All @@ -257,6 +267,11 @@ contract RollupCommitBatchTest is L1MessageBaseTest {
abi.encodeCall(IL1Staking.isStaker, (address(0))),
abi.encode(true)
);
hevm.mockCall(
address(rollup.l1StakingContract()),
abi.encodeCall(IL1Staking.getStakerBitmap, (address(0))),
abi.encode(2)
);
hevm.startPrank(address(0));
hevm.expectRevert("too many txs in one chunk");
batchDataInput = IRollup.BatchDataInput(0, batchHeader1, chunks, bitmap, bytesData1, bytesData1, bytesData4);
Expand All @@ -270,6 +285,11 @@ contract RollupCommitBatchTest is L1MessageBaseTest {
abi.encodeCall(IL1Staking.isStaker, (address(0))),
abi.encode(true)
);
hevm.mockCall(
address(rollup.l1StakingContract()),
abi.encodeCall(IL1Staking.getStakerBitmap, (address(0))),
abi.encode(2)
);
hevm.startPrank(address(0));
hevm.expectEmit(true, true, false, true);
emit IRollup.CommitBatch(2, bytes32(0x38b5e7c774281a41309d14aa892d0dfafa690cad0e593c0f8797d5c49dfad1a1));
Expand Down
Loading