From 427f4b303eba8b0631b75f01cecb528516fcb968 Mon Sep 17 00:00:00 2001 From: gzeon Date: Sat, 14 Dec 2024 02:30:16 +0900 Subject: [PATCH 01/10] test: testSetMaxTimeVariation --- test/foundry/SequencerInbox.t.sol | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/test/foundry/SequencerInbox.t.sol b/test/foundry/SequencerInbox.t.sol index 3a5446c0a..ddb76e824 100644 --- a/test/foundry/SequencerInbox.t.sol +++ b/test/foundry/SequencerInbox.t.sol @@ -621,18 +621,19 @@ contract SequencerInboxTest is Test { seqInbox.setBufferConfig(bufferConfigInvalid); } - function testSetMaxTimeVariationOverflow( + function testSetMaxTimeVariation( uint256 delayBlocks, uint256 futureBlocks, uint256 delaySeconds, uint256 futureSeconds ) public { - vm.assume(delayBlocks > uint256(type(uint64).max)); - vm.assume(futureBlocks > uint256(type(uint64).max)); - vm.assume(delaySeconds > uint256(type(uint64).max)); - vm.assume(futureSeconds > uint256(type(uint64).max)); (SequencerInbox seqInbox,) = deployRollup(false, false, bufferConfigDefault); - vm.expectRevert(abi.encodeWithSelector(BadMaxTimeVariation.selector)); + if ( + delayBlocks > uint256(type(uint64).max) || futureBlocks > uint256(type(uint64).max) + || delaySeconds > uint256(type(uint64).max) || futureSeconds > uint256(type(uint64).max) + ) { + vm.expectRevert(abi.encodeWithSelector(BadMaxTimeVariation.selector)); + } vm.prank(rollupOwner); seqInbox.setMaxTimeVariation( ISequencerInbox.MaxTimeVariation({ From dd7e92dadb154ab64ac3123dcc0e4b945e88e2f1 Mon Sep 17 00:00:00 2001 From: gzeon Date: Sat, 14 Dec 2024 02:46:21 +0900 Subject: [PATCH 02/10] test: DataTooLarge --- test/foundry/AbsInbox.t.sol | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/foundry/AbsInbox.t.sol b/test/foundry/AbsInbox.t.sol index 864e078d8..710e2fd07 100644 --- a/test/foundry/AbsInbox.t.sol +++ b/test/foundry/AbsInbox.t.sol @@ -255,6 +255,14 @@ abstract contract AbsInboxTest is Test { inbox.sendL2Message(abi.encodePacked("some msg")); } + function test_sendL2Message_revert_DataTooLarge() public { + uint256 maxDataSize = inbox.maxDataSize(); + bytes memory data = new bytes(maxDataSize + 1); + vm.expectRevert(abi.encodeWithSelector(DataTooLarge.selector, maxDataSize + 1, maxDataSize)); + vm.prank(user); + inbox.sendL2Message(data); + } + function test_sendL2Message_revert_NotAllowed() public { vm.prank(rollup); inbox.setAllowListEnabled(true); From ffe6bf42051e283f783eff6ba96f65456dbd57f1 Mon Sep 17 00:00:00 2001 From: gzeon Date: Sat, 14 Dec 2024 02:46:30 +0900 Subject: [PATCH 03/10] test: bridge.updateRollupAddress --- test/foundry/AbsBridge.t.sol | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/foundry/AbsBridge.t.sol b/test/foundry/AbsBridge.t.sol index 9945a13ca..0d278003f 100644 --- a/test/foundry/AbsBridge.t.sol +++ b/test/foundry/AbsBridge.t.sol @@ -457,6 +457,12 @@ abstract contract AbsBridgeTest is Test { AbsBridge(address(bridge)).setSequencerReportedSubMessageCount(123); } + function test_updateRollupAddress() public { + vm.prank(rollup); + bridge.updateRollupAddress(IOwnable(address(1337))); + assertEq(address(bridge.rollup()), address(1337), "Invalid rollup"); + } + /** * * Event declarations From fed9da70a4dd4653328a6c695fcb7d26506caee8 Mon Sep 17 00:00:00 2001 From: gzeon Date: Sat, 14 Dec 2024 02:53:54 +0900 Subject: [PATCH 04/10] test: outbox updateRollupAddress --- test/foundry/AbsOutbox.t.sol | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/test/foundry/AbsOutbox.t.sol b/test/foundry/AbsOutbox.t.sol index 98e92958a..cfd5665b0 100644 --- a/test/foundry/AbsOutbox.t.sol +++ b/test/foundry/AbsOutbox.t.sol @@ -25,4 +25,17 @@ abstract contract AbsOutboxTest is Test { assertEq(outbox.l2ToL1Timestamp(), 0, "Invalid l2ToL1Timestamp"); assertEq(outbox.l2ToL1OutputId(), bytes32(0), "Invalid l2ToL1OutputId"); } + + function test_updateRollupAddress() public { + vm.prank(rollup); + bridge.updateRollupAddress(IOwnable(address(1337))); + vm.mockCall( + address(rollup), + 0, + abi.encodeWithSelector(IOwnable.owner.selector), + abi.encode(address(this)) + ); + outbox.updateRollupAddress(); + assertEq(address(outbox.rollup()), address(1337), "Invalid rollup"); + } } From 1f83de11033c9e82d2f50bd8592e01ff17e6ad9f Mon Sep 17 00:00:00 2001 From: gzeon Date: Sat, 14 Dec 2024 03:01:03 +0900 Subject: [PATCH 05/10] test: outbox --- test/foundry/AbsOutbox.t.sol | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/test/foundry/AbsOutbox.t.sol b/test/foundry/AbsOutbox.t.sol index cfd5665b0..2693ba535 100644 --- a/test/foundry/AbsOutbox.t.sol +++ b/test/foundry/AbsOutbox.t.sol @@ -3,7 +3,7 @@ pragma solidity ^0.8.4; import "forge-std/Test.sol"; import "./util/TestUtil.sol"; -import "../../src/bridge/IOutbox.sol"; +import "../../src/bridge/AbsOutbox.sol"; import "../../src/bridge/IBridge.sol"; abstract contract AbsOutboxTest is Test { @@ -38,4 +38,26 @@ abstract contract AbsOutboxTest is Test { outbox.updateRollupAddress(); assertEq(address(outbox.rollup()), address(1337), "Invalid rollup"); } + + function test_updateRollupAddress_revert_NotOwner() public { + vm.mockCall( + address(rollup), + 0, + abi.encodeWithSelector(IOwnable.owner.selector), + abi.encode(address(1337)) + ); + vm.expectRevert(abi.encodeWithSelector(NotOwner.selector, address(this), address(1337))); + outbox.updateRollupAddress(); + } + + function test_executeTransactionSimulation( + address from + ) public { + vm.assume(from != address(0)); + vm.prank(from); + vm.expectRevert(SimulationOnlyEntrypoint.selector); + outbox.executeTransactionSimulation( + 0, from, address(1337), 0, 0, 0, 0, abi.encodePacked("some msg") + ); + } } From aaa19f236fd92c7d2028b18f703224b62bcccf12 Mon Sep 17 00:00:00 2001 From: gzeon Date: Sat, 14 Dec 2024 03:05:44 +0900 Subject: [PATCH 06/10] test: seqinbox updateRollupAddress --- test/foundry/SequencerInbox.t.sol | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/test/foundry/SequencerInbox.t.sol b/test/foundry/SequencerInbox.t.sol index ddb76e824..85e6a14ea 100644 --- a/test/foundry/SequencerInbox.t.sol +++ b/test/foundry/SequencerInbox.t.sol @@ -644,4 +644,32 @@ contract SequencerInboxTest is Test { }) ); } + + function test_updateRollupAddress() public { + (SequencerInbox seqInbox, Bridge bridge) = deployRollup(false, true, bufferConfigDefault); + address rollup = address(bridge.rollup()); + vm.prank(rollup); + bridge.updateRollupAddress(IOwnable(address(1337))); + vm.mockCall( + address(rollup), + 0, + abi.encodeWithSelector(IOwnable.owner.selector), + abi.encode(address(this)) + ); + seqInbox.updateRollupAddress(); + assertEq(address(seqInbox.rollup()), address(1337), "Invalid rollup"); + } + + function test_updateRollupAddress_revert_NotOwner() public { + (SequencerInbox seqInbox, Bridge bridge) = deployRollup(false, true, bufferConfigDefault); + address rollup = address(bridge.rollup()); + vm.mockCall( + address(rollup), + 0, + abi.encodeWithSelector(IOwnable.owner.selector), + abi.encode(address(1337)) + ); + vm.expectRevert(abi.encodeWithSelector(NotOwner.selector, address(this), address(1337))); + seqInbox.updateRollupAddress(); + } } From 823955c160fbab6a497b87dcdd9d926dd4da3071 Mon Sep 17 00:00:00 2001 From: gzeon Date: Sat, 14 Dec 2024 03:18:08 +0900 Subject: [PATCH 07/10] test: rei updateRollupAddress --- test/foundry/AbsRollupEventInbox.t.sol | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/test/foundry/AbsRollupEventInbox.t.sol b/test/foundry/AbsRollupEventInbox.t.sol index 44484f6a8..a3d84e76c 100644 --- a/test/foundry/AbsRollupEventInbox.t.sol +++ b/test/foundry/AbsRollupEventInbox.t.sol @@ -25,6 +25,30 @@ abstract contract AbsRollupEventInboxTest is Test { rollupEventInbox.initialize(bridge); } + function test_updateRollupAddress() public { + vm.prank(rollup); + bridge.updateRollupAddress(IOwnable(address(1337))); + vm.mockCall( + address(rollup), + 0, + abi.encodeWithSelector(IOwnable.owner.selector), + abi.encode(address(this)) + ); + rollupEventInbox.updateRollupAddress(); + assertEq(address(rollupEventInbox.rollup()), address(1337), "Invalid rollup"); + } + + function test_updateRollupAddress_revert_NotOwner() public { + vm.mockCall( + address(rollup), + 0, + abi.encodeWithSelector(IOwnable.owner.selector), + abi.encode(address(1337)) + ); + vm.expectRevert(abi.encodeWithSelector(NotOwner.selector, address(this), address(1337))); + rollupEventInbox.updateRollupAddress(); + } + /** * * Event declarations From c7a1238941723300530505d3eb97ce7e76b7ff08 Mon Sep 17 00:00:00 2001 From: gzeon Date: Sat, 14 Dec 2024 03:18:15 +0900 Subject: [PATCH 08/10] test: bridge updateRollupAddress 2 --- test/foundry/AbsBridge.t.sol | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/test/foundry/AbsBridge.t.sol b/test/foundry/AbsBridge.t.sol index 0d278003f..2c6246cee 100644 --- a/test/foundry/AbsBridge.t.sol +++ b/test/foundry/AbsBridge.t.sol @@ -463,6 +463,21 @@ abstract contract AbsBridgeTest is Test { assertEq(address(bridge.rollup()), address(1337), "Invalid rollup"); } + function test_updateRollupAddress_revert_NotOwner() public { + vm.mockCall( + address(rollup), + 0, + abi.encodeWithSelector(IOwnable.owner.selector), + abi.encode(address(1337)) + ); + vm.expectRevert( + abi.encodeWithSelector( + NotRollupOrOwner.selector, address(this), address(rollup), address(1337) + ) + ); + bridge.updateRollupAddress(IOwnable(address(1234))); + } + /** * * Event declarations From ab06568d0e9faa00e2a1a6c600b84d3afa8ed52b Mon Sep 17 00:00:00 2001 From: gzeon Date: Sat, 14 Dec 2024 03:23:41 +0900 Subject: [PATCH 09/10] test: check SetMaxTimeVariation --- test/foundry/SequencerInbox.t.sol | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/foundry/SequencerInbox.t.sol b/test/foundry/SequencerInbox.t.sol index 85e6a14ea..7d6a4855f 100644 --- a/test/foundry/SequencerInbox.t.sol +++ b/test/foundry/SequencerInbox.t.sol @@ -628,11 +628,13 @@ contract SequencerInboxTest is Test { uint256 futureSeconds ) public { (SequencerInbox seqInbox,) = deployRollup(false, false, bufferConfigDefault); + bool checkValue = true; if ( delayBlocks > uint256(type(uint64).max) || futureBlocks > uint256(type(uint64).max) || delaySeconds > uint256(type(uint64).max) || futureSeconds > uint256(type(uint64).max) ) { vm.expectRevert(abi.encodeWithSelector(BadMaxTimeVariation.selector)); + checkValue = false; } vm.prank(rollupOwner); seqInbox.setMaxTimeVariation( @@ -643,6 +645,14 @@ contract SequencerInboxTest is Test { futureSeconds: futureSeconds }) ); + (uint256 _delayBlocks, uint256 _futureBlocks, uint256 _delaySeconds, uint256 _futureSeconds) + = seqInbox.maxTimeVariation(); + if (checkValue) { + assertEq(_delayBlocks, delayBlocks); + assertEq(_futureBlocks, futureBlocks); + assertEq(_delaySeconds, delaySeconds); + assertEq(_futureSeconds, futureSeconds); + } } function test_updateRollupAddress() public { From 842e3f490a950f1cd92125cf7a9372a2a081ac73 Mon Sep 17 00:00:00 2001 From: gzeon Date: Sat, 14 Dec 2024 03:35:15 +0900 Subject: [PATCH 10/10] test: seqinbox postUpgradeInit revert --- test/foundry/SequencerInbox.t.sol | 44 +++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 11 deletions(-) diff --git a/test/foundry/SequencerInbox.t.sol b/test/foundry/SequencerInbox.t.sol index 7d6a4855f..1aa10ce08 100644 --- a/test/foundry/SequencerInbox.t.sol +++ b/test/foundry/SequencerInbox.t.sol @@ -66,7 +66,7 @@ contract SequencerInboxTest is Test { bool isArbHosted, bool isDelayBufferable, BufferConfig memory bufferConfig - ) internal returns (SequencerInbox, Bridge) { + ) internal returns (SequencerInbox, Bridge, address) { RollupMock rollupMock = new RollupMock(rollupOwner); Bridge bridgeImpl = new Bridge(); Bridge bridge = @@ -93,7 +93,7 @@ contract SequencerInboxTest is Test { vm.prank(rollupOwner); bridge.setSequencerInbox(address(seqInbox)); - return (seqInbox, bridge); + return (seqInbox, bridge, address(seqInboxImpl)); } function deployFeeTokenBasedRollup() internal returns (SequencerInbox, ERC20Bridge) { @@ -227,7 +227,7 @@ contract SequencerInboxTest is Test { function testAddSequencerL2BatchFromOrigin( BufferConfig memory bufferConfig ) public { - (SequencerInbox seqInbox, Bridge bridge) = deployRollup(false, false, bufferConfig); + (SequencerInbox seqInbox, Bridge bridge,) = deployRollup(false, false, bufferConfig); address delayedInboxSender = address(140); uint8 delayedInboxKind = 3; bytes32 messageDataHash = RAND.Bytes32(); @@ -355,7 +355,7 @@ contract SequencerInboxTest is Test { abi.encodeWithSelector(ArbSys.arbOSVersion.selector), abi.encode(uint256(11)) ); - (SequencerInbox seqInbox, Bridge bridge) = deployRollup(true, false, bufferConfig); + (SequencerInbox seqInbox, Bridge bridge,) = deployRollup(true, false, bufferConfig); address delayedInboxSender = address(140); uint8 delayedInboxKind = 3; @@ -414,7 +414,7 @@ contract SequencerInboxTest is Test { } function testAddSequencerL2BatchFromOriginReverts() public { - (SequencerInbox seqInbox, Bridge bridge) = deployRollup(false, false, bufferConfigDefault); + (SequencerInbox seqInbox, Bridge bridge,) = deployRollup(false, false, bufferConfigDefault); address delayedInboxSender = address(140); uint8 delayedInboxKind = 3; bytes32 messageDataHash = RAND.Bytes32(); @@ -517,7 +517,7 @@ contract SequencerInboxTest is Test { BufferConfig memory bufferConfig ) public returns (SequencerInbox, SequencerInbox) { vm.assume(DelayBuffer.isValidBufferConfig(bufferConfig)); - (SequencerInbox seqInbox,) = deployRollup(false, false, bufferConfigDefault); + (SequencerInbox seqInbox,,) = deployRollup(false, false, bufferConfigDefault); SequencerInbox seqInboxImpl = new SequencerInbox(maxDataSize, dummyReader4844, false, true); vm.prank(proxyAdmin); TransparentUpgradeableProxy(payable(address(seqInbox))).upgradeToAndCall( @@ -606,7 +606,7 @@ contract SequencerInboxTest is Test { BufferConfig memory bufferConfig ) public { vm.assume(DelayBuffer.isValidBufferConfig(bufferConfig)); - (SequencerInbox seqInbox,) = deployRollup(false, true, bufferConfig); + (SequencerInbox seqInbox,,) = deployRollup(false, true, bufferConfig); vm.prank(rollupOwner); seqInbox.setBufferConfig(bufferConfig); } @@ -615,7 +615,7 @@ contract SequencerInboxTest is Test { BufferConfig memory bufferConfigInvalid ) public { vm.assume(!DelayBuffer.isValidBufferConfig(bufferConfigInvalid)); - (SequencerInbox seqInbox,) = deployRollup(false, true, bufferConfigDefault); + (SequencerInbox seqInbox,,) = deployRollup(false, true, bufferConfigDefault); vm.expectRevert(abi.encodeWithSelector(BadBufferConfig.selector)); vm.prank(rollupOwner); seqInbox.setBufferConfig(bufferConfigInvalid); @@ -627,7 +627,7 @@ contract SequencerInboxTest is Test { uint256 delaySeconds, uint256 futureSeconds ) public { - (SequencerInbox seqInbox,) = deployRollup(false, false, bufferConfigDefault); + (SequencerInbox seqInbox,,) = deployRollup(false, false, bufferConfigDefault); bool checkValue = true; if ( delayBlocks > uint256(type(uint64).max) || futureBlocks > uint256(type(uint64).max) @@ -656,7 +656,7 @@ contract SequencerInboxTest is Test { } function test_updateRollupAddress() public { - (SequencerInbox seqInbox, Bridge bridge) = deployRollup(false, true, bufferConfigDefault); + (SequencerInbox seqInbox, Bridge bridge,) = deployRollup(false, true, bufferConfigDefault); address rollup = address(bridge.rollup()); vm.prank(rollup); bridge.updateRollupAddress(IOwnable(address(1337))); @@ -671,7 +671,7 @@ contract SequencerInboxTest is Test { } function test_updateRollupAddress_revert_NotOwner() public { - (SequencerInbox seqInbox, Bridge bridge) = deployRollup(false, true, bufferConfigDefault); + (SequencerInbox seqInbox, Bridge bridge,) = deployRollup(false, true, bufferConfigDefault); address rollup = address(bridge.rollup()); vm.mockCall( address(rollup), @@ -682,4 +682,26 @@ contract SequencerInboxTest is Test { vm.expectRevert(abi.encodeWithSelector(NotOwner.selector, address(this), address(1337))); seqInbox.updateRollupAddress(); } + + function test_postUpgradeInit_revert_NotDelayBufferable() public { + (SequencerInbox seqInbox,, address seqInboxImpl) = + deployRollup(false, false, bufferConfigDefault); + vm.expectRevert(abi.encodeWithSelector(NotDelayBufferable.selector)); + vm.prank(proxyAdmin); + TransparentUpgradeableProxy(payable(address(seqInbox))).upgradeToAndCall( + address(seqInboxImpl), + abi.encodeWithSelector(SequencerInbox.postUpgradeInit.selector, bufferConfigDefault) + ); + } + + function test_postUpgradeInit_revert_AlreadyInit() public { + (SequencerInbox seqInbox,, address seqInboxImpl) = + deployRollup(false, true, bufferConfigDefault); + vm.expectRevert(abi.encodeWithSelector(AlreadyInit.selector)); + vm.prank(proxyAdmin); + TransparentUpgradeableProxy(payable(address(seqInbox))).upgradeToAndCall( + address(seqInboxImpl), + abi.encodeWithSelector(SequencerInbox.postUpgradeInit.selector, bufferConfigDefault) + ); + } }