ETH Price: $2,435.59 (+1.40%)

Contract

0x3203E813930bD710043c1d899fE38dD359307352
 

Overview

ETH Balance

0 ETH

Eth Value

$0.00

Multichain Info

No addresses found
Transaction Hash
Method
Block
From
To
0x60a03461195749592024-04-03 11:31:11191 days ago1712143871IN
 Create: L1ERC20Bridge
0 ETH0.0428898824.68988525

View more zero value Internal Transactions in Advanced View mode

Advanced mode:
Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
L1ERC20Bridge

Compiler Version
v0.8.18+commit.87f61d96

Optimization Enabled:
Yes with 200 runs

Other Settings:
default evmVersion
File 1 of 19 : L1ERC20Bridge.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import {IERC20Metadata} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";

import {IL1BridgeLegacy} from "./interfaces/IL1BridgeLegacy.sol";
import {IL1Bridge} from "./interfaces/IL1Bridge.sol";
import {IL2Bridge} from "./interfaces/IL2Bridge.sol";
import {IL2ERC20Bridge} from "./interfaces/IL2ERC20Bridge.sol";

import {BridgeInitializationHelper} from "./libraries/BridgeInitializationHelper.sol";

import {IMailbox, TxStatus} from "../zksync/interfaces/IMailbox.sol";
import {L2Message} from "../zksync/Storage.sol";
import {UnsafeBytes} from "../common/libraries/UnsafeBytes.sol";
import {L2ContractHelper} from "../common/libraries/L2ContractHelper.sol";
import {ReentrancyGuard} from "../common/ReentrancyGuard.sol";
import {AddressAliasHelper} from "../vendor/AddressAliasHelper.sol";

/// @author Matter Labs
/// @custom:security-contact [email protected]
/// @notice Smart contract that allows depositing ERC20 tokens from Ethereum to zkSync Era
/// @dev It is standard implementation of ERC20 Bridge that can be used as a reference
/// for any other custom token bridges.
contract L1ERC20Bridge is IL1Bridge, IL1BridgeLegacy, ReentrancyGuard {
    using SafeERC20 for IERC20;

    /// @dev zkSync smart contract that is used to operate with L2 via asynchronous L2 <-> L1 communication
    IMailbox internal immutable zkSync;

    /// @dev A mapping L2 batch number => message number => flag
    /// @dev Used to indicate that zkSync L2 -> L1 message was already processed
    mapping(uint256 l2BatchNumber => mapping(uint256 l2ToL1MessageNumber => bool isFinalized))
        public isWithdrawalFinalized;

    /// @dev A mapping account => L1 token address => L2 deposit transaction hash => amount
    /// @dev Used for saving the number of deposited funds, to claim them in case the deposit transaction will fail
    mapping(address account => mapping(address l1Token => mapping(bytes32 depositL2TxHash => uint256 amount)))
        internal depositAmount;

    /// @dev The address of deployed L2 bridge counterpart
    address public l2Bridge;

    /// @dev The address that acts as a beacon for L2 tokens
    address public l2TokenBeacon;

    /// @dev The bytecode hash of the L2 token contract
    bytes32 public l2TokenProxyBytecodeHash;

    mapping(address => uint256) private __DEPRECATED_lastWithdrawalLimitReset;

    /// @dev A mapping L1 token address => the accumulated withdrawn amount during the withdrawal limit window
    mapping(address => uint256) private __DEPRECATED_withdrawnAmountInWindow;

    /// @dev The accumulated deposited amount per user.
    /// @dev A mapping L1 token address => user address => the total deposited amount by the user
    mapping(address => mapping(address => uint256)) private __DEPRECATED_totalDepositedAmountPerUser;

    /// @dev Contract is expected to be used as proxy implementation.
    /// @dev Initialize the implementation to prevent Parity hack.
    constructor(IMailbox _zkSync) reentrancyGuardInitializer {
        zkSync = _zkSync;
    }

    /// @dev Initializes a contract bridge for later use. Expected to be used in the proxy
    /// @dev During initialization deploys L2 bridge counterpart as well as provides some factory deps for it
    /// @param _factoryDeps A list of raw bytecodes that are needed for deployment of the L2 bridge
    /// @notice _factoryDeps[0] == a raw bytecode of L2 bridge implementation
    /// @notice _factoryDeps[1] == a raw bytecode of proxy that is used as L2 bridge
    /// @notice _factoryDeps[2] == a raw bytecode of token proxy
    /// @param _factoryDepByteCodeHashes A list of raw bytecode sha256 hashes that are needed for deployment of the L2 bridge
    /// @param _l2TokenBeacon Pre-calculated address of the L2 token upgradeable beacon
    /// @notice At the time of the function call, it is not yet deployed in L2, but knowledge of its address
    /// @notice is necessary for determining L2 token address by L1 address, see `l2TokenAddress(address)` function
    /// @param _governor Address which can change L2 token implementation and upgrade the bridge
    /// @param _deployBridgeImplementationFee How much of the sent value should be allocated to deploying the L2 bridge
    /// implementation
    /// @param _deployBridgeProxyFee How much of the sent value should be allocated to deploying the L2 bridge proxy
    function initialize(
        bytes[] calldata _factoryDeps,
        bytes32[] calldata _factoryDepByteCodeHashes,
        address _l2TokenBeacon,
        address _governor,
        uint256 _deployBridgeImplementationFee,
        uint256 _deployBridgeProxyFee
    ) external payable reentrancyGuardInitializer {
        require(_l2TokenBeacon != address(0), "nf");
        require(_governor != address(0), "nh");
        // We are expecting to see the exact three bytecodes that are needed to initialize the bridge
        require(_factoryDeps.length == 3, "mk");
        require(_factoryDeps.length == _factoryDepByteCodeHashes.length, "mg");
        // The caller miscalculated deploy transactions fees
        require(msg.value == _deployBridgeImplementationFee + _deployBridgeProxyFee, "fee");
        l2TokenProxyBytecodeHash = L2ContractHelper.hashL2Bytecode(
            _factoryDeps[2].length,
            _factoryDepByteCodeHashes[2]
        );
        l2TokenBeacon = _l2TokenBeacon;

        bytes32 l2BridgeImplementationBytecodeHash = L2ContractHelper.hashL2Bytecode(
            _factoryDeps[0].length,
            _factoryDepByteCodeHashes[0]
        );
        bytes32 l2BridgeProxyBytecodeHash = L2ContractHelper.hashL2Bytecode(
            _factoryDeps[1].length,
            _factoryDepByteCodeHashes[1]
        );

        // Deploy L2 bridge implementation contract
        address bridgeImplementationAddr = BridgeInitializationHelper.requestDeployTransaction(
            zkSync,
            _deployBridgeImplementationFee,
            l2BridgeImplementationBytecodeHash,
            "", // Empty constructor data
            _factoryDeps // All factory deps are needed for L2 bridge
        );

        // Prepare the proxy constructor data
        bytes memory l2BridgeProxyConstructorData;
        {
            // Data to be used in delegate call to initialize the proxy
            bytes memory proxyInitializationParams = abi.encodeCall(
                IL2ERC20Bridge.initialize,
                (address(this), l2TokenProxyBytecodeHash, _governor)
            );
            l2BridgeProxyConstructorData = abi.encode(bridgeImplementationAddr, _governor, proxyInitializationParams);
        }

        // Deploy L2 bridge proxy contract
        l2Bridge = BridgeInitializationHelper.requestDeployTransaction(
            zkSync,
            _deployBridgeProxyFee,
            l2BridgeProxyBytecodeHash,
            l2BridgeProxyConstructorData,
            // No factory deps are needed for the L2 bridge proxy, because it is already passed in previous step
            new bytes[](0)
        );
    }

    /// @notice Legacy deposit method with refunding the fee to the caller, use another `deposit` method instead.
    /// @dev Initiates a deposit by locking funds on the contract and sending the request
    /// of processing an L2 transaction where tokens would be minted.
    /// @dev If the token is bridged for the first time, the L2 token contract will be deployed. Note however, that the
    /// newly-deployed token does not support any custom logic, i.e. rebase tokens' functionality is not supported.
    /// @param _l2Receiver The account address that should receive funds on L2
    /// @param _l1Token The L1 token address which is deposited
    /// @param _amount The total amount of tokens to be bridged
    /// @param _l2TxGasLimit The L2 gas limit to be used in the corresponding L2 transaction
    /// @param _l2TxGasPerPubdataByte The gasPerPubdataByteLimit to be used in the corresponding L2 transaction
    /// @return l2TxHash The L2 transaction hash of deposit finalization
    /// NOTE: the function doesn't use `nonreentrant` modifier, because the inner method does.
    function deposit(
        address _l2Receiver,
        address _l1Token,
        uint256 _amount,
        uint256 _l2TxGasLimit,
        uint256 _l2TxGasPerPubdataByte
    ) external payable returns (bytes32 l2TxHash) {
        l2TxHash = deposit(_l2Receiver, _l1Token, _amount, _l2TxGasLimit, _l2TxGasPerPubdataByte, address(0));
    }

    /// @notice Initiates a deposit by locking funds on the contract and sending the request
    /// of processing an L2 transaction where tokens would be minted
    /// @dev If the token is bridged for the first time, the L2 token contract will be deployed. Note however, that the
    /// newly-deployed token does not support any custom logic, i.e. rebase tokens' functionality is not supported.
    /// @param _l2Receiver The account address that should receive funds on L2
    /// @param _l1Token The L1 token address which is deposited
    /// @param _amount The total amount of tokens to be bridged
    /// @param _l2TxGasLimit The L2 gas limit to be used in the corresponding L2 transaction
    /// @param _l2TxGasPerPubdataByte The gasPerPubdataByteLimit to be used in the corresponding L2 transaction
    /// @param _refundRecipient The address on L2 that will receive the refund for the transaction.
    /// @dev 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.
    /// @dev The address aliasing of L1 contracts as refund recipient on L2 is necessary to guarantee that the funds
    /// are controllable through the Mailbox, since the Mailbox applies address aliasing to the from address for the
    /// L2 tx 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.
    /// @return l2TxHash The L2 transaction hash of deposit finalization
    function deposit(
        address _l2Receiver,
        address _l1Token,
        uint256 _amount,
        uint256 _l2TxGasLimit,
        uint256 _l2TxGasPerPubdataByte,
        address _refundRecipient
    ) public payable nonReentrant returns (bytes32 l2TxHash) {
        l2TxHash = _deposit(
            _l2Receiver,
            _l1Token,
            _amount,
            _l2TxGasLimit,
            _l2TxGasPerPubdataByte,
            _refundRecipient,
            false
        );
    }

    /// @notice Initiates a deposit by locking funds on the contract and sending the request
    /// of processing an L2 transaction where merge tokens would be minted
    /// @dev If the token is bridged for the first time, the L2 token and merge token contract will be deployed. Note however, that the
    /// newly-deployed token does not support any custom logic, i.e. rebase tokens' functionality is not supported.
    /// @param _l2Receiver The account address that should receive funds on L2
    /// @param _l1Token The L1 token address which is deposited
    /// @param _amount The total amount of tokens to be bridged
    /// @param _l2TxGasLimit The L2 gas limit to be used in the corresponding L2 transaction
    /// @param _l2TxGasPerPubdataByte The gasPerPubdataByteLimit to be used in the corresponding L2 transaction
    /// @param _refundRecipient The address on L2 that will receive the refund for the transaction.
    /// @dev 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.
    /// @dev The address aliasing of L1 contracts as refund recipient on L2 is necessary to guarantee that the funds
    /// are controllable through the Mailbox, since the Mailbox applies address aliasing to the from address for the
    /// L2 tx 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.
    /// @return l2TxHash The L2 transaction hash of depositToMerge finalization
    function depositToMerge(
        address _l2Receiver,
        address _l1Token,
        uint256 _amount,
        uint256 _l2TxGasLimit,
        uint256 _l2TxGasPerPubdataByte,
        address _refundRecipient
    ) external payable nonReentrant returns (bytes32 l2TxHash) {
        l2TxHash = _deposit(
            _l2Receiver,
            _l1Token,
            _amount,
            _l2TxGasLimit,
            _l2TxGasPerPubdataByte,
            _refundRecipient,
            true
        );
    }

    function _deposit(
        address _l2Receiver,
        address _l1Token,
        uint256 _amount,
        uint256 _l2TxGasLimit,
        uint256 _l2TxGasPerPubdataByte,
        address _refundRecipient,
        bool _toMerge
    ) internal returns (bytes32 l2TxHash) {
        require(_amount != 0, "2T"); // empty deposit amount
        uint256 amount = _depositFunds(msg.sender, IERC20(_l1Token), _amount);
        require(amount == _amount, "1T"); // The token has non-standard transfer logic

        bytes memory l2TxCalldata = _getDepositL2Calldata(msg.sender, _l2Receiver, _l1Token, amount, _toMerge);
        // If the refund recipient is not specified, the refund will be sent to the sender of the transaction.
        // Otherwise, the refund will be sent to the specified address.
        // If the recipient is a contract on L1, the address alias will be applied.
        address refundRecipient = _refundRecipient;
        if (_refundRecipient == address(0)) {
            refundRecipient = msg.sender != tx.origin ? AddressAliasHelper.applyL1ToL2Alias(msg.sender) : msg.sender;
        }
        l2TxHash = zkSync.requestL2Transaction{value: msg.value}(
            l2Bridge,
            0, // L2 msg.value
            l2TxCalldata,
            _l2TxGasLimit,
            _l2TxGasPerPubdataByte,
            new bytes[](0),
            refundRecipient
        );

        // Save the deposited amount to claim funds on L1 if the deposit failed on L2
        depositAmount[msg.sender][_l1Token][l2TxHash] = amount;
        if (_toMerge) {
            emit DepositToMergeInitiated(l2TxHash, msg.sender, _l2Receiver, _l1Token, amount, _toMerge);
        } else {
            emit DepositInitiated(l2TxHash, msg.sender, _l2Receiver, _l1Token, amount);
        }
    }

    /// @dev Transfers tokens from the depositor address to the smart contract address
    /// @return The difference between the contract balance before and after the transferring of funds
    function _depositFunds(address _from, IERC20 _token, uint256 _amount) internal returns (uint256) {
        uint256 balanceBefore = _token.balanceOf(address(this));
        _token.safeTransferFrom(_from, address(this), _amount);
        uint256 balanceAfter = _token.balanceOf(address(this));

        return balanceAfter - balanceBefore;
    }

    /// @dev Generate a calldata for calling the deposit finalization on the L2 bridge contract
    function _getDepositL2Calldata(
        address _l1Sender,
        address _l2Receiver,
        address _l1Token,
        uint256 _amount,
        bool _toMerge
    ) internal view returns (bytes memory txCalldata) {
        bytes memory gettersData = _getERC20Getters(_l1Token);
        if (_toMerge) {
            txCalldata = abi.encodeCall(
                IL2Bridge.finalizeDepositToMerge,
                (_l1Sender, _l2Receiver, _l1Token, _amount, gettersData)
            );
        } else {
            txCalldata = abi.encodeCall(
                IL2Bridge.finalizeDeposit,
                (_l1Sender, _l2Receiver, _l1Token, _amount, gettersData)
            );
        }
    }

    /// @dev Receives and parses (name, symbol, decimals) from the token contract
    function _getERC20Getters(address _token) internal view returns (bytes memory data) {
        (, bytes memory data1) = _token.staticcall(abi.encodeCall(IERC20Metadata.name, ()));
        (, bytes memory data2) = _token.staticcall(abi.encodeCall(IERC20Metadata.symbol, ()));
        (, bytes memory data3) = _token.staticcall(abi.encodeCall(IERC20Metadata.decimals, ()));
        data = abi.encode(data1, data2, data3);
    }

    /// @dev Withdraw funds from the initiated deposit, that failed when finalizing on L2
    /// @param _depositSender The address of the deposit initiator
    /// @param _l1Token The address of the deposited L1 ERC20 token
    /// @param _l2TxHash The L2 transaction hash of the failed deposit finalization
    /// @param _l2BatchNumber The L2 batch number where the deposit finalization was processed
    /// @param _l2MessageIndex The position in the L2 logs Merkle tree of the l2Log that was sent with the message
    /// @param _l2TxNumberInBatch The L2 transaction number in a batch, in which the log was sent
    /// @param _merkleProof The Merkle proof of the processing L1 -> L2 transaction with deposit finalization
    function claimFailedDeposit(
        address _depositSender,
        address _l1Token,
        bytes32 _l2TxHash,
        uint256 _l2BatchNumber,
        uint256 _l2MessageIndex,
        uint16 _l2TxNumberInBatch,
        bytes32[] calldata _merkleProof
    ) external nonReentrant {
        bool proofValid = zkSync.proveL1ToL2TransactionStatus(
            _l2TxHash,
            _l2BatchNumber,
            _l2MessageIndex,
            _l2TxNumberInBatch,
            _merkleProof,
            TxStatus.Failure
        );
        require(proofValid, "yn");

        uint256 amount = depositAmount[_depositSender][_l1Token][_l2TxHash];
        require(amount > 0, "y1");

        delete depositAmount[_depositSender][_l1Token][_l2TxHash];
        // Withdraw funds
        IERC20(_l1Token).safeTransfer(_depositSender, amount);

        emit ClaimedFailedDeposit(_depositSender, _l1Token, amount);
    }

    /// @notice Finalize the withdrawal and release funds
    /// @param _l2BatchNumber The L2 batch number where the withdrawal was processed
    /// @param _l2MessageIndex The position in the L2 logs Merkle tree of the l2Log that was sent with the message
    /// @param _l2TxNumberInBatch The L2 transaction number in the batch, in which the log was sent
    /// @param _message The L2 withdraw data, stored in an L2 -> L1 message
    /// @param _merkleProof The Merkle proof of the inclusion L2 -> L1 message about withdrawal initialization
    function finalizeWithdrawal(
        uint256 _l2BatchNumber,
        uint256 _l2MessageIndex,
        uint16 _l2TxNumberInBatch,
        bytes calldata _message,
        bytes32[] calldata _merkleProof
    ) external nonReentrant {
        require(!isWithdrawalFinalized[_l2BatchNumber][_l2MessageIndex], "pw");

        L2Message memory l2ToL1Message = L2Message({
            txNumberInBatch: _l2TxNumberInBatch,
            sender: l2Bridge,
            data: _message
        });

        (address l1Receiver, address l1Token, uint256 amount) = _parseL2WithdrawalMessage(l2ToL1Message.data);
        // Preventing the stack too deep error
        {
            bool success = zkSync.proveL2MessageInclusion(_l2BatchNumber, _l2MessageIndex, l2ToL1Message, _merkleProof);
            require(success, "nq");
        }

        isWithdrawalFinalized[_l2BatchNumber][_l2MessageIndex] = true;
        // Withdraw funds
        IERC20(l1Token).safeTransfer(l1Receiver, amount);

        emit WithdrawalFinalized(l1Receiver, l1Token, amount);
    }

    /// @dev Decode the withdraw message that came from L2
    function _parseL2WithdrawalMessage(
        bytes memory _l2ToL1message
    ) internal pure returns (address l1Receiver, address l1Token, uint256 amount) {
        // Check that the message length is correct.
        // It should be equal to the length of the function signature + address + address + uint256 = 4 + 20 + 20 + 32 =
        // 76 (bytes).
        require(_l2ToL1message.length == 76, "kk");

        (uint32 functionSignature, uint256 offset) = UnsafeBytes.readUint32(_l2ToL1message, 0);
        require(bytes4(functionSignature) == this.finalizeWithdrawal.selector, "nt");

        (l1Receiver, offset) = UnsafeBytes.readAddress(_l2ToL1message, offset);
        (l1Token, offset) = UnsafeBytes.readAddress(_l2ToL1message, offset);
        (amount, offset) = UnsafeBytes.readUint256(_l2ToL1message, offset);
    }

    /// @return The L2 token address that would be minted for deposit of the given L1 token
    function l2TokenAddress(address _l1Token) public view returns (address) {
        bytes32 constructorInputHash = keccak256(abi.encode(l2TokenBeacon, ""));
        bytes32 salt = bytes32(uint256(uint160(_l1Token)));

        return L2ContractHelper.computeCreate2Address(l2Bridge, salt, l2TokenProxyBytecodeHash, constructorInputHash);
    }
}

File 2 of 19 : IERC20Metadata.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol)

pragma solidity ^0.8.0;

import "../IERC20.sol";

/**
 * @dev Interface for the optional metadata functions from the ERC20 standard.
 *
 * _Available since v4.1._
 */
interface IERC20Metadata is IERC20 {
    /**
     * @dev Returns the name of the token.
     */
    function name() external view returns (string memory);

    /**
     * @dev Returns the symbol of the token.
     */
    function symbol() external view returns (string memory);

    /**
     * @dev Returns the decimals places of the token.
     */
    function decimals() external view returns (uint8);
}

File 3 of 19 : IERC20Permit.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.4) (token/ERC20/extensions/IERC20Permit.sol)

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
 * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
 *
 * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
 * presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't
 * need to send a transaction, and thus is not required to hold Ether at all.
 *
 * ==== Security Considerations
 *
 * There are two important considerations concerning the use of `permit`. The first is that a valid permit signature
 * expresses an allowance, and it should not be assumed to convey additional meaning. In particular, it should not be
 * considered as an intention to spend the allowance in any specific way. The second is that because permits have
 * built-in replay protection and can be submitted by anyone, they can be frontrun. A protocol that uses permits should
 * take this into consideration and allow a `permit` call to fail. Combining these two aspects, a pattern that may be
 * generally recommended is:
 *
 * ```solidity
 * function doThingWithPermit(..., uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) public {
 *     try token.permit(msg.sender, address(this), value, deadline, v, r, s) {} catch {}
 *     doThing(..., value);
 * }
 *
 * function doThing(..., uint256 value) public {
 *     token.safeTransferFrom(msg.sender, address(this), value);
 *     ...
 * }
 * ```
 *
 * Observe that: 1) `msg.sender` is used as the owner, leaving no ambiguity as to the signer intent, and 2) the use of
 * `try/catch` allows the permit to fail and makes the code tolerant to frontrunning. (See also
 * {SafeERC20-safeTransferFrom}).
 *
 * Additionally, note that smart contract wallets (such as Argent or Safe) are not able to produce permit signatures, so
 * contracts should have entry points that don't rely on permit.
 */
interface IERC20Permit {
    /**
     * @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,
     * given ``owner``'s signed approval.
     *
     * IMPORTANT: The same issues {IERC20-approve} has related to transaction
     * ordering also apply here.
     *
     * Emits an {Approval} event.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     * - `deadline` must be a timestamp in the future.
     * - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`
     * over the EIP712-formatted function arguments.
     * - the signature must use ``owner``'s current nonce (see {nonces}).
     *
     * For more information on the signature format, see the
     * https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP
     * section].
     *
     * CAUTION: See Security Considerations above.
     */
    function permit(
        address owner,
        address spender,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) external;

    /**
     * @dev Returns the current nonce for `owner`. This value must be
     * included whenever a signature is generated for {permit}.
     *
     * Every successful call to {permit} increases ``owner``'s nonce by one. This
     * prevents a signature from being used multiple times.
     */
    function nonces(address owner) external view returns (uint256);

    /**
     * @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.
     */
    // solhint-disable-next-line func-name-mixedcase
    function DOMAIN_SEPARATOR() external view returns (bytes32);
}

File 4 of 19 : IERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/IERC20.sol)

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC20 standard as defined in the EIP.
 */
interface IERC20 {
    /**
     * @dev Emitted when `value` tokens are moved from one account (`from`) to
     * another (`to`).
     *
     * Note that `value` may be zero.
     */
    event Transfer(address indexed from, address indexed to, uint256 value);

    /**
     * @dev Emitted when the allowance of a `spender` for an `owner` is set by
     * a call to {approve}. `value` is the new allowance.
     */
    event Approval(address indexed owner, address indexed spender, uint256 value);

    /**
     * @dev Returns the amount of tokens in existence.
     */
    function totalSupply() external view returns (uint256);

    /**
     * @dev Returns the amount of tokens owned by `account`.
     */
    function balanceOf(address account) external view returns (uint256);

    /**
     * @dev Moves `amount` tokens from the caller's account to `to`.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transfer(address to, uint256 amount) external returns (bool);

    /**
     * @dev Returns the remaining number of tokens that `spender` will be
     * allowed to spend on behalf of `owner` through {transferFrom}. This is
     * zero by default.
     *
     * This value changes when {approve} or {transferFrom} are called.
     */
    function allowance(address owner, address spender) external view returns (uint256);

    /**
     * @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * IMPORTANT: Beware that changing an allowance with this method brings the risk
     * that someone may use both the old and the new allowance by unfortunate
     * transaction ordering. One possible solution to mitigate this race
     * condition is to first reduce the spender's allowance to 0 and set the
     * desired value afterwards:
     * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
     *
     * Emits an {Approval} event.
     */
    function approve(address spender, uint256 amount) external returns (bool);

    /**
     * @dev Moves `amount` tokens from `from` to `to` using the
     * allowance mechanism. `amount` is then deducted from the caller's
     * allowance.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transferFrom(address from, address to, uint256 amount) external returns (bool);
}

File 5 of 19 : SafeERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.3) (token/ERC20/utils/SafeERC20.sol)

pragma solidity ^0.8.0;

import "../IERC20.sol";
import "../extensions/IERC20Permit.sol";
import "../../../utils/Address.sol";

/**
 * @title SafeERC20
 * @dev Wrappers around ERC20 operations that throw on failure (when the token
 * contract returns false). Tokens that return no value (and instead revert or
 * throw on failure) are also supported, non-reverting calls are assumed to be
 * successful.
 * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
 * which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
 */
library SafeERC20 {
    using Address for address;

    /**
     * @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,
     * non-reverting calls are assumed to be successful.
     */
    function safeTransfer(IERC20 token, address to, uint256 value) internal {
        _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
    }

    /**
     * @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the
     * calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.
     */
    function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
        _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
    }

    /**
     * @dev Deprecated. This function has issues similar to the ones found in
     * {IERC20-approve}, and its usage is discouraged.
     *
     * Whenever possible, use {safeIncreaseAllowance} and
     * {safeDecreaseAllowance} instead.
     */
    function safeApprove(IERC20 token, address spender, uint256 value) internal {
        // safeApprove should only be called when setting an initial allowance,
        // or when resetting it to zero. To increase and decrease it, use
        // 'safeIncreaseAllowance' and 'safeDecreaseAllowance'
        require(
            (value == 0) || (token.allowance(address(this), spender) == 0),
            "SafeERC20: approve from non-zero to non-zero allowance"
        );
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
    }

    /**
     * @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
     * non-reverting calls are assumed to be successful.
     */
    function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
        uint256 oldAllowance = token.allowance(address(this), spender);
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance + value));
    }

    /**
     * @dev Decrease the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
     * non-reverting calls are assumed to be successful.
     */
    function safeDecreaseAllowance(IERC20 token, address spender, uint256 value) internal {
        unchecked {
            uint256 oldAllowance = token.allowance(address(this), spender);
            require(oldAllowance >= value, "SafeERC20: decreased allowance below zero");
            _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance - value));
        }
    }

    /**
     * @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,
     * non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval
     * to be set to zero before setting it to a non-zero value, such as USDT.
     */
    function forceApprove(IERC20 token, address spender, uint256 value) internal {
        bytes memory approvalCall = abi.encodeWithSelector(token.approve.selector, spender, value);

        if (!_callOptionalReturnBool(token, approvalCall)) {
            _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, 0));
            _callOptionalReturn(token, approvalCall);
        }
    }

    /**
     * @dev Use a ERC-2612 signature to set the `owner` approval toward `spender` on `token`.
     * Revert on invalid signature.
     */
    function safePermit(
        IERC20Permit token,
        address owner,
        address spender,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) internal {
        uint256 nonceBefore = token.nonces(owner);
        token.permit(owner, spender, value, deadline, v, r, s);
        uint256 nonceAfter = token.nonces(owner);
        require(nonceAfter == nonceBefore + 1, "SafeERC20: permit did not succeed");
    }

    /**
     * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
     * on the return value: the return value is optional (but if data is returned, it must not be false).
     * @param token The token targeted by the call.
     * @param data The call data (encoded using abi.encode or one of its variants).
     */
    function _callOptionalReturn(IERC20 token, bytes memory data) private {
        // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
        // we're implementing it ourselves. We use {Address-functionCall} to perform this call, which verifies that
        // the target address contains contract code and also asserts for success in the low-level call.

        bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed");
        require(returndata.length == 0 || abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
    }

    /**
     * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
     * on the return value: the return value is optional (but if data is returned, it must not be false).
     * @param token The token targeted by the call.
     * @param data The call data (encoded using abi.encode or one of its variants).
     *
     * This is a variant of {_callOptionalReturn} that silents catches all reverts and returns a bool instead.
     */
    function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
        // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
        // we're implementing it ourselves. We cannot use {Address-functionCall} here since this should return false
        // and not revert is the subcall reverts.

        (bool success, bytes memory returndata) = address(token).call(data);
        return
            success && (returndata.length == 0 || abi.decode(returndata, (bool))) && Address.isContract(address(token));
    }
}

File 6 of 19 : Address.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/Address.sol)

pragma solidity ^0.8.1;

/**
 * @dev Collection of functions related to the address type
 */
library Address {
    /**
     * @dev Returns true if `account` is a contract.
     *
     * [IMPORTANT]
     * ====
     * It is unsafe to assume that an address for which this function returns
     * false is an externally-owned account (EOA) and not a contract.
     *
     * Among others, `isContract` will return false for the following
     * types of addresses:
     *
     *  - an externally-owned account
     *  - a contract in construction
     *  - an address where a contract will be created
     *  - an address where a contract lived, but was destroyed
     *
     * Furthermore, `isContract` will also return true if the target contract within
     * the same transaction is already scheduled for destruction by `SELFDESTRUCT`,
     * which only has an effect at the end of a transaction.
     * ====
     *
     * [IMPORTANT]
     * ====
     * You shouldn't rely on `isContract` to protect against flash loan attacks!
     *
     * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
     * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
     * constructor.
     * ====
     */
    function isContract(address account) internal view returns (bool) {
        // This method relies on extcodesize/address.code.length, which returns 0
        // for contracts in construction, since the code is only stored at the end
        // of the constructor execution.

        return account.code.length > 0;
    }

    /**
     * @dev Replacement for Solidity's `transfer`: sends `amount` wei to
     * `recipient`, forwarding all available gas and reverting on errors.
     *
     * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
     * of certain opcodes, possibly making contracts go over the 2300 gas limit
     * imposed by `transfer`, making them unable to receive funds via
     * `transfer`. {sendValue} removes this limitation.
     *
     * https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].
     *
     * IMPORTANT: because control is transferred to `recipient`, care must be
     * taken to not create reentrancy vulnerabilities. Consider using
     * {ReentrancyGuard} or the
     * https://solidity.readthedocs.io/en/v0.8.0/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
     */
    function sendValue(address payable recipient, uint256 amount) internal {
        require(address(this).balance >= amount, "Address: insufficient balance");

        (bool success, ) = recipient.call{value: amount}("");
        require(success, "Address: unable to send value, recipient may have reverted");
    }

    /**
     * @dev Performs a Solidity function call using a low level `call`. A
     * plain `call` is an unsafe replacement for a function call: use this
     * function instead.
     *
     * If `target` reverts with a revert reason, it is bubbled up by this
     * function (like regular Solidity function calls).
     *
     * Returns the raw returned data. To convert to the expected return value,
     * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
     *
     * Requirements:
     *
     * - `target` must be a contract.
     * - calling `target` with `data` must not revert.
     *
     * _Available since v3.1._
     */
    function functionCall(address target, bytes memory data) internal returns (bytes memory) {
        return functionCallWithValue(target, data, 0, "Address: low-level call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
     * `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    function functionCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal returns (bytes memory) {
        return functionCallWithValue(target, data, 0, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but also transferring `value` wei to `target`.
     *
     * Requirements:
     *
     * - the calling contract must have an ETH balance of at least `value`.
     * - the called Solidity function must be `payable`.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
        return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
    }

    /**
     * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
     * with `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(
        address target,
        bytes memory data,
        uint256 value,
        string memory errorMessage
    ) internal returns (bytes memory) {
        require(address(this).balance >= value, "Address: insufficient balance for call");
        (bool success, bytes memory returndata) = target.call{value: value}(data);
        return verifyCallResultFromTarget(target, success, returndata, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
        return functionStaticCall(target, data, "Address: low-level static call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal view returns (bytes memory) {
        (bool success, bytes memory returndata) = target.staticcall(data);
        return verifyCallResultFromTarget(target, success, returndata, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a delegate call.
     *
     * _Available since v3.4._
     */
    function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
        return functionDelegateCall(target, data, "Address: low-level delegate call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
     * but performing a delegate call.
     *
     * _Available since v3.4._
     */
    function functionDelegateCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal returns (bytes memory) {
        (bool success, bytes memory returndata) = target.delegatecall(data);
        return verifyCallResultFromTarget(target, success, returndata, errorMessage);
    }

    /**
     * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling
     * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.
     *
     * _Available since v4.8._
     */
    function verifyCallResultFromTarget(
        address target,
        bool success,
        bytes memory returndata,
        string memory errorMessage
    ) internal view returns (bytes memory) {
        if (success) {
            if (returndata.length == 0) {
                // only check isContract if the call was successful and the return data is empty
                // otherwise we already know that it was a contract
                require(isContract(target), "Address: call to non-contract");
            }
            return returndata;
        } else {
            _revert(returndata, errorMessage);
        }
    }

    /**
     * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the
     * revert reason or using the provided one.
     *
     * _Available since v4.3._
     */
    function verifyCallResult(
        bool success,
        bytes memory returndata,
        string memory errorMessage
    ) internal pure returns (bytes memory) {
        if (success) {
            return returndata;
        } else {
            _revert(returndata, errorMessage);
        }
    }

    function _revert(bytes memory returndata, string memory errorMessage) private pure {
        // Look for revert reason and bubble it up if present
        if (returndata.length > 0) {
            // The easiest way to bubble the revert reason is using memory via assembly
            /// @solidity memory-safe-assembly
            assembly {
                let returndata_size := mload(returndata)
                revert(add(32, returndata), returndata_size)
            }
        } else {
            revert(errorMessage);
        }
    }
}

File 7 of 19 : IL1Bridge.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

/// @title L1 Bridge contract interface
/// @author Matter Labs
/// @custom:security-contact [email protected]
interface IL1Bridge {
    event DepositInitiated(
        bytes32 indexed l2DepositTxHash,
        address indexed from,
        address indexed to,
        address l1Token,
        uint256 amount
    );

    event DepositToMergeInitiated(
        bytes32 indexed l2DepositTxHash,
        address indexed from,
        address indexed to,
        address l1Token,
        uint256 amount,
        bool toMerge
    );

    event WithdrawalFinalized(address indexed to, address indexed l1Token, uint256 amount);

    event ClaimedFailedDeposit(address indexed to, address indexed l1Token, uint256 amount);

    function isWithdrawalFinalized(uint256 _l2BatchNumber, uint256 _l2MessageIndex) external view returns (bool);

    function deposit(
        address _l2Receiver,
        address _l1Token,
        uint256 _amount,
        uint256 _l2TxGasLimit,
        uint256 _l2TxGasPerPubdataByte,
        address _refundRecipient
    ) external payable returns (bytes32 txHash);

    function depositToMerge(
        address _l2Receiver,
        address _l1Token,
        uint256 _amount,
        uint256 _l2TxGasLimit,
        uint256 _l2TxGasPerPubdataByte,
        address _refundRecipient
    ) external payable returns (bytes32 txHash);

    function claimFailedDeposit(
        address _depositSender,
        address _l1Token,
        bytes32 _l2TxHash,
        uint256 _l2BatchNumber,
        uint256 _l2MessageIndex,
        uint16 _l2TxNumberInBatch,
        bytes32[] calldata _merkleProof
    ) external;

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

    function l2TokenAddress(address _l1Token) external view returns (address);

    function l2Bridge() external view returns (address);
}

File 8 of 19 : IL1BridgeLegacy.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

/// @title L1 Bridge contract legacy interface
/// @author Matter Labs
/// @custom:security-contact [email protected]
interface IL1BridgeLegacy {
    function deposit(
        address _l2Receiver,
        address _l1Token,
        uint256 _amount,
        uint256 _l2TxGasLimit,
        uint256 _l2TxGasPerPubdataByte
    ) external payable returns (bytes32 txHash);
}

File 9 of 19 : IL2Bridge.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

/// @author Matter Labs
interface IL2Bridge {
    function finalizeDeposit(
        address _l1Sender,
        address _l2Receiver,
        address _l1Token,
        uint256 _amount,
        bytes calldata _data
    ) external payable;

    function finalizeDepositToMerge(
        address _l1Sender,
        address _l2Receiver,
        address _l1Token,
        uint256 _amount,
        bytes calldata _data
    ) external payable;

    function withdraw(address _l1Receiver, address _l2Token, uint256 _amount) external;

    function l1TokenAddress(address _l2Token) external view returns (address);

    function l2TokenAddress(address _l1Token) external view returns (address);

    function l1Bridge() external view returns (address);
}

File 10 of 19 : IL2ERC20Bridge.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

/// @author Matter Labs
interface IL2ERC20Bridge {
    function initialize(address _l1Bridge, bytes32 _l2TokenProxyBytecodeHash, address _governor) external;
}

File 11 of 19 : BridgeInitializationHelper.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import "../../zksync/interfaces/IMailbox.sol";
import "../../vendor/AddressAliasHelper.sol";
import "../../common/libraries/L2ContractHelper.sol";
import {L2_DEPLOYER_SYSTEM_CONTRACT_ADDR} from "../../common/L2ContractAddresses.sol";
import "../../common/interfaces/IL2ContractDeployer.sol";

/// @author Matter Labs
/// @custom:security-contact [email protected]
/// @dev A helper library for initializing L2 bridges in zkSync L2 network.
library BridgeInitializationHelper {
    /// @dev The L2 gas limit for requesting L1 -> L2 transaction of deploying L2 bridge instance.
    /// @dev It is big enough to deploy any contract, so we can use the same value for all bridges.
    /// NOTE: this constant will be accurately calculated in the future.
    uint256 constant DEPLOY_L2_BRIDGE_COUNTERPART_GAS_LIMIT = 10000000;

    /// @dev The default l2GasPricePerPubdata to be used in bridges.
    uint256 constant REQUIRED_L2_GAS_PRICE_PER_PUBDATA = 800;

    /// @notice Requests L2 transaction that will deploy a contract with a given bytecode hash and constructor data.
    /// NOTE: it is always used to deploy via create2 with ZERO salt
    /// @param _zkSync The address of the zkSync contract
    /// @param _deployTransactionFee The fee that will be paid for the L1 -> L2 transaction
    /// @param _bytecodeHash The hash of the bytecode of the contract to be deployed
    /// @param _constructorData The data to be passed to the contract constructor
    /// @param _factoryDeps A list of raw bytecodes that are needed for deployment
    function requestDeployTransaction(
        IMailbox _zkSync,
        uint256 _deployTransactionFee,
        bytes32 _bytecodeHash,
        bytes memory _constructorData,
        bytes[] memory _factoryDeps
    ) internal returns (address deployedAddress) {
        bytes memory deployCalldata = abi.encodeCall(
            IL2ContractDeployer.create2,
            (bytes32(0), _bytecodeHash, _constructorData)
        );
        _zkSync.requestL2Transaction{value: _deployTransactionFee}(
            L2_DEPLOYER_SYSTEM_CONTRACT_ADDR,
            0,
            deployCalldata,
            DEPLOY_L2_BRIDGE_COUNTERPART_GAS_LIMIT,
            REQUIRED_L2_GAS_PRICE_PER_PUBDATA,
            _factoryDeps,
            msg.sender
        );

        deployedAddress = L2ContractHelper.computeCreate2Address(
            // Apply the alias to the address of the bridge contract, to get the `msg.sender` in L2.
            AddressAliasHelper.applyL1ToL2Alias(address(this)),
            bytes32(0), // Zero salt
            _bytecodeHash,
            keccak256(_constructorData)
        );
    }
}

File 12 of 19 : IL2ContractDeployer.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

/**
 * @author Matter Labs
 * @notice System smart contract that is responsible for deploying other smart contracts on zkSync.
 */
interface IL2ContractDeployer {
    /// @notice A struct that describes a forced deployment on an address.
    /// @param bytecodeHash The bytecode hash to put on an address.
    /// @param newAddress The address on which to deploy the bytecodehash to.
    /// @param callConstructor Whether to run the constructor on the force deployment.
    /// @param value The `msg.value` with which to initialize a contract.
    /// @param input The constructor calldata.
    struct ForceDeployment {
        bytes32 bytecodeHash;
        address newAddress;
        bool callConstructor;
        uint256 value;
        bytes input;
    }

    /// @notice This method is to be used only during an upgrade to set bytecodes on specific addresses.
    function forceDeployOnAddresses(ForceDeployment[] calldata _deployParams) external;

    /// @notice Deploys a contract with similar address derivation rules to the EVM's `CREATE2` opcode.
    /// @param _salt The create2 salt.
    /// @param _bytecodeHash The correctly formatted hash of the bytecode.
    /// @param _input The constructor calldata.
    function create2(bytes32 _salt, bytes32 _bytecodeHash, bytes calldata _input) external;
}

File 13 of 19 : L2ContractAddresses.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

/// @dev The address of the L2 deployer system contract.
address constant L2_DEPLOYER_SYSTEM_CONTRACT_ADDR = address(0x8006);

/// @dev The special reserved L2 address. It is located in the system contracts space but doesn't have deployed
/// bytecode.
/// @dev The L2 deployer system contract allows changing bytecodes on any address if the `msg.sender` is this address.
/// @dev So, whenever the governor wants to redeploy system contracts, it just initiates the L1 upgrade call deployer
/// system contract
/// via the L1 -> L2 transaction with `sender == L2_FORCE_DEPLOYER_ADDR`. For more details see the
/// `diamond-initializers` contracts.
address constant L2_FORCE_DEPLOYER_ADDR = address(0x8007);

/// @dev The address of the special smart contract that can send arbitrary length message as an L2 log
address constant L2_TO_L1_MESSENGER_SYSTEM_CONTRACT_ADDR = address(0x8008);

/// @dev The formal address of the initial program of the system: the bootloader
address constant L2_BOOTLOADER_ADDRESS = address(0x8001);

/// @dev The address of the eth token system contract
address constant L2_ETH_TOKEN_SYSTEM_CONTRACT_ADDR = address(0x800a);

/// @dev The address of the known code storage system contract
address constant L2_KNOWN_CODE_STORAGE_SYSTEM_CONTRACT_ADDR = address(0x8004);

/// @dev The address of the context system contract
address constant L2_SYSTEM_CONTEXT_SYSTEM_CONTRACT_ADDR = address(0x800b);

File 14 of 19 : L2ContractHelper.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

/**
 * @author Matter Labs
 * @custom:security-contact [email protected]
 * @notice Helper library for working with L2 contracts on L1.
 */
library L2ContractHelper {
    /// @dev The prefix used to create CREATE2 addresses.
    bytes32 private constant CREATE2_PREFIX = keccak256("zksyncCreate2");

    /// @notice Validate the bytecode format and calculate its hash.
    /// @param _bytecodeLength The bytecode length.
    /// @param _bytecodeHash The bytecode hash.
    /// @return hashedBytecode The 32-byte hash of the bytecode.
    /// Note: The function reverts the execution if the bytecode has non expected format:
    /// - Bytecode bytes length is not a multiple of 32
    /// - Bytecode bytes length is not less than 2^21 bytes (2^16 words)
    /// - Bytecode words length is not odd
    function hashL2Bytecode(
        uint256 _bytecodeLength,
        bytes32 _bytecodeHash
    ) internal pure returns (bytes32 hashedBytecode) {
        // Note that the length of the bytecode must be provided in 32-byte words.
        require(_bytecodeLength % 32 == 0, "pq");

        uint256 bytecodeLenInWords = _bytecodeLength / 32;
        require(bytecodeLenInWords < 2 ** 16, "pp"); // bytecode length must be less than 2^16 words
        require(bytecodeLenInWords % 2 == 1, "ps"); // bytecode length in words must be odd
        hashedBytecode = _bytecodeHash & 0x00000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF;
        // Setting the version of the hash
        hashedBytecode = (hashedBytecode | bytes32(uint256(1 << 248)));
        // Setting the length
        hashedBytecode = hashedBytecode | bytes32(bytecodeLenInWords << 224);
    }

    /// @notice Validates the format of the given bytecode hash.
    /// @dev Due to the specification of the L2 bytecode hash, not every 32 bytes could be a legit bytecode hash.
    /// @dev The function reverts on invalid bytecode hash formam.
    /// @param _bytecodeHash The hash of the bytecode to validate.
    function validateBytecodeHash(bytes32 _bytecodeHash) internal pure {
        uint8 version = uint8(_bytecodeHash[0]);
        require(version == 1 && _bytecodeHash[1] == bytes1(0), "zf"); // Incorrectly formatted bytecodeHash

        require(_bytecodeLen(_bytecodeHash) % 2 == 1, "uy"); // Code length in words must be odd
    }

    /// @notice Returns the length of the bytecode associated with the given hash.
    /// @param _bytecodeHash The hash of the bytecode.
    /// @return codeLengthInWords The length of the bytecode in words.
    function _bytecodeLen(bytes32 _bytecodeHash) private pure returns (uint256 codeLengthInWords) {
        codeLengthInWords = uint256(uint8(_bytecodeHash[2])) * 256 + uint256(uint8(_bytecodeHash[3]));
    }

    /// @notice Computes the create2 address for a Layer 2 contract.
    /// @param _sender The address of the sender.
    /// @param _salt The salt value to use in the create2 address computation.
    /// @param _bytecodeHash The contract bytecode hash.
    /// @param _constructorInputHash The hash of the constructor input data.
    /// @return The create2 address of the contract.
    /// NOTE: L2 create2 derivation is different from L1 derivation!
    function computeCreate2Address(
        address _sender,
        bytes32 _salt,
        bytes32 _bytecodeHash,
        bytes32 _constructorInputHash
    ) internal pure returns (address) {
        bytes32 senderBytes = bytes32(uint256(uint160(_sender)));
        bytes32 data = keccak256(
            bytes.concat(CREATE2_PREFIX, senderBytes, _salt, _bytecodeHash, _constructorInputHash)
        );

        return address(uint160(uint256(data)));
    }
}

File 15 of 19 : UnsafeBytes.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

/**
 * @author Matter Labs
 * @custom:security-contact [email protected]
 * @dev The library provides a set of functions that help read data from an "abi.encodePacked" byte array.
 * @dev Each of the functions accepts the `bytes memory` and the offset where data should be read and returns a value of a certain type.
 *
 * @dev WARNING!
 * 1) Functions don't check the length of the bytes array, so it can go out of bounds.
 * The user of the library must check for bytes length before using any functions from the library!
 *
 * 2) Read variables are not cleaned up - https://docs.soliditylang.org/en/v0.8.16/internals/variable_cleanup.html.
 * Using data in inline assembly can lead to unexpected behavior!
 */
library UnsafeBytes {
    function readUint32(bytes memory _bytes, uint256 _start) internal pure returns (uint32 result, uint256 offset) {
        assembly {
            offset := add(_start, 4)
            result := mload(add(_bytes, offset))
        }
    }

    function readAddress(bytes memory _bytes, uint256 _start) internal pure returns (address result, uint256 offset) {
        assembly {
            offset := add(_start, 20)
            result := mload(add(_bytes, offset))
        }
    }

    function readUint256(bytes memory _bytes, uint256 _start) internal pure returns (uint256 result, uint256 offset) {
        assembly {
            offset := add(_start, 32)
            result := mload(add(_bytes, offset))
        }
    }

    function readBytes32(bytes memory _bytes, uint256 _start) internal pure returns (bytes32 result, uint256 offset) {
        assembly {
            offset := add(_start, 32)
            result := mload(add(_bytes, offset))
        }
    }

    // Original source code: https://github.com/GNSPS/solidity-bytes-utils/blob/master/contracts/BytesLib.sol#L228
    // Get slice from bytes arrays
    // Returns the newly created 'bytes memory'
    // NOTE: theoretically possible overflow of (_start + _length)
    function slice(bytes memory _bytes, uint256 _start, uint256 _length) internal pure returns (bytes memory) {
        require(_bytes.length >= (_start + _length), "Z"); // bytes length is less then start byte + length bytes

        bytes memory tempBytes = new bytes(_length);

        if (_length != 0) {
            assembly {
                let slice_curr := add(tempBytes, 0x20)
                let slice_end := add(slice_curr, _length)

                for {
                    let array_current := add(_bytes, add(_start, 0x20))
                } lt(slice_curr, slice_end) {
                    slice_curr := add(slice_curr, 0x20)
                    array_current := add(array_current, 0x20)
                } {
                    mstore(slice_curr, mload(array_current))
                }
            }
        }

        return tempBytes;
    }
}

File 16 of 19 : ReentrancyGuard.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

/**
 * @custom:security-contact [email protected]
 * @dev Contract module that helps prevent reentrant calls to a function.
 *
 * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
 * available, which can be applied to functions to make sure there are no nested
 * (reentrant) calls to them.
 *
 * Note that because there is a single `nonReentrant` guard, functions marked as
 * `nonReentrant` may not call one another. This can be worked around by making
 * those functions `private`, and then adding `external` `nonReentrant` entry
 * points to them.
 *
 * TIP: If you would like to learn more about reentrancy and alternative ways
 * to protect against it, check out our blog post
 * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
 *
 * _Since v2.5.0:_ this module is now much more gas efficient, given net gas
 * metering changes introduced in the Istanbul hardfork.
 */
abstract contract ReentrancyGuard {
    /// @dev Address of lock flag variable.
    /// @dev Flag is placed at random memory location to not interfere with Storage contract.
    // keccak256("ReentrancyGuard") - 1;
    uint256 private constant LOCK_FLAG_ADDRESS = 0x8e94fed44239eb2314ab7a406345e6c5a8f0ccedf3b600de3d004e672c33abf4;

    // solhint-disable-next-line max-line-length
    // https://github.com/OpenZeppelin/openzeppelin-contracts/blob/566a774222707e424896c0c390a84dc3c13bdcb2/contracts/security/ReentrancyGuard.sol
    // The values being non-zero value makes deployment a bit more expensive,
    // but in exchange the refund on every call to nonReentrant will be lower in
    // amount. Since refunds are capped to a percentage of the total
    // transaction's gas, it is best to keep them low in cases like this one, to
    // increase the likelihood of the full refund coming into effect.
    uint256 private constant _NOT_ENTERED = 1;
    uint256 private constant _ENTERED = 2;

    modifier reentrancyGuardInitializer() {
        _initializeReentrancyGuard();
        _;
    }

    function _initializeReentrancyGuard() private {
        uint256 lockSlotOldValue;

        // Storing an initial non-zero value makes deployment a bit more
        // expensive but in exchange every call to nonReentrant
        // will be cheaper.
        assembly {
            lockSlotOldValue := sload(LOCK_FLAG_ADDRESS)
            sstore(LOCK_FLAG_ADDRESS, _NOT_ENTERED)
        }

        // Check that storage slot for reentrancy guard is empty to rule out possibility of slot conflict
        require(lockSlotOldValue == 0, "1B");
    }

    /**
     * @dev Prevents a contract from calling itself, directly or indirectly.
     * Calling a `nonReentrant` function from another `nonReentrant`
     * function is not supported. It is possible to prevent this from happening
     * by making the `nonReentrant` function external, and make it call a
     * `private` function that does the actual work.
     */
    modifier nonReentrant() {
        uint256 _status;
        assembly {
            _status := sload(LOCK_FLAG_ADDRESS)
        }

        // On the first call to nonReentrant, _notEntered will be true
        require(_status == _NOT_ENTERED, "r1");

        // Any calls to nonReentrant after this point will fail
        assembly {
            sstore(LOCK_FLAG_ADDRESS, _ENTERED)
        }

        _;

        // By storing the original value once again, a refund is triggered (see
        // https://eips.ethereum.org/EIPS/eip-2200)
        assembly {
            sstore(LOCK_FLAG_ADDRESS, _NOT_ENTERED)
        }
    }
}

File 17 of 19 : AddressAliasHelper.sol
// SPDX-License-Identifier: Apache-2.0

/*
 * Copyright 2019-2021, Offchain Labs, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

pragma solidity ^0.8.0;

library AddressAliasHelper {
    uint160 internal constant OFFSET = uint160(0x1111000000000000000000000000000000001111);

    /// @notice Utility function converts the address that submitted a tx
    /// to the inbox on L1 to the msg.sender viewed on L2
    /// @param l1Address the address in the L1 that triggered the tx to L2
    /// @return l2Address L2 address as viewed in msg.sender
    function applyL1ToL2Alias(address l1Address) internal pure returns (address l2Address) {
        unchecked {
            l2Address = address(uint160(l1Address) + OFFSET);
        }
    }

    /// @notice Utility function that converts the msg.sender viewed on L2 to the
    /// address that submitted a tx to the inbox on L1
    /// @param l2Address L2 address as viewed in msg.sender
    /// @return l1Address the address in the L1 that triggered the tx to L2
    function undoL1ToL2Alias(address l2Address) internal pure returns (address l1Address) {
        unchecked {
            l1Address = address(uint160(l2Address) - OFFSET);
        }
    }
}

File 18 of 19 : IMailbox.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import {L2Message} from "../Storage.sol";

/// @dev The enum that represents the transaction execution status
/// @param Failure The transaction execution failed
/// @param Success The transaction execution succeeded
enum TxStatus {
    Failure,
    Success
}

/// @title The interface of the zkSync Mailbox contract that provides interfaces for L1 <-> L2 interaction.
/// @author Matter Labs
/// @custom:security-contact [email protected]
interface IMailbox {
    /// @dev Structure that includes all fields of the L2 transaction
    /// @dev The hash of this structure is the "canonical L2 transaction hash" and can be used as a unique identifier of a tx
    /// @param txType The tx type number, depending on which the L2 transaction can be interpreted differently
    /// @param from The sender's address. `uint256` type for possible address format changes and maintaining backward compatibility
    /// @param to The recipient's address. `uint256` type for possible address format changes and maintaining backward compatibility
    /// @param gasLimit The L2 gas limit for L2 transaction. Analog to the `gasLimit` on an L1 transactions
    /// @param gasPerPubdataByteLimit Maximum number of L2 gas that will cost one byte of pubdata (every piece of data that will be stored on L1 as calldata)
    /// @param maxFeePerGas The absolute maximum sender willing to pay per unit of L2 gas to get the transaction included in a batch. Analog to the EIP-1559 `maxFeePerGas` on an L1 transactions
    /// @param maxPriorityFeePerGas The additional fee that is paid directly to the validator to incentivize them to include the transaction in a batch. Analog to the EIP-1559 `maxPriorityFeePerGas` on an L1 transactions
    /// @param paymaster The address of the EIP-4337 paymaster, that will pay fees for the transaction. `uint256` type for possible address format changes and maintaining backward compatibility
    /// @param nonce The nonce of the transaction. For L1->L2 transactions it is the priority operation Id.
    /// @param value The value to pass with the transaction
    /// @param reserved The fixed-length fields for usage in a future extension of transaction formats
    /// @param data The calldata that is transmitted for the transaction call
    /// @param signature An abstract set of bytes that are used for transaction authorization
    /// @param factoryDeps The set of L2 bytecode hashes whose preimages were shown on L1
    /// @param paymasterInput The arbitrary-length data that is used as a calldata to the paymaster pre-call
    /// @param reservedDynamic The arbitrary-length field for usage in a future extension of transaction formats
    struct L2CanonicalTransaction {
        uint256 txType;
        uint256 from;
        uint256 to;
        uint256 gasLimit;
        uint256 gasPerPubdataByteLimit;
        uint256 maxFeePerGas;
        uint256 maxPriorityFeePerGas;
        uint256 paymaster;
        uint256 nonce;
        uint256 value;
        // In the future, we might want to add some
        // new fields to the struct. The `txData` struct
        // is to be passed to account and any changes to its structure
        // would mean a breaking change to these accounts. To prevent this,
        // we should keep some fields as "reserved".
        // It is also recommended that their length is fixed, since
        // it would allow easier proof integration (in case we will need
        // some special circuit for preprocessing transactions).
        uint256[4] reserved;
        bytes data;
        bytes signature;
        uint256[] factoryDeps;
        bytes paymasterInput;
        // Reserved dynamic type for the future use-case. Using it should be avoided,
        // But it is still here, just in case we want to enable some additional functionality.
        bytes reservedDynamic;
    }

    /// @dev Internal structure that contains the parameters for the forwardRequestL2Transaction
    /// @param gateway The secondary chain gateway;
    /// @param isContractCall It's true when the request come from a contract.
    /// @param sender The sender's address.
    /// @param txId The id of the priority transaction.
    /// @param contractAddressL2 The address of the contract on L2 to call.
    /// @param l2Value The msg.value of the L2 transaction.
    /// @param l2CallData The call data of the L2 transaction.
    /// @param l2GasLimit The limit of the L2 gas for the L2 transaction
    /// @param l2GasPrice The price of the L2 gas in Wei to be used for this transaction.
    /// @param l2GasPricePerPubdata The price for a single pubdata byte in L2 gas.
    /// @param refundRecipient The recipient of the refund for the transaction on L2. If the transaction fails, then
    /// this address will receive the `l2Value`.
    struct ForwardL2Request {
        address gateway;
        bool isContractCall;
        address sender;
        uint256 txId;
        address contractAddressL2;
        uint256 l2Value;
        bytes l2CallData;
        uint256 l2GasLimit;
        uint256 l2GasPricePerPubdata;
        bytes[] factoryDeps;
        address refundRecipient;
    }

    /// @notice Prove that a specific arbitrary-length message was sent in a specific L2 batch number
    /// @param _l2BatchNumber The executed L2 batch number in which the message appeared
    /// @param _index The position in the L2 logs Merkle tree of the l2Log that was sent with the message
    /// @param _message Information about the sent message: sender address, the message itself, tx index in the L2 batch where the message was sent
    /// @param _proof Merkle proof for inclusion of L2 log that was sent with the message
    /// @return Whether the proof is valid
    function proveL2MessageInclusion(
        uint256 _l2BatchNumber,
        uint256 _index,
        L2Message calldata _message,
        bytes32[] calldata _proof
    ) external view returns (bool);

    /// @notice Prove that the L1 -> L2 transaction was processed with the specified status.
    /// @param _l2TxHash The L2 canonical transaction hash
    /// @param _l2BatchNumber The L2 batch number where the transaction was processed
    /// @param _l2MessageIndex The position in the L2 logs Merkle tree of the l2Log that was sent with the message
    /// @param _l2TxNumberInBatch The L2 transaction number in the batch, in which the log was sent
    /// @param _merkleProof The Merkle proof of the processing L1 -> L2 transaction
    /// @param _status The execution status of the L1 -> L2 transaction (true - success & 0 - fail)
    /// @return Whether 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!
    function proveL1ToL2TransactionStatus(
        bytes32 _l2TxHash,
        uint256 _l2BatchNumber,
        uint256 _l2MessageIndex,
        uint16 _l2TxNumberInBatch,
        bytes32[] calldata _merkleProof,
        TxStatus _status
    ) external view returns (bool);

    /// @notice Request execution of L2 transaction from L1.
    /// @param _contractL2 The L2 receiver address
    /// @param _l2Value `msg.value` of L2 transaction
    /// @param _calldata The input of the L2 transaction
    /// @param _l2GasLimit Maximum amount of L2 gas that transaction can consume during execution on L2
    /// @param _l2GasPerPubdataByteLimit The maximum amount L2 gas that the operator may charge the user for single byte of pubdata.
    /// @param _factoryDeps An array of L2 bytecodes that will be marked as known on L2
    /// @param _refundRecipient The address on L2 that will receive the refund for the transaction.
    /// @dev 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.
    /// @dev 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.
    /// @return canonicalTxHash The hash of the requested L2 transaction. This hash can be used to follow the transaction status
    function requestL2Transaction(
        address _contractL2,
        uint256 _l2Value,
        bytes calldata _calldata,
        uint256 _l2GasLimit,
        uint256 _l2GasPerPubdataByteLimit,
        bytes[] calldata _factoryDeps,
        address _refundRecipient
    ) external payable returns (bytes32 canonicalTxHash);

    /// @notice Finalize the withdrawal and release funds
    /// @param _l2BatchNumber The L2 batch number where the withdrawal was processed
    /// @param _l2MessageIndex The position in the L2 logs Merkle tree of the l2Log that was sent with the message
    /// @param _l2TxNumberInBatch The L2 transaction number in a batch, in which the log was sent
    /// @param _message The L2 withdraw data, stored in an L2 -> L1 message
    /// @param _merkleProof The Merkle proof of the inclusion L2 -> L1 message about withdrawal initialization
    function finalizeEthWithdrawal(
        uint256 _l2BatchNumber,
        uint256 _l2MessageIndex,
        uint16 _l2TxNumberInBatch,
        bytes calldata _message,
        bytes32[] calldata _merkleProof
    ) external;

    /// @notice Estimates the cost in Ether of requesting execution of an L2 transaction from L1
    /// @param _gasPrice expected L1 gas price at which the user requests the transaction execution
    /// @param _l2GasLimit Maximum amount of L2 gas that transaction can consume during execution on L2
    /// @param _l2GasPerPubdataByteLimit The maximum amount of L2 gas that the operator may charge the user for a single byte of pubdata.
    /// @return The estimated ETH spent on L2 gas for the transaction
    function l2TransactionBaseCost(
        uint256 _gasPrice,
        uint256 _l2GasLimit,
        uint256 _l2GasPerPubdataByteLimit
    ) external view returns (uint256);
}

File 19 of 19 : Storage.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

/// @dev The log passed from L2
/// @param l2ShardId The shard identifier, 0 - rollup, 1 - porter. All other values are not used but are reserved for
/// the future
/// @param isService A boolean flag that is part of the log along with `key`, `value`, and `sender` address.
/// This field is required formally but does not have any special meaning.
/// @param txNumberInBatch The L2 transaction number in the batch, in which the log was sent
/// @param sender The L2 address which sent the log
/// @param key The 32 bytes of information that was sent in the log
/// @param value The 32 bytes of information that was sent in the log
// Both `key` and `value` are arbitrary 32-bytes selected by the log sender
struct L2Log {
    uint8 l2ShardId;
    bool isService;
    uint16 txNumberInBatch;
    address sender;
    bytes32 key;
    bytes32 value;
}

/// @dev An arbitrary length message passed from L2
/// @notice Under the hood it is `L2Log` sent from the special system L2 contract
/// @param txNumberInBatch The L2 transaction number in the batch, in which the message was sent
/// @param sender The address of the L2 account from which the message was passed
/// @param data An arbitrary length message
struct L2Message {
    uint16 txNumberInBatch;
    address sender;
    bytes data;
}

/// @notice The struct that describes whether users will be charged for pubdata for L1->L2 transactions.
/// @param Rollup The users are charged for pubdata & it is priced based on the gas price on Ethereum.
/// @param Validium The pubdata is considered free with regard to the L1 gas price.
enum PubdataPricingMode {
    Rollup,
    Validium
}

/// @notice The fee params for L1->L2 transactions for the network.
/// @param pubdataPricingMode How the users will charged for pubdata in L1->L2 transactions.
/// @param batchOverheadL1Gas The amount of L1 gas required to process the batch (except for the calldata).
/// @param maxPubdataPerBatch The maximal number of pubdata that can be emitted per batch.
/// @param priorityTxMaxPubdata The maximal amount of pubdata a priority transaction is allowed to publish.
/// It can be slightly less than maxPubdataPerBatch in order to have some margin for the bootloader execution.
/// @param minimalL2GasPrice The minimal L2 gas price to be used by L1->L2 transactions. It should represent
/// the price that a single unit of compute costs.
struct FeeParams {
    PubdataPricingMode pubdataPricingMode;
    uint32 batchOverheadL1Gas;
    uint32 maxPubdataPerBatch;
    uint32 maxL2GasPerBatch;
    uint32 priorityTxMaxPubdata;
    uint64 minimalL2GasPrice;
}

/// @dev The sync status for priority op of secondary chain
/// @param hash The cumulative canonicalTxHash
/// @param amount The cumulative l2 value
struct SecondaryChainSyncStatus {
    bytes32 hash;
    uint256 amount;
}

Settings
{
  "viaIR": true,
  "optimizer": {
    "enabled": true,
    "runs": 200
  },
  "outputSelection": {
    "*": {
      "*": [
        "evm.bytecode",
        "evm.deployedBytecode",
        "devdoc",
        "userdoc",
        "metadata",
        "abi"
      ]
    }
  },
  "libraries": {}
}

Contract Security Audit

Contract ABI

[{"inputs":[{"internalType":"contract IMailbox","name":"_zkSync","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":true,"internalType":"address","name":"l1Token","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"ClaimedFailedDeposit","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"l2DepositTxHash","type":"bytes32"},{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"address","name":"l1Token","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"DepositInitiated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"l2DepositTxHash","type":"bytes32"},{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"address","name":"l1Token","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"bool","name":"toMerge","type":"bool"}],"name":"DepositToMergeInitiated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":true,"internalType":"address","name":"l1Token","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"WithdrawalFinalized","type":"event"},{"inputs":[{"internalType":"address","name":"_depositSender","type":"address"},{"internalType":"address","name":"_l1Token","type":"address"},{"internalType":"bytes32","name":"_l2TxHash","type":"bytes32"},{"internalType":"uint256","name":"_l2BatchNumber","type":"uint256"},{"internalType":"uint256","name":"_l2MessageIndex","type":"uint256"},{"internalType":"uint16","name":"_l2TxNumberInBatch","type":"uint16"},{"internalType":"bytes32[]","name":"_merkleProof","type":"bytes32[]"}],"name":"claimFailedDeposit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_l2Receiver","type":"address"},{"internalType":"address","name":"_l1Token","type":"address"},{"internalType":"uint256","name":"_amount","type":"uint256"},{"internalType":"uint256","name":"_l2TxGasLimit","type":"uint256"},{"internalType":"uint256","name":"_l2TxGasPerPubdataByte","type":"uint256"}],"name":"deposit","outputs":[{"internalType":"bytes32","name":"l2TxHash","type":"bytes32"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"_l2Receiver","type":"address"},{"internalType":"address","name":"_l1Token","type":"address"},{"internalType":"uint256","name":"_amount","type":"uint256"},{"internalType":"uint256","name":"_l2TxGasLimit","type":"uint256"},{"internalType":"uint256","name":"_l2TxGasPerPubdataByte","type":"uint256"},{"internalType":"address","name":"_refundRecipient","type":"address"}],"name":"deposit","outputs":[{"internalType":"bytes32","name":"l2TxHash","type":"bytes32"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"_l2Receiver","type":"address"},{"internalType":"address","name":"_l1Token","type":"address"},{"internalType":"uint256","name":"_amount","type":"uint256"},{"internalType":"uint256","name":"_l2TxGasLimit","type":"uint256"},{"internalType":"uint256","name":"_l2TxGasPerPubdataByte","type":"uint256"},{"internalType":"address","name":"_refundRecipient","type":"address"}],"name":"depositToMerge","outputs":[{"internalType":"bytes32","name":"l2TxHash","type":"bytes32"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_l2BatchNumber","type":"uint256"},{"internalType":"uint256","name":"_l2MessageIndex","type":"uint256"},{"internalType":"uint16","name":"_l2TxNumberInBatch","type":"uint16"},{"internalType":"bytes","name":"_message","type":"bytes"},{"internalType":"bytes32[]","name":"_merkleProof","type":"bytes32[]"}],"name":"finalizeWithdrawal","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes[]","name":"_factoryDeps","type":"bytes[]"},{"internalType":"bytes32[]","name":"_factoryDepByteCodeHashes","type":"bytes32[]"},{"internalType":"address","name":"_l2TokenBeacon","type":"address"},{"internalType":"address","name":"_governor","type":"address"},{"internalType":"uint256","name":"_deployBridgeImplementationFee","type":"uint256"},{"internalType":"uint256","name":"_deployBridgeProxyFee","type":"uint256"}],"name":"initialize","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"l2BatchNumber","type":"uint256"},{"internalType":"uint256","name":"l2ToL1MessageNumber","type":"uint256"}],"name":"isWithdrawalFinalized","outputs":[{"internalType":"bool","name":"isFinalized","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"l2Bridge","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_l1Token","type":"address"}],"name":"l2TokenAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"l2TokenBeacon","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"l2TokenProxyBytecodeHash","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"}]

60a0346100db57601f611ef938819003918201601f19168301916001600160401b038311848410176100e0578084926020946040528339810103126100db57516001600160a01b03811681036100db577f8e94fed44239eb2314ab7a406345e6c5a8f0ccedf3b600de3d004e672c33abf46001815491556100b157608052604051611e0290816100f7823960805181818161034b015281816104ed01528181610756015281816109a801526119790152f35b60405162461bcd60e51b815260206004820152600260248201526118a160f11b6044820152606490fd5b600080fd5b634e487b7160e01b600052604160045260246000fdfe6080604052600436101561001257600080fd5b60003560e01c806311a2ccc1146100c757806314490720146100c257806319fa7f62146100bd5780634bed8212146100b857806366550c4e146100b35780636dde7209146100ae578063823f1d96146100a9578063933999fb146100a4578063ae1f6aaf1461009f578063e8b99b1b1461009a5763f5f151681461009557600080fd5b610b70565b610ac5565b610a9c565b6108d4565b6108b6565b61088d565b6106a6565b61061d565b610442565b6101e8565b610112565b6044359061ffff821682036100dd57565b600080fd5b9181601f840112156100dd578235916001600160401b0383116100dd576020808501948460051b0101116100dd57565b346100dd5760a03660031901126100dd5761012b6100cc565b6001600160401b036064358181116100dd57366023820112156100dd5780600401358281116100dd5736602482840101116100dd576084359283116100dd5761018e9361017e60249436906004016100e2565b949093019060243560043561189d565b005b604435906001600160a01b03821682036100dd57565b606435906001600160a01b03821682036100dd57565b600435906001600160a01b03821682036100dd57565b602435906001600160a01b03821682036100dd57565b60c03660031901126100dd576001600160401b036004358181116100dd576102149036906004016100e2565b916024359081116100dd5761022d9036906004016100e2565b9190610237610190565b936102406101a6565b916084359460a43591600080516020611dad83398151915260018154915561041857610382878561034588946102f86103e89761033d61018e9f9b6103f69f8f9d828f8f61032b938f6102d461032693610337986102b86102db9460018060a01b03906102b08289161515610c38565b161515610c69565b6102c460038914610c9a565b6102cf8d8914610ccb565b610d12565b3414610d24565b6103046102ff8c6102f88c6102f08989610d6c565b939050610e2b565b3590611cae565b600455565b60018060a01b03166bffffffffffffffffffffffff60a01b6003541617600355565b610db1565b90506102f88588610e3a565b9c610deb565b939050610e43565b9661037b7f00000000000000000000000000000000000000000000000000000000000000009a610373610f34565b933691610f7e565b928a611bcb565b6004546040516369359f3760e11b602082015230602482015260448101919091526001600160a01b03929092166064808401919091528252601f19916103dc906103cd608482610ed9565b60405197889360208501611040565b03908101855284610ed9565b6103f061106c565b93611bcb565b60018060a01b03166bffffffffffffffffffffffff60a01b6002541617600255565b60405162461bcd60e51b815260206004820152600260248201526118a160f11b6044820152606490fd5b346100dd5760e03660031901126100dd5761045b6101bc565b6104636101d2565b9060a4359060443561ffff831683036100dd5760c4356001600160401b0381116100dd576104959036906004016100e2565b936104da600080516020611dad833981519152956104b6600188541461107f565b6002875560405163042901c760e01b815293849360843560643588600488016117c0565b6001600160a01b039160209184919003817f000000000000000000000000000000000000000000000000000000000000000085165afa80156106185760019661054e83927fbe066dc591f4a444f75176d387c3e6c775e5706d9ea9a91d11eb49030c66cf60956000916105ea575b506117fa565b60006105cd61059d8761058e856105778c60018060a01b03166000526001602052604060002090565b9060018060a01b0316600052602052604060002090565b90600052602052604060002090565b54966105aa88151561182b565b6001600160a01b038916600090815260016020526040902061058e908590610577565b5516936105db84828761185c565b6040519384521691602090a355005b61060b915060203d8111610611575b6106038183610ed9565b8101906113a9565b38610548565b503d6105f9565b611278565b346100dd5760403660031901126100dd5760043560005260006020526040600020602435600052602052602060ff604060002054166040519015158152f35b60c09060031901126100dd576001600160a01b039060043582811681036100dd579160243581811681036100dd579160443591606435916084359160a43590811681036100dd5790565b6106af3661065c565b91949290936020600080516020611dad833981519152936106d3600186541461107f565b600285556106e28415156110b0565b6001600160a01b03966107036106fb86868b1633611291565b9586146110e1565b61070f858589336115ae565b9188811615610863575b60025461075091906001600160a01b03165b9261073461106c565b906040519c8d96879663eb67241960e01b885260048801611121565b038134897f0000000000000000000000000000000000000000000000000000000000000000165af193841561061857602096600095610811575b50937f46825fb1efbc2ac58f7529d18b84230c9818ca01aa51e874715a59f68c7fd6c58196600196856107d78561058e886105773360018060a01b03166000526001602052604060002090565b55610805604051928392169633968360409060019294936060820195848060a01b0316825260208201520152565b0390a455604051908152f35b600195506108557f46825fb1efbc2ac58f7529d18b84230c9818ca01aa51e874715a59f68c7fd6c591893d811161085c575b61084d8183610ed9565b810190611112565b955061078a565b503d610843565b50333214610884576107508861111161111160901b013301165b9050610719565b6107503361087d565b346100dd5760003660031901126100dd576003546040516001600160a01b039091168152602090f35b346100dd5760003660031901126100dd576020600454604051908152f35b60a03660031901126100dd576108e86101bc565b6108f06101d2565b9060443590600080516020611dad833981519152610911600182541461107f565b600281556109208315156110b0565b6001600160a01b03926109416109398287871633611291565b9182146110e1565b61094d81868533611697565b94333214610a935760208561111161111160901b01330116965b6002546001600160a01b03166109a261097e61106c565b996040519a8b94859463eb67241960e01b8652608435916064359160048801611121565b038134897f0000000000000000000000000000000000000000000000000000000000000000165af193841561061857602096600095610a51575b50937fdd341179f4edc78148d894d0213a96d212af2cbaf223d19ef6d483bdd47ab81d819660019685610a298561058e886105773360018060a01b03166000526001602052604060002090565b55604080516001600160a01b0390961686526020860196909652169333939081908101610805565b60019550610a8c7fdd341179f4edc78148d894d0213a96d212af2cbaf223d19ef6d483bdd47ab81d91893d811161085c5761084d8183610ed9565b95506109dc565b60203396610967565b346100dd5760003660031901126100dd576002546040516001600160a01b039091168152602090f35b610ace3661065c565b91949290936020600080516020611dad83398151915293610af2600186541461107f565b60028555610b018415156110b0565b6001600160a01b0396610b1a6106fb86868b1633611291565b610b2685858933611697565b9188811615610b46575b6002546109a291906001600160a01b031661072b565b50333214610b67576109a28861111161111160901b013301165b9050610b30565b6109a233610b60565b346100dd5760203660031901126100dd57610c34610b8c6101bc565b60018060a01b0380600354169160409283516020810191825284808201526000606082015260608152610bbe81610e68565b519020908260025416916004548486519360208501957f2020dba91b30cc0006188af794c2fb30dd8520db7e2c088b7fc7c103c00ca494875288860152166060840152608083015260a082015260a08152610c1881610e88565b519020915191166001600160a01b031681529081906020820190565b0390f35b15610c3f57565b60405162461bcd60e51b8152602060048201526002602482015261373360f11b6044820152606490fd5b15610c7057565b60405162461bcd60e51b81526020600482015260026024820152610dcd60f31b6044820152606490fd5b15610ca157565b60405162461bcd60e51b81526020600482015260026024820152616d6b60f01b6044820152606490fd5b15610cd257565b60405162461bcd60e51b81526020600482015260026024820152616d6760f01b6044820152606490fd5b634e487b7160e01b600052601160045260246000fd5b91908201809211610d1f57565b610cfc565b15610d2b57565b60405162461bcd60e51b815260206004820152600360248201526266656560e81b6044820152606490fd5b634e487b7160e01b600052603260045260246000fd5b9060021015610dac57604081013590601e19813603018212156100dd5701908135916001600160401b0383116100dd5760200182360381136100dd579190565b610d56565b9015610dac57803590601e19813603018212156100dd5701908135916001600160401b0383116100dd5760200182360381136100dd579190565b9060011015610dac57602081013590601e19813603018212156100dd5701908135916001600160401b0383116100dd5760200182360381136100dd579190565b9060021015610dac5760400190565b9015610dac5790565b9060011015610dac5760200190565b634e487b7160e01b600052604160045260246000fd5b608081019081106001600160401b03821117610e8357604052565b610e52565b60c081019081106001600160401b03821117610e8357604052565b602081019081106001600160401b03821117610e8357604052565b604081019081106001600160401b03821117610e8357604052565b90601f801991011681019081106001600160401b03821117610e8357604052565b60405190606082018281106001600160401b03821117610e8357604052565b6001600160401b038111610e8357601f01601f191660200190565b60405190610f4182610ea3565b60008252565b929192610f5382610f19565b91610f616040519384610ed9565b8294818452818301116100dd578281602093846000960137010152565b929190926001600160401b0391828511610e83578460051b6040519360208095610faa82850182610ed9565b8098815201918401938385116100dd5780925b858410610fcd5750505050505050565b83358381116100dd57820185601f820112156100dd578791610ff58783858095359101610f47565b815201930192610fbd565b919082519283825260005b84811061102c575050826000602080949584010152601f8019910116010190565b60208183018101518483018201520161100b565b6001600160a01b0391821681529116602082015260606040820181905261106992910190611000565b90565b60405161107881610ea3565b6000815290565b1561108657565b60405162461bcd60e51b8152602060048201526002602482015261723160f01b6044820152606490fd5b156110b757565b60405162461bcd60e51b81526020600482015260026024820152610c9560f21b6044820152606490fd5b156110e857565b60405162461bcd60e51b81526020600482015260026024820152610c5560f21b6044820152606490fd5b908160209103126100dd575190565b969594939060018060a01b0316875261114d6020926000848a015260e060408a015260e0890190611000565b926060880152608087015285820360a08701528251908183528083019281808460051b8301019501936000915b84831061119f575050505050509060c061119d9294019060018060a01b03169052565b565b90919293949584806111bd600193601f198682030187528a51611000565b980193019301919493929061117a565b9392919061800685526111f360209160008388015260e0604088015260e0870190611000565b90629896806060870152610320608087015285820360a08701528251908183528083019281808460051b8301019501936000915b84831061124a575050505050509060c061119d9294019060018060a01b03169052565b9091929394958480611268600193601f198682030187528a51611000565b9801930193019194939290611227565b6040513d6000823e3d90fd5b91908203918211610d1f57565b6040516370a0823160e01b80825230600483015260209492936001600160a01b03811693908684602481885afa95861561061857879460009761132a575b50906112dd92913091611351565b60405190815230600482015291829060249082905afa908115610618576110699360009261130d575b5050611284565b6113239250803d1061085c5761084d8183610ed9565b3880611306565b6112dd939291975061134890863d881161085c5761084d8183610ed9565b969091926112cf565b6040516323b872dd60e01b60208201526001600160a01b03928316602482015292909116604483015260648083019390935291815260a08101918183106001600160401b03841117610e835761119d926040526113c1565b908160209103126100dd575180151581036100dd5790565b60405161141f916001600160a01b03166113da82610ebe565b6000806020958685527f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c656487860152868151910182855af16114196114a7565b916114d7565b80519082821592831561148f575b505050156114385750565b6084906040519062461bcd60e51b82526004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152fd5b61149f93508201810191016113a9565b38828161142d565b3d156114d2573d906114b882610f19565b916114c66040519384610ed9565b82523d6000602084013e565b606090565b9192901561153957508151156114eb575090565b3b156114f45790565b60405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606490fd5b82519091501561154c5750805190602001fd5b60405162461bcd60e51b815260206004820152908190611570906024830190611000565b0390fd5b6001600160a01b03918216815291811660208301529091166040820152606081019190915260a06080820181905261106992910190611000565b61168b6110699392946040519060208201916306fdde0360e01b8352600481526115d781610ebe565b6000809381925190885afa506115eb6114a7565b828060405160208101906395d89b4160e01b82526004815261160c81610ebe565b5190895afa5061161a6114a7565b9280604051602081019063313ce56760e01b82526004815261163b81610ebe565b5190895afa5061165b61164c6114a7565b60405194859360208501611765565b039461166f601f1996878101855284610ed9565b6040516367bf062560e01b602082015297889560248701611574565b03908101835282610ed9565b61168b6110699392946040519060208201916306fdde0360e01b8352600481526116c081610ebe565b6000809381925190885afa506116d46114a7565b828060405160208101906395d89b4160e01b8252600481526116f581610ebe565b5190895afa506117036114a7565b9280604051602081019063313ce56760e01b82526004815261172481610ebe565b5190895afa5061173561164c6114a7565b0394611749601f1996878101855284610ed9565b6040516333f9ebdf60e21b602082015297889560248701611574565b9161178e906117806110699593606086526060860190611000565b908482036020860152611000565b916040818403910152611000565b81835290916001600160fb1b0383116100dd5760209260051b809284830137010190565b96959060a0946117f5946000979461ffff938b5260208b015260408a015216606088015260c0608088015260c087019161179c565b930152565b1561180157565b60405162461bcd60e51b81526020600482015260026024820152613cb760f11b6044820152606490fd5b1561183257565b60405162461bcd60e51b8152602060048201526002602482015261793160f01b6044820152606490fd5b60405163a9059cbb60e01b60208201526001600160a01b0392909216602483015260448083019390935291815261119d91611898606483610ed9565b6113c1565b61194561193a611965969798939495600080516020611dad833981519152986118c960018b541461107f565b60028a556118fe6118f96118f56118ee8a61058e8a6000526000602052604060002090565b5460ff1690565b1590565b611a3c565b600254611933906001600160a01b0316611923611919610efa565b61ffff909b168b52565b6001600160a01b031660208a0152565b3691610f47565b806040870152611af7565b9591969093604051998a9363e4948f4360e01b8552878660048701611a6d565b6001600160a01b0393916020918a919003817f000000000000000000000000000000000000000000000000000000000000000087165afa918215610618576119f57fac1b18083978656d557d6e91c88203585cfda1031bdb14538327121ef140d3839561058e611a02936119e5889760019e600091611a1e575b50611ac6565b6000526000602052604060002090565b805460ff19166001179055565b1693611a0f84828761185c565b6040519384521691602090a355565b611a36915060203d8111610611576106038183610ed9565b386119df565b15611a4357565b60405162461bcd60e51b8152602060048201526002602482015261707760f01b6044820152606490fd5b93916110699593604091611ab8938752602087015260808287015261ffff815116608087015260018060a01b0360208201511660a08701520151606060c086015260e0850190611000565b92606081850391015261179c565b15611acd57565b60405162461bcd60e51b81526020600482015260026024820152616e7160f01b6044820152606490fd5b604c815103611b8357600481015163ee5d333f60e01b60e09190911b6001600160e01b03191601611b5957611b4591611b55611b368360188091015191565b60148186018101519296910190565b9093906020908181019201015191565b5090565b60405162461bcd60e51b81526020600482015260026024820152611b9d60f21b6044820152606490fd5b60405162461bcd60e51b81526020600482015260026024820152616b6b60f01b6044820152606490fd5b60609061106993926000825260208201528160408201520190611000565b9290611c229460209160405191633cda335160e01b84840152611c0483611bf6878960248401611bad565b03601f198101855284610ed9565b60405180988194829363eb67241960e01b84523391600485016111cd565b6001600160a01b0398919003929088165af19384156106185761106994611c5f575b50602081519101209161111161111160901b01300116611d4b565b611c769060203d811161085c5761084d8183610ed9565b5038611c44565b15611c8457565b60405162461bcd60e51b8152602060048201526002602482015261707360f01b6044820152606490fd5b90601f8216611d21578160051c62010000811015611cf757600180611cd4921614611c7d565b6001600160e01b031660db9190911b6001600160e01b03191617600160f81b1790565b60405162461bcd60e51b8152602060048201526002602482015261070760f41b6044820152606490fd5b60405162461bcd60e51b8152602060048201526002602482015261707160f01b6044820152606490fd5b916040519060208201927f2020dba91b30cc0006188af794c2fb30dd8520db7e2c088b7fc7c103c00ca494845260018060a01b03809516604084015260006060840152608083015260a082015260a08152611da581610e88565b519020169056fe8e94fed44239eb2314ab7a406345e6c5a8f0ccedf3b600de3d004e672c33abf4a26469706673582212202f462ca6bb6d2916d94ed94802fd9edb4d039c72d41e867b0023e4aa4f8b9a0d64736f6c634300081200330000000000000000000000005fd9f73286b7e8683bab45019c94553b93e015cf

Deployed Bytecode

0x6080604052600436101561001257600080fd5b60003560e01c806311a2ccc1146100c757806314490720146100c257806319fa7f62146100bd5780634bed8212146100b857806366550c4e146100b35780636dde7209146100ae578063823f1d96146100a9578063933999fb146100a4578063ae1f6aaf1461009f578063e8b99b1b1461009a5763f5f151681461009557600080fd5b610b70565b610ac5565b610a9c565b6108d4565b6108b6565b61088d565b6106a6565b61061d565b610442565b6101e8565b610112565b6044359061ffff821682036100dd57565b600080fd5b9181601f840112156100dd578235916001600160401b0383116100dd576020808501948460051b0101116100dd57565b346100dd5760a03660031901126100dd5761012b6100cc565b6001600160401b036064358181116100dd57366023820112156100dd5780600401358281116100dd5736602482840101116100dd576084359283116100dd5761018e9361017e60249436906004016100e2565b949093019060243560043561189d565b005b604435906001600160a01b03821682036100dd57565b606435906001600160a01b03821682036100dd57565b600435906001600160a01b03821682036100dd57565b602435906001600160a01b03821682036100dd57565b60c03660031901126100dd576001600160401b036004358181116100dd576102149036906004016100e2565b916024359081116100dd5761022d9036906004016100e2565b9190610237610190565b936102406101a6565b916084359460a43591600080516020611dad83398151915260018154915561041857610382878561034588946102f86103e89761033d61018e9f9b6103f69f8f9d828f8f61032b938f6102d461032693610337986102b86102db9460018060a01b03906102b08289161515610c38565b161515610c69565b6102c460038914610c9a565b6102cf8d8914610ccb565b610d12565b3414610d24565b6103046102ff8c6102f88c6102f08989610d6c565b939050610e2b565b3590611cae565b600455565b60018060a01b03166bffffffffffffffffffffffff60a01b6003541617600355565b610db1565b90506102f88588610e3a565b9c610deb565b939050610e43565b9661037b7f0000000000000000000000005fd9f73286b7e8683bab45019c94553b93e015cf9a610373610f34565b933691610f7e565b928a611bcb565b6004546040516369359f3760e11b602082015230602482015260448101919091526001600160a01b03929092166064808401919091528252601f19916103dc906103cd608482610ed9565b60405197889360208501611040565b03908101855284610ed9565b6103f061106c565b93611bcb565b60018060a01b03166bffffffffffffffffffffffff60a01b6002541617600255565b60405162461bcd60e51b815260206004820152600260248201526118a160f11b6044820152606490fd5b346100dd5760e03660031901126100dd5761045b6101bc565b6104636101d2565b9060a4359060443561ffff831683036100dd5760c4356001600160401b0381116100dd576104959036906004016100e2565b936104da600080516020611dad833981519152956104b6600188541461107f565b6002875560405163042901c760e01b815293849360843560643588600488016117c0565b6001600160a01b039160209184919003817f0000000000000000000000005fd9f73286b7e8683bab45019c94553b93e015cf85165afa80156106185760019661054e83927fbe066dc591f4a444f75176d387c3e6c775e5706d9ea9a91d11eb49030c66cf60956000916105ea575b506117fa565b60006105cd61059d8761058e856105778c60018060a01b03166000526001602052604060002090565b9060018060a01b0316600052602052604060002090565b90600052602052604060002090565b54966105aa88151561182b565b6001600160a01b038916600090815260016020526040902061058e908590610577565b5516936105db84828761185c565b6040519384521691602090a355005b61060b915060203d8111610611575b6106038183610ed9565b8101906113a9565b38610548565b503d6105f9565b611278565b346100dd5760403660031901126100dd5760043560005260006020526040600020602435600052602052602060ff604060002054166040519015158152f35b60c09060031901126100dd576001600160a01b039060043582811681036100dd579160243581811681036100dd579160443591606435916084359160a43590811681036100dd5790565b6106af3661065c565b91949290936020600080516020611dad833981519152936106d3600186541461107f565b600285556106e28415156110b0565b6001600160a01b03966107036106fb86868b1633611291565b9586146110e1565b61070f858589336115ae565b9188811615610863575b60025461075091906001600160a01b03165b9261073461106c565b906040519c8d96879663eb67241960e01b885260048801611121565b038134897f0000000000000000000000005fd9f73286b7e8683bab45019c94553b93e015cf165af193841561061857602096600095610811575b50937f46825fb1efbc2ac58f7529d18b84230c9818ca01aa51e874715a59f68c7fd6c58196600196856107d78561058e886105773360018060a01b03166000526001602052604060002090565b55610805604051928392169633968360409060019294936060820195848060a01b0316825260208201520152565b0390a455604051908152f35b600195506108557f46825fb1efbc2ac58f7529d18b84230c9818ca01aa51e874715a59f68c7fd6c591893d811161085c575b61084d8183610ed9565b810190611112565b955061078a565b503d610843565b50333214610884576107508861111161111160901b013301165b9050610719565b6107503361087d565b346100dd5760003660031901126100dd576003546040516001600160a01b039091168152602090f35b346100dd5760003660031901126100dd576020600454604051908152f35b60a03660031901126100dd576108e86101bc565b6108f06101d2565b9060443590600080516020611dad833981519152610911600182541461107f565b600281556109208315156110b0565b6001600160a01b03926109416109398287871633611291565b9182146110e1565b61094d81868533611697565b94333214610a935760208561111161111160901b01330116965b6002546001600160a01b03166109a261097e61106c565b996040519a8b94859463eb67241960e01b8652608435916064359160048801611121565b038134897f0000000000000000000000005fd9f73286b7e8683bab45019c94553b93e015cf165af193841561061857602096600095610a51575b50937fdd341179f4edc78148d894d0213a96d212af2cbaf223d19ef6d483bdd47ab81d819660019685610a298561058e886105773360018060a01b03166000526001602052604060002090565b55604080516001600160a01b0390961686526020860196909652169333939081908101610805565b60019550610a8c7fdd341179f4edc78148d894d0213a96d212af2cbaf223d19ef6d483bdd47ab81d91893d811161085c5761084d8183610ed9565b95506109dc565b60203396610967565b346100dd5760003660031901126100dd576002546040516001600160a01b039091168152602090f35b610ace3661065c565b91949290936020600080516020611dad83398151915293610af2600186541461107f565b60028555610b018415156110b0565b6001600160a01b0396610b1a6106fb86868b1633611291565b610b2685858933611697565b9188811615610b46575b6002546109a291906001600160a01b031661072b565b50333214610b67576109a28861111161111160901b013301165b9050610b30565b6109a233610b60565b346100dd5760203660031901126100dd57610c34610b8c6101bc565b60018060a01b0380600354169160409283516020810191825284808201526000606082015260608152610bbe81610e68565b519020908260025416916004548486519360208501957f2020dba91b30cc0006188af794c2fb30dd8520db7e2c088b7fc7c103c00ca494875288860152166060840152608083015260a082015260a08152610c1881610e88565b519020915191166001600160a01b031681529081906020820190565b0390f35b15610c3f57565b60405162461bcd60e51b8152602060048201526002602482015261373360f11b6044820152606490fd5b15610c7057565b60405162461bcd60e51b81526020600482015260026024820152610dcd60f31b6044820152606490fd5b15610ca157565b60405162461bcd60e51b81526020600482015260026024820152616d6b60f01b6044820152606490fd5b15610cd257565b60405162461bcd60e51b81526020600482015260026024820152616d6760f01b6044820152606490fd5b634e487b7160e01b600052601160045260246000fd5b91908201809211610d1f57565b610cfc565b15610d2b57565b60405162461bcd60e51b815260206004820152600360248201526266656560e81b6044820152606490fd5b634e487b7160e01b600052603260045260246000fd5b9060021015610dac57604081013590601e19813603018212156100dd5701908135916001600160401b0383116100dd5760200182360381136100dd579190565b610d56565b9015610dac57803590601e19813603018212156100dd5701908135916001600160401b0383116100dd5760200182360381136100dd579190565b9060011015610dac57602081013590601e19813603018212156100dd5701908135916001600160401b0383116100dd5760200182360381136100dd579190565b9060021015610dac5760400190565b9015610dac5790565b9060011015610dac5760200190565b634e487b7160e01b600052604160045260246000fd5b608081019081106001600160401b03821117610e8357604052565b610e52565b60c081019081106001600160401b03821117610e8357604052565b602081019081106001600160401b03821117610e8357604052565b604081019081106001600160401b03821117610e8357604052565b90601f801991011681019081106001600160401b03821117610e8357604052565b60405190606082018281106001600160401b03821117610e8357604052565b6001600160401b038111610e8357601f01601f191660200190565b60405190610f4182610ea3565b60008252565b929192610f5382610f19565b91610f616040519384610ed9565b8294818452818301116100dd578281602093846000960137010152565b929190926001600160401b0391828511610e83578460051b6040519360208095610faa82850182610ed9565b8098815201918401938385116100dd5780925b858410610fcd5750505050505050565b83358381116100dd57820185601f820112156100dd578791610ff58783858095359101610f47565b815201930192610fbd565b919082519283825260005b84811061102c575050826000602080949584010152601f8019910116010190565b60208183018101518483018201520161100b565b6001600160a01b0391821681529116602082015260606040820181905261106992910190611000565b90565b60405161107881610ea3565b6000815290565b1561108657565b60405162461bcd60e51b8152602060048201526002602482015261723160f01b6044820152606490fd5b156110b757565b60405162461bcd60e51b81526020600482015260026024820152610c9560f21b6044820152606490fd5b156110e857565b60405162461bcd60e51b81526020600482015260026024820152610c5560f21b6044820152606490fd5b908160209103126100dd575190565b969594939060018060a01b0316875261114d6020926000848a015260e060408a015260e0890190611000565b926060880152608087015285820360a08701528251908183528083019281808460051b8301019501936000915b84831061119f575050505050509060c061119d9294019060018060a01b03169052565b565b90919293949584806111bd600193601f198682030187528a51611000565b980193019301919493929061117a565b9392919061800685526111f360209160008388015260e0604088015260e0870190611000565b90629896806060870152610320608087015285820360a08701528251908183528083019281808460051b8301019501936000915b84831061124a575050505050509060c061119d9294019060018060a01b03169052565b9091929394958480611268600193601f198682030187528a51611000565b9801930193019194939290611227565b6040513d6000823e3d90fd5b91908203918211610d1f57565b6040516370a0823160e01b80825230600483015260209492936001600160a01b03811693908684602481885afa95861561061857879460009761132a575b50906112dd92913091611351565b60405190815230600482015291829060249082905afa908115610618576110699360009261130d575b5050611284565b6113239250803d1061085c5761084d8183610ed9565b3880611306565b6112dd939291975061134890863d881161085c5761084d8183610ed9565b969091926112cf565b6040516323b872dd60e01b60208201526001600160a01b03928316602482015292909116604483015260648083019390935291815260a08101918183106001600160401b03841117610e835761119d926040526113c1565b908160209103126100dd575180151581036100dd5790565b60405161141f916001600160a01b03166113da82610ebe565b6000806020958685527f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c656487860152868151910182855af16114196114a7565b916114d7565b80519082821592831561148f575b505050156114385750565b6084906040519062461bcd60e51b82526004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152fd5b61149f93508201810191016113a9565b38828161142d565b3d156114d2573d906114b882610f19565b916114c66040519384610ed9565b82523d6000602084013e565b606090565b9192901561153957508151156114eb575090565b3b156114f45790565b60405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606490fd5b82519091501561154c5750805190602001fd5b60405162461bcd60e51b815260206004820152908190611570906024830190611000565b0390fd5b6001600160a01b03918216815291811660208301529091166040820152606081019190915260a06080820181905261106992910190611000565b61168b6110699392946040519060208201916306fdde0360e01b8352600481526115d781610ebe565b6000809381925190885afa506115eb6114a7565b828060405160208101906395d89b4160e01b82526004815261160c81610ebe565b5190895afa5061161a6114a7565b9280604051602081019063313ce56760e01b82526004815261163b81610ebe565b5190895afa5061165b61164c6114a7565b60405194859360208501611765565b039461166f601f1996878101855284610ed9565b6040516367bf062560e01b602082015297889560248701611574565b03908101835282610ed9565b61168b6110699392946040519060208201916306fdde0360e01b8352600481526116c081610ebe565b6000809381925190885afa506116d46114a7565b828060405160208101906395d89b4160e01b8252600481526116f581610ebe565b5190895afa506117036114a7565b9280604051602081019063313ce56760e01b82526004815261172481610ebe565b5190895afa5061173561164c6114a7565b0394611749601f1996878101855284610ed9565b6040516333f9ebdf60e21b602082015297889560248701611574565b9161178e906117806110699593606086526060860190611000565b908482036020860152611000565b916040818403910152611000565b81835290916001600160fb1b0383116100dd5760209260051b809284830137010190565b96959060a0946117f5946000979461ffff938b5260208b015260408a015216606088015260c0608088015260c087019161179c565b930152565b1561180157565b60405162461bcd60e51b81526020600482015260026024820152613cb760f11b6044820152606490fd5b1561183257565b60405162461bcd60e51b8152602060048201526002602482015261793160f01b6044820152606490fd5b60405163a9059cbb60e01b60208201526001600160a01b0392909216602483015260448083019390935291815261119d91611898606483610ed9565b6113c1565b61194561193a611965969798939495600080516020611dad833981519152986118c960018b541461107f565b60028a556118fe6118f96118f56118ee8a61058e8a6000526000602052604060002090565b5460ff1690565b1590565b611a3c565b600254611933906001600160a01b0316611923611919610efa565b61ffff909b168b52565b6001600160a01b031660208a0152565b3691610f47565b806040870152611af7565b9591969093604051998a9363e4948f4360e01b8552878660048701611a6d565b6001600160a01b0393916020918a919003817f0000000000000000000000005fd9f73286b7e8683bab45019c94553b93e015cf87165afa918215610618576119f57fac1b18083978656d557d6e91c88203585cfda1031bdb14538327121ef140d3839561058e611a02936119e5889760019e600091611a1e575b50611ac6565b6000526000602052604060002090565b805460ff19166001179055565b1693611a0f84828761185c565b6040519384521691602090a355565b611a36915060203d8111610611576106038183610ed9565b386119df565b15611a4357565b60405162461bcd60e51b8152602060048201526002602482015261707760f01b6044820152606490fd5b93916110699593604091611ab8938752602087015260808287015261ffff815116608087015260018060a01b0360208201511660a08701520151606060c086015260e0850190611000565b92606081850391015261179c565b15611acd57565b60405162461bcd60e51b81526020600482015260026024820152616e7160f01b6044820152606490fd5b604c815103611b8357600481015163ee5d333f60e01b60e09190911b6001600160e01b03191601611b5957611b4591611b55611b368360188091015191565b60148186018101519296910190565b9093906020908181019201015191565b5090565b60405162461bcd60e51b81526020600482015260026024820152611b9d60f21b6044820152606490fd5b60405162461bcd60e51b81526020600482015260026024820152616b6b60f01b6044820152606490fd5b60609061106993926000825260208201528160408201520190611000565b9290611c229460209160405191633cda335160e01b84840152611c0483611bf6878960248401611bad565b03601f198101855284610ed9565b60405180988194829363eb67241960e01b84523391600485016111cd565b6001600160a01b0398919003929088165af19384156106185761106994611c5f575b50602081519101209161111161111160901b01300116611d4b565b611c769060203d811161085c5761084d8183610ed9565b5038611c44565b15611c8457565b60405162461bcd60e51b8152602060048201526002602482015261707360f01b6044820152606490fd5b90601f8216611d21578160051c62010000811015611cf757600180611cd4921614611c7d565b6001600160e01b031660db9190911b6001600160e01b03191617600160f81b1790565b60405162461bcd60e51b8152602060048201526002602482015261070760f41b6044820152606490fd5b60405162461bcd60e51b8152602060048201526002602482015261707160f01b6044820152606490fd5b916040519060208201927f2020dba91b30cc0006188af794c2fb30dd8520db7e2c088b7fc7c103c00ca494845260018060a01b03809516604084015260006060840152608083015260a082015260a08152611da581610e88565b519020169056fe8e94fed44239eb2314ab7a406345e6c5a8f0ccedf3b600de3d004e672c33abf4a26469706673582212202f462ca6bb6d2916d94ed94802fd9edb4d039c72d41e867b0023e4aa4f8b9a0d64736f6c63430008120033

Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)

0000000000000000000000005fd9f73286b7e8683bab45019c94553b93e015cf

-----Decoded View---------------
Arg [0] : _zkSync (address): 0x5fD9F73286b7E8683Bab45019C94553b93e015Cf

-----Encoded View---------------
1 Constructor Arguments found :
Arg [0] : 0000000000000000000000005fd9f73286b7e8683bab45019c94553b93e015cf


Block Transaction Difficulty Gas Used Reward
View All Blocks Produced

Block Uncle Number Difficulty Gas Used Reward
View All Uncles
Loading...
Loading
Loading...
Loading

Validator Index Block Amount
View All Withdrawals

Transaction Hash Block Value Eth2 PubKey Valid
View All Deposits
Loading...
Loading
[ Download: CSV Export  ]

A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.