Skip to content

Commit

Permalink
refactor: disallow prune in devnet + add onlyOwners (#8134)
Browse files Browse the repository at this point in the history
Fixes #8103. 

Disallow pruning when in devnet, and adds `onlyOwner` modifier to
`setDevNet`, `setVerifier` and `setVkTreeRoot`.
  • Loading branch information
LHerskind authored Aug 28, 2024
1 parent daa57cc commit c736f96
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
10 changes: 7 additions & 3 deletions l1-contracts/src/core/Rollup.sol
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,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();
}
Expand Down Expand Up @@ -159,7 +163,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;
}

Expand All @@ -170,7 +174,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);
}

Expand All @@ -181,7 +185,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;
}

Expand Down
3 changes: 3 additions & 0 deletions l1-contracts/src/core/libraries/Errors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions l1-contracts/test/Rollup.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,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();

Expand All @@ -95,6 +102,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");
Expand Down

0 comments on commit c736f96

Please sign in to comment.