From 7c742da4887a26a14d78f0552e41c9d1375dea33 Mon Sep 17 00:00:00 2001 From: Xi Lin Date: Sat, 7 Oct 2023 04:33:09 -0500 Subject: [PATCH] feat(contracts): add emergency role to pause L1/L2ScrollMessenger (#975) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Péter Garamvölgyi --- .../scripts/foundry/DeployL2RateLimiter.s.sol | 49 ------------------- .../foundry/InitializeL1ScrollOwner.s.sol | 25 +++++++--- .../foundry/InitializeL2ScrollOwner.s.sol | 49 ++++--------------- 3 files changed, 27 insertions(+), 96 deletions(-) delete mode 100644 contracts/scripts/foundry/DeployL2RateLimiter.s.sol diff --git a/contracts/scripts/foundry/DeployL2RateLimiter.s.sol b/contracts/scripts/foundry/DeployL2RateLimiter.s.sol deleted file mode 100644 index d1f500c053..0000000000 --- a/contracts/scripts/foundry/DeployL2RateLimiter.s.sol +++ /dev/null @@ -1,49 +0,0 @@ -// SPDX-License-Identifier: UNLICENSED -pragma solidity ^0.8.10; - -import {Script} from "forge-std/Script.sol"; -import {console} from "forge-std/console.sol"; - -import {ScrollGatewayBase} from "../../src/libraries/gateway/ScrollGatewayBase.sol"; -import {ScrollMessengerBase} from "../../src/libraries/ScrollMessengerBase.sol"; - -import {ETHRateLimiter} from "../../src/rate-limiter/ETHRateLimiter.sol"; -import {TokenRateLimiter} from "../../src/rate-limiter/TokenRateLimiter.sol"; - -contract DeployL2RateLimiter is Script { - uint256 L2_DEPLOYER_PRIVATE_KEY = vm.envUint("L2_DEPLOYER_PRIVATE_KEY"); - - address L2_SCROLL_MESSENGER_PROXY_ADDR = vm.envAddress("L2_SCROLL_MESSENGER_PROXY_ADDR"); - - uint256 RATE_LIMITER_PERIOD_LENGTH = vm.envUint("RATE_LIMITER_PERIOD_LENGTH"); - uint104 ETH_TOTAL_LIMIT = uint104(vm.envUint("ETH_TOTAL_LIMIT")); - - function run() external { - vm.startBroadcast(L2_DEPLOYER_PRIVATE_KEY); - - deployETHRateLimiter(); - deployTokenRateLimiter(); - - vm.stopBroadcast(); - } - - function deployETHRateLimiter() internal { - ETHRateLimiter limiter = new ETHRateLimiter( - RATE_LIMITER_PERIOD_LENGTH, - L2_SCROLL_MESSENGER_PROXY_ADDR, - ETH_TOTAL_LIMIT - ); - - logAddress("L2_ETH_RATE_LIMITER_ADDR", address(limiter)); - } - - function deployTokenRateLimiter() internal { - TokenRateLimiter limiter = new TokenRateLimiter(RATE_LIMITER_PERIOD_LENGTH); - - logAddress("L2_TOKEN_RATE_LIMITER_ADDR", address(limiter)); - } - - function logAddress(string memory name, address addr) internal view { - console.log(string(abi.encodePacked(name, "=", vm.toString(address(addr))))); - } -} diff --git a/contracts/scripts/foundry/InitializeL1ScrollOwner.s.sol b/contracts/scripts/foundry/InitializeL1ScrollOwner.s.sol index 8dfb4724f4..1752e863eb 100644 --- a/contracts/scripts/foundry/InitializeL1ScrollOwner.s.sol +++ b/contracts/scripts/foundry/InitializeL1ScrollOwner.s.sol @@ -30,12 +30,14 @@ contract InitializeL1ScrollOwner is Script { bytes32 constant SECURITY_COUNCIL_NO_DELAY_ROLE = keccak256("SECURITY_COUNCIL_NO_DELAY_ROLE"); bytes32 constant SCROLL_MULTISIG_NO_DELAY_ROLE = keccak256("SCROLL_MULTISIG_NO_DELAY_ROLE"); + bytes32 constant EMERGENCY_MULTISIG_NO_DELAY_ROLE = keccak256("EMERGENCY_MULTISIG_NO_DELAY_ROLE"); bytes32 constant TIMELOCK_1DAY_DELAY_ROLE = keccak256("TIMELOCK_1DAY_DELAY_ROLE"); bytes32 constant TIMELOCK_7DAY_DELAY_ROLE = keccak256("TIMELOCK_7DAY_DELAY_ROLE"); address SCROLL_MULTISIG_ADDR = vm.envAddress("L1_SCROLL_MULTISIG_ADDR"); address SECURITY_COUNCIL_ADDR = vm.envAddress("L1_SECURITY_COUNCIL_ADDR"); + address EMERGENCY_MULTISIG_ADDR = vm.envAddress("L1_EMERGENCY_MULTISIG_ADDR"); address L1_SCROLL_OWNER_ADDR = vm.envAddress("L1_SCROLL_OWNER_ADDR"); address L1_1D_TIMELOCK_ADDR = vm.envAddress("L1_1D_TIMELOCK_ADDR"); @@ -111,6 +113,7 @@ contract InitializeL1ScrollOwner is Script { function grantRoles() internal { owner.grantRole(SECURITY_COUNCIL_NO_DELAY_ROLE, SECURITY_COUNCIL_ADDR); owner.grantRole(SCROLL_MULTISIG_NO_DELAY_ROLE, SCROLL_MULTISIG_ADDR); + owner.grantRole(EMERGENCY_MULTISIG_NO_DELAY_ROLE, EMERGENCY_MULTISIG_ADDR); owner.grantRole(TIMELOCK_1DAY_DELAY_ROLE, L1_1D_TIMELOCK_ADDR); owner.grantRole(TIMELOCK_7DAY_DELAY_ROLE, L1_7D_TIMELOCK_ADDR); @@ -131,20 +134,25 @@ contract InitializeL1ScrollOwner is Script { function configScrollChain() internal { bytes4[] memory _selectors; - // no delay, scroll multisig - _selectors = new bytes4[](5); + // no delay, scroll multisig and emergency multisig + _selectors = new bytes4[](4); _selectors[0] = ScrollChain.revertBatch.selector; _selectors[1] = ScrollChain.removeSequencer.selector; _selectors[2] = ScrollChain.removeProver.selector; - _selectors[3] = ScrollChain.updateMaxNumTxInChunk.selector; - _selectors[4] = ScrollChain.setPause.selector; + _selectors[3] = ScrollChain.setPause.selector; owner.updateAccess(L1_SCROLL_CHAIN_PROXY_ADDR, _selectors, SCROLL_MULTISIG_NO_DELAY_ROLE, true); + owner.updateAccess(L1_SCROLL_CHAIN_PROXY_ADDR, _selectors, EMERGENCY_MULTISIG_NO_DELAY_ROLE, true); // delay 1 day, scroll multisig _selectors = new bytes4[](2); _selectors[0] = ScrollChain.addSequencer.selector; _selectors[1] = ScrollChain.addProver.selector; owner.updateAccess(L1_SCROLL_CHAIN_PROXY_ADDR, _selectors, TIMELOCK_1DAY_DELAY_ROLE, true); + + // delay 7 day, scroll multisig + _selectors = new bytes4[](1); + _selectors[0] = ScrollChain.updateMaxNumTxInChunk.selector; + owner.updateAccess(L1_SCROLL_CHAIN_PROXY_ADDR, _selectors, TIMELOCK_7DAY_DELAY_ROLE, true); } function configL1MessageQueue() internal { @@ -160,10 +168,11 @@ contract InitializeL1ScrollOwner is Script { function configL1ScrollMessenger() internal { bytes4[] memory _selectors; - // no delay, scroll multisig + // no delay, scroll multisig and emergency multisig _selectors = new bytes4[](1); _selectors[0] = ScrollMessengerBase.setPause.selector; owner.updateAccess(L1_SCROLL_MESSENGER_PROXY_ADDR, _selectors, SCROLL_MULTISIG_NO_DELAY_ROLE, true); + owner.updateAccess(L1_SCROLL_MESSENGER_PROXY_ADDR, _selectors, EMERGENCY_MULTISIG_NO_DELAY_ROLE, true); // delay 1 day, scroll multisig _selectors = new bytes4[](1); @@ -174,10 +183,11 @@ contract InitializeL1ScrollOwner is Script { function configL2GasPriceOracle() internal { bytes4[] memory _selectors; - // no delay, scroll multisig + // no delay, scroll multisig and emergency multisig _selectors = new bytes4[](1); _selectors[0] = L2GasPriceOracle.setIntrinsicParams.selector; owner.updateAccess(L2_GAS_PRICE_ORACLE_PROXY_ADDR, _selectors, SCROLL_MULTISIG_NO_DELAY_ROLE, true); + owner.updateAccess(L2_GAS_PRICE_ORACLE_PROXY_ADDR, _selectors, EMERGENCY_MULTISIG_NO_DELAY_ROLE, true); } function configL1Whitelist() internal { @@ -254,10 +264,11 @@ contract InitializeL1ScrollOwner is Script { function configEnforcedTxGateway() internal { bytes4[] memory _selectors; - // no delay, scroll multisig + // no delay, scroll multisig and emergency multisig _selectors = new bytes4[](1); _selectors[0] = EnforcedTxGateway.setPause.selector; owner.updateAccess(L1_ENFORCED_TX_GATEWAY_PROXY_ADDR, _selectors, SCROLL_MULTISIG_NO_DELAY_ROLE, true); + owner.updateAccess(L1_ENFORCED_TX_GATEWAY_PROXY_ADDR, _selectors, EMERGENCY_MULTISIG_NO_DELAY_ROLE, true); } */ } diff --git a/contracts/scripts/foundry/InitializeL2ScrollOwner.s.sol b/contracts/scripts/foundry/InitializeL2ScrollOwner.s.sol index 240daac77a..841a75eea5 100644 --- a/contracts/scripts/foundry/InitializeL2ScrollOwner.s.sol +++ b/contracts/scripts/foundry/InitializeL2ScrollOwner.s.sol @@ -19,8 +19,6 @@ import {L1GasPriceOracle} from "../../src/L2/predeploys/L1GasPriceOracle.sol"; import {L2TxFeeVault} from "../../src/L2/predeploys/L2TxFeeVault.sol"; import {Whitelist} from "../../src/L2/predeploys/Whitelist.sol"; import {ScrollOwner} from "../../src/misc/ScrollOwner.sol"; -import {ETHRateLimiter} from "../../src/rate-limiter/ETHRateLimiter.sol"; -import {TokenRateLimiter} from "../../src/rate-limiter/TokenRateLimiter.sol"; // solhint-disable max-states-count // solhint-disable state-visibility @@ -31,12 +29,14 @@ contract InitializeL2ScrollOwner is Script { bytes32 constant SECURITY_COUNCIL_NO_DELAY_ROLE = keccak256("SECURITY_COUNCIL_NO_DELAY_ROLE"); bytes32 constant SCROLL_MULTISIG_NO_DELAY_ROLE = keccak256("SCROLL_MULTISIG_NO_DELAY_ROLE"); + bytes32 constant EMERGENCY_MULTISIG_NO_DELAY_ROLE = keccak256("EMERGENCY_MULTISIG_NO_DELAY_ROLE"); bytes32 constant TIMELOCK_1DAY_DELAY_ROLE = keccak256("TIMELOCK_1DAY_DELAY_ROLE"); bytes32 constant TIMELOCK_7DAY_DELAY_ROLE = keccak256("TIMELOCK_7DAY_DELAY_ROLE"); address SCROLL_MULTISIG_ADDR = vm.envAddress("L2_SCROLL_MULTISIG_ADDR"); address SECURITY_COUNCIL_ADDR = vm.envAddress("L2_SECURITY_COUNCIL_ADDR"); + address EMERGENCY_MULTISIG_ADDR = vm.envAddress("L2_EMERGENCY_MULTISIG_ADDR"); address L2_SCROLL_OWNER_ADDR = vm.envAddress("L2_SCROLL_OWNER_ADDR"); address L2_1D_TIMELOCK_ADDR = vm.envAddress("L2_1D_TIMELOCK_ADDR"); @@ -59,9 +59,6 @@ contract InitializeL2ScrollOwner is Script { address L2_ERC721_GATEWAY_PROXY_ADDR = vm.envAddress("L2_ERC721_GATEWAY_PROXY_ADDR"); address L2_ERC1155_GATEWAY_PROXY_ADDR = vm.envAddress("L2_ERC1155_GATEWAY_PROXY_ADDR"); - address L2_ETH_RATE_LIMITER_ADDR = vm.envAddress("L2_ETH_RATE_LIMITER_ADDR"); - address L2_TOKEN_RATE_LIMITER_ADDR = vm.envAddress("L2_TOKEN_RATE_LIMITER_ADDR"); - ScrollOwner owner; function run() external { @@ -79,8 +76,6 @@ contract InitializeL2ScrollOwner is Script { configL2CustomERC20Gateway(); configL2ERC721Gateway(); configL2ERC1155Gateway(); - configETHRateLimiter(); - configTokenRateLimiter(); // @note comments out for testnet // configL2USDCGateway(); @@ -107,17 +102,12 @@ contract InitializeL2ScrollOwner is Script { Ownable(L2_ERC1155_GATEWAY_PROXY_ADDR).transferOwnership(address(owner)); // Ownable(L2_USDC_GATEWAY_PROXY_ADDR).transferOwnership(address(owner)); - - Ownable(L2_ETH_RATE_LIMITER_ADDR).transferOwnership(address(owner)); - - TokenRateLimiter tokenRateLimiter = TokenRateLimiter(L2_TOKEN_RATE_LIMITER_ADDR); - tokenRateLimiter.grantRole(tokenRateLimiter.DEFAULT_ADMIN_ROLE(), address(owner)); - tokenRateLimiter.revokeRole(tokenRateLimiter.DEFAULT_ADMIN_ROLE(), vm.addr(L2_DEPLOYER_PRIVATE_KEY)); } function grantRoles() internal { owner.grantRole(SECURITY_COUNCIL_NO_DELAY_ROLE, SECURITY_COUNCIL_ADDR); owner.grantRole(SCROLL_MULTISIG_NO_DELAY_ROLE, SCROLL_MULTISIG_ADDR); + owner.grantRole(EMERGENCY_MULTISIG_NO_DELAY_ROLE, EMERGENCY_MULTISIG_ADDR); owner.grantRole(TIMELOCK_1DAY_DELAY_ROLE, L2_1D_TIMELOCK_ADDR); owner.grantRole(TIMELOCK_7DAY_DELAY_ROLE, L2_7D_TIMELOCK_ADDR); @@ -138,20 +128,22 @@ contract InitializeL2ScrollOwner is Script { function configL1GasPriceOracle() internal { bytes4[] memory _selectors; - // no delay, scroll multisig + // no delay, scroll multisig and emergency multisig _selectors = new bytes4[](2); _selectors[0] = L1GasPriceOracle.setOverhead.selector; _selectors[1] = L1GasPriceOracle.setScalar.selector; owner.updateAccess(L1_GAS_PRICE_ORACLE_ADDR, _selectors, SCROLL_MULTISIG_NO_DELAY_ROLE, true); + owner.updateAccess(L1_GAS_PRICE_ORACLE_ADDR, _selectors, EMERGENCY_MULTISIG_NO_DELAY_ROLE, true); } function configL2TxFeeVault() internal { bytes4[] memory _selectors; - // no delay, scroll multisig + // no delay, scroll multisig and emergency multisig _selectors = new bytes4[](1); _selectors[0] = L2TxFeeVault.updateMinWithdrawAmount.selector; owner.updateAccess(L2_TX_FEE_VAULT_ADDR, _selectors, SCROLL_MULTISIG_NO_DELAY_ROLE, true); + owner.updateAccess(L2_TX_FEE_VAULT_ADDR, _selectors, EMERGENCY_MULTISIG_NO_DELAY_ROLE, true); } function configL2Whitelist() internal { @@ -166,10 +158,11 @@ contract InitializeL2ScrollOwner is Script { function configL2ScrollMessenger() internal { bytes4[] memory _selectors; - // no delay, scroll multisig + // no delay, scroll multisig and emergency multisig _selectors = new bytes4[](1); _selectors[0] = ScrollMessengerBase.setPause.selector; owner.updateAccess(L2_SCROLL_MESSENGER_PROXY_ADDR, _selectors, SCROLL_MULTISIG_NO_DELAY_ROLE, true); + owner.updateAccess(L2_SCROLL_MESSENGER_PROXY_ADDR, _selectors, EMERGENCY_MULTISIG_NO_DELAY_ROLE, true); } function configL2GatewayRouter() internal { @@ -208,30 +201,6 @@ contract InitializeL2ScrollOwner is Script { owner.updateAccess(L2_ERC1155_GATEWAY_PROXY_ADDR, _selectors, TIMELOCK_1DAY_DELAY_ROLE, true); } - function configETHRateLimiter() internal { - bytes4[] memory _selectors; - - // no delay, scroll multisig - _selectors = new bytes4[](1); - _selectors[0] = ETHRateLimiter.updateTotalLimit.selector; - owner.updateAccess(L2_ETH_RATE_LIMITER_ADDR, _selectors, SCROLL_MULTISIG_NO_DELAY_ROLE, true); - } - - function configTokenRateLimiter() internal { - bytes4[] memory _selectors; - - // no delay, scroll multisig - _selectors = new bytes4[](2); - _selectors[0] = TokenRateLimiter.updateTotalLimit.selector; - _selectors[1] = AccessControl.grantRole.selector; - owner.updateAccess(L2_TOKEN_RATE_LIMITER_ADDR, _selectors, SCROLL_MULTISIG_NO_DELAY_ROLE, true); - - // delay 7 day, scroll multisig - _selectors = new bytes4[](1); - _selectors[0] = AccessControl.revokeRole.selector; - owner.updateAccess(L2_TOKEN_RATE_LIMITER_ADDR, _selectors, TIMELOCK_7DAY_DELAY_ROLE, true); - } - /* function configL2USDCGateway() internal { bytes4[] memory _selectors;