Skip to content

Commit

Permalink
add TimestampAsserter to sync-layer-stable (#1057)
Browse files Browse the repository at this point in the history
  • Loading branch information
perekopskiy committed Nov 11, 2024
1 parent 53b0283 commit c38e957
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 0 deletions.
16 changes: 16 additions & 0 deletions l1-contracts/deploy-scripts/DeployL2Contracts.sol
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ contract DeployL2Script is Script {
address consensusRegistryImplementation;
address consensusRegistryProxy;
address multicall3;
address timestampAsserter;
}

function run() public {
Expand All @@ -55,6 +56,7 @@ contract DeployL2Script is Script {
deployConsensusRegistry();
deployConsensusRegistryProxy();
deployMulticall3();
deployTimestampAsserter();

saveOutput();
}
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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 {
Expand Down
9 changes: 9 additions & 0 deletions l1-contracts/deploy-scripts/L2ContractsBytecodesLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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"
);
}
}
6 changes: 6 additions & 0 deletions l2-contracts/contracts/dev-contracts/ITimestampAsserter.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;

interface ITimestampAsserter {
function assertTimestampInRange(uint256 start, uint256 end) external view;
}
20 changes: 20 additions & 0 deletions l2-contracts/contracts/dev-contracts/TimestampAsserter.sol
Original file line number Diff line number Diff line change
@@ -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 [email protected]
/// @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);
}
}
}

0 comments on commit c38e957

Please sign in to comment.