diff --git a/l1-contracts-foundry/script/AcceptAdmin.s.sol b/l1-contracts-foundry/script/AcceptAdmin.s.sol new file mode 100644 index 000000000..2cee6fe16 --- /dev/null +++ b/l1-contracts-foundry/script/AcceptAdmin.s.sol @@ -0,0 +1,25 @@ +// SPDX-License-Identifier: UNLICENSED +pragma solidity ^0.8.0; + +import {Script, console2 as console} from "forge-std/Script.sol"; +import {stdToml} from "forge-std/StdToml.sol"; + +import {Ownable2Step} from "@openzeppelin/contracts/access/Ownable2Step.sol"; +import {Utils} from "./Utils.sol"; + +contract AcceptAdmin is Script { + using stdToml for string; + + // This function should be called by the owner to accept the admin role + function run() public { + console.log("Accept admin Hyperchain"); + string memory root = vm.projectRoot(); + string memory path = string.concat(root, "/script-config/config-accept-admin.toml"); + string memory toml = vm.readFile(path); + address admin = toml.readAddress("$.target_addr"); + address governor = toml.readAddress("$.governor"); + console.log(governor); + Ownable2Step adminContract = Ownable2Step(admin); + Utils.executeUpgrade(governor, bytes32(0), admin, abi.encodeCall(adminContract.acceptOwnership, ()), 0, 0); + } +} diff --git a/l1-contracts-foundry/script/InitializeSharedBridgeOnL2.sol b/l1-contracts-foundry/script/InitializeSharedBridgeOnL2.sol index 5517178b5..d9759da27 100644 --- a/l1-contracts-foundry/script/InitializeSharedBridgeOnL2.sol +++ b/l1-contracts-foundry/script/InitializeSharedBridgeOnL2.sol @@ -40,7 +40,7 @@ contract DeployL2Script is Script { deployFactoryDeps(); deploySharedBridge(); deploySharedBridgeProxy(); - initialize_chain(); + initializeChain(); saveOutput(); } @@ -143,9 +143,10 @@ contract DeployL2Script is Script { }); } - function initialize_chain() public { + function initializeChain() public { L1SharedBridge bridge = L1SharedBridge(config.l1SharedBridgeProxy); - vm.broadcast(); - bridge.initializeChainGovernance(config.chainId, config.l2SharedBridgeProxy); + Utils.executeUpgrade(bridge.owner(), bytes32(0), config.l1SharedBridgeProxy, + abi.encodeCall(bridge.initializeChainGovernance, (config.chainId, config.l2SharedBridgeProxy)), 0, 0 + ); } } diff --git a/l1-contracts-foundry/script/RegisterHyperchain.s.sol b/l1-contracts-foundry/script/RegisterHyperchain.s.sol index c7114ac0b..0456cbaa0 100644 --- a/l1-contracts-foundry/script/RegisterHyperchain.s.sol +++ b/l1-contracts-foundry/script/RegisterHyperchain.s.sol @@ -7,6 +7,7 @@ import {Script, console2 as console} from "forge-std/Script.sol"; import {Vm} from "forge-std/Vm.sol"; import {stdToml} from "forge-std/StdToml.sol"; +import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol"; import {IBridgehub} from "contracts/bridgehub/IBridgehub.sol"; import {IZkSyncHyperchain} from "contracts/state-transition/chain-interfaces/IZkSyncHyperchain.sol"; import {ValidatorTimelock} from "contracts/state-transition/ValidatorTimelock.sol"; @@ -32,7 +33,6 @@ contract RegisterHyperchainScript is Script { uint128 baseTokenGasPriceMultiplierNominator; uint128 baseTokenGasPriceMultiplierDenominator; address bridgehub; - address bridgehubGovernance; address stateTransitionProxy; address validatorTimelock; bytes diamondCutData; @@ -60,24 +60,6 @@ contract RegisterHyperchainScript is Script { saveOutput(); } - // This function should be called by the owner to accept the admin role - function acceptAdmin() public { - console.log("Accept admin Hyperchain"); - string memory root = vm.projectRoot(); - string memory path = string.concat(root, "/script-config/accept-admin.toml"); - string memory toml = vm.readFile(path); - address diamondProxy = toml.readAddress("$.diamond_proxy_addr"); - IZkSyncHyperchain zkSyncStateTransition = IZkSyncHyperchain(diamondProxy); - bytes memory data = abi.encodeCall(zkSyncStateTransition.acceptAdmin, ()); - Utils.executeUpgrade({ - _governor: config.bridgehubGovernance, - _salt: bytes32(config.bridgehubCreateNewChainSalt), - _target: config.bridgehub, - _data: data, - _value: 0, - _delay: 0 - }); - } function initializeConfig() internal { // Grab config from output of l1 deployment @@ -93,7 +75,6 @@ contract RegisterHyperchainScript is Script { config.ownerAddress = toml.readAddress("$.owner_address"); config.bridgehub = toml.readAddress("$.deployed_addresses.bridgehub.bridgehub_proxy_addr"); - config.bridgehubGovernance = toml.readAddress("$.deployed_addresses.bridge_governance"); config.stateTransitionProxy = toml.readAddress( "$.deployed_addresses.state_transition.state_transition_proxy_addr" ); @@ -136,13 +117,14 @@ contract RegisterHyperchainScript is Script { function registerTokenOnBridgehub() internal { IBridgehub bridgehub = IBridgehub(config.bridgehub); + Ownable ownable = Ownable(config.bridgehub); if (bridgehub.tokenIsRegistered(config.baseToken)) { console.log("Token already registered on Bridgehub"); } else { bytes memory data = abi.encodeCall(bridgehub.addToken, (config.baseToken)); Utils.executeUpgrade({ - _governor: config.bridgehubGovernance, + _governor: ownable.owner(), _salt: bytes32(config.bridgehubCreateNewChainSalt), _target: config.bridgehub, _data: data, @@ -165,8 +147,9 @@ contract RegisterHyperchainScript is Script { function registerHyperchain() internal { IBridgehub bridgehub = IBridgehub(config.bridgehub); + Ownable ownable = Ownable(config.bridgehub); + - vm.broadcast(); vm.recordLogs(); bytes memory data = abi.encodeCall( bridgehub.createNewChain, @@ -181,7 +164,7 @@ contract RegisterHyperchainScript is Script { ); Utils.executeUpgrade({ - _governor: config.bridgehubGovernance, + _governor: ownable.owner(), _salt: bytes32(config.bridgehubCreateNewChainSalt), _target: config.bridgehub, _data: data, diff --git a/l1-contracts-foundry/script/Utils.sol b/l1-contracts-foundry/script/Utils.sol index 719da5fe0..6602f9289 100644 --- a/l1-contracts-foundry/script/Utils.sol +++ b/l1-contracts-foundry/script/Utils.sol @@ -2,10 +2,12 @@ pragma solidity 0.8.24; import {Vm} from "forge-std/Vm.sol"; +import {console2 as console} from "forge-std/Script.sol"; import {Bridgehub} from "contracts/bridgehub/Bridgehub.sol"; import {L2TransactionRequestDirect} from "contracts/bridgehub/IBridgehub.sol"; import {IGovernance} from "contracts/governance/IGovernance.sol"; +import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol"; import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import {REQUIRED_L2_GAS_PRICE_PER_PUBDATA} from "contracts/common/Config.sol"; import {L2_DEPLOYER_SYSTEM_CONTRACT_ADDR} from "contracts/common/L2ContractAddresses.sol"; @@ -18,7 +20,7 @@ library Utils { // Create2Factory deterministic bytecode. // https://github.com/Arachnid/deterministic-deployment-proxy bytes internal constant CREATE2_FACTORY_BYTECODE = - hex"604580600e600039806000f350fe7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe03601600081602082378035828234f58015156039578182fd5b8082525050506014600cf3"; + hex"604580600e600039806000f350fe7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe03601600081602082378035828234f58015156039578182fd5b8082525050506014600cf3"; address constant ADDRESS_ONE = 0x0000000000000000000000000000000000000001; uint256 constant MAX_PRIORITY_TX_GAS = 72000000; @@ -111,7 +113,7 @@ library Utils { */ function readSystemContractsBytecode(string memory filename) internal view returns (bytes memory) { string memory file = vm.readFile( - // solhint-disable-next-line func-named-parameters + // solhint-disable-next-line func-named-parameters string.concat( "../system-contracts/artifacts-zk/contracts-preprocessed/", filename, @@ -231,7 +233,7 @@ library Utils { gasPrice, l2GasLimit, REQUIRED_L2_GAS_PRICE_PER_PUBDATA - ); + ) * 2; L2TransactionRequestDirect memory l2TransactionRequestDirect = L2TransactionRequestDirect({ chainId: chainId, @@ -245,17 +247,23 @@ library Utils { refundRecipient: msg.sender }); - vm.startBroadcast(); address baseTokenAddress = bridgehub.baseToken(chainId); if (ADDRESS_ONE != baseTokenAddress) { IERC20 baseToken = IERC20(baseTokenAddress); - baseToken.approve(l1SharedBridgeProxy, requiredValueToDeploy * 2); + vm.broadcast(); + baseToken.approve(l1SharedBridgeProxy, requiredValueToDeploy); requiredValueToDeploy = 0; } - bridgehub.requestL2TransactionDirect{value: requiredValueToDeploy}(l2TransactionRequestDirect); - vm.stopBroadcast(); + executeUpgrade(bridgehub.owner(), bytes32(0), bridgehubAddress, + abi.encodeCall(bridgehub.requestL2TransactionDirect, + (l2TransactionRequestDirect) + ), + requiredValueToDeploy, + 0 + ); + } /** @@ -293,7 +301,7 @@ library Utils { address _governor, bytes32 _salt, address _target, - bytes calldata _data, + bytes memory _data, uint256 _value, uint256 _delay ) public { @@ -307,10 +315,15 @@ library Utils { predecessor: bytes32(0), salt: _salt }); - vm.broadcast(); + + Ownable ownable = Ownable(_governor); + console.log(msg.sender); + console.log(ownable.owner()); + vm.startBroadcast(); governance.scheduleTransparent(operation, _delay); if (_delay == 0) { governance.execute{value: _value}(operation); } + vm.stopBroadcast(); } } diff --git a/yarn.lock b/yarn.lock index 2c64e92e6..14c214541 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6028,7 +6028,7 @@ resolve@1.17.0: dependencies: path-parse "^1.0.6" -resolve@^1.1.6, resolve@^1.10.0, resolve@^1.22.4, resolve@^1.8.1: +resolve@^1.1.6, resolve@^1.22.4, resolve@^1.8.1: version "1.22.8" resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.22.8.tgz#b6c87a9f2aa06dfab52e3d70ac8cde321fa5a48d" integrity sha512-oKWePCxqpd6FlLvGV1VU0x7bkPmmCNolxzjMf4NczoDnQcIWrAF+cPtZn5i6n+RfD2d9i0tzpKnG6Yk168yIyw==