Verified contractExactMIT
MailboxFacet
Address0x97d6eb8b4f650df77b2af828a5c0041111ff09ae
- Balance
0 ETH
- Transactions
0
- Compiler
solc 0.8.28
- Same code
6 more contracts
Details
- Compiler
- solc 0.8.28+commit.7893614a
- Language
- solidity
- Optimization
- Yes, 9,999,999 runs
- EVM version
- prague
- License
- MIT
- Match
- Exactcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 25,444,316
- Creation transaction
- 0x76dab745ab…1a3a5dad4e
76 files
The source code is large: one file is shown at a time. Choose a file in the list.
- contracts/state-transition/chain-deps/facets/Mailbox.solmain27.61 KB
- ../system-contracts/contracts/Constants.sol10.57 KB
- contracts/bridge/asset-router/IAssetRouterBase.sol1.39 KB
- contracts/bridge/asset-router/IAssetRouterShared.sol1.61 KB
- contracts/bridge/asset-router/IL1AssetRouter.sol9 KB
- contracts/bridge/asset-router/IL2AssetRouter.sol1.59 KB
- contracts/bridge/asset-tracker/IAssetTrackerBase.sol950 B
- contracts/bridge/asset-tracker/IGWAssetTracker.sol8.5 KB
- contracts/bridge/asset-tracker/IL1AssetTracker.sol3.34 KB
- contracts/bridge/asset-tracker/IL2AssetTracker.sol2.59 KB
- contracts/bridge/interfaces/IAssetHandler.sol2.27 KB
- contracts/bridge/interfaces/IL1AssetDeploymentTracker.sol375 B
- contracts/bridge/interfaces/IL1CrossChainSender.sol1.91 KB
- contracts/bridge/interfaces/IL1ERC20Bridge.sol2.75 KB
- contracts/bridge/interfaces/IL1Nullifier.sol6.78 KB
- contracts/bridge/interfaces/IL1SharedBridgeLegacy.sol291 B
- contracts/bridge/interfaces/IL2CrossChainSender.sol1.64 KB
- contracts/bridge/ntv/IL1NativeTokenVault.sol1.55 KB
- contracts/bridge/ntv/IL2NativeTokenVault.sol1.07 KB
- contracts/bridge/ntv/INativeTokenVaultBase.sol2.17 KB
- contracts/common/Config.sol15.2 KB
- contracts/common/L1ContractErrors.sol14.13 KB
- contracts/common/MessageVerification.sol6.1 KB
- contracts/common/Messaging.sol21.68 KB
- contracts/common/ReentrancyGuard.sol4.06 KB
- contracts/common/interfaces/IL2ContractDeployer.sol2.65 KB
- contracts/common/interfaces/IMessageVerification.sol4.59 KB
- contracts/common/interfaces/ISystemContext.sol2.77 KB
- contracts/common/l2-helpers/IBaseToken.sol1.26 KB
- contracts/common/l2-helpers/IL2ToL1MessengerEra.sol3.01 KB
- contracts/common/l2-helpers/L2ContractAddresses.sol8.1 KB
- contracts/common/l2-helpers/L2ContractHelper.sol11.32 KB
- contracts/common/l2-helpers/L2ContractInterfaces.sol4.62 KB
- contracts/common/libraries/DynamicIncrementalMerkle.sol7.04 KB
- contracts/common/libraries/Merkle.sol5.88 KB
- contracts/common/libraries/MessageHashing.sol10.91 KB
- contracts/common/libraries/UncheckedMath.sol671 B
- contracts/core/bridgehub/IBridgehubBase.sol6.56 KB
- contracts/core/bridgehub/IL1Bridgehub.sol1.94 KB
- contracts/core/bridgehub/L1BridgehubErrors.sol3.36 KB
- contracts/core/chain-asset-handler/IChainAssetHandler.sol3.67 KB
- contracts/core/chain-asset-handler/IL1ChainAssetHandler.sol2.06 KB
- contracts/core/ctm-deployment/ICTMDeploymentTracker.sol729 B
- contracts/core/message-root/IMessageRoot.sol4.47 KB
- contracts/interop/IInteropCenter.sol8.56 KB
- contracts/interop/IInteropHandler.sol2.56 KB
- contracts/interop/IL2InteropRootStorage.sol595 B
- contracts/l2-system/interfaces/IBaseTokenHolder.sol3.41 KB
- contracts/state-transition/L1StateTransitionErrors.sol3.85 KB
- contracts/state-transition/chain-deps/StoredBatchHashing.sol1.31 KB
- contracts/state-transition/chain-deps/ZKChainStorage.sol14.45 KB
- contracts/state-transition/chain-deps/facets/ZKChainBase.sol13.21 KB
- contracts/state-transition/chain-interfaces/IAdmin.sol9.27 KB
- contracts/state-transition/chain-interfaces/IChainUpgrader.sol1.09 KB
- contracts/state-transition/chain-interfaces/ICommitter.sol7.94 KB
- contracts/state-transition/chain-interfaces/IEIP7702Checker.sol549 B
- contracts/state-transition/chain-interfaces/IExecutor.sol9.89 KB
- contracts/state-transition/chain-interfaces/IGetters.sol9.62 KB
- contracts/state-transition/chain-interfaces/IMailbox.sol790 B
- contracts/state-transition/chain-interfaces/IMailboxImpl.sol8.95 KB
- contracts/state-transition/chain-interfaces/IMailboxLegacy.sol3.61 KB
- contracts/state-transition/chain-interfaces/IMigrator.sol2.44 KB
- contracts/state-transition/chain-interfaces/ITransactionFilterer.sol1.08 KB
- contracts/state-transition/chain-interfaces/IVerifier.sol1.18 KB
- contracts/state-transition/chain-interfaces/IZKChain.sol811 B
- contracts/state-transition/chain-interfaces/IZKChainBase.sol507 B
- contracts/state-transition/libraries/Diamond.sol15.39 KB
- contracts/state-transition/libraries/PriorityQueue.sol3.85 KB
- contracts/state-transition/libraries/PriorityTree.sol7.72 KB
- contracts/state-transition/libraries/TransactionValidator.sol11.88 KB
- contracts/vendor/AddressAliasHelper.sol4.61 KB
- lib/openzeppelin-contracts-v4/contracts/token/ERC20/IERC20.sol2.74 KB
- lib/openzeppelin-contracts-v4/contracts/utils/Arrays.sol3.97 KB
- lib/openzeppelin-contracts-v4/contracts/utils/StorageSlot.sol4.11 KB
- lib/openzeppelin-contracts-v4/contracts/utils/math/Math.sol12.79 KB
- lib/openzeppelin-contracts-v4/contracts/utils/math/SafeCast.sol35.08 KB
contracts/state-transition/chain-deps/facets/Mailbox.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.28;
import {IMailbox} from "../../chain-interfaces/IMailbox.sol";
import {IMailboxImpl} from "../../chain-interfaces/IMailboxImpl.sol";
import {IMailboxLegacy} from "../../chain-interfaces/IMailboxLegacy.sol";
import {IInteropCenter} from "../../../interop/IInteropCenter.sol";
import {IBridgehubBase} from "../../../core/bridgehub/IBridgehubBase.sol";
import {ITransactionFilterer} from "../../chain-interfaces/ITransactionFilterer.sol";
import {IEIP7702Checker} from "../../chain-interfaces/IEIP7702Checker.sol";
import {PriorityTree} from "../../libraries/PriorityTree.sol";
import {TransactionValidator} from "../../libraries/TransactionValidator.sol";
import {
BalanceChange,
BridgehubL2TransactionRequest,
L2CanonicalTransaction,
L2Log,
L2Message,
TxStatus,
WritePriorityOpParams
} from "../../../common/Messaging.sol";
import {MessageHashing} from "../../../common/libraries/MessageHashing.sol";
import {UncheckedMath} from "../../../common/libraries/UncheckedMath.sol";
import {L2ContractHelper} from "../../../common/l2-helpers/L2ContractHelper.sol";
import {AddressAliasHelper} from "../../../vendor/AddressAliasHelper.sol";
import {ZKChainBase} from "./ZKChainBase.sol";
import {
MAX_NEW_FACTORY_DEPS,
REQUIRED_L2_GAS_PRICE_PER_PUBDATA,
SERVICE_TRANSACTION_SENDER,
SETTLEMENT_LAYER_RELAY_SENDER,
PAUSE_DEPOSITS_TIME_WINDOW_START_TESTNET,
PAUSE_DEPOSITS_TIME_WINDOW_START_MAINNET
} from "../../../common/Config.sol";
import {L2_INTEROP_CENTER_ADDR} from "../../../common/l2-helpers/L2ContractAddresses.sol";
import {IL1AssetRouter} from "../../../bridge/asset-router/IL1AssetRouter.sol";
import {IAssetRouterShared} from "../../../bridge/asset-router/IAssetRouterShared.sol";
import {
AddressNotZero,
GasPerPubdataMismatch,
InvalidChainId,
MsgValueTooLow,
NotAssetRouter,
OnlyEraSupported,
TooManyFactoryDeps,
TransactionNotAllowed,
ValueMismatch,
ZeroAddress
} from "../../../common/L1ContractErrors.sol";
import {DepositsPaused, NotL1, NotSettlementLayer, NotZKChain} from "../../L1StateTransitionErrors.sol";
// While formally the following import is not used, it is needed to inherit documentation from it
import {IZKChainBase} from "../../chain-interfaces/IZKChainBase.sol";
import {IMessageVerification, MessageVerification} from "../../../common/MessageVerification.sol";
import {IL1AssetTracker} from "../../../bridge/asset-tracker/IL1AssetTracker.sol";
import {BALANCE_CHANGE_VERSION} from "../../../bridge/asset-tracker/IAssetTrackerBase.sol";
import {INativeTokenVaultBase} from "../../../bridge/ntv/INativeTokenVaultBase.sol";
import {OnlyGateway} from "../../../core/bridgehub/L1BridgehubErrors.sol";
import {IL1ChainAssetHandler} from "../../../core/chain-asset-handler/IL1ChainAssetHandler.sol";
/// @title ZKsync Mailbox contract providing interfaces for L1 <-> L2 interaction.
/// @author Matter Labs
/// @custom:security-contact [email protected]
contract MailboxFacet is ZKChainBase, IMailboxImpl, MessageVerification, IMailboxLegacy {
using UncheckedMath for uint256;
using PriorityTree for PriorityTree.Tree;
/// @inheritdoc IZKChainBase
// solhint-disable-next-line const-name-snakecase
string public constant override getName = "MailboxFacet";
/// @dev Deployed utility contract to check that account is EIP7702 one
IEIP7702Checker internal immutable EIP_7702_CHECKER;
/// @notice The chain id of L1. This contract can be deployed on multiple layers, but this value is still equal to the
/// L1 that is at the most base layer.
uint256 internal immutable L1_CHAIN_ID;
/// @dev Era's chainID
uint256 internal immutable ERA_CHAIN_ID; // TODO(EVM-1216): remove after the legacy mailbox.finalizeEthWithdrawal and mailbox.requestL2Transaction are deprecated.
/// @dev The address of the L1ChainAssetHandler system contract. Only used on L1.
address internal immutable CHAIN_ASSET_HANDLER;
uint256 internal immutable PAUSE_DEPOSITS_TIME_WINDOW_START;
modifier onlyL1() {
if (block.chainid != L1_CHAIN_ID) {
revert NotL1(block.chainid);
}
_;
}
modifier onlyGateway() {
if (block.chainid == L1_CHAIN_ID) {
revert OnlyGateway();
}
_;
}
constructor(
uint256 _eraChainId,
uint256 _l1ChainId,
address _chainAssetHandler,
IEIP7702Checker _eip7702Checker,
bool _isTestnet
) {
if (address(_eip7702Checker) == address(0) && block.chainid == _l1ChainId) {
revert ZeroAddress();
} else if (address(_eip7702Checker) != address(0) && block.chainid != _l1ChainId) {
revert AddressNotZero();
}
ERA_CHAIN_ID = _eraChainId; // TODO(EVM-1216): remove after the legacy mailbox.finalizeEthWithdrawal and mailbox.requestL2Transaction are deprecated.
L1_CHAIN_ID = _l1ChainId;
CHAIN_ASSET_HANDLER = _chainAssetHandler;
EIP_7702_CHECKER = _eip7702Checker;
PAUSE_DEPOSITS_TIME_WINDOW_START = _isTestnet
? PAUSE_DEPOSITS_TIME_WINDOW_START_TESTNET
: PAUSE_DEPOSITS_TIME_WINDOW_START_MAINNET;
}
/// @inheritdoc IMailboxImpl
function bridgehubRequestL2Transaction(
BridgehubL2TransactionRequest calldata _request
) external onlyBridgehub returns (bytes32 canonicalTxHash) {
canonicalTxHash = _requestL2TransactionSender(_request);
}
/// @inheritdoc IMessageVerification
function proveL2MessageInclusionShared(
uint256 _chainId,
uint256 _blockOrBatchNumber,
uint256 _index,
L2Message calldata _message,
bytes32[] calldata _proof
) public view override returns (bool) {
if (s.chainId != _chainId) {
revert InvalidChainId();
}
return
super.proveL2MessageInclusionShared({
_chainId: _chainId,
_blockOrBatchNumber: _blockOrBatchNumber,
_index: _index,
_message: _message,
_proof: _proof
});
}
/// @inheritdoc IMailboxImpl
function proveL2MessageInclusion(
uint256 _batchNumber,
uint256 _index,
L2Message calldata _message,
bytes32[] calldata _proof
) public view returns (bool) {
return
_proveL2LogInclusion({
_chainId: s.chainId,
_blockOrBatchNumber: _batchNumber,
_index: _index,
_log: MessageHashing._l2MessageToLog(_message),
_proof: _proof
});
}
/// @inheritdoc IMessageVerification
function proveL2LogInclusionShared(
uint256 _chainId,
uint256 _blockOrBatchNumber,
uint256 _index,
L2Log calldata _log,
bytes32[] calldata _proof
) public view override returns (bool) {
if (s.chainId != _chainId) {
revert InvalidChainId();
}
return
super.proveL2LogInclusionShared({
_chainId: _chainId,
_blockOrBatchNumber: _blockOrBatchNumber,
_index: _index,
_log: _log,
_proof: _proof
});
}
/// @inheritdoc IMailboxImpl
function proveL2LogInclusion(
uint256 _batchNumber,
uint256 _index,
L2Log calldata _log,
bytes32[] calldata _proof
) external view returns (bool) {
return
_proveL2LogInclusion({
_chainId: s.chainId,
_blockOrBatchNumber: _batchNumber,
_index: _index,
_log: _log,
_proof: _proof
});
}
/// @inheritdoc IMailboxImpl
function proveL1ToL2TransactionStatus(
bytes32 _l2TxHash,
uint256 _l2BatchNumber,
uint256 _l2MessageIndex,
uint16 _l2TxNumberInBatch,
bytes32[] calldata _merkleProof,
TxStatus _status
) public view returns (bool) {
return
proveL1ToL2TransactionStatusShared({
_chainId: s.chainId,
_l2TxHash: _l2TxHash,
_l2BatchNumber: _l2BatchNumber,
_l2MessageIndex: _l2MessageIndex,
_l2TxNumberInBatch: _l2TxNumberInBatch,
_merkleProof: _merkleProof,
_status: _status
});
}
/// @inheritdoc IMessageVerification
function proveL2LeafInclusionShared(
uint256 _chainId,
uint256 _blockOrBatchNumber,
uint256 _leafProofMask,
bytes32 _leaf,
bytes32[] calldata _proof
) public view virtual override returns (bool) {
if (s.chainId != _chainId) {
revert InvalidChainId();
}
return
super.proveL2LeafInclusionShared({
_chainId: _chainId,
_blockOrBatchNumber: _blockOrBatchNumber,
_leafProofMask: _leafProofMask,
_leaf: _leaf,
_proof: _proof
});
}
/// @inheritdoc IMailboxImpl
function proveL2LeafInclusion(
uint256 _batchNumber,
uint256 _leafProofMask,
bytes32 _leaf,
bytes32[] calldata _proof
) external view returns (bool) {
return
_proveL2LeafInclusion({
_chainId: s.chainId,
_blockOrBatchNumber: _batchNumber,
_leafProofMask: _leafProofMask,
_leaf: _leaf,
_proof: _proof
});
}
function _proveL2LeafInclusionRecursive(
uint256 _chainId,
uint256 _batchNumber,
uint256 _leafProofMask,
bytes32 _leaf,
bytes32[] calldata _proof,
uint256 _depth
) internal view override returns (bool) {
// No gas optimization here as the usage of the method is discouraged and the Bridgehub one should be used.
return
MessageVerification(address(IBridgehubBase(s.bridgehub).messageRoot()))
.proveL2LeafInclusionSharedRecursive({
_chainId: _chainId,
_blockOrBatchNumber: _batchNumber,
_leafProofMask: _leafProofMask,
_leaf: _leaf,
_proof: _proof,
_depth: _depth
});
}
/// @inheritdoc IMailboxImpl
function l2TransactionBaseCost(
uint256 _gasPrice,
uint256 _l2GasLimit,
uint256 _l2GasPerPubdataByteLimit
) public view returns (uint256) {
uint256 l2GasPrice = _deriveL2GasPrice(_gasPrice, _l2GasPerPubdataByteLimit);
return l2GasPrice * _l2GasLimit;
}
/// @inheritdoc IMailboxImpl
// slither-disable-next-line reentrancy-no-eth
function requestL2TransactionToGatewayMailboxWithBalanceChange(
uint256 _chainId,
bytes32 _canonicalTxHash,
uint64 _expirationTimestamp,
uint256 _baseTokenAmount,
bool _getBalanceChange
) public override onlyL1 returns (bytes32 canonicalTxHash) {
if (!IBridgehubBase(s.bridgehub).whitelistedSettlementLayers(s.chainId)) {
revert NotSettlementLayer();
}
if (IBridgehubBase(s.bridgehub).getZKChain(_chainId) != msg.sender) {
revert NotZKChain();
}
if (_expirationTimestamp != 0) {
revert ValueMismatch(0, _expirationTimestamp);
}
// Note during the upgrade to V31 no chain will be on GW.
bytes32 baseTokenAssetId = IBridgehubBase(s.bridgehub).baseTokenAssetId(_chainId);
if (_baseTokenAmount > 0 && baseTokenAssetId == bytes32(0)) {
revert InvalidChainId();
}
BalanceChange memory balanceChange;
if (_getBalanceChange) {
IL1AssetTracker assetTracker = IL1AssetTracker(s.assetTracker);
INativeTokenVaultBase nativeTokenVault = INativeTokenVaultBase(s.nativeTokenVault);
(bytes32 assetId, uint256 amount) = (assetTracker.consumeBalanceChange(s.chainId, _chainId));
uint256 tokenOriginChainId = nativeTokenVault.originChainId(assetId);
address originToken = nativeTokenVault.originToken(assetId);
balanceChange = BalanceChange({
version: BALANCE_CHANGE_VERSION,
baseTokenAssetId: baseTokenAssetId,
baseTokenAmount: _baseTokenAmount,
assetId: assetId,
amount: amount,
tokenOriginChainId: tokenOriginChainId,
originToken: originToken
});
} else {
balanceChange = BalanceChange({
version: BALANCE_CHANGE_VERSION,
baseTokenAssetId: baseTokenAssetId,
baseTokenAmount: _baseTokenAmount,
assetId: bytes32(0),
amount: 0,
tokenOriginChainId: 0,
originToken: address(0)
});
}
BridgehubL2TransactionRequest memory wrappedRequest = _wrapRequest({
_chainId: _chainId,
_canonicalTxHash: _canonicalTxHash,
_expirationTimestamp: _expirationTimestamp,
_balanceChange: balanceChange
});
canonicalTxHash = _requestL2TransactionFree(wrappedRequest);
}
/// @inheritdoc IMailboxImpl
function bridgehubRequestL2TransactionOnGateway(
bytes32 _canonicalTxHash,
uint64
) external override onlyBridgehubOrInteropCenter {
_writePriorityOpHash(_canonicalTxHash);
emit NewRelayedPriorityTransaction(_getTotalPriorityTxs(), _canonicalTxHash, 0);
emit NewPriorityRequestId(_getTotalPriorityTxs(), _canonicalTxHash);
}
function _wrapRequest(
uint256 _chainId,
bytes32 _canonicalTxHash,
uint64 _expirationTimestamp,
BalanceChange memory _balanceChange
) internal pure returns (BridgehubL2TransactionRequest memory) {
// solhint-disable-next-line func-named-parameters
bytes memory data = abi.encodeCall(
IInteropCenter.forwardTransactionOnGatewayWithBalanceChange,
(_chainId, _canonicalTxHash, _expirationTimestamp, _balanceChange)
);
return
BridgehubL2TransactionRequest({
/// There is no sender for the wrapping, we use a virtual address.
sender: SETTLEMENT_LAYER_RELAY_SENDER,
contractL2: L2_INTEROP_CENTER_ADDR,
mintValue: 0,
l2Value: 0,
// Very large amount
l2GasLimit: 72_000_000,
l2Calldata: data,
l2GasPerPubdataByteLimit: REQUIRED_L2_GAS_PRICE_PER_PUBDATA,
factoryDeps: new bytes[](0),
// Tx is free, no so refund recipient needed
refundRecipient: address(0)
});
}
/// @inheritdoc IMailboxImpl
function requestL2ServiceTransaction(
address _contractL2,
bytes calldata _l2Calldata
) external onlyServiceTransaction onlyL1 returns (bytes32 canonicalTxHash) {
canonicalTxHash = _requestL2TransactionFree(
BridgehubL2TransactionRequest({
sender: SERVICE_TRANSACTION_SENDER,
contractL2: _contractL2,
mintValue: 0,
l2Value: 0,
// Very large amount
l2GasLimit: 72_000_000,
l2Calldata: _l2Calldata,
l2GasPerPubdataByteLimit: REQUIRED_L2_GAS_PRICE_PER_PUBDATA,
factoryDeps: new bytes[](0),
// Tx is free, so no refund recipient needed
refundRecipient: address(0)
})
);
if (s.settlementLayer != address(0)) {
// slither-disable-next-line unused-return
IMailbox(s.settlementLayer).requestL2TransactionToGatewayMailboxWithBalanceChange({
_chainId: s.chainId,
_canonicalTxHash: canonicalTxHash,
_expirationTimestamp: 0,
_baseTokenAmount: 0,
_getBalanceChange: false
});
}
}
function _requestL2TransactionSender(
BridgehubL2TransactionRequest memory _request
) internal nonReentrant returns (bytes32 canonicalTxHash) {
// Check that the transaction is allowed by the filterer (if the filterer is set).
if (s.transactionFilterer != address(0)) {
if (
!ITransactionFilterer(s.transactionFilterer).isTransactionAllowed({
sender: _request.sender,
contractL2: _request.contractL2,
mintValue: _request.mintValue,
l2Value: _request.l2Value,
l2Calldata: _request.l2Calldata,
refundRecipient: _request.refundRecipient
})
) {
revert TransactionNotAllowed();
}
}
// Enforcing that `_request.l2GasPerPubdataByteLimit` equals to a certain constant number. This is needed
// to ensure that users do not get used to using "exotic" numbers for _request.l2GasPerPubdataByteLimit, e.g. 1-2, etc.
// VERY IMPORTANT: nobody should rely on this constant to be fixed and every contract should give their users the ability to provide the
// ability to provide `_request.l2GasPerPubdataByteLimit` for each independent transaction.
// CHANGING THIS CONSTANT SHOULD BE A CLIENT-SIDE CHANGE.
if (_request.l2GasPerPubdataByteLimit != REQUIRED_L2_GAS_PRICE_PER_PUBDATA) {
revert GasPerPubdataMismatch();
}
WritePriorityOpParams memory params;
params.request = _request;
canonicalTxHash = _requestL2Transaction(params);
}
function _requestL2Transaction(WritePriorityOpParams memory _params) internal returns (bytes32 canonicalTxHash) {
BridgehubL2TransactionRequest memory request = _params.request;
// For ZKsync OS factory deps will be ignored
if (request.factoryDeps.length > MAX_NEW_FACTORY_DEPS) {
revert TooManyFactoryDeps();
}
_params.txId = _nextPriorityTxId();
// Checking that the user provided enough ether to pay for the transaction.
_params.l2GasPrice = _deriveL2GasPrice(tx.gasprice, request.l2GasPerPubdataByteLimit);
uint256 baseCost = _params.l2GasPrice * request.l2GasLimit;
// User must pay the base cost for the L1 -> L2 transaction.
// L2 msg.value can be anything, but if it’s too low the tx will fail.
if (request.mintValue < baseCost) {
revert MsgValueTooLow(baseCost, request.mintValue);
}
bool is7702AccountRefundRecipient = false;
bool is7702AccountSender = false;
if (block.chainid == L1_CHAIN_ID) {
is7702AccountRefundRecipient = EIP_7702_CHECKER.isEIP7702Account(request.refundRecipient);
is7702AccountSender = EIP_7702_CHECKER.isEIP7702Account(request.sender); // This is not the same as refundRecipient, as it appears to be the AR during TwoBridges.
}
request.refundRecipient = AddressAliasHelper.actualRefundRecipientMailbox(
request.refundRecipient,
request.sender,
is7702AccountRefundRecipient,
is7702AccountSender
);
// Change the sender address if it is a smart contract to prevent address collision between L1 and L2.
// Please note, currently ZKsync address derivation is different from Ethereum one, but it may be changed in the future.
// solhint-disable avoid-tx-origin
// slither-disable-next-line tx-origin
if (request.sender != tx.origin && !is7702AccountSender) {
request.sender = AddressAliasHelper.applyL1ToL2Alias(request.sender);
}
L2CanonicalTransaction memory transaction;
(transaction, canonicalTxHash) = _validateTx(_params);
_writePriorityOp(transaction, _params.request.factoryDeps, canonicalTxHash);
if (s.settlementLayer != address(0)) {
address assetRouter = address(IBridgehubBase(s.bridgehub).assetRouter());
bool getBalanceChange = _params.request.sender == AddressAliasHelper.applyL1ToL2Alias(assetRouter);
// slither-disable-next-line unused-return
IMailbox(s.settlementLayer).requestL2TransactionToGatewayMailboxWithBalanceChange({
_chainId: s.chainId,
_canonicalTxHash: canonicalTxHash,
_expirationTimestamp: 0,
_baseTokenAmount: _params.request.mintValue,
_getBalanceChange: getBalanceChange
});
}
}
function _nextPriorityTxId() internal view returns (uint256) {
return s.priorityTree.getTotalPriorityTxs();
}
function _requestL2TransactionFree(
BridgehubL2TransactionRequest memory _request
) internal nonReentrant returns (bytes32 canonicalTxHash) {
WritePriorityOpParams memory params = WritePriorityOpParams({
request: _request,
txId: _nextPriorityTxId(),
l2GasPrice: 0
});
L2CanonicalTransaction memory transaction;
(transaction, canonicalTxHash) = _validateTx(params);
_writePriorityOp(transaction, params.request.factoryDeps, canonicalTxHash);
}
function _serializeL2Transaction(
WritePriorityOpParams memory _priorityOpParams
) internal view returns (L2CanonicalTransaction memory transaction) {
BridgehubL2TransactionRequest memory request = _priorityOpParams.request;
transaction = L2CanonicalTransaction({
txType: _getPriorityTxType(),
from: uint256(uint160(request.sender)),
to: uint256(uint160(request.contractL2)),
gasLimit: request.l2GasLimit,
gasPerPubdataByteLimit: request.l2GasPerPubdataByteLimit,
maxFeePerGas: uint256(_priorityOpParams.l2GasPrice),
maxPriorityFeePerGas: uint256(0),
paymaster: uint256(0),
// Note, that the priority operation id is used as "nonce" for L1->L2 transactions
nonce: uint256(_priorityOpParams.txId),
value: request.l2Value,
reserved: [request.mintValue, uint256(uint160(request.refundRecipient)), 0, 0],
data: request.l2Calldata,
signature: new bytes(0),
factoryDeps: L2ContractHelper.hashFactoryDeps(request.factoryDeps),
paymasterInput: new bytes(0),
reservedDynamic: new bytes(0)
});
}
function _validateTx(
WritePriorityOpParams memory _priorityOpParams
) internal view returns (L2CanonicalTransaction memory transaction, bytes32 canonicalTxHash) {
transaction = _serializeL2Transaction(_priorityOpParams);
bytes memory transactionEncoding = abi.encode(transaction);
// solhint-disable-next-line func-named-parameters
TransactionValidator.validateL1ToL2Transaction(
transaction,
transactionEncoding,
s.priorityTxMaxGasLimit,
s.feeParams.priorityTxMaxPubdata,
s.zksyncOS
);
canonicalTxHash = keccak256(transactionEncoding);
}
/// @notice Deposits are paused when a chain migrates to/from GW.
function depositsPaused() public view returns (bool) {
return
_isInDepositsPausedWindow(PAUSE_DEPOSITS_TIME_WINDOW_START) ||
(block.chainid == L1_CHAIN_ID &&
IL1ChainAssetHandler(CHAIN_ASSET_HANDLER).isMigrationInProgress(s.chainId));
}
/// @notice Stores a transaction record in storage & send event about that
function _writePriorityOp(
L2CanonicalTransaction memory _transaction,
bytes[] memory _factoryDeps,
bytes32 _canonicalTxHash
) internal {
_writePriorityOpHash(_canonicalTxHash);
/// We only check deposits paused on L1 to keep the GW and L1 Priority queues the same.
if (block.chainid == L1_CHAIN_ID) {
require(!depositsPaused(), DepositsPaused());
}
// Data that is needed for the operator to simulate priority queue offchain
// solhint-disable-next-line func-named-parameters
emit NewPriorityRequest(_transaction.nonce, _canonicalTxHash, 0, _transaction, _factoryDeps);
emit NewPriorityRequestId(_transaction.nonce, _canonicalTxHash);
}
// solhint-disable-next-line no-unused-vars
function _writePriorityOpHash(bytes32 _canonicalTxHash) internal {
s.priorityTree.push(_canonicalTxHash);
uint256 totalPriorityTxs = s.priorityTree.getTotalPriorityTxs();
uint256 newRequestId = totalPriorityTxs - 1;
s.priorityOpsRequestTimestamp[newRequestId] = block.timestamp;
}
///////////////////////////////////////////////////////
//////// Legacy Era functions
/// @inheritdoc IMailboxLegacy
function finalizeEthWithdrawal(
// TODO(EVM-1216): remove after the legacy mailbox.finalizeEthWithdrawal and mailbox.requestL2Transaction are deprecated.
uint256 _l2BatchNumber,
uint256 _l2MessageIndex,
uint16 _l2TxNumberInBatch,
bytes calldata _message,
bytes32[] calldata _merkleProof
) external nonReentrant onlyL1 {
if (s.chainId != ERA_CHAIN_ID) {
revert OnlyEraSupported();
}
address sharedBridge = address(IBridgehubBase(s.bridgehub).assetRouter());
IL1AssetRouter(sharedBridge).finalizeWithdrawal({
_chainId: ERA_CHAIN_ID,
_l2BatchNumber: _l2BatchNumber,
_l2MessageIndex: _l2MessageIndex,
_l2TxNumberInBatch: _l2TxNumberInBatch,
_message: _message,
_merkleProof: _merkleProof
});
}
/// @inheritdoc IMailboxLegacy
function requestL2Transaction(
// TODO(EVM-1216): remove after the legacy mailbox.finalizeEthWithdrawal and mailbox.requestL2Transaction are deprecated.
address _contractL2,
uint256 _l2Value,
bytes calldata _calldata,
uint256 _l2GasLimit,
uint256 _l2GasPerPubdataByteLimit,
bytes[] calldata _factoryDeps,
address _refundRecipient
) external payable onlyL1 returns (bytes32 canonicalTxHash) {
if (s.chainId != ERA_CHAIN_ID) {
revert OnlyEraSupported();
}
address assetRouter = address(IBridgehubBase(s.bridgehub).assetRouter());
require(msg.sender != assetRouter, NotAssetRouter(msg.sender, assetRouter));
canonicalTxHash = _requestL2TransactionSender(
BridgehubL2TransactionRequest({
sender: msg.sender,
contractL2: _contractL2,
mintValue: msg.value,
l2Value: _l2Value,
l2GasLimit: _l2GasLimit,
l2Calldata: _calldata,
l2GasPerPubdataByteLimit: _l2GasPerPubdataByteLimit,
factoryDeps: _factoryDeps,
refundRecipient: _refundRecipient
})
);
address sharedBridge = address(IBridgehubBase(s.bridgehub).assetRouter());
IAssetRouterShared(sharedBridge).bridgehubDepositBaseToken{value: msg.value}(
s.chainId,
s.baseTokenAssetId,
msg.sender,
msg.value
);
}
}
Compiler settingsShow
{
"viaIR": false,
"metadata": {
"appendCBOR": true,
"bytecodeHash": "ipfs",
"useLiteralContent": false
},
"optimizer": {
"runs": 9999999,
"enabled": true
},
"evmVersion": "prague",
"remappings": [
"@ensdomains/=node_modules/@ensdomains/",
"ds-test/=lib/forge-std/lib/ds-test/src/",
"eth-gas-reporter/=node_modules/eth-gas-reporter/",
"forge-std/=lib/forge-std/src/",
"hardhat/=node_modules/hardhat/",
"murky/=lib/murky/src/",
"foundry-test/=test/foundry/",
"l2-contracts/=../l2-contracts/contracts/",
"system-contracts/=../system-contracts/",
"@openzeppelin/contracts-v4/=lib/openzeppelin-contracts-v4/contracts/",
"@openzeppelin/contracts-upgradeable-v4/=lib/openzeppelin-contracts-upgradeable-v4/contracts/",
"test-utils/=test/foundry/l1/integration/utils/",
"erc4626-tests/=lib/openzeppelin-contracts-upgradeable-v4/lib/erc4626-tests/",
"openzeppelin-contracts-upgradeable-v4/=lib/openzeppelin-contracts-upgradeable-v4/",
"openzeppelin-contracts-v4/=lib/openzeppelin-contracts-v4/",
"openzeppelin-contracts/=lib/murky/lib/openzeppelin-contracts/"
]
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.