Skip to content

Commit

Permalink
diamondInit change
Browse files Browse the repository at this point in the history
  • Loading branch information
kelemeno committed Oct 18, 2023
1 parent 87b65e4 commit 5f78a1b
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 26 deletions.
47 changes: 27 additions & 20 deletions ethereum/contracts/state-transition/chain-deps/DiamondInit.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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;
}
Expand Down
13 changes: 7 additions & 6 deletions ethereum/contracts/state-transition/chain-interfaces/IAdmin.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ struct InitializeData {
address bridgehub;
address stateTransition;
address governor;
address admin;
bytes32 storedBatchZero;
IAllowList allowList;
IVerifier verifier;
Expand Down

0 comments on commit 5f78a1b

Please sign in to comment.