-
Notifications
You must be signed in to change notification settings - Fork 345
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
20 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: 14 additions & 6 deletions
20
l2-contracts/contracts/dev-contracts/TimestampAsserter.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,20 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.24; | ||
|
||
interface ITimestampAsserter { | ||
function assertTimestampInRange(uint256 start, uint256 end) external view; | ||
} | ||
import "./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) public view { | ||
require(start < block.timestamp && end > block.timestamp, "Block timestamp is out of range"); | ||
function assertTimestampInRange(uint256 _start, uint256 _end) public view { | ||
if (block.timestamp < _start || block.timestamp > _end) { | ||
revert TimestampOutOfRange(block.timestamp, _start, _end); | ||
} | ||
} | ||
} | ||
} |