From 5f78a1bdf680e8e5a3e068b2cdb9022aa514e5e2 Mon Sep 17 00:00:00 2001 From: kelemeno Date: Wed, 18 Oct 2023 14:19:05 +0100 Subject: [PATCH] diamondInit change --- .../chain-deps/DiamondInit.sol | 47 +++++++++++-------- .../chain-interfaces/IAdmin.sol | 13 ++--- .../chain-interfaces/IDiamondInit.sol | 1 + 3 files changed, 35 insertions(+), 26 deletions(-) diff --git a/ethereum/contracts/state-transition/chain-deps/DiamondInit.sol b/ethereum/contracts/state-transition/chain-deps/DiamondInit.sol index 27a3091c9..5a8d61fe5 100644 --- a/ethereum/contracts/state-transition/chain-deps/DiamondInit.sol +++ b/ethereum/contracts/state-transition/chain-deps/DiamondInit.sol @@ -3,12 +3,10 @@ pragma solidity ^0.8.13; import "../../common/interfaces/IAllowList.sol"; -// import "../chain-interfaces/IExecutor.sol"; import "../../common/libraries/Diamond.sol"; -// import "../../bridgehub/bridgehub-interfaces/IBridgehubForProof.sol"; import "./facets/Base.sol"; -// import "../../common/Config.sol"; -import {InitializeData} from "../chain-interfaces/IDiamondInit.sol"; +import {L2_TX_MAX_GAS_LIMIT, L2_TO_L1_LOG_SERIALIZE_SIZE} from "../../common/Config.sol"; +import {InitializeData } from "../chain-interfaces/IDiamondInit.sol"; /// @author Matter Labs /// @dev The contract is used only once to initialize the diamond proxy. @@ -20,22 +18,31 @@ contract DiamondInit is StateTransitionChainBase { /// @notice zkSync contract initialization /// @return Magic 32 bytes, which indicates that the contract logic is expected to be used as a diamond proxy /// initializer - function initialize(InitializeData calldata _initData) external reentrancyGuardInitializer returns (bytes32) { - require(_initData.governor != address(0), "vy"); - - chainStorage.chainId = _initData.chainId; - chainStorage.stateTransition = _initData.stateTransition; - chainStorage.bridgehub = _initData.bridgehub; - - chainStorage.verifier = _initData.verifier; - chainStorage.governor = _initData.governor; - - chainStorage.storedBatchHashes[0] = _initData.storedBatchZero; - chainStorage.allowList = _initData.allowList; - chainStorage.verifierParams = _initData.verifierParams; - chainStorage.l2BootloaderBytecodeHash = _initData.l2BootloaderBytecodeHash; - chainStorage.l2DefaultAccountBytecodeHash = _initData.l2DefaultAccountBytecodeHash; - chainStorage.priorityTxMaxGasLimit = _initData.priorityTxMaxGasLimit; + function initialize(InitializeData calldata _initializeData) external reentrancyGuardInitializer returns (bytes32) { + + require(address(_initializeData.verifier) != address(0), "vt"); + require(_initializeData.governor != address(0), "vy"); + require(_initializeData.admin != address(0), "hc"); + require(_initializeData.priorityTxMaxGasLimit <= L2_TX_MAX_GAS_LIMIT, "vu"); + + chainStorage.chainId = _initializeData.chainId; + chainStorage.stateTransition = _initializeData.stateTransition; + chainStorage.bridgehub = _initializeData.bridgehub; + + chainStorage.verifier = _initializeData.verifier; + chainStorage.governor = _initializeData.governor; + chainStorage.admin = _initializeData.admin; + + chainStorage.storedBatchHashes[0] = _initializeData.storedBatchZero; + chainStorage.allowList = _initializeData.allowList; + chainStorage.verifierParams = _initializeData.verifierParams; + chainStorage.l2BootloaderBytecodeHash = _initializeData.l2BootloaderBytecodeHash; + chainStorage.l2DefaultAccountBytecodeHash = _initializeData.l2DefaultAccountBytecodeHash; + chainStorage.priorityTxMaxGasLimit = _initializeData.priorityTxMaxGasLimit; + + // While this does not provide a protection in the production, it is needed for local testing + // Length of the L2Log encoding should not be equal to the length of other L2Logs' tree nodes preimages + assert(L2_TO_L1_LOG_SERIALIZE_SIZE != 2 * 32); return Diamond.DIAMOND_INIT_SUCCESS_RETURN_VALUE; } diff --git a/ethereum/contracts/state-transition/chain-interfaces/IAdmin.sol b/ethereum/contracts/state-transition/chain-interfaces/IAdmin.sol index ebe51a45f..c7a17e31f 100644 --- a/ethereum/contracts/state-transition/chain-interfaces/IAdmin.sol +++ b/ethereum/contracts/state-transition/chain-interfaces/IAdmin.sol @@ -31,6 +31,13 @@ interface IAdmin is IStateTransitionChainBase { function unfreezeDiamond() external; + /// @notice Porter availability status changes + event IsPorterAvailableStatusUpdate(bool isPorterAvailable); + + /// @notice Validator's status changed + event ValidatorStatusUpdate(address indexed validatorAddress, bool isActive); + + /// @notice pendingGovernor is changed /// @dev Also emitted when new governor is accepted and in this case, `newPendingGovernor` would be zero address event NewPendingGovernor(address indexed oldPendingGovernor, address indexed newPendingGovernor); @@ -48,12 +55,6 @@ interface IAdmin is IStateTransitionChainBase { /// @notice Priority transaction max L2 gas limit changed event NewPriorityTxMaxGasLimit(uint256 oldPriorityTxMaxGasLimit, uint256 newPriorityTxMaxGasLimit); - /// @notice Validator's status changed - event ValidatorStatusUpdate(address indexed validatorAddress, bool isActive); - - /// @notice Porter availability status changes - event IsPorterAvailableStatusUpdate(bool isPorterAvailable); - /// @notice Emitted when an upgrade is executed. event ExecuteUpgrade(Diamond.DiamondCutData diamondCut); diff --git a/ethereum/contracts/state-transition/chain-interfaces/IDiamondInit.sol b/ethereum/contracts/state-transition/chain-interfaces/IDiamondInit.sol index cf3509076..7b0d9c1a5 100644 --- a/ethereum/contracts/state-transition/chain-interfaces/IDiamondInit.sol +++ b/ethereum/contracts/state-transition/chain-interfaces/IDiamondInit.sol @@ -21,6 +21,7 @@ struct InitializeData { address bridgehub; address stateTransition; address governor; + address admin; bytes32 storedBatchZero; IAllowList allowList; IVerifier verifier;