From b35cf762a74cc980f44088c85c5e1c37f4274fc1 Mon Sep 17 00:00:00 2001 From: perekopskiy Date: Fri, 8 Nov 2024 15:31:24 +0200 Subject: [PATCH 1/2] add TimestampAsserter --- .../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 5c4fc3f05..2939ff911 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(); } @@ -110,6 +112,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(); @@ -184,6 +187,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..b36ef4e6a 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); + } + } +} From 4cea7e1a420fbfa7d9453e01b4ebde6de195f85c Mon Sep 17 00:00:00 2001 From: perekopskiy Date: Fri, 8 Nov 2024 15:43:05 +0200 Subject: [PATCH 2/2] fmt --- l1-contracts/deploy-scripts/L2ContractsBytecodesLib.sol | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/l1-contracts/deploy-scripts/L2ContractsBytecodesLib.sol b/l1-contracts/deploy-scripts/L2ContractsBytecodesLib.sol index b36ef4e6a..d0bb7d34c 100644 --- a/l1-contracts/deploy-scripts/L2ContractsBytecodesLib.sol +++ b/l1-contracts/deploy-scripts/L2ContractsBytecodesLib.sol @@ -308,7 +308,7 @@ library L2ContractsBytecodesLib { function readTimestampAsserterBytecode() internal view returns (bytes memory) { return Utils.readHardhatBytecode( - "/../l2-contracts/artifacts-zk/contracts/dev-contracts/TimestampAsserter.sol/TimestampAsserter.json" - ); + "/../l2-contracts/artifacts-zk/contracts/dev-contracts/TimestampAsserter.sol/TimestampAsserter.json" + ); } }