creation_sourcecode: {{
    "language": "Solidity",
    "sources": {
      "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../utils/ContextUpgradeable.sol\";\nimport \"../proxy/utils/Initializable.sol\";\n\n/**\n * @dev Contract module which provides a basic access control mechanism, where\n * there is an account (an owner) that can be granted exclusive access to\n * specific functions.\n *\n * By default, the owner account will be the one that deploys the contract. This\n * can later be changed with {transferOwnership}.\n *\n * This module is used through inheritance. It will make available the modifier\n * `onlyOwner`, which can be applied to your functions to restrict their use to\n * the owner.\n */\nabstract contract OwnableUpgradeable is Initializable, ContextUpgradeable {\n    address private _owner;\n\n    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);\n\n    /**\n     * @dev Initializes the contract setting the deployer as the initial owner.\n     */\n    function __Ownable_init() internal onlyInitializing {\n        __Ownable_init_unchained();\n    }\n\n    function __Ownable_init_unchained() internal onlyInitializing {\n        _transferOwnership(_msgSender());\n    }\n\n    /**\n     * @dev Throws if called by any account other than the owner.\n     */\n    modifier onlyOwner() {\n        _checkOwner();\n        _;\n    }\n\n    /**\n     * @dev Returns the address of the current owner.\n     */\n    function owner() public view virtual returns (address) {\n        return _owner;\n    }\n\n    /**\n     * @dev Throws if the sender is not the owner.\n     */\n    function _checkOwner() internal view virtual {\n        require(owner() == _msgSender(), \"Ownable: caller is not the owner\");\n    }\n\n    /**\n     * @dev Leaves the contract without owner. It will not be possible to call\n     * `onlyOwner` functions. Can only be called by the current owner.\n     *\n     * NOTE: Renouncing ownership will leave the contract without an owner,\n     * thereby disabling any functionality that is only available to the owner.\n     */\n    function renounceOwnership() public virtual onlyOwner {\n        _transferOwnership(address(0));\n    }\n\n    /**\n     * @dev Transfers ownership of the contract to a new account (`newOwner`).\n     * Can only be called by the current owner.\n     */\n    function transferOwnership(address newOwner) public virtual onlyOwner {\n        require(newOwner != address(0), \"Ownable: new owner is the zero address\");\n        _transferOwnership(newOwner);\n    }\n\n    /**\n     * @dev Transfers ownership of the contract to a new account (`newOwner`).\n     * Internal function without access restriction.\n     */\n    function _transferOwnership(address newOwner) internal virtual {\n        address oldOwner = _owner;\n        _owner = newOwner;\n        emit OwnershipTransferred(oldOwner, newOwner);\n    }\n\n    /**\n     * @dev This empty reserved space is put in place to allow future versions to add new\n     * variables without shifting down storage in the inheritance chain.\n     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n     */\n    uint256[49] private __gap;\n}\n"
      },
      "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.9.0) (proxy/utils/Initializable.sol)\n\npragma solidity ^0.8.2;\n\nimport \"../../utils/AddressUpgradeable.sol\";\n\n/**\n * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed\n * behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an\n * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer\n * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.\n *\n * The initialization functions use a version number. Once a version number is used, it is consumed and cannot be\n * reused. This mechanism prevents re-execution of each \"step\" but allows the creation of new initialization steps in\n * case an upgrade adds a module that needs to be initialized.\n *\n * For example:\n *\n * [.hljs-theme-light.nopadding]\n * ```solidity\n * contract MyToken is ERC20Upgradeable {\n *     function initialize() initializer public {\n *         __ERC20_init(\"MyToken\", \"MTK\");\n *     }\n * }\n *\n * contract MyTokenV2 is MyToken, ERC20PermitUpgradeable {\n *     function initializeV2() reinitializer(2) public {\n *         __ERC20Permit_init(\"MyToken\");\n *     }\n * }\n * ```\n *\n * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as\n * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.\n *\n * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure\n * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.\n *\n * [CAUTION]\n * ====\n * Avoid leaving a contract uninitialized.\n *\n * An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation\n * contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke\n * the {_disableInitializers} function in the constructor to automatically lock it when it is deployed:\n *\n * [.hljs-theme-light.nopadding]\n * ```\n * /// @custom:oz-upgrades-unsafe-allow constructor\n * constructor() {\n *     _disableInitializers();\n * }\n * ```\n * ====\n */\nabstract contract Initializable {\n    /**\n     * @dev Indicates that the contract has been initialized.\n     * @custom:oz-retyped-from bool\n     */\n    uint8 private _initialized;\n\n    /**\n     * @dev Indicates that the contract is in the process of being initialized.\n     */\n    bool private _initializing;\n\n    /**\n     * @dev Triggered when the contract has been initialized or reinitialized.\n     */\n    event Initialized(uint8 version);\n\n    /**\n     * @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,\n     * `onlyInitializing` functions can be used to initialize parent contracts.\n     *\n     * Similar to `reinitializer(1)`, except that functions marked with `initializer` can be nested in the context of a\n     * constructor.\n     *\n     * Emits an {Initialized} event.\n     */\n    modifier initializer() {\n        bool isTopLevelCall = !_initializing;\n        require(\n            (isTopLevelCall && _initialized < 1) || (!AddressUpgradeable.isContract(address(this)) && _initialized == 1),\n            \"Initializable: contract is already initialized\"\n        );\n        _initialized = 1;\n        if (isTopLevelCall) {\n            _initializing = true;\n        }\n        _;\n        if (isTopLevelCall) {\n            _initializing = false;\n            emit Initialized(1);\n        }\n    }\n\n    /**\n     * @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the\n     * contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be\n     * used to initialize parent contracts.\n     *\n     * A reinitializer may be used after the original initialization step. This is essential to configure modules that\n     * are added through upgrades and that require initialization.\n     *\n     * When `version` is 1, this modifier is similar to `initializer`, except that functions marked with `reinitializer`\n     * cannot be nested. If one is invoked in the context of another, execution will revert.\n     *\n     * Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in\n     * a contract, executing them in the right order is up to the developer or operator.\n     *\n     * WARNING: setting the version to 255 will prevent any future reinitialization.\n     *\n     * Emits an {Initialized} event.\n     */\n    modifier reinitializer(uint8 version) {\n        require(!_initializing && _initialized < version, \"Initializable: contract is already initialized\");\n        _initialized = version;\n        _initializing = true;\n        _;\n        _initializing = false;\n        emit Initialized(version);\n    }\n\n    /**\n     * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the\n     * {initializer} and {reinitializer} modifiers, directly or indirectly.\n     */\n    modifier onlyInitializing() {\n        require(_initializing, \"Initializable: contract is not initializing\");\n        _;\n    }\n\n    /**\n     * @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.\n     * Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized\n     * to any version. It is recommended to use this to lock implementation contracts that are designed to be called\n     * through proxies.\n     *\n     * Emits an {Initialized} event the first time it is successfully executed.\n     */\n    function _disableInitializers() internal virtual {\n        require(!_initializing, \"Initializable: contract is initializing\");\n        if (_initialized != type(uint8).max) {\n            _initialized = type(uint8).max;\n            emit Initialized(type(uint8).max);\n        }\n    }\n\n    /**\n     * @dev Returns the highest version that has been initialized. See {reinitializer}.\n     */\n    function _getInitializedVersion() internal view returns (uint8) {\n        return _initialized;\n    }\n\n    /**\n     * @dev Returns `true` if the contract is currently initializing. See {onlyInitializing}.\n     */\n    function _isInitializing() internal view returns (bool) {\n        return _initializing;\n    }\n}\n"
      },
      "@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.7.0) (security/Pausable.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../utils/ContextUpgradeable.sol\";\nimport \"../proxy/utils/Initializable.sol\";\n\n/**\n * @dev Contract module which allows children to implement an emergency stop\n * mechanism that can be triggered by an authorized account.\n *\n * This module is used through inheritance. It will make available the\n * modifiers `whenNotPaused` and `whenPaused`, which can be applied to\n * the functions of your contract. Note that they will not be pausable by\n * simply including this module, only once the modifiers are put in place.\n */\nabstract contract PausableUpgradeable is Initializable, ContextUpgradeable {\n    /**\n     * @dev Emitted when the pause is triggered by `account`.\n     */\n    event Paused(address account);\n\n    /**\n     * @dev Emitted when the pause is lifted by `account`.\n     */\n    event Unpaused(address account);\n\n    bool private _paused;\n\n    /**\n     * @dev Initializes the contract in unpaused state.\n     */\n    function __Pausable_init() internal onlyInitializing {\n        __Pausable_init_unchained();\n    }\n\n    function __Pausable_init_unchained() internal onlyInitializing {\n        _paused = false;\n    }\n\n    /**\n     * @dev Modifier to make a function callable only when the contract is not paused.\n     *\n     * Requirements:\n     *\n     * - The contract must not be paused.\n     */\n    modifier whenNotPaused() {\n        _requireNotPaused();\n        _;\n    }\n\n    /**\n     * @dev Modifier to make a function callable only when the contract is paused.\n     *\n     * Requirements:\n     *\n     * - The contract must be paused.\n     */\n    modifier whenPaused() {\n        _requirePaused();\n        _;\n    }\n\n    /**\n     * @dev Returns true if the contract is paused, and false otherwise.\n     */\n    function paused() public view virtual returns (bool) {\n        return _paused;\n    }\n\n    /**\n     * @dev Throws if the contract is paused.\n     */\n    function _requireNotPaused() internal view virtual {\n        require(!paused(), \"Pausable: paused\");\n    }\n\n    /**\n     * @dev Throws if the contract is not paused.\n     */\n    function _requirePaused() internal view virtual {\n        require(paused(), \"Pausable: not paused\");\n    }\n\n    /**\n     * @dev Triggers stopped state.\n     *\n     * Requirements:\n     *\n     * - The contract must not be paused.\n     */\n    function _pause() internal virtual whenNotPaused {\n        _paused = true;\n        emit Paused(_msgSender());\n    }\n\n    /**\n     * @dev Returns to normal state.\n     *\n     * Requirements:\n     *\n     * - The contract must be paused.\n     */\n    function _unpause() internal virtual whenPaused {\n        _paused = false;\n        emit Unpaused(_msgSender());\n    }\n\n    /**\n     * @dev This empty reserved space is put in place to allow future versions to add new\n     * variables without shifting down storage in the inheritance chain.\n     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n     */\n    uint256[49] private __gap;\n}\n"
      },
      "@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.9.0) (utils/Address.sol)\n\npragma solidity ^0.8.1;\n\n/**\n * @dev Collection of functions related to the address type\n */\nlibrary AddressUpgradeable {\n    /**\n     * @dev Returns true if `account` is a contract.\n     *\n     * [IMPORTANT]\n     * ====\n     * It is unsafe to assume that an address for which this function returns\n     * false is an externally-owned account (EOA) and not a contract.\n     *\n     * Among others, `isContract` will return false for the following\n     * types of addresses:\n     *\n     *  - an externally-owned account\n     *  - a contract in construction\n     *  - an address where a contract will be created\n     *  - an address where a contract lived, but was destroyed\n     *\n     * Furthermore, `isContract` will also return true if the target contract within\n     * the same transaction is already scheduled for destruction by `SELFDESTRUCT`,\n     * which only has an effect at the end of a transaction.\n     * ====\n     *\n     * [IMPORTANT]\n     * ====\n     * You shouldn't rely on `isContract` to protect against flash loan attacks!\n     *\n     * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets\n     * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract\n     * constructor.\n     * ====\n     */\n    function isContract(address account) internal view returns (bool) {\n        // This method relies on extcodesize/address.code.length, which returns 0\n        // for contracts in construction, since the code is only stored at the end\n        // of the constructor execution.\n\n        return account.code.length > 0;\n    }\n\n    /**\n     * @dev Replacement for Solidity's `transfer`: sends `amount` wei to\n     * `recipient`, forwarding all available gas and reverting on errors.\n     *\n     * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost\n     * of certain opcodes, possibly making contracts go over the 2300 gas limit\n     * imposed by `transfer`, making them unable to receive funds via\n     * `transfer`. {sendValue} removes this limitation.\n     *\n     * https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].\n     *\n     * IMPORTANT: because control is transferred to `recipient`, care must be\n     * taken to not create reentrancy vulnerabilities. Consider using\n     * {ReentrancyGuard} or the\n     * https://solidity.readthedocs.io/en/v0.8.0/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].\n     */\n    function sendValue(address payable recipient, uint256 amount) internal {\n        require(address(this).balance >= amount, \"Address: insufficient balance\");\n\n        (bool success, ) = recipient.call{value: amount}(\"\");\n        require(success, \"Address: unable to send value, recipient may have reverted\");\n    }\n\n    /**\n     * @dev Performs a Solidity function call using a low level `call`. A\n     * plain `call` is an unsafe replacement for a function call: use this\n     * function instead.\n     *\n     * If `target` reverts with a revert reason, it is bubbled up by this\n     * function (like regular Solidity function calls).\n     *\n     * Returns the raw returned data. To convert to the expected return value,\n     * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].\n     *\n     * Requirements:\n     *\n     * - `target` must be a contract.\n     * - calling `target` with `data` must not revert.\n     *\n     * _Available since v3.1._\n     */\n    function functionCall(address target, bytes memory data) internal returns (bytes memory) {\n        return functionCallWithValue(target, data, 0, \"Address: low-level call failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with\n     * `errorMessage` as a fallback revert reason when `target` reverts.\n     *\n     * _Available since v3.1._\n     */\n    function functionCall(\n        address target,\n        bytes memory data,\n        string memory errorMessage\n    ) internal returns (bytes memory) {\n        return functionCallWithValue(target, data, 0, errorMessage);\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n     * but also transferring `value` wei to `target`.\n     *\n     * Requirements:\n     *\n     * - the calling contract must have an ETH balance of at least `value`.\n     * - the called Solidity function must be `payable`.\n     *\n     * _Available since v3.1._\n     */\n    function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {\n        return functionCallWithValue(target, data, value, \"Address: low-level call with value failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but\n     * with `errorMessage` as a fallback revert reason when `target` reverts.\n     *\n     * _Available since v3.1._\n     */\n    function functionCallWithValue(\n        address target,\n        bytes memory data,\n        uint256 value,\n        string memory errorMessage\n    ) internal returns (bytes memory) {\n        require(address(this).balance >= value, \"Address: insufficient balance for call\");\n        (bool success, bytes memory returndata) = target.call{value: value}(data);\n        return verifyCallResultFromTarget(target, success, returndata, errorMessage);\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n     * but performing a static call.\n     *\n     * _Available since v3.3._\n     */\n    function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {\n        return functionStaticCall(target, data, \"Address: low-level static call failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n     * but performing a static call.\n     *\n     * _Available since v3.3._\n     */\n    function functionStaticCall(\n        address target,\n        bytes memory data,\n        string memory errorMessage\n    ) internal view returns (bytes memory) {\n        (bool success, bytes memory returndata) = target.staticcall(data);\n        return verifyCallResultFromTarget(target, success, returndata, errorMessage);\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n     * but performing a delegate call.\n     *\n     * _Available since v3.4._\n     */\n    function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {\n        return functionDelegateCall(target, data, \"Address: low-level delegate call failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n     * but performing a delegate call.\n     *\n     * _Available since v3.4._\n     */\n    function functionDelegateCall(\n        address target,\n        bytes memory data,\n        string memory errorMessage\n    ) internal returns (bytes memory) {\n        (bool success, bytes memory returndata) = target.delegatecall(data);\n        return verifyCallResultFromTarget(target, success, returndata, errorMessage);\n    }\n\n    /**\n     * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling\n     * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.\n     *\n     * _Available since v4.8._\n     */\n    function verifyCallResultFromTarget(\n        address target,\n        bool success,\n        bytes memory returndata,\n        string memory errorMessage\n    ) internal view returns (bytes memory) {\n        if (success) {\n            if (returndata.length == 0) {\n                // only check isContract if the call was successful and the return data is empty\n                // otherwise we already know that it was a contract\n                require(isContract(target), \"Address: call to non-contract\");\n            }\n            return returndata;\n        } else {\n            _revert(returndata, errorMessage);\n        }\n    }\n\n    /**\n     * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the\n     * revert reason or using the provided one.\n     *\n     * _Available since v4.3._\n     */\n    function verifyCallResult(\n        bool success,\n        bytes memory returndata,\n        string memory errorMessage\n    ) internal pure returns (bytes memory) {\n        if (success) {\n            return returndata;\n        } else {\n            _revert(returndata, errorMessage);\n        }\n    }\n\n    function _revert(bytes memory returndata, string memory errorMessage) private pure {\n        // Look for revert reason and bubble it up if present\n        if (returndata.length > 0) {\n            // The easiest way to bubble the revert reason is using memory via assembly\n            /// @solidity memory-safe-assembly\n            assembly {\n                let returndata_size := mload(returndata)\n                revert(add(32, returndata), returndata_size)\n            }\n        } else {\n            revert(errorMessage);\n        }\n    }\n}\n"
      },
      "@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)\n\npragma solidity ^0.8.0;\nimport \"../proxy/utils/Initializable.sol\";\n\n/**\n * @dev Provides information about the current execution context, including the\n * sender of the transaction and its data. While these are generally available\n * via msg.sender and msg.data, they should not be accessed in such a direct\n * manner, since when dealing with meta-transactions the account sending and\n * paying for execution may not be the actual sender (as far as an application\n * is concerned).\n *\n * This contract is only required for intermediate, library-like contracts.\n */\nabstract contract ContextUpgradeable is Initializable {\n    function __Context_init() internal onlyInitializing {\n    }\n\n    function __Context_init_unchained() internal onlyInitializing {\n    }\n    function _msgSender() internal view virtual returns (address) {\n        return msg.sender;\n    }\n\n    function _msgData() internal view virtual returns (bytes calldata) {\n        return msg.data;\n    }\n\n    /**\n     * @dev This empty reserved space is put in place to allow future versions to add new\n     * variables without shifting down storage in the inheritance chain.\n     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n     */\n    uint256[50] private __gap;\n}\n"
      },
      "src/L1/rollup/IL1MessageQueue.sol": {
        "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.24;\n\ninterface IL1MessageQueue {\n    /**********\n     * Events *\n     **********/\n\n    /// @notice Emitted when a new L1 => L2 transaction is appended to the queue.\n    /// @param sender The address of account who initiates the transaction.\n    /// @param target The address of account who will receive the transaction.\n    /// @param value The value passed with the transaction.\n    /// @param queueIndex The index of this transaction in the queue.\n    /// @param gasLimit Gas limit required to complete the message relay on L2.\n    /// @param data The calldata of the transaction.\n    event QueueTransaction(\n        address indexed sender,\n        address indexed target,\n        uint256 value,\n        uint64 queueIndex,\n        uint256 gasLimit,\n        bytes data\n    );\n\n    /// @notice Emitted when some L1 => L2 transactions are included in L1.\n    /// @param startIndex The start index of messages popped.\n    /// @param count The number of messages popped.\n    /// @param skippedBitmap A bitmap indicates whether a message is skipped.\n    event DequeueTransaction(uint256 startIndex, uint256 count, uint256 skippedBitmap);\n\n    /// @notice Emitted when a message is dropped from L1.\n    /// @param index The index of message dropped.\n    event DropTransaction(uint256 index);\n\n    /// @notice Emitted when owner updates gas oracle contract.\n    /// @param _oldGasOracle The address of old gas oracle contract.\n    /// @param _newGasOracle The address of new gas oracle contract.\n    event UpdateGasOracle(address indexed _oldGasOracle, address indexed _newGasOracle);\n\n    /// @notice Emitted when owner updates max gas limit.\n    /// @param _oldMaxGasLimit The old max gas limit.\n    /// @param _newMaxGasLimit The new max gas limit.\n    event UpdateMaxGasLimit(uint256 _oldMaxGasLimit, uint256 _newMaxGasLimit);\n\n    /**********\n     * Errors *\n     **********/\n\n    /// @dev Thrown when the given address is `address(0)`.\n    error ErrorZeroAddress();\n\n    /*************************\n     * Public View Functions *\n     *************************/\n\n    /// @notice The start index of all pending inclusion messages.\n    function pendingQueueIndex() external view returns (uint256);\n\n    /// @notice Return the index of next appended message.\n    /// @dev Also the total number of appended messages.\n    function nextCrossDomainMessageIndex() external view returns (uint256);\n\n    /// @notice Return the message of in `queueIndex`.\n    /// @param queueIndex The index to query.\n    function getCrossDomainMessage(uint256 queueIndex) external view returns (bytes32);\n\n    /// @notice Return the amount of ETH should pay for cross domain message.\n    /// @param gasLimit Gas limit required to complete the message relay on L2.\n    function estimateCrossDomainMessageFee(uint256 gasLimit) external view returns (uint256);\n\n    /// @notice Return the amount of intrinsic gas fee should pay for cross domain message.\n    /// @param _calldata The calldata of L1-initiated transaction.\n    function calculateIntrinsicGasFee(bytes calldata _calldata) external view returns (uint256);\n\n    /// @notice Return the hash of a L1 message.\n    /// @param sender The address of sender.\n    /// @param queueIndex The queue index of this message.\n    /// @param value The amount of Ether transfer to target.\n    /// @param target The address of target.\n    /// @param gasLimit The gas limit provided.\n    /// @param data The calldata passed to target address.\n    function computeTransactionHash(\n        address sender,\n        uint256 queueIndex,\n        uint256 value,\n        address target,\n        uint256 gasLimit,\n        bytes calldata data\n    ) external view returns (bytes32);\n\n    /// @notice Return whether the message is skipped.\n    /// @param queueIndex The queue index of the message to check.\n    function isMessageSkipped(uint256 queueIndex) external view returns (bool);\n\n    /// @notice Return whether the message is dropped.\n    /// @param queueIndex The queue index of the message to check.\n    function isMessageDropped(uint256 queueIndex) external view returns (bool);\n\n    /*****************************\n     * Public Mutating Functions *\n     *****************************/\n\n    /// @notice Append a L1 to L2 message into this contract.\n    /// @param target The address of target contract to call in L2.\n    /// @param gasLimit The maximum gas should be used for relay this message in L2.\n    /// @param data The calldata passed to target contract.\n    function appendCrossDomainMessage(\n        address target,\n        uint256 gasLimit,\n        bytes calldata data\n    ) external;\n\n    /// @notice Append an enforced transaction to this contract.\n    /// @dev The address of sender should be an EOA.\n    /// @param sender The address of sender who will initiate this transaction in L2.\n    /// @param target The address of target contract to call in L2.\n    /// @param value The value passed\n    /// @param gasLimit The maximum gas should be used for this transaction in L2.\n    /// @param data The calldata passed to target contract.\n    function appendEnforcedTransaction(\n        address sender,\n        address target,\n        uint256 value,\n        uint256 gasLimit,\n        bytes calldata data\n    ) external;\n\n    /// @notice Pop finalized messages from queue.\n    ///\n    /// @dev We can pop at most 256 messages each time. And if the message is not skipped,\n    ///      the corresponding entry will be cleared.\n    ///\n    /// @param startIndex The start index to pop.\n    /// @param count The number of messages to pop.\n    /// @param skippedBitmap A bitmap indicates whether a message is skipped.\n    function popCrossDomainMessage(\n        uint256 startIndex,\n        uint256 count,\n        uint256 skippedBitmap\n    ) external;\n\n    /// @notice Drop a skipped message from the queue.\n    function dropCrossDomainMessage(uint256 index) external;\n}\n"
      },
      "src/L1/rollup/IScrollChain.sol": {
        "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.24;\n\n/// @title IScrollChain\n/// @notice The interface for ScrollChain.\ninterface IScrollChain {\n    /**********\n     * Events *\n     **********/\n\n    /// @notice Emitted when a new batch is committed.\n    /// @param batchIndex The index of the batch.\n    /// @param batchHash The hash of the batch.\n    event CommitBatch(uint256 indexed batchIndex, bytes32 indexed batchHash);\n\n    /// @notice revert a pending batch.\n    /// @param batchIndex The index of the batch.\n    /// @param batchHash The hash of the batch\n    event RevertBatch(uint256 indexed batchIndex, bytes32 indexed batchHash);\n\n    /// @notice Emitted when a batch is finalized.\n    /// @param batchIndex The index of the batch.\n    /// @param batchHash The hash of the batch\n    /// @param stateRoot The state root on layer 2 after this batch.\n    /// @param withdrawRoot The merkle root on layer2 after this batch.\n    event FinalizeBatch(uint256 indexed batchIndex, bytes32 indexed batchHash, bytes32 stateRoot, bytes32 withdrawRoot);\n\n    /// @notice Emitted when owner updates the status of sequencer.\n    /// @param account The address of account updated.\n    /// @param status The status of the account updated.\n    event UpdateSequencer(address indexed account, bool status);\n\n    /// @notice Emitted when owner updates the status of prover.\n    /// @param account The address of account updated.\n    /// @param status The status of the account updated.\n    event UpdateProver(address indexed account, bool status);\n\n    /// @notice Emitted when the value of `maxNumTxInChunk` is updated.\n    /// @param oldMaxNumTxInChunk The old value of `maxNumTxInChunk`.\n    /// @param newMaxNumTxInChunk The new value of `maxNumTxInChunk`.\n    event UpdateMaxNumTxInChunk(uint256 oldMaxNumTxInChunk, uint256 newMaxNumTxInChunk);\n\n    /*************************\n     * Public View Functions *\n     *************************/\n\n    /// @return The latest finalized batch index.\n    function lastFinalizedBatchIndex() external view returns (uint256);\n\n    /// @param batchIndex The index of the batch.\n    /// @return The batch hash of a committed batch.\n    function committedBatches(uint256 batchIndex) external view returns (bytes32);\n\n    /// @param batchIndex The index of the batch.\n    /// @return The state root of a committed batch.\n    function finalizedStateRoots(uint256 batchIndex) external view returns (bytes32);\n\n    /// @param batchIndex The index of the batch.\n    /// @return The message root of a committed batch.\n    function withdrawRoots(uint256 batchIndex) external view returns (bytes32);\n\n    /// @param batchIndex The index of the batch.\n    /// @return Whether the batch is finalized by batch index.\n    function isBatchFinalized(uint256 batchIndex) external view returns (bool);\n\n    /*****************************\n     * Public Mutating Functions *\n     *****************************/\n\n    /// @notice Commit a batch of transactions on layer 1.\n    ///\n    /// @param version The version of current batch.\n    /// @param parentBatchHeader The header of parent batch, see the comments of `BatchHeaderV0Codec`.\n    /// @param chunks The list of encoded chunks, see the comments of `ChunkCodec`.\n    /// @param skippedL1MessageBitmap The bitmap indicates whether each L1 message is skipped or not.\n    function commitBatch(\n        uint8 version,\n        bytes calldata parentBatchHeader,\n        bytes[] memory chunks,\n        bytes calldata skippedL1MessageBitmap\n    ) external;\n\n    /// @notice Revert a pending batch.\n    /// @dev one can only revert unfinalized batches.\n    /// @param batchHeader The header of current batch, see the encoding in comments of `commitBatch`.\n    /// @param count The number of subsequent batches to revert, including current batch.\n    function revertBatch(bytes calldata batchHeader, uint256 count) external;\n\n    /// @notice Finalize a committed batch on layer 1.\n    /// @param batchHeader The header of current batch, see the encoding in comments of `commitBatch.\n    /// @param prevStateRoot The state root of parent batch.\n    /// @param postStateRoot The state root of current batch.\n    /// @param withdrawRoot The withdraw trie root of current batch.\n    /// @param aggrProof The aggregation proof for current batch.\n    function finalizeBatchWithProof(\n        bytes calldata batchHeader,\n        bytes32 prevStateRoot,\n        bytes32 postStateRoot,\n        bytes32 withdrawRoot,\n        bytes calldata aggrProof\n    ) external;\n\n    /// @notice Finalize a committed batch (with blob) on layer 1.\n    ///\n    /// @dev Memory layout of `blobDataProof`:\n    /// |    z    |    y    | kzg_commitment | kzg_proof |\n    /// |---------|---------|----------------|-----------|\n    /// | bytes32 | bytes32 |    bytes48     |  bytes48  |\n    ///\n    /// @param batchHeader The header of current batch, see the encoding in comments of `commitBatch.\n    /// @param prevStateRoot The state root of parent batch.\n    /// @param postStateRoot The state root of current batch.\n    /// @param withdrawRoot The withdraw trie root of current batch.\n    /// @param blobDataProof The proof for blob data.\n    /// @param aggrProof The aggregation proof for current batch.\n    function finalizeBatchWithProof4844(\n        bytes calldata batchHeader,\n        bytes32 prevStateRoot,\n        bytes32 postStateRoot,\n        bytes32 withdrawRoot,\n        bytes calldata blobDataProof,\n        bytes calldata aggrProof\n    ) external;\n}\n"
      },
      "src/L1/rollup/ScrollChain.sol": {
        "content": "// SPDX-License-Identifier: MIT\n\npragma solidity =0.8.24;\n\nimport {OwnableUpgradeable} from \"@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol\";\nimport {PausableUpgradeable} from \"@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol\";\n\nimport {IL1MessageQueue} from \"./IL1MessageQueue.sol\";\nimport {IScrollChain} from \"./IScrollChain.sol\";\nimport {BatchHeaderV0Codec} from \"../../libraries/codec/BatchHeaderV0Codec.sol\";\nimport {BatchHeaderV1Codec} from \"../../libraries/codec/BatchHeaderV1Codec.sol\";\nimport {ChunkCodecV0} from \"../../libraries/codec/ChunkCodecV0.sol\";\nimport {ChunkCodecV1} from \"../../libraries/codec/ChunkCodecV1.sol\";\nimport {IRollupVerifier} from \"../../libraries/verifier/IRollupVerifier.sol\";\n\n// solhint-disable no-inline-assembly\n// solhint-disable reason-string\n\n/// @title ScrollChain\n/// @notice This contract maintains data for the Scroll rollup.\ncontract ScrollChain is OwnableUpgradeable, PausableUpgradeable, IScrollChain {\n    /**********\n     * Errors *\n     **********/\n\n    /// @dev Thrown when the given account is not EOA account.\n    error ErrorAccountIsNotEOA();\n\n    /// @dev Thrown when committing a committed batch.\n    error ErrorBatchIsAlreadyCommitted();\n\n    /// @dev Thrown when finalizing a verified batch.\n    error ErrorBatchIsAlreadyVerified();\n\n    /// @dev Thrown when committing empty batch (batch without chunks)\n    error ErrorBatchIsEmpty();\n\n    /// @dev Thrown when call precompile failed.\n    error ErrorCallPointEvaluationPrecompileFailed();\n\n    /// @dev Thrown when the caller is not prover.\n    error ErrorCallerIsNotProver();\n\n    /// @dev Thrown when the caller is not sequencer.\n    error ErrorCallerIsNotSequencer();\n\n    /// @dev Thrown when the transaction has multiple blobs.\n    error ErrorFoundMultipleBlob();\n\n    /// @dev Thrown when some fields are not zero in genesis batch.\n    error ErrorGenesisBatchHasNonZeroField();\n\n    /// @dev Thrown when importing genesis batch twice.\n    error ErrorGenesisBatchImported();\n\n    /// @dev Thrown when data hash in genesis batch is zero.\n    error ErrorGenesisDataHashIsZero();\n\n    /// @dev Thrown when the parent batch hash in genesis batch is zero.\n    error ErrorGenesisParentBatchHashIsNonZero();\n\n    /// @dev Thrown when the l2 transaction is incomplete.\n    error ErrorIncompleteL2TransactionData();\n\n    /// @dev Thrown when the batch hash is incorrect.\n    error ErrorIncorrectBatchHash();\n\n    /// @dev Thrown when the batch index is incorrect.\n    error ErrorIncorrectBatchIndex();\n\n    /// @dev Thrown when the bitmap length is incorrect.\n    error ErrorIncorrectBitmapLength();\n\n    /// @dev Thrown when the previous state root doesn't match stored one.\n    error ErrorIncorrectPreviousStateRoot();\n\n    /// @dev Thrown when the batch header version is invalid.\n    error ErrorInvalidBatchHeaderVersion();\n\n    /// @dev Thrown when the last message is skipped.\n    error ErrorLastL1MessageSkipped();\n\n    /// @dev Thrown when no blob found in the transaction.\n    error ErrorNoBlobFound();\n\n    /// @dev Thrown when the number of transactions is less than number of L1 message in one block.\n    error ErrorNumTxsLessThanNumL1Msgs();\n\n    /// @dev Thrown when the given previous state is zero.\n    error ErrorPreviousStateRootIsZero();\n\n    /// @dev Thrown when the number of batches to revert is zero.\n    error ErrorRevertZeroBatches();\n\n    /// @dev Thrown when the reverted batches are not in the ending of commited batch chain.\n    error ErrorRevertNotStartFromEnd();\n\n    /// @dev Thrown when reverting a finialized batch.\n    error ErrorRevertFinalizedBatch();\n\n    /// @dev Thrown when the given state root is zero.\n    error ErrorStateRootIsZero();\n\n    /// @dev Thrown when a chunk contains too many transactions.\n    error ErrorTooManyTxsInOneChunk();\n\n    /// @dev Thrown when the precompile output is incorrect.\n    error ErrorUnexpectedPointEvaluationPrecompileOutput();\n\n    /// @dev Thrown when the given address is `address(0)`.\n    error ErrorZeroAddress();\n\n    /*************\n     * Constants *\n     *************/\n\n    /// @dev Address of the point evaluation precompile used for EIP-4844 blob verification.\n    address private constant POINT_EVALUATION_PRECOMPILE_ADDR = address(0x0A);\n\n    /// @dev BLS Modulus value defined in EIP-4844 and the magic value returned from a successful call to the\n    /// point evaluation precompile\n    uint256 private constant BLS_MODULUS = 52435875175126190479447740508185965837690552500527637822603658699938581184513;\n\n    /// @notice The chain id of the corresponding layer 2 chain.\n    uint64 public immutable layer2ChainId;\n\n    /// @notice The address of L1MessageQueue contract.\n    address public immutable messageQueue;\n\n    /// @notice The address of RollupVerifier.\n    address public immutable verifier;\n\n    /*************\n     * Variables *\n     *************/\n\n    /// @notice The maximum number of transactions allowed in each chunk.\n    uint256 public maxNumTxInChunk;\n\n    /// @dev The storage slot used as L1MessageQueue contract, which is deprecated now.\n    address private __messageQueue;\n\n    /// @dev The storage slot used as RollupVerifier contract, which is deprecated now.\n    address private __verifier;\n\n    /// @notice Whether an account is a sequencer.\n    mapping(address => bool) public isSequencer;\n\n    /// @notice Whether an account is a prover.\n    mapping(address => bool) public isProver;\n\n    /// @inheritdoc IScrollChain\n    uint256 public override lastFinalizedBatchIndex;\n\n    /// @inheritdoc IScrollChain\n    mapping(uint256 => bytes32) public override committedBatches;\n\n    /// @inheritdoc IScrollChain\n    mapping(uint256 => bytes32) public override finalizedStateRoots;\n\n    /// @inheritdoc IScrollChain\n    mapping(uint256 => bytes32) public override withdrawRoots;\n\n    /**********************\n     * Function Modifiers *\n     **********************/\n\n    modifier OnlySequencer() {\n        // @note In the decentralized mode, it should be only called by a list of validator.\n        if (!isSequencer[_msgSender()]) revert ErrorCallerIsNotSequencer();\n        _;\n    }\n\n    modifier OnlyProver() {\n        if (!isProver[_msgSender()]) revert ErrorCallerIsNotProver();\n        _;\n    }\n\n    /***************\n     * Constructor *\n     ***************/\n\n    /// @notice Constructor for `ScrollChain` implementation contract.\n    ///\n    /// @param _chainId The chain id of L2.\n    /// @param _messageQueue The address of `L1MessageQueue` contract.\n    /// @param _verifier The address of zkevm verifier contract.\n    constructor(\n        uint64 _chainId,\n        address _messageQueue,\n        address _verifier\n    ) {\n        if (_messageQueue == address(0) || _verifier == address(0)) {\n            revert ErrorZeroAddress();\n        }\n\n        _disableInitializers();\n\n        layer2ChainId = _chainId;\n        messageQueue = _messageQueue;\n        verifier = _verifier;\n    }\n\n    /// @notice Initialize the storage of ScrollChain.\n    ///\n    /// @dev The parameters `_messageQueue` are no longer used.\n    ///\n    /// @param _messageQueue The address of `L1MessageQueue` contract.\n    /// @param _verifier The address of zkevm verifier contract.\n    /// @param _maxNumTxInChunk The maximum number of transactions allowed in each chunk.\n    function initialize(\n        address _messageQueue,\n        address _verifier,\n        uint256 _maxNumTxInChunk\n    ) public initializer {\n        OwnableUpgradeable.__Ownable_init();\n\n        maxNumTxInChunk = _maxNumTxInChunk;\n        __verifier = _verifier;\n        __messageQueue = _messageQueue;\n\n        emit UpdateMaxNumTxInChunk(0, _maxNumTxInChunk);\n    }\n\n    /*************************\n     * Public View Functions *\n     *************************/\n\n    /// @inheritdoc IScrollChain\n    function isBatchFinalized(uint256 _batchIndex) external view override returns (bool) {\n        return _batchIndex <= lastFinalizedBatchIndex;\n    }\n\n    /*****************************\n     * Public Mutating Functions *\n     *****************************/\n\n    /// @notice Import layer 2 genesis block\n    /// @param _batchHeader The header of the genesis batch.\n    /// @param _stateRoot The state root of the genesis block.\n    function importGenesisBatch(bytes calldata _batchHeader, bytes32 _stateRoot) external {\n        // check genesis batch header length\n        if (_stateRoot == bytes32(0)) revert ErrorStateRootIsZero();\n\n        // check whether the genesis batch is imported\n        if (finalizedStateRoots[0] != bytes32(0)) revert ErrorGenesisBatchImported();\n\n        (uint256 memPtr, bytes32 _batchHash, , ) = _loadBatchHeader(_batchHeader);\n\n        // check all fields except `dataHash` and `lastBlockHash` are zero\n        unchecked {\n            uint256 sum = BatchHeaderV0Codec.getVersion(memPtr) +\n                BatchHeaderV0Codec.getBatchIndex(memPtr) +\n                BatchHeaderV0Codec.getL1MessagePopped(memPtr) +\n                BatchHeaderV0Codec.getTotalL1MessagePopped(memPtr);\n            if (sum != 0) revert ErrorGenesisBatchHasNonZeroField();\n        }\n        if (BatchHeaderV0Codec.getDataHash(memPtr) == bytes32(0)) revert ErrorGenesisDataHashIsZero();\n        if (BatchHeaderV0Codec.getParentBatchHash(memPtr) != bytes32(0)) revert ErrorGenesisParentBatchHashIsNonZero();\n\n        committedBatches[0] = _batchHash;\n        finalizedStateRoots[0] = _stateRoot;\n\n        emit CommitBatch(0, _batchHash);\n        emit FinalizeBatch(0, _batchHash, _stateRoot, bytes32(0));\n    }\n\n    /// @inheritdoc IScrollChain\n    function commitBatch(\n        uint8 _version,\n        bytes calldata _parentBatchHeader,\n        bytes[] memory _chunks,\n        bytes calldata _skippedL1MessageBitmap\n    ) external override OnlySequencer whenNotPaused {\n        // check whether the batch is empty\n        if (_chunks.length == 0) revert ErrorBatchIsEmpty();\n\n        (, bytes32 _parentBatchHash, uint256 _batchIndex, uint256 _totalL1MessagesPoppedOverall) = _loadBatchHeader(\n            _parentBatchHeader\n        );\n        unchecked {\n            _batchIndex += 1;\n        }\n        if (committedBatches[_batchIndex] != 0) revert ErrorBatchIsAlreadyCommitted();\n\n        bytes32 _batchHash;\n        uint256 batchPtr;\n        bytes32 _dataHash;\n        uint256 _totalL1MessagesPoppedInBatch;\n        if (_version == 0) {\n            (_dataHash, _totalL1MessagesPoppedInBatch) = _commitChunksV0(\n                _totalL1MessagesPoppedOverall,\n                _chunks,\n                _skippedL1MessageBitmap\n            );\n            assembly {\n                batchPtr := mload(0x40)\n                _totalL1MessagesPoppedOverall := add(_totalL1MessagesPoppedOverall, _totalL1MessagesPoppedInBatch)\n            }\n            // store entries, the order matters\n            BatchHeaderV0Codec.storeVersion(batchPtr, 0);\n            BatchHeaderV0Codec.storeBatchIndex(batchPtr, _batchIndex);\n            BatchHeaderV0Codec.storeL1MessagePopped(batchPtr, _totalL1MessagesPoppedInBatch);\n            BatchHeaderV0Codec.storeTotalL1MessagePopped(batchPtr, _totalL1MessagesPoppedOverall);\n            BatchHeaderV0Codec.storeDataHash(batchPtr, _dataHash);\n            BatchHeaderV0Codec.storeParentBatchHash(batchPtr, _parentBatchHash);\n            BatchHeaderV0Codec.storeSkippedBitmap(batchPtr, _skippedL1MessageBitmap);\n            // compute batch hash\n            _batchHash = BatchHeaderV0Codec.computeBatchHash(\n                batchPtr,\n                BatchHeaderV0Codec.BATCH_HEADER_FIXED_LENGTH + _skippedL1MessageBitmap.length\n            );\n        } else if (_version == 1) {\n            bytes32 blobVersionedHash;\n            (blobVersionedHash, _dataHash, _totalL1MessagesPoppedInBatch) = _commitChunksV1(\n                _totalL1MessagesPoppedOverall,\n                _chunks,\n                _skippedL1MessageBitmap\n            );\n            assembly {\n                batchPtr := mload(0x40)\n                _totalL1MessagesPoppedOverall := add(_totalL1MessagesPoppedOverall, _totalL1MessagesPoppedInBatch)\n            }\n            // store entries, the order matters\n            BatchHeaderV1Codec.storeVersion(batchPtr, 1);\n            BatchHeaderV1Codec.storeBatchIndex(batchPtr, _batchIndex);\n            BatchHeaderV1Codec.storeL1MessagePopped(batchPtr, _totalL1MessagesPoppedInBatch);\n            BatchHeaderV1Codec.storeTotalL1MessagePopped(batchPtr, _totalL1MessagesPoppedOverall);\n            BatchHeaderV1Codec.storeDataHash(batchPtr, _dataHash);\n            BatchHeaderV1Codec.storeBlobVersionedHash(batchPtr, blobVersionedHash);\n            BatchHeaderV1Codec.storeParentBatchHash(batchPtr, _parentBatchHash);\n            BatchHeaderV1Codec.storeSkippedBitmap(batchPtr, _skippedL1MessageBitmap);\n            // compute batch hash\n            _batchHash = BatchHeaderV1Codec.computeBatchHash(\n                batchPtr,\n                BatchHeaderV1Codec.BATCH_HEADER_FIXED_LENGTH + _skippedL1MessageBitmap.length\n            );\n        } else {\n            revert ErrorInvalidBatchHeaderVersion();\n        }\n\n        // check the length of bitmap\n        unchecked {\n            if (((_totalL1MessagesPoppedInBatch + 255) / 256) * 32 != _skippedL1MessageBitmap.length) {\n                revert ErrorIncorrectBitmapLength();\n            }\n        }\n\n        committedBatches[_batchIndex] = _batchHash;\n        emit CommitBatch(_batchIndex, _batchHash);\n    }\n\n    /// @inheritdoc IScrollChain\n    /// @dev If the owner want to revert a sequence of batches by sending multiple transactions,\n    ///      make sure to revert recent batches first.\n    function revertBatch(bytes calldata _batchHeader, uint256 _count) external onlyOwner {\n        if (_count == 0) revert ErrorRevertZeroBatches();\n\n        (, bytes32 _batchHash, uint256 _batchIndex, ) = _loadBatchHeader(_batchHeader);\n        // make sure no gap is left when reverting from the ending to the beginning.\n        if (committedBatches[_batchIndex + _count] != bytes32(0)) revert ErrorRevertNotStartFromEnd();\n\n        // check finalization\n        if (_batchIndex <= lastFinalizedBatchIndex) revert ErrorRevertFinalizedBatch();\n\n        while (_count > 0) {\n            committedBatches[_batchIndex] = bytes32(0);\n\n            emit RevertBatch(_batchIndex, _batchHash);\n\n            unchecked {\n                _batchIndex += 1;\n                _count -= 1;\n            }\n\n            _batchHash = committedBatches[_batchIndex];\n            if (_batchHash == bytes32(0)) break;\n        }\n    }\n\n    /// @inheritdoc IScrollChain\n    /// @dev We keep this function to upgrade to 4844 more smoothly.\n    function finalizeBatchWithProof(\n        bytes calldata _batchHeader,\n        bytes32 _prevStateRoot,\n        bytes32 _postStateRoot,\n        bytes32 _withdrawRoot,\n        bytes calldata _aggrProof\n    ) external override OnlyProver whenNotPaused {\n        if (_prevStateRoot == bytes32(0)) revert ErrorPreviousStateRootIsZero();\n        if (_postStateRoot == bytes32(0)) revert ErrorStateRootIsZero();\n\n        // compute batch hash and verify\n        (uint256 memPtr, bytes32 _batchHash, uint256 _batchIndex, ) = _loadBatchHeader(_batchHeader);\n        bytes32 _dataHash = BatchHeaderV0Codec.getDataHash(memPtr);\n\n        // verify previous state root.\n        if (finalizedStateRoots[_batchIndex - 1] != _prevStateRoot) revert ErrorIncorrectPreviousStateRoot();\n\n        // avoid duplicated verification\n        if (finalizedStateRoots[_batchIndex] != bytes32(0)) revert ErrorBatchIsAlreadyVerified();\n\n        // compute public input hash\n        bytes32 _publicInputHash = keccak256(\n            abi.encodePacked(layer2ChainId, _prevStateRoot, _postStateRoot, _withdrawRoot, _dataHash)\n        );\n\n        // verify batch\n        IRollupVerifier(verifier).verifyAggregateProof(0, _batchIndex, _aggrProof, _publicInputHash);\n\n        // check and update lastFinalizedBatchIndex\n        unchecked {\n            if (lastFinalizedBatchIndex + 1 != _batchIndex) revert ErrorIncorrectBatchIndex();\n            lastFinalizedBatchIndex = _batchIndex;\n        }\n\n        // record state root and withdraw root\n        finalizedStateRoots[_batchIndex] = _postStateRoot;\n        withdrawRoots[_batchIndex] = _withdrawRoot;\n\n        // Pop finalized and non-skipped message from L1MessageQueue.\n        _popL1Messages(\n            BatchHeaderV0Codec.getSkippedBitmapPtr(memPtr),\n            BatchHeaderV0Codec.getTotalL1MessagePopped(memPtr),\n            BatchHeaderV0Codec.getL1MessagePopped(memPtr)\n        );\n\n        emit FinalizeBatch(_batchIndex, _batchHash, _postStateRoot, _withdrawRoot);\n    }\n\n    /// @inheritdoc IScrollChain\n    /// @dev Memory layout of `_blobDataProof`:\n    /// ```text\n    /// | z       | y       | kzg_commitment | kzg_proof |\n    /// |---------|---------|----------------|-----------|\n    /// | bytes32 | bytes32 | bytes48        | bytes48   |\n    /// ```\n    function finalizeBatchWithProof4844(\n        bytes calldata _batchHeader,\n        bytes32 _prevStateRoot,\n        bytes32 _postStateRoot,\n        bytes32 _withdrawRoot,\n        bytes calldata _blobDataProof,\n        bytes calldata _aggrProof\n    ) external override OnlyProver whenNotPaused {\n        if (_prevStateRoot == bytes32(0)) revert ErrorPreviousStateRootIsZero();\n        if (_postStateRoot == bytes32(0)) revert ErrorStateRootIsZero();\n\n        // compute batch hash and verify\n        (uint256 memPtr, bytes32 _batchHash, uint256 _batchIndex, ) = _loadBatchHeader(_batchHeader);\n        bytes32 _dataHash = BatchHeaderV1Codec.getDataHash(memPtr);\n        bytes32 _blobVersionedHash = BatchHeaderV1Codec.getBlobVersionedHash(memPtr);\n\n        // Calls the point evaluation precompile and verifies the output\n        {\n            (bool success, bytes memory data) = POINT_EVALUATION_PRECOMPILE_ADDR.staticcall(\n                abi.encodePacked(_blobVersionedHash, _blobDataProof)\n            );\n            // We verify that the point evaluation precompile call was successful by testing the latter 32 bytes of the\n            // response is equal to BLS_MODULUS as defined in https://eips.ethereum.org/EIPS/eip-4844#point-evaluation-precompile\n            if (!success) revert ErrorCallPointEvaluationPrecompileFailed();\n            (, uint256 result) = abi.decode(data, (uint256, uint256));\n            if (result != BLS_MODULUS) revert ErrorUnexpectedPointEvaluationPrecompileOutput();\n        }\n\n        // verify previous state root.\n        if (finalizedStateRoots[_batchIndex - 1] != _prevStateRoot) revert ErrorIncorrectPreviousStateRoot();\n\n        // avoid duplicated verification\n        if (finalizedStateRoots[_batchIndex] != bytes32(0)) revert ErrorBatchIsAlreadyVerified();\n\n        // compute public input hash\n        bytes32 _publicInputHash = keccak256(\n            abi.encodePacked(\n                layer2ChainId,\n                _prevStateRoot,\n                _postStateRoot,\n                _withdrawRoot,\n                _dataHash,\n                _blobDataProof[0:64],\n                _blobVersionedHash\n            )\n        );\n\n        // load version from batch header, it is always the first byte.\n        uint256 batchVersion;\n        assembly {\n            batchVersion := shr(248, calldataload(_batchHeader.offset))\n        }\n        // verify batch\n        IRollupVerifier(verifier).verifyAggregateProof(batchVersion, _batchIndex, _aggrProof, _publicInputHash);\n\n        // check and update lastFinalizedBatchIndex\n        unchecked {\n            if (lastFinalizedBatchIndex + 1 != _batchIndex) revert ErrorIncorrectBatchIndex();\n            lastFinalizedBatchIndex = _batchIndex;\n        }\n\n        // record state root and withdraw root\n        finalizedStateRoots[_batchIndex] = _postStateRoot;\n        withdrawRoots[_batchIndex] = _withdrawRoot;\n\n        // Pop finalized and non-skipped message from L1MessageQueue.\n        _popL1Messages(\n            BatchHeaderV1Codec.getSkippedBitmapPtr(memPtr),\n            BatchHeaderV1Codec.getTotalL1MessagePopped(memPtr),\n            BatchHeaderV1Codec.getL1MessagePopped(memPtr)\n        );\n\n        emit FinalizeBatch(_batchIndex, _batchHash, _postStateRoot, _withdrawRoot);\n    }\n\n    /************************\n     * Restricted Functions *\n     ************************/\n\n    /// @notice Add an account to the sequencer list.\n    /// @param _account The address of account to add.\n    function addSequencer(address _account) external onlyOwner {\n        // @note Currently many external services rely on EOA sequencer to decode metadata directly from tx.calldata.\n        // So we explicitly make sure the account is EOA.\n        if (_account.code.length > 0) revert ErrorAccountIsNotEOA();\n\n        isSequencer[_account] = true;\n\n        emit UpdateSequencer(_account, true);\n    }\n\n    /// @notice Remove an account from the sequencer list.\n    /// @param _account The address of account to remove.\n    function removeSequencer(address _account) external onlyOwner {\n        isSequencer[_account] = false;\n\n        emit UpdateSequencer(_account, false);\n    }\n\n    /// @notice Add an account to the prover list.\n    /// @param _account The address of account to add.\n    function addProver(address _account) external onlyOwner {\n        // @note Currently many external services rely on EOA prover to decode metadata directly from tx.calldata.\n        // So we explicitly make sure the account is EOA.\n        if (_account.code.length > 0) revert ErrorAccountIsNotEOA();\n        isProver[_account] = true;\n\n        emit UpdateProver(_account, true);\n    }\n\n    /// @notice Add an account from the prover list.\n    /// @param _account The address of account to remove.\n    function removeProver(address _account) external onlyOwner {\n        isProver[_account] = false;\n\n        emit UpdateProver(_account, false);\n    }\n\n    /// @notice Update the value of `maxNumTxInChunk`.\n    /// @param _maxNumTxInChunk The new value of `maxNumTxInChunk`.\n    function updateMaxNumTxInChunk(uint256 _maxNumTxInChunk) external onlyOwner {\n        uint256 _oldMaxNumTxInChunk = maxNumTxInChunk;\n        maxNumTxInChunk = _maxNumTxInChunk;\n\n        emit UpdateMaxNumTxInChunk(_oldMaxNumTxInChunk, _maxNumTxInChunk);\n    }\n\n    /// @notice Pause the contract\n    /// @param _status The pause status to update.\n    function setPause(bool _status) external onlyOwner {\n        if (_status) {\n            _pause();\n        } else {\n            _unpause();\n        }\n    }\n\n    /**********************\n     * Internal Functions *\n     **********************/\n\n    /// @dev Internal function to commit chunks with version 0\n    /// @param _totalL1MessagesPoppedOverall The number of L1 messages popped before the list of chunks.\n    /// @param _chunks The list of chunks to commit.\n    /// @param _skippedL1MessageBitmap The bitmap indicates whether each L1 message is skipped or not.\n    /// @return _batchDataHash The computed data hash for the list of chunks.\n    /// @return _totalL1MessagesPoppedInBatch The total number of L1 messages poped in this batch, including skipped one.\n    function _commitChunksV0(\n        uint256 _totalL1MessagesPoppedOverall,\n        bytes[] memory _chunks,\n        bytes calldata _skippedL1MessageBitmap\n    ) internal view returns (bytes32 _batchDataHash, uint256 _totalL1MessagesPoppedInBatch) {\n        uint256 _chunksLength = _chunks.length;\n\n        // load `batchDataHashPtr` and reserve the memory region for chunk data hashes\n        uint256 batchDataHashPtr;\n        assembly {\n            batchDataHashPtr := mload(0x40)\n            mstore(0x40, add(batchDataHashPtr, mul(_chunksLength, 32)))\n        }\n\n        // compute the data hash for each chunk\n        for (uint256 i = 0; i < _chunksLength; i++) {\n            uint256 _totalNumL1MessagesInChunk;\n            bytes32 _chunkDataHash;\n            (_chunkDataHash, _totalNumL1MessagesInChunk) = _commitChunkV0(\n                _chunks[i],\n                _totalL1MessagesPoppedInBatch,\n                _totalL1MessagesPoppedOverall,\n                _skippedL1MessageBitmap\n            );\n            unchecked {\n                _totalL1MessagesPoppedInBatch += _totalNumL1MessagesInChunk;\n                _totalL1MessagesPoppedOverall += _totalNumL1MessagesInChunk;\n            }\n            assembly {\n                mstore(batchDataHashPtr, _chunkDataHash)\n                batchDataHashPtr := add(batchDataHashPtr, 0x20)\n            }\n        }\n\n        assembly {\n            let dataLen := mul(_chunksLength, 0x20)\n            _batchDataHash := keccak256(sub(batchDataHashPtr, dataLen), dataLen)\n        }\n    }\n\n    /// @dev Internal function to commit chunks with version 1\n    /// @param _totalL1MessagesPoppedOverall The number of L1 messages popped before the list of chunks.\n    /// @param _chunks The list of chunks to commit.\n    /// @param _skippedL1MessageBitmap The bitmap indicates whether each L1 message is skipped or not.\n    /// @return _blobVersionedHash The blob versioned hash for the blob carried in this transaction.\n    /// @return _batchDataHash The computed data hash for the list of chunks.\n    /// @return _totalL1MessagesPoppedInBatch The total number of L1 messages poped in this batch, including skipped one.\n    function _commitChunksV1(\n        uint256 _totalL1MessagesPoppedOverall,\n        bytes[] memory _chunks,\n        bytes calldata _skippedL1MessageBitmap\n    )\n        internal\n        view\n        returns (\n            bytes32 _blobVersionedHash,\n            bytes32 _batchDataHash,\n            uint256 _totalL1MessagesPoppedInBatch\n        )\n    {\n        {\n            bytes32 _secondBlob;\n            // Get blob's versioned hash\n            assembly {\n                _blobVersionedHash := blobhash(0)\n                _secondBlob := blobhash(1)\n            }\n            if (_blobVersionedHash == bytes32(0)) revert ErrorNoBlobFound();\n            if (_secondBlob != bytes32(0)) revert ErrorFoundMultipleBlob();\n        }\n\n        uint256 _chunksLength = _chunks.length;\n\n        // load `batchDataHashPtr` and reserve the memory region for chunk data hashes\n        uint256 batchDataHashPtr;\n        assembly {\n            batchDataHashPtr := mload(0x40)\n            mstore(0x40, add(batchDataHashPtr, mul(_chunksLength, 32)))\n        }\n\n        // compute the data hash for each chunk\n        for (uint256 i = 0; i < _chunksLength; i++) {\n            uint256 _totalNumL1MessagesInChunk;\n            bytes32 _chunkDataHash;\n            (_chunkDataHash, _totalNumL1MessagesInChunk) = _commitChunkV1(\n                _chunks[i],\n                _totalL1MessagesPoppedInBatch,\n                _totalL1MessagesPoppedOverall,\n                _skippedL1MessageBitmap\n            );\n            unchecked {\n                _totalL1MessagesPoppedInBatch += _totalNumL1MessagesInChunk;\n                _totalL1MessagesPoppedOverall += _totalNumL1MessagesInChunk;\n            }\n            assembly {\n                mstore(batchDataHashPtr, _chunkDataHash)\n                batchDataHashPtr := add(batchDataHashPtr, 0x20)\n            }\n        }\n\n        // compute the data hash for current batch\n        assembly {\n            let dataLen := mul(_chunksLength, 0x20)\n            _batchDataHash := keccak256(sub(batchDataHashPtr, dataLen), dataLen)\n        }\n    }\n\n    /// @dev Internal function to load batch header from calldata to memory.\n    /// @param _batchHeader The batch header in calldata.\n    /// @return batchPtr The start memory offset of loaded batch header.\n    /// @return _batchHash The hash of the loaded batch header.\n    /// @return _batchIndex The index of this batch.\n    /// @param _totalL1MessagesPoppedOverall The number of L1 messages popped after this batch.\n    function _loadBatchHeader(bytes calldata _batchHeader)\n        internal\n        view\n        returns (\n            uint256 batchPtr,\n            bytes32 _batchHash,\n            uint256 _batchIndex,\n            uint256 _totalL1MessagesPoppedOverall\n        )\n    {\n        // load version from batch header, it is always the first byte.\n        uint256 version;\n        assembly {\n            version := shr(248, calldataload(_batchHeader.offset))\n        }\n\n        // version should be always 0 or 1 in current code\n        uint256 _length;\n        if (version == 0) {\n            (batchPtr, _length) = BatchHeaderV0Codec.loadAndValidate(_batchHeader);\n            _batchHash = BatchHeaderV0Codec.computeBatchHash(batchPtr, _length);\n            _batchIndex = BatchHeaderV0Codec.getBatchIndex(batchPtr);\n        } else if (version == 1) {\n            (batchPtr, _length) = BatchHeaderV1Codec.loadAndValidate(_batchHeader);\n            _batchHash = BatchHeaderV1Codec.computeBatchHash(batchPtr, _length);\n            _batchIndex = BatchHeaderV1Codec.getBatchIndex(batchPtr);\n        } else {\n            revert ErrorInvalidBatchHeaderVersion();\n        }\n        // only check when genesis is imported\n        if (committedBatches[_batchIndex] != _batchHash && finalizedStateRoots[0] != bytes32(0)) {\n            revert ErrorIncorrectBatchHash();\n        }\n        _totalL1MessagesPoppedOverall = BatchHeaderV0Codec.getTotalL1MessagePopped(batchPtr);\n    }\n\n    /// @dev Internal function to commit a chunk with version 0.\n    /// @param _chunk The encoded chunk to commit.\n    /// @param _totalL1MessagesPoppedInBatch The total number of L1 messages popped in the current batch before this chunk.\n    /// @param _totalL1MessagesPoppedOverall The total number of L1 messages popped in all batches including the current batch, before this chunk.\n    /// @param _skippedL1MessageBitmap The bitmap indicates whether each L1 message is skipped or not.\n    /// @return _dataHash The computed data hash for this chunk.\n    /// @return _totalNumL1MessagesInChunk The total number of L1 message popped in current chunk\n    function _commitChunkV0(\n        bytes memory _chunk,\n        uint256 _totalL1MessagesPoppedInBatch,\n        uint256 _totalL1MessagesPoppedOverall,\n        bytes calldata _skippedL1MessageBitmap\n    ) internal view returns (bytes32 _dataHash, uint256 _totalNumL1MessagesInChunk) {\n        uint256 chunkPtr;\n        uint256 startDataPtr;\n        uint256 dataPtr;\n\n        assembly {\n            dataPtr := mload(0x40)\n            startDataPtr := dataPtr\n            chunkPtr := add(_chunk, 0x20) // skip chunkLength\n        }\n\n        uint256 _numBlocks = ChunkCodecV0.validateChunkLength(chunkPtr, _chunk.length);\n\n        // concatenate block contexts, use scope to avoid stack too deep\n        {\n            uint256 _totalTransactionsInChunk;\n            for (uint256 i = 0; i < _numBlocks; i++) {\n                dataPtr = ChunkCodecV0.copyBlockContext(chunkPtr, dataPtr, i);\n                uint256 blockPtr = chunkPtr + 1 + i * ChunkCodecV0.BLOCK_CONTEXT_LENGTH;\n                uint256 _numTransactionsInBlock = ChunkCodecV0.getNumTransactions(blockPtr);\n                unchecked {\n                    _totalTransactionsInChunk += _numTransactionsInBlock;\n                }\n            }\n            assembly {\n                mstore(0x40, add(dataPtr, mul(_totalTransactionsInChunk, 0x20))) // reserve memory for tx hashes\n            }\n        }\n\n        // It is used to compute the actual number of transactions in chunk.\n        uint256 txHashStartDataPtr = dataPtr;\n        // concatenate tx hashes\n        uint256 l2TxPtr = ChunkCodecV0.getL2TxPtr(chunkPtr, _numBlocks);\n        chunkPtr += 1;\n        while (_numBlocks > 0) {\n            // concatenate l1 message hashes\n            uint256 _numL1MessagesInBlock = ChunkCodecV0.getNumL1Messages(chunkPtr);\n            dataPtr = _loadL1MessageHashes(\n                dataPtr,\n                _numL1MessagesInBlock,\n                _totalL1MessagesPoppedInBatch,\n                _totalL1MessagesPoppedOverall,\n                _skippedL1MessageBitmap\n            );\n\n            // concatenate l2 transaction hashes\n            uint256 _numTransactionsInBlock = ChunkCodecV0.getNumTransactions(chunkPtr);\n            if (_numTransactionsInBlock < _numL1MessagesInBlock) revert ErrorNumTxsLessThanNumL1Msgs();\n            for (uint256 j = _numL1MessagesInBlock; j < _numTransactionsInBlock; j++) {\n                bytes32 txHash;\n                (txHash, l2TxPtr) = ChunkCodecV0.loadL2TxHash(l2TxPtr);\n                assembly {\n                    mstore(dataPtr, txHash)\n                    dataPtr := add(dataPtr, 0x20)\n                }\n            }\n\n            unchecked {\n                _totalNumL1MessagesInChunk += _numL1MessagesInBlock;\n                _totalL1MessagesPoppedInBatch += _numL1MessagesInBlock;\n                _totalL1MessagesPoppedOverall += _numL1MessagesInBlock;\n\n                _numBlocks -= 1;\n                chunkPtr += ChunkCodecV0.BLOCK_CONTEXT_LENGTH;\n            }\n        }\n\n        // check the actual number of transactions in the chunk\n        if ((dataPtr - txHashStartDataPtr) / 32 > maxNumTxInChunk) revert ErrorTooManyTxsInOneChunk();\n\n        assembly {\n            chunkPtr := add(_chunk, 0x20)\n        }\n        // check chunk has correct length\n        if (l2TxPtr - chunkPtr != _chunk.length) revert ErrorIncompleteL2TransactionData();\n\n        // compute data hash and store to memory\n        assembly {\n            _dataHash := keccak256(startDataPtr, sub(dataPtr, startDataPtr))\n        }\n    }\n\n    /// @dev Internal function to commit a chunk with version 1.\n    /// @param _chunk The encoded chunk to commit.\n    /// @param _totalL1MessagesPoppedInBatch The total number of L1 messages popped in current batch.\n    /// @param _totalL1MessagesPoppedOverall The total number of L1 messages popped in all batches including current batch.\n    /// @param _skippedL1MessageBitmap The bitmap indicates whether each L1 message is skipped or not.\n    /// @return _dataHash The computed data hash for this chunk.\n    /// @return _totalNumL1MessagesInChunk The total number of L1 message popped in current chunk\n    function _commitChunkV1(\n        bytes memory _chunk,\n        uint256 _totalL1MessagesPoppedInBatch,\n        uint256 _totalL1MessagesPoppedOverall,\n        bytes calldata _skippedL1MessageBitmap\n    ) internal view returns (bytes32 _dataHash, uint256 _totalNumL1MessagesInChunk) {\n        uint256 chunkPtr;\n        uint256 startDataPtr;\n        uint256 dataPtr;\n\n        assembly {\n            dataPtr := mload(0x40)\n            startDataPtr := dataPtr\n            chunkPtr := add(_chunk, 0x20) // skip chunkLength\n        }\n\n        uint256 _numBlocks = ChunkCodecV1.validateChunkLength(chunkPtr, _chunk.length);\n        // concatenate block contexts, use scope to avoid stack too deep\n        for (uint256 i = 0; i < _numBlocks; i++) {\n            dataPtr = ChunkCodecV1.copyBlockContext(chunkPtr, dataPtr, i);\n            uint256 blockPtr = chunkPtr + 1 + i * ChunkCodecV1.BLOCK_CONTEXT_LENGTH;\n            uint256 _numL1MessagesInBlock = ChunkCodecV1.getNumL1Messages(blockPtr);\n            unchecked {\n                _totalNumL1MessagesInChunk += _numL1MessagesInBlock;\n            }\n        }\n        assembly {\n            mstore(0x40, add(dataPtr, mul(_totalNumL1MessagesInChunk, 0x20))) // reserve memory for l1 message hashes\n            chunkPtr := add(chunkPtr, 1)\n        }\n\n        // the number of actual transactions in one chunk: non-skipped l1 messages + l2 txs\n        uint256 _totalTransactionsInChunk;\n        // concatenate tx hashes\n        while (_numBlocks > 0) {\n            // concatenate l1 message hashes\n            uint256 _numL1MessagesInBlock = ChunkCodecV1.getNumL1Messages(chunkPtr);\n            uint256 startPtr = dataPtr;\n            dataPtr = _loadL1MessageHashes(\n                dataPtr,\n                _numL1MessagesInBlock,\n                _totalL1MessagesPoppedInBatch,\n                _totalL1MessagesPoppedOverall,\n                _skippedL1MessageBitmap\n            );\n            uint256 _numTransactionsInBlock = ChunkCodecV1.getNumTransactions(chunkPtr);\n            if (_numTransactionsInBlock < _numL1MessagesInBlock) revert ErrorNumTxsLessThanNumL1Msgs();\n            unchecked {\n                _totalTransactionsInChunk += (dataPtr - startPtr) / 32; // number of non-skipped l1 messages\n                _totalTransactionsInChunk += _numTransactionsInBlock - _numL1MessagesInBlock; // number of l2 txs\n                _totalL1MessagesPoppedInBatch += _numL1MessagesInBlock;\n                _totalL1MessagesPoppedOverall += _numL1MessagesInBlock;\n\n                _numBlocks -= 1;\n                chunkPtr += ChunkCodecV1.BLOCK_CONTEXT_LENGTH;\n            }\n        }\n\n        // check the actual number of transactions in the chunk\n        if (_totalTransactionsInChunk > maxNumTxInChunk) {\n            revert ErrorTooManyTxsInOneChunk();\n        }\n\n        // compute data hash and store to memory\n        assembly {\n            _dataHash := keccak256(startDataPtr, sub(dataPtr, startDataPtr))\n        }\n    }\n\n    /// @dev Internal function to load L1 message hashes from the message queue.\n    /// @param _ptr The memory offset to store the transaction hash.\n    /// @param _numL1Messages The number of L1 messages to load.\n    /// @param _totalL1MessagesPoppedInBatch The total number of L1 messages popped in current batch.\n    /// @param _totalL1MessagesPoppedOverall The total number of L1 messages popped in all batches including current batch.\n    /// @param _skippedL1MessageBitmap The bitmap indicates whether each L1 message is skipped or not.\n    /// @return uint256 The new memory offset after loading.\n    function _loadL1MessageHashes(\n        uint256 _ptr,\n        uint256 _numL1Messages,\n        uint256 _totalL1MessagesPoppedInBatch,\n        uint256 _totalL1MessagesPoppedOverall,\n        bytes calldata _skippedL1MessageBitmap\n    ) internal view returns (uint256) {\n        if (_numL1Messages == 0) return _ptr;\n        IL1MessageQueue _messageQueue = IL1MessageQueue(messageQueue);\n\n        unchecked {\n            uint256 _bitmap;\n            uint256 rem;\n            for (uint256 i = 0; i < _numL1Messages; i++) {\n                uint256 quo = _totalL1MessagesPoppedInBatch >> 8;\n                rem = _totalL1MessagesPoppedInBatch & 0xff;\n\n                // load bitmap every 256 bits\n                if (i == 0 || rem == 0) {\n                    assembly {\n                        _bitmap := calldataload(add(_skippedL1MessageBitmap.offset, mul(0x20, quo)))\n                    }\n                }\n                if (((_bitmap >> rem) & 1) == 0) {\n                    // message not skipped\n                    bytes32 _hash = _messageQueue.getCrossDomainMessage(_totalL1MessagesPoppedOverall);\n                    assembly {\n                        mstore(_ptr, _hash)\n                        _ptr := add(_ptr, 0x20)\n                    }\n                }\n\n                _totalL1MessagesPoppedInBatch += 1;\n                _totalL1MessagesPoppedOverall += 1;\n            }\n\n            // check last L1 message is not skipped, _totalL1MessagesPoppedInBatch must > 0\n            rem = (_totalL1MessagesPoppedInBatch - 1) & 0xff;\n            if (((_bitmap >> rem) & 1) > 0) revert ErrorLastL1MessageSkipped();\n        }\n\n        return _ptr;\n    }\n\n    /// @dev Internal function to pop finalized l1 messages.\n    /// @param bitmapPtr The memory offset of `skippedL1MessageBitmap`.\n    /// @param totalL1MessagePopped The total number of L1 messages poped in all batches including current batch.\n    /// @param l1MessagePopped The number of L1 messages popped in current batch.\n    function _popL1Messages(\n        uint256 bitmapPtr,\n        uint256 totalL1MessagePopped,\n        uint256 l1MessagePopped\n    ) internal {\n        if (l1MessagePopped == 0) return;\n\n        unchecked {\n            uint256 startIndex = totalL1MessagePopped - l1MessagePopped;\n            uint256 bitmap;\n\n            for (uint256 i = 0; i < l1MessagePopped; i += 256) {\n                uint256 _count = 256;\n                if (l1MessagePopped - i < _count) {\n                    _count = l1MessagePopped - i;\n                }\n                assembly {\n                    bitmap := mload(bitmapPtr)\n                    bitmapPtr := add(bitmapPtr, 0x20)\n                }\n                IL1MessageQueue(messageQueue).popCrossDomainMessage(startIndex, _count, bitmap);\n                startIndex += 256;\n            }\n        }\n    }\n}\n"
      },
      "src/libraries/codec/BatchHeaderV0Codec.sol": {
        "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.24;\n\n// solhint-disable no-inline-assembly\n\n/// @dev Below is the encoding for `BatchHeader` V0, total 89 + ceil(l1MessagePopped / 256) * 32 bytes.\n/// ```text\n///   * Field                   Bytes       Type        Index   Comments\n///   * version                 1           uint8       0       The batch version\n///   * batchIndex              8           uint64      1       The index of the batch\n///   * l1MessagePopped         8           uint64      9       Number of L1 messages popped in the batch\n///   * totalL1MessagePopped    8           uint64      17      Number of total L1 messages popped after the batch\n///   * dataHash                32          bytes32     25      The data hash of the batch\n///   * parentBatchHash         32          bytes32     57      The parent batch hash\n///   * skippedL1MessageBitmap  dynamic     uint256[]   89      A bitmap to indicate which L1 messages are skipped in the batch\n/// ```\nlibrary BatchHeaderV0Codec {\n    /// @dev Thrown when the length of batch header is smaller than 89\n    error ErrorBatchHeaderLengthTooSmall();\n\n    /// @dev Thrown when the length of skippedL1MessageBitmap is incorrect.\n    error ErrorIncorrectBitmapLength();\n\n    /// @dev The length of fixed parts of the batch header.\n    uint256 internal constant BATCH_HEADER_FIXED_LENGTH = 89;\n\n    /// @notice Load batch header in calldata to memory.\n    /// @param _batchHeader The encoded batch header bytes in calldata.\n    /// @return batchPtr The start memory offset of the batch header in memory.\n    /// @return length The length in bytes of the batch header.\n    function loadAndValidate(bytes calldata _batchHeader) internal pure returns (uint256 batchPtr, uint256 length) {\n        length = _batchHeader.length;\n        if (length < BATCH_HEADER_FIXED_LENGTH) revert ErrorBatchHeaderLengthTooSmall();\n\n        // copy batch header to memory.\n        assembly {\n            batchPtr := mload(0x40)\n            calldatacopy(batchPtr, _batchHeader.offset, length)\n            mstore(0x40, add(batchPtr, length))\n        }\n\n        // check batch header length\n        uint256 _l1MessagePopped = getL1MessagePopped(batchPtr);\n\n        unchecked {\n            if (length != BATCH_HEADER_FIXED_LENGTH + ((_l1MessagePopped + 255) / 256) * 32) {\n                revert ErrorIncorrectBitmapLength();\n            }\n        }\n    }\n\n    /// @notice Get the version of the batch header.\n    /// @param batchPtr The start memory offset of the batch header in memory.\n    /// @return _version The version of the batch header.\n    function getVersion(uint256 batchPtr) internal pure returns (uint256 _version) {\n        assembly {\n            _version := shr(248, mload(batchPtr))\n        }\n    }\n\n    /// @notice Get the batch index of the batch.\n    /// @param batchPtr The start memory offset of the batch header in memory.\n    /// @return _batchIndex The batch index of the batch.\n    function getBatchIndex(uint256 batchPtr) internal pure returns (uint256 _batchIndex) {\n        assembly {\n            _batchIndex := shr(192, mload(add(batchPtr, 1)))\n        }\n    }\n\n    /// @notice Get the number of L1 messages of the batch.\n    /// @param batchPtr The start memory offset of the batch header in memory.\n    /// @return _l1MessagePopped The number of L1 messages of the batch.\n    function getL1MessagePopped(uint256 batchPtr) internal pure returns (uint256 _l1MessagePopped) {\n        assembly {\n            _l1MessagePopped := shr(192, mload(add(batchPtr, 9)))\n        }\n    }\n\n    /// @notice Get the number of L1 messages popped before this batch.\n    /// @param batchPtr The start memory offset of the batch header in memory.\n    /// @return _totalL1MessagePopped The the number of L1 messages popped before this batch.\n    function getTotalL1MessagePopped(uint256 batchPtr) internal pure returns (uint256 _totalL1MessagePopped) {\n        assembly {\n            _totalL1MessagePopped := shr(192, mload(add(batchPtr, 17)))\n        }\n    }\n\n    /// @notice Get the data hash of the batch header.\n    /// @param batchPtr The start memory offset of the batch header in memory.\n    /// @return _dataHash The data hash of the batch header.\n    function getDataHash(uint256 batchPtr) internal pure returns (bytes32 _dataHash) {\n        assembly {\n            _dataHash := mload(add(batchPtr, 25))\n        }\n    }\n\n    /// @notice Get the parent batch hash of the batch header.\n    /// @param batchPtr The start memory offset of the batch header in memory.\n    /// @return _parentBatchHash The parent batch hash of the batch header.\n    function getParentBatchHash(uint256 batchPtr) internal pure returns (bytes32 _parentBatchHash) {\n        assembly {\n            _parentBatchHash := mload(add(batchPtr, 57))\n        }\n    }\n\n    /// @notice Get the start memory offset for skipped L1 messages bitmap.\n    /// @param batchPtr The start memory offset of the batch header in memory.\n    /// @return _bitmapPtr the start memory offset for skipped L1 messages bitmap.\n    function getSkippedBitmapPtr(uint256 batchPtr) internal pure returns (uint256 _bitmapPtr) {\n        assembly {\n            _bitmapPtr := add(batchPtr, BATCH_HEADER_FIXED_LENGTH)\n        }\n    }\n\n    /// @notice Get the skipped L1 messages bitmap.\n    /// @param batchPtr The start memory offset of the batch header in memory.\n    /// @param index The index of bitmap to load.\n    /// @return _bitmap The bitmap from bits `index * 256` to `index * 256 + 255`.\n    function getSkippedBitmap(uint256 batchPtr, uint256 index) internal pure returns (uint256 _bitmap) {\n        assembly {\n            batchPtr := add(batchPtr, BATCH_HEADER_FIXED_LENGTH)\n            _bitmap := mload(add(batchPtr, mul(index, 32)))\n        }\n    }\n\n    /// @notice Store the version of batch header.\n    /// @param batchPtr The start memory offset of the batch header in memory.\n    /// @param _version The version of batch header.\n    function storeVersion(uint256 batchPtr, uint256 _version) internal pure {\n        assembly {\n            mstore8(batchPtr, _version)\n        }\n    }\n\n    /// @notice Store the batch index of batch header.\n    /// @dev Because this function can overwrite the subsequent fields, it must be called before\n    /// `storeL1MessagePopped`, `storeTotalL1MessagePopped`, and `storeDataHash`.\n    /// @param batchPtr The start memory offset of the batch header in memory.\n    /// @param _batchIndex The batch index.\n    function storeBatchIndex(uint256 batchPtr, uint256 _batchIndex) internal pure {\n        assembly {\n            mstore(add(batchPtr, 1), shl(192, _batchIndex))\n        }\n    }\n\n    /// @notice Store the number of L1 messages popped in current batch to batch header.\n    /// @dev Because this function can overwrite the subsequent fields, it must be called before\n    /// `storeTotalL1MessagePopped` and `storeDataHash`.\n    /// @param batchPtr The start memory offset of the batch header in memory.\n    /// @param _l1MessagePopped The number of L1 messages popped in current batch.\n    function storeL1MessagePopped(uint256 batchPtr, uint256 _l1MessagePopped) internal pure {\n        assembly {\n            mstore(add(batchPtr, 9), shl(192, _l1MessagePopped))\n        }\n    }\n\n    /// @notice Store the total number of L1 messages popped after current batch to batch header.\n    /// @dev Because this function can overwrite the subsequent fields, it must be called before\n    /// `storeDataHash`.\n    /// @param batchPtr The start memory offset of the batch header in memory.\n    /// @param _totalL1MessagePopped The total number of L1 messages popped after current batch.\n    function storeTotalL1MessagePopped(uint256 batchPtr, uint256 _totalL1MessagePopped) internal pure {\n        assembly {\n            mstore(add(batchPtr, 17), shl(192, _totalL1MessagePopped))\n        }\n    }\n\n    /// @notice Store the data hash of batch header.\n    /// @param batchPtr The start memory offset of the batch header in memory.\n    /// @param _dataHash The data hash.\n    function storeDataHash(uint256 batchPtr, bytes32 _dataHash) internal pure {\n        assembly {\n            mstore(add(batchPtr, 25), _dataHash)\n        }\n    }\n\n    /// @notice Store the parent batch hash of batch header.\n    /// @param batchPtr The start memory offset of the batch header in memory.\n    /// @param _parentBatchHash The parent batch hash.\n    function storeParentBatchHash(uint256 batchPtr, bytes32 _parentBatchHash) internal pure {\n        assembly {\n            mstore(add(batchPtr, 57), _parentBatchHash)\n        }\n    }\n\n    /// @notice Store the skipped L1 message bitmap of batch header.\n    /// @param batchPtr The start memory offset of the batch header in memory.\n    /// @param _skippedL1MessageBitmap The skipped L1 message bitmap.\n    function storeSkippedBitmap(uint256 batchPtr, bytes calldata _skippedL1MessageBitmap) internal pure {\n        assembly {\n            calldatacopy(\n                add(batchPtr, BATCH_HEADER_FIXED_LENGTH),\n                _skippedL1MessageBitmap.offset,\n                _skippedL1MessageBitmap.length\n            )\n        }\n    }\n\n    /// @notice Compute the batch hash.\n    /// @dev Caller should make sure that the encoded batch header is correct.\n    ///\n    /// @param batchPtr The start memory offset of the batch header in memory.\n    /// @param length The length of the batch.\n    /// @return _batchHash The hash of the corresponding batch.\n    function computeBatchHash(uint256 batchPtr, uint256 length) internal pure returns (bytes32 _batchHash) {\n        // in the current version, the hash is: keccak(BatchHeader without timestamp)\n        assembly {\n            _batchHash := keccak256(batchPtr, length)\n        }\n    }\n}\n"
      },
      "src/libraries/codec/BatchHeaderV1Codec.sol": {
        "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.24;\n\n// solhint-disable no-inline-assembly\n\n/// @dev Below is the encoding for `BatchHeader` V1, total 121 + ceil(l1MessagePopped / 256) * 32 bytes.\n/// ```text\n///   * Field                   Bytes       Type        Index   Comments\n///   * version                 1           uint8       0       The batch version\n///   * batchIndex              8           uint64      1       The index of the batch\n///   * l1MessagePopped         8           uint64      9       Number of L1 messages popped in the batch\n///   * totalL1MessagePopped    8           uint64      17      Number of total L1 messages popped after the batch\n///   * dataHash                32          bytes32     25      The data hash of the batch\n///   * blobVersionedHash       32          bytes32     57      The versioned hash of the blob with this batch’s data\n///   * parentBatchHash         32          bytes32     89      The parent batch hash\n///   * skippedL1MessageBitmap  dynamic     uint256[]   121     A bitmap to indicate which L1 messages are skipped in the batch\n/// ```\nlibrary BatchHeaderV1Codec {\n    /// @dev Thrown when the length of batch header is smaller than 121.\n    error ErrorBatchHeaderLengthTooSmall();\n\n    /// @dev Thrown when the length of skippedL1MessageBitmap is incorrect.\n    error ErrorIncorrectBitmapLength();\n\n    /// @dev The length of fixed parts of the batch header.\n    uint256 internal constant BATCH_HEADER_FIXED_LENGTH = 121;\n\n    /// @notice Load batch header in calldata to memory.\n    /// @param _batchHeader The encoded batch header bytes in calldata.\n    /// @return batchPtr The start memory offset of the batch header in memory.\n    /// @return length The length in bytes of the batch header.\n    function loadAndValidate(bytes calldata _batchHeader) internal pure returns (uint256 batchPtr, uint256 length) {\n        length = _batchHeader.length;\n        if (length < BATCH_HEADER_FIXED_LENGTH) revert ErrorBatchHeaderLengthTooSmall();\n\n        // copy batch header to memory.\n        assembly {\n            batchPtr := mload(0x40)\n            calldatacopy(batchPtr, _batchHeader.offset, length)\n            mstore(0x40, add(batchPtr, length))\n        }\n\n        // check batch header length\n        uint256 _l1MessagePopped = getL1MessagePopped(batchPtr);\n\n        unchecked {\n            if (length != BATCH_HEADER_FIXED_LENGTH + ((_l1MessagePopped + 255) / 256) * 32)\n                revert ErrorIncorrectBitmapLength();\n        }\n    }\n\n    /// @notice Get the version of the batch header.\n    /// @param batchPtr The start memory offset of the batch header in memory.\n    /// @return _version The version of the batch header.\n    function getVersion(uint256 batchPtr) internal pure returns (uint256 _version) {\n        assembly {\n            _version := shr(248, mload(batchPtr))\n        }\n    }\n\n    /// @notice Get the batch index of the batch.\n    /// @param batchPtr The start memory offset of the batch header in memory.\n    /// @return _batchIndex The batch index of the batch.\n    function getBatchIndex(uint256 batchPtr) internal pure returns (uint256 _batchIndex) {\n        assembly {\n            _batchIndex := shr(192, mload(add(batchPtr, 1)))\n        }\n    }\n\n    /// @notice Get the number of L1 messages of the batch.\n    /// @param batchPtr The start memory offset of the batch header in memory.\n    /// @return _l1MessagePopped The number of L1 messages of the batch.\n    function getL1MessagePopped(uint256 batchPtr) internal pure returns (uint256 _l1MessagePopped) {\n        assembly {\n            _l1MessagePopped := shr(192, mload(add(batchPtr, 9)))\n        }\n    }\n\n    /// @notice Get the number of L1 messages popped before this batch.\n    /// @param batchPtr The start memory offset of the batch header in memory.\n    /// @return _totalL1MessagePopped The the number of L1 messages popped before this batch.\n    function getTotalL1MessagePopped(uint256 batchPtr) internal pure returns (uint256 _totalL1MessagePopped) {\n        assembly {\n            _totalL1MessagePopped := shr(192, mload(add(batchPtr, 17)))\n        }\n    }\n\n    /// @notice Get the data hash of the batch header.\n    /// @param batchPtr The start memory offset of the batch header in memory.\n    /// @return _dataHash The data hash of the batch header.\n    function getDataHash(uint256 batchPtr) internal pure returns (bytes32 _dataHash) {\n        assembly {\n            _dataHash := mload(add(batchPtr, 25))\n        }\n    }\n\n    /// @notice Get the blob versioned hash of the batch header.\n    /// @param batchPtr The start memory offset of the batch header in memory.\n    /// @return _blobVersionedHash The blob versioned hash of the batch header.\n    function getBlobVersionedHash(uint256 batchPtr) internal pure returns (bytes32 _blobVersionedHash) {\n        assembly {\n            _blobVersionedHash := mload(add(batchPtr, 57))\n        }\n    }\n\n    /// @notice Get the parent batch hash of the batch header.\n    /// @param batchPtr The start memory offset of the batch header in memory.\n    /// @return _parentBatchHash The parent batch hash of the batch header.\n    function getParentBatchHash(uint256 batchPtr) internal pure returns (bytes32 _parentBatchHash) {\n        assembly {\n            _parentBatchHash := mload(add(batchPtr, 89))\n        }\n    }\n\n    /// @notice Get the start memory offset for skipped L1 messages bitmap.\n    /// @param batchPtr The start memory offset of the batch header in memory.\n    /// @return _bitmapPtr the start memory offset for skipped L1 messages bitmap.\n    function getSkippedBitmapPtr(uint256 batchPtr) internal pure returns (uint256 _bitmapPtr) {\n        assembly {\n            _bitmapPtr := add(batchPtr, BATCH_HEADER_FIXED_LENGTH)\n        }\n    }\n\n    /// @notice Get the skipped L1 messages bitmap.\n    /// @param batchPtr The start memory offset of the batch header in memory.\n    /// @param index The index of bitmap to load.\n    /// @return _bitmap The bitmap from bits `index * 256` to `index * 256 + 255`.\n    function getSkippedBitmap(uint256 batchPtr, uint256 index) internal pure returns (uint256 _bitmap) {\n        assembly {\n            batchPtr := add(batchPtr, BATCH_HEADER_FIXED_LENGTH)\n            _bitmap := mload(add(batchPtr, mul(index, 32)))\n        }\n    }\n\n    /// @notice Store the version of batch header.\n    /// @param batchPtr The start memory offset of the batch header in memory.\n    /// @param _version The version of batch header.\n    function storeVersion(uint256 batchPtr, uint256 _version) internal pure {\n        assembly {\n            mstore8(batchPtr, _version)\n        }\n    }\n\n    /// @notice Store the batch index of batch header.\n    /// @dev Because this function can overwrite the subsequent fields, it must be called before\n    /// `storeL1MessagePopped`, `storeTotalL1MessagePopped`, and `storeDataHash`.\n    /// @param batchPtr The start memory offset of the batch header in memory.\n    /// @param _batchIndex The batch index.\n    function storeBatchIndex(uint256 batchPtr, uint256 _batchIndex) internal pure {\n        assembly {\n            mstore(add(batchPtr, 1), shl(192, _batchIndex))\n        }\n    }\n\n    /// @notice Store the number of L1 messages popped in current batch to batch header.\n    /// @dev Because this function can overwrite the subsequent fields, it must be called before\n    /// `storeTotalL1MessagePopped` and `storeDataHash`.\n    /// @param batchPtr The start memory offset of the batch header in memory.\n    /// @param _l1MessagePopped The number of L1 messages popped in current batch.\n    function storeL1MessagePopped(uint256 batchPtr, uint256 _l1MessagePopped) internal pure {\n        assembly {\n            mstore(add(batchPtr, 9), shl(192, _l1MessagePopped))\n        }\n    }\n\n    /// @notice Store the total number of L1 messages popped after current batch to batch header.\n    /// @dev Because this function can overwrite the subsequent fields, it must be called before\n    /// `storeDataHash`.\n    /// @param batchPtr The start memory offset of the batch header in memory.\n    /// @param _totalL1MessagePopped The total number of L1 messages popped after current batch.\n    function storeTotalL1MessagePopped(uint256 batchPtr, uint256 _totalL1MessagePopped) internal pure {\n        assembly {\n            mstore(add(batchPtr, 17), shl(192, _totalL1MessagePopped))\n        }\n    }\n\n    /// @notice Store the data hash of batch header.\n    /// @param batchPtr The start memory offset of the batch header in memory.\n    /// @param _dataHash The data hash.\n    function storeDataHash(uint256 batchPtr, bytes32 _dataHash) internal pure {\n        assembly {\n            mstore(add(batchPtr, 25), _dataHash)\n        }\n    }\n\n    /// @notice Store the parent batch hash of batch header.\n    /// @param batchPtr The start memory offset of the batch header in memory.\n    /// @param _blobVersionedHash The versioned hash of the blob with this batch’s data.\n    function storeBlobVersionedHash(uint256 batchPtr, bytes32 _blobVersionedHash) internal pure {\n        assembly {\n            mstore(add(batchPtr, 57), _blobVersionedHash)\n        }\n    }\n\n    /// @notice Store the parent batch hash of batch header.\n    /// @param batchPtr The start memory offset of the batch header in memory.\n    /// @param _parentBatchHash The parent batch hash.\n    function storeParentBatchHash(uint256 batchPtr, bytes32 _parentBatchHash) internal pure {\n        assembly {\n            mstore(add(batchPtr, 89), _parentBatchHash)\n        }\n    }\n\n    /// @notice Store the skipped L1 message bitmap of batch header.\n    /// @param batchPtr The start memory offset of the batch header in memory.\n    /// @param _skippedL1MessageBitmap The skipped L1 message bitmap.\n    function storeSkippedBitmap(uint256 batchPtr, bytes calldata _skippedL1MessageBitmap) internal pure {\n        assembly {\n            calldatacopy(\n                add(batchPtr, BATCH_HEADER_FIXED_LENGTH),\n                _skippedL1MessageBitmap.offset,\n                _skippedL1MessageBitmap.length\n            )\n        }\n    }\n\n    /// @notice Compute the batch hash.\n    /// @dev Caller should make sure that the encoded batch header is correct.\n    ///\n    /// @param batchPtr The start memory offset of the batch header in memory.\n    /// @param length The length of the batch.\n    /// @return _batchHash The hash of the corresponding batch.\n    function computeBatchHash(uint256 batchPtr, uint256 length) internal pure returns (bytes32 _batchHash) {\n        // in the current version, the hash is: keccak(BatchHeader without timestamp)\n        assembly {\n            _batchHash := keccak256(batchPtr, length)\n        }\n    }\n}\n"
      },
      "src/libraries/codec/ChunkCodecV0.sol": {
        "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.24;\n\n/// @dev Below is the encoding for `Chunk`, total 60*n+1+m bytes.\n/// ```text\n///   * Field           Bytes       Type            Index       Comments\n///   * numBlocks       1           uint8           0           The number of blocks in this chunk\n///   * block[0]        60          BlockContext    1           The first block in this chunk\n///   * ......\n///   * block[i]        60          BlockContext    60*i+1      The (i+1)'th block in this chunk\n///   * ......\n///   * block[n-1]      60          BlockContext    60*n-59     The last block in this chunk\n///   * l2Transactions  dynamic     bytes           60*n+1\n/// ```\n///\n/// @dev Below is the encoding for `BlockContext`, total 60 bytes.\n/// ```text\n///   * Field                   Bytes      Type         Index  Comments\n///   * blockNumber             8          uint64       0      The height of this block.\n///   * timestamp               8          uint64       8      The timestamp of this block.\n///   * baseFee                 32         uint256      16     The base fee of this block.\n///   * gasLimit                8          uint64       48     The gas limit of this block.\n///   * numTransactions         2          uint16       56     The number of transactions in this block, both L1 & L2 txs.\n///   * numL1Messages           2          uint16       58     The number of l1 messages in this block.\n/// ```\nlibrary ChunkCodecV0 {\n    /// @dev Thrown when no blocks in chunk.\n    error ErrorNoBlockInChunk();\n\n    /// @dev Thrown when the length of chunk is incorrect.\n    error ErrorIncorrectChunkLength();\n\n    /// @dev The length of one block context.\n    uint256 internal constant BLOCK_CONTEXT_LENGTH = 60;\n\n    /// @notice Validate the length of chunk.\n    /// @param chunkPtr The start memory offset of the chunk in memory.\n    /// @param _length The length of the chunk.\n    /// @return _numBlocks The number of blocks in current chunk.\n    function validateChunkLength(uint256 chunkPtr, uint256 _length) internal pure returns (uint256 _numBlocks) {\n        _numBlocks = getNumBlocks(chunkPtr);\n\n        // should contain at least one block\n        if (_numBlocks == 0) revert ErrorNoBlockInChunk();\n\n        // should contain at least the number of the blocks and block contexts\n        if (_length < 1 + _numBlocks * BLOCK_CONTEXT_LENGTH) revert ErrorIncorrectChunkLength();\n    }\n\n    /// @notice Return the start memory offset of `l2Transactions`.\n    /// @dev The caller should make sure `_numBlocks` is correct.\n    /// @param chunkPtr The start memory offset of the chunk in memory.\n    /// @param _numBlocks The number of blocks in current chunk.\n    /// @return _l2TxPtr the start memory offset of `l2Transactions`.\n    function getL2TxPtr(uint256 chunkPtr, uint256 _numBlocks) internal pure returns (uint256 _l2TxPtr) {\n        unchecked {\n            _l2TxPtr = chunkPtr + 1 + _numBlocks * BLOCK_CONTEXT_LENGTH;\n        }\n    }\n\n    /// @notice Return the number of blocks in current chunk.\n    /// @param chunkPtr The start memory offset of the chunk in memory.\n    /// @return _numBlocks The number of blocks in current chunk.\n    function getNumBlocks(uint256 chunkPtr) internal pure returns (uint256 _numBlocks) {\n        assembly {\n            _numBlocks := shr(248, mload(chunkPtr))\n        }\n    }\n\n    /// @notice Copy the block context to another memory.\n    /// @param chunkPtr The start memory offset of the chunk in memory.\n    /// @param dstPtr The destination memory offset to store the block context.\n    /// @param index The index of block context to copy.\n    /// @return uint256 The new destination memory offset after copy.\n    function copyBlockContext(\n        uint256 chunkPtr,\n        uint256 dstPtr,\n        uint256 index\n    ) internal pure returns (uint256) {\n        // only first 58 bytes is needed.\n        assembly {\n            chunkPtr := add(chunkPtr, add(1, mul(BLOCK_CONTEXT_LENGTH, index)))\n            mstore(dstPtr, mload(chunkPtr)) // first 32 bytes\n            mstore(\n                add(dstPtr, 0x20),\n                and(mload(add(chunkPtr, 0x20)), 0xffffffffffffffffffffffffffffffffffffffffffffffffffff000000000000)\n            ) // next 26 bytes\n\n            dstPtr := add(dstPtr, 58)\n        }\n\n        return dstPtr;\n    }\n\n    /// @notice Return the number of transactions in current block.\n    /// @param blockPtr The start memory offset of the block context in memory.\n    /// @return _numTransactions The number of transactions in current block.\n    function getNumTransactions(uint256 blockPtr) internal pure returns (uint256 _numTransactions) {\n        assembly {\n            _numTransactions := shr(240, mload(add(blockPtr, 56)))\n        }\n    }\n\n    /// @notice Return the number of L1 messages in current block.\n    /// @param blockPtr The start memory offset of the block context in memory.\n    /// @return _numL1Messages The number of L1 messages in current block.\n    function getNumL1Messages(uint256 blockPtr) internal pure returns (uint256 _numL1Messages) {\n        assembly {\n            _numL1Messages := shr(240, mload(add(blockPtr, 58)))\n        }\n    }\n\n    /// @notice Compute and load the transaction hash.\n    /// @param _l2TxPtr The start memory offset of the transaction in memory.\n    /// @return bytes32 The transaction hash of the transaction.\n    /// @return uint256 The start memory offset of the next transaction in memory.\n    function loadL2TxHash(uint256 _l2TxPtr) internal pure returns (bytes32, uint256) {\n        bytes32 txHash;\n        assembly {\n            // first 4 bytes indicate the length\n            let txPayloadLength := shr(224, mload(_l2TxPtr))\n            _l2TxPtr := add(_l2TxPtr, 4)\n            txHash := keccak256(_l2TxPtr, txPayloadLength)\n            _l2TxPtr := add(_l2TxPtr, txPayloadLength)\n        }\n\n        return (txHash, _l2TxPtr);\n    }\n}\n"
      },
      "src/libraries/codec/ChunkCodecV1.sol": {
        "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.24;\n\nimport {ChunkCodecV0} from \"./ChunkCodecV0.sol\";\n\n/// @dev Below is the encoding for `Chunk`, total 60*n+1 bytes.\n/// The only difference between `ChunkCodecV0` is we remove `l2Transactions` from chunk encoding.\n/// ```text\n///   * Field           Bytes       Type            Index       Comments\n///   * numBlocks       1           uint8           0           The number of blocks in this chunk\n///   * block[0]        60          BlockContext    1           The first block in this chunk\n///   * ......\n///   * block[i]        60          BlockContext    60*i+1      The (i+1)'th block in this chunk\n///   * ......\n///   * block[n-1]      60          BlockContext    60*n-59     The last block in this chunk\n/// ```\n///\n/// @dev Below is the encoding for `BlockContext`, total 60 bytes.\n/// ```text\n///   * Field                   Bytes      Type         Index  Comments\n///   * blockNumber             8          uint64       0      The height of this block.\n///   * timestamp               8          uint64       8      The timestamp of this block.\n///   * baseFee                 32         uint256      16     The base fee of this block.\n///   * gasLimit                8          uint64       48     The gas limit of this block.\n///   * numTransactions         2          uint16       56     The number of transactions in this block, both L1 & L2 txs.\n///   * numL1Messages           2          uint16       58     The number of l1 messages in this block.\n/// ```\nlibrary ChunkCodecV1 {\n    /// @dev Thrown when no blocks in chunk.\n    error ErrorNoBlockInChunk();\n\n    /// @dev Thrown when the length of chunk is incorrect.\n    error ErrorIncorrectChunkLength();\n\n    /// @dev The length of one block context.\n    uint256 internal constant BLOCK_CONTEXT_LENGTH = 60;\n\n    /// @notice Validate the length of chunk.\n    /// @param chunkPtr The start memory offset of the chunk in memory.\n    /// @param _length The length of the chunk.\n    /// @return _numBlocks The number of blocks in current chunk.\n    function validateChunkLength(uint256 chunkPtr, uint256 _length) internal pure returns (uint256 _numBlocks) {\n        _numBlocks = getNumBlocks(chunkPtr);\n\n        // should contain at least one block\n        if (_numBlocks == 0) revert ErrorNoBlockInChunk();\n\n        // should contain the number of the blocks and block contexts\n        if (_length != 1 + _numBlocks * BLOCK_CONTEXT_LENGTH) revert ErrorIncorrectChunkLength();\n    }\n\n    /// @notice Return the number of blocks in current chunk.\n    /// @param chunkPtr The start memory offset of the chunk in memory.\n    /// @return _numBlocks The number of blocks in current chunk.\n    function getNumBlocks(uint256 chunkPtr) internal pure returns (uint256 _numBlocks) {\n        return ChunkCodecV0.getNumBlocks(chunkPtr);\n    }\n\n    /// @notice Copy the block context to another memory.\n    /// @param chunkPtr The start memory offset of the chunk in memory.\n    /// @param dstPtr The destination memory offset to store the block context.\n    /// @param index The index of block context to copy.\n    /// @return uint256 The new destination memory offset after copy.\n    function copyBlockContext(\n        uint256 chunkPtr,\n        uint256 dstPtr,\n        uint256 index\n    ) internal pure returns (uint256) {\n        return ChunkCodecV0.copyBlockContext(chunkPtr, dstPtr, index);\n    }\n\n    /// @notice Return the number of transactions in current block.\n    /// @param blockPtr The start memory offset of the block context in memory.\n    /// @return _numTransactions The number of transactions in current block.\n    function getNumTransactions(uint256 blockPtr) internal pure returns (uint256 _numTransactions) {\n        return ChunkCodecV0.getNumTransactions(blockPtr);\n    }\n\n    /// @notice Return the number of L1 messages in current block.\n    /// @param blockPtr The start memory offset of the block context in memory.\n    /// @return _numL1Messages The number of L1 messages in current block.\n    function getNumL1Messages(uint256 blockPtr) internal pure returns (uint256 _numL1Messages) {\n        return ChunkCodecV0.getNumL1Messages(blockPtr);\n    }\n}\n"
      },
      "src/libraries/verifier/IRollupVerifier.sol": {
        "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.24;\n\n/// @title IRollupVerifier\n/// @notice The interface for rollup verifier.\ninterface IRollupVerifier {\n    /// @notice Verify aggregate zk proof.\n    /// @param batchIndex The batch index to verify.\n    /// @param aggrProof The aggregated proof.\n    /// @param publicInputHash The public input hash.\n    function verifyAggregateProof(\n        uint256 batchIndex,\n        bytes calldata aggrProof,\n        bytes32 publicInputHash\n    ) external view;\n\n    /// @notice Verify aggregate zk proof.\n    /// @param version The version of verifier to use.\n    /// @param batchIndex The batch index to verify.\n    /// @param aggrProof The aggregated proof.\n    /// @param publicInputHash The public input hash.\n    function verifyAggregateProof(\n        uint256 version,\n        uint256 batchIndex,\n        bytes calldata aggrProof,\n        bytes32 publicInputHash\n    ) external view;\n}\n"
      }
    },
    "settings": {
      "optimizer": {
        "enabled": true,
        "runs": 200
      },
      "evmVersion": "cancun",
      "outputSelection": {
        "*": {
          "*": [
            "evm.bytecode",
            "evm.deployedBytecode",
            "devdoc",
            "userdoc",
            "metadata",
            "abi"
          ]
        }
      },
      "libraries": {}
    }
  }}