From 6d7340a354cf11e4f3e9b2c03e8da3a854232172 Mon Sep 17 00:00:00 2001 From: zimpha Date: Tue, 8 Jul 2025 16:58:32 +0800 Subject: [PATCH] fix: allow only top level call in commitAndFinalizeBatch --- src/L1/rollup/ScrollChain.sol | 4 +++- src/test/ScrollChain.t.sol | 12 ++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/L1/rollup/ScrollChain.sol b/src/L1/rollup/ScrollChain.sol index c30c7ef..e8e0954 100644 --- a/src/L1/rollup/ScrollChain.sol +++ b/src/L1/rollup/ScrollChain.sol @@ -198,7 +198,9 @@ contract ScrollChain is OwnableUpgradeable, PausableUpgradeable, IScrollChain { modifier OnlyTopLevelCall() { // disallow contract accounts and delegated EOAs - if (msg.sender.code.length != 0) revert ErrorTopLevelCallRequired(); + if (msg.sender != tx.origin || msg.sender.code.length != 0) { + revert ErrorTopLevelCallRequired(); + } _; } diff --git a/src/test/ScrollChain.t.sol b/src/test/ScrollChain.t.sol index 5930d48..6e1deea 100644 --- a/src/test/ScrollChain.t.sol +++ b/src/test/ScrollChain.t.sol @@ -339,7 +339,7 @@ contract ScrollChainTest is DSTestPlus { // revert when ErrorNotInEnforcedBatchMode hevm.expectRevert(ScrollChain.ErrorNotInEnforcedBatchMode.selector); - hevm.startPrank(address(999)); + hevm.startPrank(address(0x00a329c0648769A73afAc7F9381E08FB43dBEA72)); rollup.commitAndFinalizeBatch( 7, bytes32(0), @@ -372,7 +372,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)); + hevm.startPrank(address(0x00a329c0648769A73afAc7F9381E08FB43dBEA72)); rollup.commitAndFinalizeBatch( 7, keccak256(headers[12]), @@ -410,7 +410,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)); + hevm.startPrank(address(0x00a329c0648769A73afAc7F9381E08FB43dBEA72)); rollup.commitAndFinalizeBatch( 7, keccak256(headers[13]), @@ -442,7 +442,7 @@ contract ScrollChainTest is DSTestPlus { // not in enforced mode hevm.expectRevert(ScrollChain.ErrorNotInEnforcedBatchMode.selector); - hevm.startPrank(address(999)); + hevm.startPrank(address(0x00a329c0648769A73afAc7F9381E08FB43dBEA72)); rollup.commitAndFinalizeBatch( 7, keccak256(headers[13]), @@ -489,7 +489,7 @@ contract ScrollChainTest is DSTestPlus { // revert when ErrorNotInEnforcedBatchMode hevm.expectRevert(ScrollChain.ErrorNotInEnforcedBatchMode.selector); - hevm.startPrank(address(999)); + hevm.startPrank(address(0x00a329c0648769A73afAc7F9381E08FB43dBEA72)); rollup.commitAndFinalizeBatch( 7, bytes32(0), @@ -514,7 +514,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)); + hevm.startPrank(address(0x00a329c0648769A73afAc7F9381E08FB43dBEA72)); rollup.commitAndFinalizeBatch( 7, keccak256(headers[12]),