Skip to content

Commit b5a0411

Browse files
committed
feat: require top-level call to commitAndFinalizeBatch (#120)
1 parent 2c0b0e4 commit b5a0411

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/L1/rollup/ScrollChain.sol

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,10 @@ contract ScrollChain is OwnableUpgradeable, PausableUpgradeable, IScrollChain {
130130
/// @dev Thrown when given batch is not committed before.
131131
error ErrorBatchNotCommitted();
132132

133+
/// @dev Thrown when the function call is not the top-level call in the transaction.
134+
/// @dev This is checked so that indexers that need to decode calldata continue to work.
135+
error ErrorTopLevelCallRequired();
136+
133137
/*************
134138
* Constants *
135139
*************/
@@ -242,6 +246,12 @@ contract ScrollChain is OwnableUpgradeable, PausableUpgradeable, IScrollChain {
242246
_;
243247
}
244248

249+
modifier OnlyTopLevelCall() {
250+
// disallow contract accounts and delegated EOAs
251+
if (msg.sender.code.length != 0) revert ErrorTopLevelCallRequired();
252+
_;
253+
}
254+
245255
/***************
246256
* Constructor *
247257
***************/
@@ -528,7 +538,7 @@ contract ScrollChain is OwnableUpgradeable, PausableUpgradeable, IScrollChain {
528538
uint8 version,
529539
bytes32 parentBatchHash,
530540
FinalizeStruct calldata finalizeStruct
531-
) external {
541+
) external OnlyTopLevelCall {
532542
ScrollChainMiscData memory cachedMiscData = miscData;
533543
if (!isEnforcedModeEnabled()) {
534544
(uint256 maxDelayEnterEnforcedMode, uint256 maxDelayMessageQueue) = SystemConfig(systemConfig)

src/test/ScrollChain.t.sol

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,7 @@ contract ScrollChainTest is DSTestPlus {
638638

639639
// revert when ErrorNotInEnforcedBatchMode
640640
hevm.expectRevert(ScrollChain.ErrorNotInEnforcedBatchMode.selector);
641+
hevm.startPrank(address(999));
641642
rollup.commitAndFinalizeBatch(
642643
7,
643644
bytes32(0),
@@ -649,6 +650,7 @@ contract ScrollChainTest is DSTestPlus {
649650
zkProof: new bytes(0)
650651
})
651652
);
653+
hevm.stopPrank();
652654

653655
system.updateEnforcedBatchParameters(
654656
SystemConfig.EnforcedBatchParameters({
@@ -669,6 +671,7 @@ contract ScrollChainTest is DSTestPlus {
669671
// succeed to call commitAndFinalizeBatch 13
670672
ScrollChainMockBlob(address(rollup)).setBlobVersionedHash(0, blobVersionedHash);
671673
ScrollChainMockBlob(address(rollup)).setBlobVersionedHash(1, bytes32(0));
674+
hevm.startPrank(address(999));
672675
rollup.commitAndFinalizeBatch(
673676
7,
674677
keccak256(headers[12]),
@@ -680,6 +683,7 @@ contract ScrollChainTest is DSTestPlus {
680683
zkProof: new bytes(0)
681684
})
682685
);
686+
hevm.stopPrank();
683687
(uint256 lastCommittedBatchIndex, uint256 lastFinalizedBatchIndex, uint256 lastFinalizeTimestamp, , ) = rollup
684688
.miscData();
685689
assertEq(lastCommittedBatchIndex, 13);
@@ -709,6 +713,7 @@ contract ScrollChainTest is DSTestPlus {
709713
// succeed to call commitAndFinalizeBatch 14, no need to warp time
710714
ScrollChainMockBlob(address(rollup)).setBlobVersionedHash(0, blobVersionedHash);
711715
ScrollChainMockBlob(address(rollup)).setBlobVersionedHash(1, bytes32(0));
716+
hevm.startPrank(address(999));
712717
rollup.commitAndFinalizeBatch(
713718
7,
714719
keccak256(headers[13]),
@@ -720,6 +725,7 @@ contract ScrollChainTest is DSTestPlus {
720725
zkProof: new bytes(0)
721726
})
722727
);
728+
hevm.stopPrank();
723729
(lastCommittedBatchIndex, lastFinalizedBatchIndex, lastFinalizeTimestamp, , ) = rollup.miscData();
724730
assertEq(lastCommittedBatchIndex, 14);
725731
assertEq(lastFinalizedBatchIndex, 14);
@@ -739,6 +745,7 @@ contract ScrollChainTest is DSTestPlus {
739745

740746
// not in enforced mode
741747
hevm.expectRevert(ScrollChain.ErrorNotInEnforcedBatchMode.selector);
748+
hevm.startPrank(address(999));
742749
rollup.commitAndFinalizeBatch(
743750
7,
744751
keccak256(headers[13]),
@@ -750,6 +757,7 @@ contract ScrollChainTest is DSTestPlus {
750757
zkProof: new bytes(0)
751758
})
752759
);
760+
hevm.stopPrank();
753761
}
754762

755763
function testCommitAndFinalizeBatchByExpiredBatch() external {
@@ -780,6 +788,7 @@ contract ScrollChainTest is DSTestPlus {
780788

781789
// revert when ErrorNotInEnforcedBatchMode
782790
hevm.expectRevert(ScrollChain.ErrorNotInEnforcedBatchMode.selector);
791+
hevm.startPrank(address(999));
783792
rollup.commitAndFinalizeBatch(
784793
7,
785794
bytes32(0),
@@ -791,6 +800,7 @@ contract ScrollChainTest is DSTestPlus {
791800
zkProof: new bytes(0)
792801
})
793802
);
803+
hevm.stopPrank();
794804

795805
system.updateEnforcedBatchParameters(
796806
SystemConfig.EnforcedBatchParameters({
@@ -803,6 +813,7 @@ contract ScrollChainTest is DSTestPlus {
803813
// succeed to call commitAndFinalizeBatch 13
804814
ScrollChainMockBlob(address(rollup)).setBlobVersionedHash(0, blobVersionedHash);
805815
ScrollChainMockBlob(address(rollup)).setBlobVersionedHash(1, bytes32(0));
816+
hevm.startPrank(address(999));
806817
rollup.commitAndFinalizeBatch(
807818
7,
808819
keccak256(headers[12]),
@@ -814,6 +825,7 @@ contract ScrollChainTest is DSTestPlus {
814825
zkProof: new bytes(0)
815826
})
816827
);
828+
hevm.stopPrank();
817829
(uint256 lastCommittedBatchIndex, uint256 lastFinalizedBatchIndex, uint256 lastFinalizeTimestamp, , ) = rollup
818830
.miscData();
819831
assertEq(lastCommittedBatchIndex, 13);

0 commit comments

Comments
 (0)