Commit fb45215a authored by Michael Amadi's avatar Michael Amadi Committed by GitHub

Add Interop Start timestamp to CrossL2Inbox (#11398)

* add interop start timestamp to CrossL2Inbox with tests

* change to function, add assertions, update tests

* correct the preimage of interop start storage slot

* rename custome error

* require id timestamp must be > interopStartTime not >=, update tests to use realistic interopStartTime (non-zero)

* bump CrossL2Inbox semver, run just semver-lock & just snapshots

* add natspec for setInteropStart

* update semver lock
parent 872ff5db
......@@ -68,8 +68,8 @@
"sourceCodeHash": "0x3a725791a0f5ed84dc46dcdae26f6170a759b2fe3dc360d704356d088b76cfd6"
},
"src/L2/CrossL2Inbox.sol": {
"initCodeHash": "0x80124454d2127d5ff340b0ef048be6d5bf5984e84c75021b6a1ffa81703a2503",
"sourceCodeHash": "0xfb26fc80fbc7febdc91ac73ea91ceb479b238e0e81804a0a21192d78c261a755"
"initCodeHash": "0x071b53cd8cf0503af856c4ee0ee34643e85059d53c096453891225472e02abfa",
"sourceCodeHash": "0x3c78129b91d9f06afa4787d4b3039f45a3b22b3edf5155ed73d4f0c3ab33c6c8"
},
"src/L2/ETHLiquidity.sol": {
"initCodeHash": "0x98177562fca0de0dfea5313c9acefe2fdbd73dee5ce6c1232055601f208f0177",
......
......@@ -75,6 +75,19 @@
"stateMutability": "payable",
"type": "function"
},
{
"inputs": [],
"name": "interopStart",
"outputs": [
{
"internalType": "uint256",
"name": "interopStart_",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "logIndex",
......@@ -101,6 +114,13 @@
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "setInteropStart",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "timestamp",
......@@ -218,6 +238,11 @@
"name": "ExecutingMessage",
"type": "event"
},
{
"inputs": [],
"name": "InteropStartAlreadySet",
"type": "error"
},
{
"inputs": [],
"name": "InvalidChainId",
......@@ -228,6 +253,11 @@
"name": "InvalidTimestamp",
"type": "error"
},
{
"inputs": [],
"name": "NotDepositor",
"type": "error"
},
{
"inputs": [],
"name": "NotEntered",
......
......@@ -17,6 +17,12 @@ interface IDependencySet {
function isInDependencySet(uint256 _chainId) external view returns (bool);
}
/// @notice Thrown when the caller is not DEPOSITOR_ACCOUNT when calling `setInteropStart()`
error NotDepositor();
/// @notice Thrown when attempting to set interop start when it's already set.
error InteropStartAlreadySet();
/// @notice Thrown when a non-written transient storage slot is attempted to be read from.
error NotEntered();
......@@ -35,6 +41,10 @@ error TargetCallFailed();
/// @notice The CrossL2Inbox is responsible for executing a cross chain message on the destination
/// chain. It is permissionless to execute a cross chain message on behalf of any user.
contract CrossL2Inbox is ICrossL2Inbox, ISemver, TransientReentrancyAware {
/// @notice Storage slot that the interop start timestamp is stored at.
/// Equal to bytes32(uint256(keccak256("crossl2inbox.interopstart")) - 1)
bytes32 internal constant INTEROP_START_SLOT = 0x5c769ee0ee8887661922049dc52480bb60322d765161507707dd9b190af5c149;
/// @notice Transient storage slot that the origin for an Identifier is stored at.
/// Equal to bytes32(uint256(keccak256("crossl2inbox.identifier.origin")) - 1)
bytes32 internal constant ORIGIN_SLOT = 0xd2b7c5071ec59eb3ff0017d703a8ea513a7d0da4779b0dbefe845808c300c815;
......@@ -55,15 +65,42 @@ contract CrossL2Inbox is ICrossL2Inbox, ISemver, TransientReentrancyAware {
/// Equal to bytes32(uint256(keccak256("crossl2inbox.identifier.chainid")) - 1)
bytes32 internal constant CHAINID_SLOT = 0x6e0446e8b5098b8c8193f964f1b567ec3a2bdaeba33d36acb85c1f1d3f92d313;
/// @notice The address that represents the system caller responsible for L1 attributes
/// transactions.
address internal constant DEPOSITOR_ACCOUNT = 0xDeaDDEaDDeAdDeAdDEAdDEaddeAddEAdDEAd0001;
/// @notice Semantic version.
/// @custom:semver 1.0.0-beta.4
string public constant version = "1.0.0-beta.4";
/// @custom:semver 1.0.0-beta.5
string public constant version = "1.0.0-beta.5";
/// @notice Emitted when a cross chain message is being executed.
/// @param msgHash Hash of message payload being executed.
/// @param id Encoded Identifier of the message.
event ExecutingMessage(bytes32 indexed msgHash, Identifier id);
/// @notice Sets the Interop Start Timestamp for this chain. Can only be performed once and when the caller is the
/// DEPOSITOR_ACCOUNT.
function setInteropStart() external {
// Check that caller is the DEPOSITOR_ACCOUNT
if (msg.sender != DEPOSITOR_ACCOUNT) revert NotDepositor();
// Check that it has not been set already
if (interopStart() != 0) revert InteropStartAlreadySet();
// Set Interop Start to block.timestamp
assembly {
sstore(INTEROP_START_SLOT, timestamp())
}
}
/// @notice Returns the interop start timestamp.
/// @return interopStart_ interop start timestamp.
function interopStart() public view returns (uint256 interopStart_) {
assembly {
interopStart_ := sload(INTEROP_START_SLOT)
}
}
/// @notice Returns the origin address of the Identifier. If not entered, reverts.
/// @return Origin address of the Identifier.
function origin() external view notEntered returns (address) {
......@@ -140,7 +177,7 @@ contract CrossL2Inbox is ICrossL2Inbox, ISemver, TransientReentrancyAware {
/// is in the destination chain's dependency set.
/// @param _id Identifier of the message.
function _checkIdentifier(Identifier calldata _id) internal view {
if (_id.timestamp > block.timestamp) revert InvalidTimestamp();
if (_id.timestamp > block.timestamp || _id.timestamp <= interopStart()) revert InvalidTimestamp();
if (!IDependencySet(Predeploys.L1_BLOCK_ATTRIBUTES).isInDependencySet(_id.chainId)) {
revert InvalidChainId();
}
......
......@@ -13,6 +13,10 @@ interface ICrossL2Inbox {
uint256 chainId;
}
/// @notice Returns the interop start timestamp.
/// @return interopStart_ interop start timestamp.
function interopStart() external view returns (uint256 interopStart_);
/// @notice Returns the origin address of the Identifier.
/// @return _origin The origin address of the Identifier.
function origin() external view returns (address _origin);
......@@ -44,4 +48,12 @@ interface ICrossL2Inbox {
)
external
payable;
/// @notice Validates a cross chain message on the destination chain
/// and emits an ExecutingMessage event. This function is useful
/// for applications that understand the schema of the _message payload and want to
/// process it in a custom way.
/// @param _id Identifier of the message.
/// @param _msgHash Hash of the message payload to call target with.
function validateMessage(Identifier calldata _id, bytes32 _msgHash) external;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment