From 2451c42b856773ef06dccd14b3b9fe115cf1b7dc Mon Sep 17 00:00:00 2001 From: perekopskiy <53865202+perekopskiy@users.noreply.github.com> Date: Mon, 11 Nov 2024 16:34:04 +0200 Subject: [PATCH] add TimestampAsserter to sync-layer-stable (#1057) --- .../deploy-scripts/DeployL2Contracts.sol | 16 +++++++++++++++ .../L2ContractsBytecodesLib.sol | 9 +++++++++ .../dev-contracts/ITimestampAsserter.sol | 6 ++++++ .../dev-contracts/TimestampAsserter.sol | 20 +++++++++++++++++++ 4 files changed, 51 insertions(+) create mode 100644 l2-contracts/contracts/dev-contracts/ITimestampAsserter.sol create mode 100644 l2-contracts/contracts/dev-contracts/TimestampAsserter.sol diff --git a/l1-contracts/deploy-scripts/DeployL2Contracts.sol b/l1-contracts/deploy-scripts/DeployL2Contracts.sol index 31415e186..c1eae207d 100644 --- a/l1-contracts/deploy-scripts/DeployL2Contracts.sol +++ b/l1-contracts/deploy-scripts/DeployL2Contracts.sol @@ -35,6 +35,7 @@ contract DeployL2Script is Script { address consensusRegistryImplementation; address consensusRegistryProxy; address multicall3; + address timestampAsserter; } function run() public { @@ -55,6 +56,7 @@ contract DeployL2Script is Script { deployConsensusRegistry(); deployConsensusRegistryProxy(); deployMulticall3(); + deployTimestampAsserter(); saveOutput(); } @@ -118,6 +120,7 @@ contract DeployL2Script is Script { vm.serializeAddress("root", "multicall3", deployed.multicall3); vm.serializeAddress("root", "consensus_registry_implementation", deployed.consensusRegistryImplementation); vm.serializeAddress("root", "consensus_registry_proxy", deployed.consensusRegistryProxy); + vm.serializeAddress("root", "timestamp_asserter", deployed.timestampAsserter); string memory toml = vm.serializeAddress("root", "l2_default_upgrader", deployed.forceDeployUpgraderAddress); string memory root = vm.projectRoot(); @@ -192,6 +195,19 @@ contract DeployL2Script is Script { }); } + function deployTimestampAsserter() internal { + deployed.timestampAsserter = Utils.deployThroughL1({ + bytecode: L2ContractsBytecodesLib.readTimestampAsserterBytecode(), + constructorargs: "", + create2salt: "", + l2GasLimit: Utils.MAX_PRIORITY_TX_GAS, + factoryDeps: new bytes[](0), + chainId: config.chainId, + bridgehubAddress: config.bridgehubAddress, + l1SharedBridgeProxy: config.l1SharedBridgeProxy + }); + } + // Deploy a transparent upgradable proxy for the already deployed consensus registry // implementation and save its address into the config. function deployConsensusRegistryProxy() internal { diff --git a/l1-contracts/deploy-scripts/L2ContractsBytecodesLib.sol b/l1-contracts/deploy-scripts/L2ContractsBytecodesLib.sol index 9b672deb2..d0bb7d34c 100644 --- a/l1-contracts/deploy-scripts/L2ContractsBytecodesLib.sol +++ b/l1-contracts/deploy-scripts/L2ContractsBytecodesLib.sol @@ -302,4 +302,13 @@ library L2ContractsBytecodesLib { "/../l1-contracts/artifacts-zk/contracts/governance/L2ProxyAdminDeployer.sol/L2ProxyAdminDeployer.json" ); } + + /// @notice Reads the bytecode of the TimestampAsserter contract. + /// @return The bytecode of the TimestampAsserter contract. + function readTimestampAsserterBytecode() internal view returns (bytes memory) { + return + Utils.readHardhatBytecode( + "/../l2-contracts/artifacts-zk/contracts/dev-contracts/TimestampAsserter.sol/TimestampAsserter.json" + ); + } } diff --git a/l2-contracts/contracts/dev-contracts/ITimestampAsserter.sol b/l2-contracts/contracts/dev-contracts/ITimestampAsserter.sol new file mode 100644 index 000000000..47d9ec103 --- /dev/null +++ b/l2-contracts/contracts/dev-contracts/ITimestampAsserter.sol @@ -0,0 +1,6 @@ +// SPDX-License-Identifier: MIT +pragma solidity 0.8.24; + +interface ITimestampAsserter { + function assertTimestampInRange(uint256 start, uint256 end) external view; +} diff --git a/l2-contracts/contracts/dev-contracts/TimestampAsserter.sol b/l2-contracts/contracts/dev-contracts/TimestampAsserter.sol new file mode 100644 index 000000000..445313fe0 --- /dev/null +++ b/l2-contracts/contracts/dev-contracts/TimestampAsserter.sol @@ -0,0 +1,20 @@ +// SPDX-License-Identifier: MIT +pragma solidity 0.8.24; + +import {ITimestampAsserter} from "./ITimestampAsserter.sol"; + +error TimestampOutOfRange(uint256 currentTimestamp, uint256 start, uint256 end); + +/// @title TimestampAsserter +/// @author Matter Labs +/// @custom:security-contact security@matterlabs.dev +/// @dev A contract that verifies if the current block timestamp falls within a specified range. +/// This is useful for custom account abstraction where time-bound checks are needed but accessing block.timestamp +/// directly is not possible. +contract TimestampAsserter is ITimestampAsserter { + function assertTimestampInRange(uint256 _start, uint256 _end) external view { + if (block.timestamp < _start || block.timestamp > _end) { + revert TimestampOutOfRange(block.timestamp, _start, _end); + } + } +}