From 3c510f7041b6922a42f636793b22c74085f53064 Mon Sep 17 00:00:00 2001 From: LHerskind Date: Thu, 22 Aug 2024 10:05:59 +0000 Subject: [PATCH] refactor: disallow prune in devnet + add onlyOwners --- l1-contracts/src/core/Rollup.sol | 10 +++++++--- l1-contracts/src/core/libraries/Errors.sol | 3 +++ l1-contracts/test/Rollup.t.sol | 11 +++++++++++ 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/l1-contracts/src/core/Rollup.sol b/l1-contracts/src/core/Rollup.sol index 798d15e0bd3..da0270b2b2b 100644 --- a/l1-contracts/src/core/Rollup.sol +++ b/l1-contracts/src/core/Rollup.sol @@ -105,6 +105,10 @@ contract Rollup is Leonidas, IRollup, ITestRollup { * @dev Will revert if there is nothing to prune or if the chain is not ready to be pruned */ function prune() external override(IRollup) { + if (isDevNet) { + revert Errors.DevNet__NoPruningAllowed(); + } + if (pendingBlockCount == provenBlockCount) { revert Errors.Rollup__NothingToPrune(); } @@ -154,7 +158,7 @@ contract Rollup is Leonidas, IRollup, ITestRollup { * * @param _devNet - Whether or not the contract is in devnet mode */ - function setDevNet(bool _devNet) external override(ITestRollup) { + function setDevNet(bool _devNet) external override(ITestRollup) onlyOwner { isDevNet = _devNet; } @@ -165,7 +169,7 @@ contract Rollup is Leonidas, IRollup, ITestRollup { * * @param _verifier - The new verifier contract */ - function setVerifier(address _verifier) external override(ITestRollup) { + function setVerifier(address _verifier) external override(ITestRollup) onlyOwner { verifier = IVerifier(_verifier); } @@ -176,7 +180,7 @@ contract Rollup is Leonidas, IRollup, ITestRollup { * * @param _vkTreeRoot - The new vkTreeRoot to be used by proofs */ - function setVkTreeRoot(bytes32 _vkTreeRoot) external override(ITestRollup) { + function setVkTreeRoot(bytes32 _vkTreeRoot) external override(ITestRollup) onlyOwner { vkTreeRoot = _vkTreeRoot; } diff --git a/l1-contracts/src/core/libraries/Errors.sol b/l1-contracts/src/core/libraries/Errors.sol index caab6bce463..b3a185879e0 100644 --- a/l1-contracts/src/core/libraries/Errors.sol +++ b/l1-contracts/src/core/libraries/Errors.sol @@ -10,6 +10,9 @@ pragma solidity >=0.8.18; * when there are multiple contracts that could have thrown the error. */ library Errors { + // DEVNET related + error DevNet__NoPruningAllowed(); // 0x6984c590 + // Inbox error Inbox__Unauthorized(); // 0xe5336a6b error Inbox__ActorTooLarge(bytes32 actor); // 0xa776a06e diff --git a/l1-contracts/test/Rollup.t.sol b/l1-contracts/test/Rollup.t.sol index 358041e68c3..e1ff096e90e 100644 --- a/l1-contracts/test/Rollup.t.sol +++ b/l1-contracts/test/Rollup.t.sol @@ -80,6 +80,13 @@ contract RollupTest is DecoderBase { } function testRevertPrune() public setUpFor("mixed_block_1") { + if (rollup.isDevNet()) { + vm.expectRevert(abi.encodeWithSelector(Errors.DevNet__NoPruningAllowed.selector)); + rollup.prune(); + + return; + } + vm.expectRevert(abi.encodeWithSelector(Errors.Rollup__NothingToPrune.selector)); rollup.prune(); @@ -96,6 +103,10 @@ contract RollupTest is DecoderBase { } function testPrune() public setUpFor("mixed_block_1") { + if (rollup.isDevNet()) { + return; + } + _testBlock("mixed_block_1", false); assertEq(inbox.inProgress(), 3, "Invalid in progress");