Skip to content

Commit 4533559

Browse files
committed
fix commitBatchWithProof by any
1 parent 895120c commit 4533559

File tree

2 files changed

+43
-4
lines changed

2 files changed

+43
-4
lines changed

contracts/contracts/l1/rollup/Rollup.sol

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -238,12 +238,14 @@ contract Rollup is IRollup, OwnableUpgradeable, PausableUpgradeable {
238238
) {
239239
require(batchDataInput.numL1Messages > 0, "l1msg delay");
240240
}
241-
_commitBatchWithBatchData(batchDataInput, batchSignatureInput);
241+
uint256 submitterBitmap = IL1Staking(l1StakingContract).getStakerBitmap(_msgSender());
242+
_commitBatchWithBatchData(batchDataInput, batchSignatureInput, submitterBitmap);
242243
}
243244

244245
function _commitBatchWithBatchData(
245246
BatchDataInput calldata batchDataInput,
246-
BatchSignatureInput calldata batchSignatureInput
247+
BatchSignatureInput calldata batchSignatureInput,
248+
uint256 submitterBitmap
247249
) internal {
248250
require(batchDataInput.version == 0 || batchDataInput.version == 1, "invalid version");
249251
require(batchDataInput.prevStateRoot != bytes32(0), "previous state root is zero");
@@ -324,7 +326,7 @@ contract Rollup is IRollup, OwnableUpgradeable, PausableUpgradeable {
324326
batchDataInput.lastBlockNumber,
325327
// Before BLS is implemented, the accuracy of the sequencer set uploaded by rollup cannot be guaranteed.
326328
// Therefore, if the batch is successfully challenged, only the submitter will be punished.
327-
IL1Staking(l1StakingContract).getStakerBitmap(_msgSender()) // => batchSignature.signedSequencersBitmap
329+
submitterBitmap // => batchSignature.signedSequencersBitmap
328330
);
329331

330332
lastCommittedBatchIndex = _batchIndex;
@@ -367,7 +369,7 @@ contract Rollup is IRollup, OwnableUpgradeable, PausableUpgradeable {
367369
}
368370
require(rollupDelay || l1MsgQueueDelayed, "invalid timing");
369371

370-
_commitBatchWithBatchData(batchDataInput, batchSignatureInput);
372+
_commitBatchWithBatchData(batchDataInput, batchSignatureInput,0);
371373

372374
// get batch data from batch header
373375
(uint256 memPtr, bytes32 _batchHash) = _loadBatchHeader(_batchHeader);

contracts/contracts/test/Rollup.t.sol

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,43 @@ contract RollupCommitBatchWithProofTest is L1MessageBaseTest {
539539
);
540540
}
541541

542+
/// @notice Test: commitBatchWithProof can be called by anyone (not only staker) when delay is met
543+
/// @dev Ensures permissionless batch submission: any address can submit when rollup/L1 queue is stalled.
544+
function test_commitBatchWithProof_anyone_can_call_when_delay_met() public {
545+
_mockVerifierCall();
546+
_mockMessageQueueStalled();
547+
hevm.warp(block.timestamp + 7200);
548+
549+
bytes32 prevStateRoot = bytes32(uint256(1));
550+
bytes32 postStateRoot = bytes32(uint256(2));
551+
bytes32 withdrawalRoot = getTreeRoot();
552+
553+
IRollup.BatchDataInput memory batchDataInput = IRollup.BatchDataInput({
554+
version: 0,
555+
parentBatchHeader: batchHeader0,
556+
lastBlockNumber: 1,
557+
numL1Messages: 0,
558+
prevStateRoot: prevStateRoot,
559+
postStateRoot: postStateRoot,
560+
withdrawalRoot: withdrawalRoot
561+
});
562+
563+
bytes memory batchHeader1 = _createMatchingBatchHeader(1, 0, prevStateRoot, postStateRoot, withdrawalRoot);
564+
565+
// Caller is bob: not a staker, not owner. Anyone can submit when delay is met.
566+
hevm.prank(bob);
567+
rollup.commitBatchWithProof(
568+
batchDataInput,
569+
batchSignatureInput,
570+
batchHeader1,
571+
hex"deadbeef"
572+
);
573+
574+
assertEq(rollup.lastCommittedBatchIndex(), 1);
575+
assertTrue(rollup.batchExist(1));
576+
assertEq(rollup.committedStateRoots(1), postStateRoot);
577+
}
578+
542579
/// @notice Test: commitBatchWithProof succeeds when queue is empty (no unfinalized messages)
543580
function test_commitBatchWithProof_succeeds_when_queue_empty() public {
544581
_mockVerifierCall();

0 commit comments

Comments
 (0)