Skip to content

feat: require top-level call to commitAndFinalizeBatch #120

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
12 changes: 11 additions & 1 deletion src/L1/rollup/ScrollChain.sol
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ contract ScrollChain is OwnableUpgradeable, PausableUpgradeable, IScrollChain {
/// @dev Thrown when given batch is not committed before.
error ErrorBatchNotCommitted();

/// @dev Thrown when the function call is not the top-level call in the transaction.
/// @dev This is checked so that indexers that need to decode calldata continue to work.
error ErrorTopLevelCallRequired();

/*************
* Constants *
*************/
Expand Down Expand Up @@ -242,6 +246,12 @@ contract ScrollChain is OwnableUpgradeable, PausableUpgradeable, IScrollChain {
_;
}

modifier OnlyTopLevelCall() {
// disallow contract accounts and delegated EOAs
if (msg.sender.code.length != 0) revert ErrorTopLevelCallRequired();
_;
}

/***************
* Constructor *
***************/
Expand Down Expand Up @@ -528,7 +538,7 @@ contract ScrollChain is OwnableUpgradeable, PausableUpgradeable, IScrollChain {
uint8 version,
bytes32 parentBatchHash,
FinalizeStruct calldata finalizeStruct
) external {
) external OnlyTopLevelCall {
ScrollChainMiscData memory cachedMiscData = miscData;
if (!isEnforcedModeEnabled()) {
(uint256 maxDelayEnterEnforcedMode, uint256 maxDelayMessageQueue) = SystemConfig(systemConfig)
Expand Down
12 changes: 12 additions & 0 deletions src/test/ScrollChain.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,7 @@ contract ScrollChainTest is DSTestPlus {

// revert when ErrorNotInEnforcedBatchMode
hevm.expectRevert(ScrollChain.ErrorNotInEnforcedBatchMode.selector);
hevm.startPrank(address(999));
rollup.commitAndFinalizeBatch(
7,
bytes32(0),
Expand All @@ -649,6 +650,7 @@ contract ScrollChainTest is DSTestPlus {
zkProof: new bytes(0)
})
);
hevm.stopPrank();

system.updateEnforcedBatchParameters(
SystemConfig.EnforcedBatchParameters({
Expand All @@ -669,6 +671,7 @@ contract ScrollChainTest is DSTestPlus {
// succeed to call commitAndFinalizeBatch 13
ScrollChainMockBlob(address(rollup)).setBlobVersionedHash(0, blobVersionedHash);
ScrollChainMockBlob(address(rollup)).setBlobVersionedHash(1, bytes32(0));
hevm.startPrank(address(999));
rollup.commitAndFinalizeBatch(
7,
keccak256(headers[12]),
Expand All @@ -680,6 +683,7 @@ contract ScrollChainTest is DSTestPlus {
zkProof: new bytes(0)
})
);
hevm.stopPrank();
(uint256 lastCommittedBatchIndex, uint256 lastFinalizedBatchIndex, uint256 lastFinalizeTimestamp, , ) = rollup
.miscData();
assertEq(lastCommittedBatchIndex, 13);
Expand Down Expand Up @@ -709,6 +713,7 @@ contract ScrollChainTest is DSTestPlus {
// succeed to call commitAndFinalizeBatch 14, no need to warp time
ScrollChainMockBlob(address(rollup)).setBlobVersionedHash(0, blobVersionedHash);
ScrollChainMockBlob(address(rollup)).setBlobVersionedHash(1, bytes32(0));
hevm.startPrank(address(999));
rollup.commitAndFinalizeBatch(
7,
keccak256(headers[13]),
Expand All @@ -720,6 +725,7 @@ contract ScrollChainTest is DSTestPlus {
zkProof: new bytes(0)
})
);
hevm.stopPrank();
(lastCommittedBatchIndex, lastFinalizedBatchIndex, lastFinalizeTimestamp, , ) = rollup.miscData();
assertEq(lastCommittedBatchIndex, 14);
assertEq(lastFinalizedBatchIndex, 14);
Expand All @@ -739,6 +745,7 @@ contract ScrollChainTest is DSTestPlus {

// not in enforced mode
hevm.expectRevert(ScrollChain.ErrorNotInEnforcedBatchMode.selector);
hevm.startPrank(address(999));
rollup.commitAndFinalizeBatch(
7,
keccak256(headers[13]),
Expand All @@ -750,6 +757,7 @@ contract ScrollChainTest is DSTestPlus {
zkProof: new bytes(0)
})
);
hevm.stopPrank();
}

function testCommitAndFinalizeBatchByExpiredBatch() external {
Expand Down Expand Up @@ -780,6 +788,7 @@ contract ScrollChainTest is DSTestPlus {

// revert when ErrorNotInEnforcedBatchMode
hevm.expectRevert(ScrollChain.ErrorNotInEnforcedBatchMode.selector);
hevm.startPrank(address(999));
rollup.commitAndFinalizeBatch(
7,
bytes32(0),
Expand All @@ -791,6 +800,7 @@ contract ScrollChainTest is DSTestPlus {
zkProof: new bytes(0)
})
);
hevm.stopPrank();

system.updateEnforcedBatchParameters(
SystemConfig.EnforcedBatchParameters({
Expand All @@ -803,6 +813,7 @@ contract ScrollChainTest is DSTestPlus {
// succeed to call commitAndFinalizeBatch 13
ScrollChainMockBlob(address(rollup)).setBlobVersionedHash(0, blobVersionedHash);
ScrollChainMockBlob(address(rollup)).setBlobVersionedHash(1, bytes32(0));
hevm.startPrank(address(999));
rollup.commitAndFinalizeBatch(
7,
keccak256(headers[12]),
Expand All @@ -814,6 +825,7 @@ contract ScrollChainTest is DSTestPlus {
zkProof: new bytes(0)
})
);
hevm.stopPrank();
(uint256 lastCommittedBatchIndex, uint256 lastFinalizedBatchIndex, uint256 lastFinalizeTimestamp, , ) = rollup
.miscData();
assertEq(lastCommittedBatchIndex, 13);
Expand Down
Loading