Skip to content

Commit

Permalink
timelock and diamond init
Browse files Browse the repository at this point in the history
  • Loading branch information
koloz193 committed May 17, 2024
1 parent 32765d7 commit 58ae2ca
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 12 deletions.
1 change: 1 addition & 0 deletions .codespell/wordlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ ue
tha
bu
crate
DNE
2 changes: 2 additions & 0 deletions l1-contracts/contracts/common/L1ContractErrors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ error InvalidDelay();
error PreviousOperationNotExecuted();
error HashMismatch(bytes32 expected, bytes32 actual);
error HyperchainLimitReached();
error TimeNotReached();
error TooMuchGas();

enum SharedBridgeKey {
PostUpgradeFirstBatch,
Expand Down
13 changes: 10 additions & 3 deletions l1-contracts/contracts/state-transition/ValidatorTimelock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {Ownable2Step} from "@openzeppelin/contracts/access/Ownable2Step.sol";
import {LibMap} from "./libraries/LibMap.sol";
import {IExecutor} from "./chain-interfaces/IExecutor.sol";
import {IStateTransitionManager} from "./IStateTransitionManager.sol";
import {Unauthorized, TimeNotReached} from "../common/L1ContractErrors.sol";

/// @author Matter Labs
/// @custom:security-contact [email protected]
Expand Down Expand Up @@ -62,13 +63,17 @@ contract ValidatorTimelock is IExecutor, Ownable2Step {

/// @notice Checks if the caller is the admin of the chain.
modifier onlyChainAdmin(uint256 _chainId) {
require(msg.sender == stateTransitionManager.getChainAdmin(_chainId), "ValidatorTimelock: only chain admin");
if (msg.sender != stateTransitionManager.getChainAdmin(_chainId)) {
revert Unauthorized(msg.sender);
}
_;
}

/// @notice Checks if the caller is a validator.
modifier onlyValidator(uint256 _chainId) {
require(validators[_chainId][msg.sender], "ValidatorTimelock: only validator");
if (!validators[_chainId][msg.sender]) {
revert Unauthorized(msg.sender);
}
_;
}

Expand Down Expand Up @@ -203,7 +208,9 @@ contract ValidatorTimelock is IExecutor, Ownable2Step {
// * The batch wasn't committed at all, so execution will fail in the zkSync contract.
// We allow executing such batches.

require(block.timestamp >= commitBatchTimestamp + delay, "5c"); // The delay is not passed
if (block.timestamp < commitBatchTimestamp + delay) {
revert TimeNotReached();
}
}
}
_propagateToZkSyncHyperchain(_chainId);
Expand Down
37 changes: 28 additions & 9 deletions l1-contracts/contracts/state-transition/chain-deps/DiamondInit.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {Diamond} from "../libraries/Diamond.sol";
import {ZkSyncHyperchainBase} from "./facets/ZkSyncHyperchainBase.sol";
import {L2_TO_L1_LOG_SERIALIZE_SIZE, MAX_GAS_PER_TRANSACTION} from "../../common/Config.sol";
import {InitializeData, IDiamondInit} from "../chain-interfaces/IDiamondInit.sol";
import {ZeroAddress, TooMuchGas} from "../../common/L1ContractErrors.sol";

/// @author Matter Labs
/// @dev The contract is used only once to initialize the diamond proxy.
Expand All @@ -18,15 +19,33 @@ contract DiamondInit is ZkSyncHyperchainBase, IDiamondInit {
/// @return Magic 32 bytes, which indicates that the contract logic is expected to be used as a diamond proxy
/// initializer
function initialize(InitializeData calldata _initializeData) external reentrancyGuardInitializer returns (bytes32) {
require(address(_initializeData.verifier) != address(0), "vt");
require(_initializeData.admin != address(0), "vy");
require(_initializeData.validatorTimelock != address(0), "hc");
require(_initializeData.priorityTxMaxGasLimit <= MAX_GAS_PER_TRANSACTION, "vu");
require(_initializeData.bridgehub != address(0), "DiamondInit: b0");
require(_initializeData.stateTransitionManager != address(0), "DiamondInit: stm0");
require(_initializeData.baseToken != address(0), "DiamondInit: bt0");
require(_initializeData.baseTokenBridge != address(0), "DiamondInit: btb0");
require(_initializeData.blobVersionedHashRetriever != address(0), "DiamondInit: bvhr0");
if (address(_initializeData.verifier) == address(0)) {
revert ZeroAddress();
}
if (_initializeData.admin == address(0)) {
revert ZeroAddress();
}
if (_initializeData.validatorTimelock == address(0)) {
revert ZeroAddress();
}
if (_initializeData.priorityTxMaxGasLimit > MAX_GAS_PER_TRANSACTION) {
revert TooMuchGas();
}
if (_initializeData.bridgehub == address(0)) {
revert ZeroAddress();
}
if (_initializeData.stateTransitionManager == address(0)) {
revert ZeroAddress();
}
if (_initializeData.baseToken == address(0)) {
revert ZeroAddress();
}
if (_initializeData.baseTokenBridge == address(0)) {
revert ZeroAddress();
}
if (_initializeData.blobVersionedHashRetriever == address(0)) {
revert ZeroAddress();
}

s.chainId = _initializeData.chainId;
s.bridgehub = _initializeData.bridgehub;
Expand Down

0 comments on commit 58ae2ca

Please sign in to comment.