IMailbox

Git Source

Inherits: IZKChainBase

Author: Matter Labs

Note: security-contact: security@matterlabs.dev

Functions

proveL2MessageInclusion

Prove that a specific arbitrary-length message was sent in a specific L2 batch number

function proveL2MessageInclusion(
  uint256 _batchNumber,
  uint256 _index,
  L2Message calldata _message,
  bytes32[] calldata _proof
) external view returns (bool);

Parameters

NameTypeDescription
_batchNumberuint256The executed L2 batch number in which the message appeared
_indexuint256The position in the L2 logs Merkle tree of the l2Log that was sent with the message
_messageL2MessageInformation about the sent message: sender address, the message itself, tx index in the L2 batch where the message was sent
_proofbytes32[]Merkle proof for inclusion of L2 log that was sent with the message

Returns

NameTypeDescription
<none>boolWhether the proof is valid

proveL2LogInclusion

Prove that a specific L2 log was sent in a specific L2 batch

function proveL2LogInclusion(
  uint256 _batchNumber,
  uint256 _index,
  L2Log memory _log,
  bytes32[] calldata _proof
) external view returns (bool);

Parameters

NameTypeDescription
_batchNumberuint256The executed L2 batch number in which the log appeared
_indexuint256The position of the l2log in the L2 logs Merkle tree
_logL2LogInformation about the sent log
_proofbytes32[]Merkle proof for inclusion of the L2 log

Returns

NameTypeDescription
<none>boolWhether the proof is correct and L2 log is included in batch

proveL1ToL2TransactionStatus

Prove that the L1 -> L2 transaction was processed with the specified status.

function proveL1ToL2TransactionStatus(
  bytes32 _l2TxHash,
  uint256 _l2BatchNumber,
  uint256 _l2MessageIndex,
  uint16 _l2TxNumberInBatch,
  bytes32[] calldata _merkleProof,
  TxStatus _status
) external view returns (bool);

Parameters

NameTypeDescription
_l2TxHashbytes32The L2 canonical transaction hash
_l2BatchNumberuint256The L2 batch number where the transaction was processed
_l2MessageIndexuint256The position in the L2 logs Merkle tree of the l2Log that was sent with the message
_l2TxNumberInBatchuint16The L2 transaction number in the batch, in which the log was sent
_merkleProofbytes32[]The Merkle proof of the processing L1 -> L2 transaction
_statusTxStatusThe execution status of the L1 -> L2 transaction (true - success & 0 - fail)

Returns

NameTypeDescription
<none>boolWhether the proof is correct and the transaction was actually executed with provided status NOTE: It may return false for incorrect proof, but it doesn't mean that the L1 -> L2 transaction has an opposite status!

finalizeEthWithdrawal

Finalize the withdrawal and release funds

function finalizeEthWithdrawal(
  uint256 _l2BatchNumber,
  uint256 _l2MessageIndex,
  uint16 _l2TxNumberInBatch,
  bytes calldata _message,
  bytes32[] calldata _merkleProof
) external;

Parameters

NameTypeDescription
_l2BatchNumberuint256The L2 batch number where the withdrawal was processed
_l2MessageIndexuint256The position in the L2 logs Merkle tree of the l2Log that was sent with the message
_l2TxNumberInBatchuint16The L2 transaction number in a batch, in which the log was sent
_messagebytesThe L2 withdraw data, stored in an L2 -> L1 message
_merkleProofbytes32[]The Merkle proof of the inclusion L2 -> L1 message about withdrawal initialization

requestL2Transaction

Request execution of L2 transaction from L1.

*If the L2 deposit finalization transaction fails, the _refundRecipient will receive the _l2Value. Please note, the contract may change the refund recipient's address to eliminate sending funds to addresses out of control.

  • If _refundRecipient is a contract on L1, the refund will be sent to the aliased _refundRecipient.
  • If _refundRecipient is set to address(0) and the sender has NO deployed bytecode on L1, the refund will be sent to the msg.sender address.
  • If _refundRecipient is set to address(0) and the sender has deployed bytecode on L1, the refund will be sent to the aliased msg.sender address.*

The address aliasing of L1 contracts as refund recipient on L2 is necessary to guarantee that the funds are controllable, since address aliasing to the from address for the L2 tx will be applied if the L1 msg.sender is a contract. Without address aliasing for L1 contracts as refund recipients they would not be able to make proper L2 tx requests through the Mailbox to use or withdraw the funds from L2, and the funds would be lost.

function requestL2Transaction(
  address _contractL2,
  uint256 _l2Value,
  bytes calldata _calldata,
  uint256 _l2GasLimit,
  uint256 _l2GasPerPubdataByteLimit,
  bytes[] calldata _factoryDeps,
  address _refundRecipient
) external payable returns (bytes32 canonicalTxHash);

Parameters

NameTypeDescription
_contractL2addressThe L2 receiver address
_l2Valueuint256msg.value of L2 transaction
_calldatabytesThe input of the L2 transaction
_l2GasLimituint256Maximum amount of L2 gas that transaction can consume during execution on L2
_l2GasPerPubdataByteLimituint256The maximum amount L2 gas that the operator may charge the user for single byte of pubdata.
_factoryDepsbytes[]An array of L2 bytecodes that will be marked as known on L2
_refundRecipientaddressThe address on L2 that will receive the refund for the transaction.

Returns

NameTypeDescription
canonicalTxHashbytes32The hash of the requested L2 transaction. This hash can be used to follow the transaction status

bridgehubRequestL2Transaction

when requesting transactions through the bridgehub

function bridgehubRequestL2Transaction(
  BridgehubL2TransactionRequest calldata _request
) external returns (bytes32 canonicalTxHash);

bridgehubRequestL2TransactionOnGateway

On the Gateway the chain's mailbox receives the tx from the bridgehub.

function bridgehubRequestL2TransactionOnGateway(
  bytes32 _canonicalTxHash,
  uint64 _expirationTimestamp
) external;

requestL2ServiceTransaction

Request execution of service L2 transaction from L1.

Used for chain configuration. Can be called only by DiamondProxy itself.

function requestL2ServiceTransaction(
  address _contractL2,
  bytes calldata _l2Calldata
) external returns (bytes32 canonicalTxHash);

Parameters

NameTypeDescription
_contractL2addressThe L2 receiver address
_l2CalldatabytesThe input of the L2 transaction

requestL2TransactionToGatewayMailbox

On L1 we have to forward to the Gateway's mailbox which sends to the Bridgehub on the Gw

function requestL2TransactionToGatewayMailbox(
  uint256 _chainId,
  bytes32 _canonicalTxHash,
  uint64 _expirationTimestamp
) external returns (bytes32 canonicalTxHash);

Parameters

NameTypeDescription
_chainIduint256the chainId of the chain
_canonicalTxHashbytes32the canonical transaction hash
_expirationTimestampuint64the expiration timestamp

l2TransactionBaseCost

Estimates the cost in Ether of requesting execution of an L2 transaction from L1

function l2TransactionBaseCost(
  uint256 _gasPrice,
  uint256 _l2GasLimit,
  uint256 _l2GasPerPubdataByteLimit
) external view returns (uint256);

Parameters

NameTypeDescription
_gasPriceuint256expected L1 gas price at which the user requests the transaction execution
_l2GasLimituint256Maximum amount of L2 gas that transaction can consume during execution on L2
_l2GasPerPubdataByteLimituint256The maximum amount of L2 gas that the operator may charge the user for a single byte of pubdata.

Returns

NameTypeDescription
<none>uint256The estimated ETH spent on L2 gas for the transaction

proveL2LeafInclusion

Proves that a certain leaf was included as part of the log merkle tree.

Warning: this function does not enforce any additional checks on the structure of the leaf. This means that it can accept intermediate nodes of the Merkle tree as a _leaf as well as the default "empty" leaves. It is the responsibility of the caller to ensure that the _leaf is a hash of a valid leaf.

function proveL2LeafInclusion(
  uint256 _batchNumber,
  uint256 _batchRootMask,
  bytes32 _leaf,
  bytes32[] calldata _proof
) external view returns (bool);

Events

NewPriorityRequest

transfer Eth to shared bridge as part of migration process

New priority request event. Emitted when a request is placed into the priority queue

event NewPriorityRequest(
  uint256 txId,
  bytes32 txHash,
  uint64 expirationTimestamp,
  L2CanonicalTransaction transaction,
  bytes[] factoryDeps
);

Parameters

NameTypeDescription
txIduint256Serial number of the priority operation
txHashbytes32keccak256 hash of encoded transaction representation
expirationTimestampuint64Timestamp up to which priority request should be processed
transactionL2CanonicalTransactionThe whole transaction structure that is requested to be executed on L2
factoryDepsbytes[]An array of bytecodes that were shown in the L1 public data. Will be marked as known bytecodes in L2

NewRelayedPriorityTransaction

New relayed priority request event. It is emitted on a chain that is deployed on top of the gateway when it receives a request relayed via the Bridgehub.

IMPORTANT: this event most likely will be removed in the future, so no one should rely on it for indexing purposes.

event NewRelayedPriorityTransaction(
  uint256 txId, bytes32 txHash, uint64 expirationTimestamp
);

Parameters

NameTypeDescription
txIduint256Serial number of the priority operation
txHashbytes32keccak256 hash of encoded transaction representation
expirationTimestampuint64Timestamp up to which priority request should be processed