ETH Price: $3,573.62 (+6.99%)

Transaction Decoder

Block:
22796196 at Jun-27-2025 01:52:35 PM +UTC
Transaction Fee:
0.000137374524189694 ETH $0.49
Gas Used:
70,417 Gas / 1.950871582 Gwei

Account State Difference:

  Address   Before After State Difference Code
0x77Af42D8...6fE56d946
0.265204848823857812 Eth
Nonce: 14
0.265067474299668118 Eth
Nonce: 15
0.000137374524189694
(BuilderNet)
9.524630714983138921 Eth9.524639150235568921 Eth0.00000843525243

Execution Trace

ETH 0.017 Proxy.e9e05c42( )
  • ETH 0.017 OptimismPortal2.depositTransaction( _to=0x77Af42D8cF1FDe7F062F6d0707BbEB36fE56d946, _value=17000000000000000, _gasLimit=100000, _isCreation=False, _data=0x )
    • Proxy.STATICCALL( )
      • SystemConfig.DELEGATECALL( )
        File 1 of 4: Proxy
        // SPDX-License-Identifier: MIT
        pragma solidity 0.8.15;
        /**
         * @title Proxy
         * @notice Proxy is a transparent proxy that passes through the call if the caller is the owner or
         *         if the caller is address(0), meaning that the call originated from an off-chain
         *         simulation.
         */
        contract Proxy {
            /**
             * @notice The storage slot that holds the address of the implementation.
             *         bytes32(uint256(keccak256('eip1967.proxy.implementation')) - 1)
             */
            bytes32 internal constant IMPLEMENTATION_KEY =
                0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
            /**
             * @notice The storage slot that holds the address of the owner.
             *         bytes32(uint256(keccak256('eip1967.proxy.admin')) - 1)
             */
            bytes32 internal constant OWNER_KEY =
                0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103;
            /**
             * @notice An event that is emitted each time the implementation is changed. This event is part
             *         of the EIP-1967 specification.
             *
             * @param implementation The address of the implementation contract
             */
            event Upgraded(address indexed implementation);
            /**
             * @notice An event that is emitted each time the owner is upgraded. This event is part of the
             *         EIP-1967 specification.
             *
             * @param previousAdmin The previous owner of the contract
             * @param newAdmin      The new owner of the contract
             */
            event AdminChanged(address previousAdmin, address newAdmin);
            /**
             * @notice A modifier that reverts if not called by the owner or by address(0) to allow
             *         eth_call to interact with this proxy without needing to use low-level storage
             *         inspection. We assume that nobody is able to trigger calls from address(0) during
             *         normal EVM execution.
             */
            modifier proxyCallIfNotAdmin() {
                if (msg.sender == _getAdmin() || msg.sender == address(0)) {
                    _;
                } else {
                    // This WILL halt the call frame on completion.
                    _doProxyCall();
                }
            }
            /**
             * @notice Sets the initial admin during contract deployment. Admin address is stored at the
             *         EIP-1967 admin storage slot so that accidental storage collision with the
             *         implementation is not possible.
             *
             * @param _admin Address of the initial contract admin. Admin as the ability to access the
             *               transparent proxy interface.
             */
            constructor(address _admin) {
                _changeAdmin(_admin);
            }
            // slither-disable-next-line locked-ether
            receive() external payable {
                // Proxy call by default.
                _doProxyCall();
            }
            // slither-disable-next-line locked-ether
            fallback() external payable {
                // Proxy call by default.
                _doProxyCall();
            }
            /**
             * @notice Set the implementation contract address. The code at the given address will execute
             *         when this contract is called.
             *
             * @param _implementation Address of the implementation contract.
             */
            function upgradeTo(address _implementation) public virtual proxyCallIfNotAdmin {
                _setImplementation(_implementation);
            }
            /**
             * @notice Set the implementation and call a function in a single transaction. Useful to ensure
             *         atomic execution of initialization-based upgrades.
             *
             * @param _implementation Address of the implementation contract.
             * @param _data           Calldata to delegatecall the new implementation with.
             */
            function upgradeToAndCall(address _implementation, bytes calldata _data)
                public
                payable
                virtual
                proxyCallIfNotAdmin
                returns (bytes memory)
            {
                _setImplementation(_implementation);
                (bool success, bytes memory returndata) = _implementation.delegatecall(_data);
                require(success, "Proxy: delegatecall to new implementation contract failed");
                return returndata;
            }
            /**
             * @notice Changes the owner of the proxy contract. Only callable by the owner.
             *
             * @param _admin New owner of the proxy contract.
             */
            function changeAdmin(address _admin) public virtual proxyCallIfNotAdmin {
                _changeAdmin(_admin);
            }
            /**
             * @notice Gets the owner of the proxy contract.
             *
             * @return Owner address.
             */
            function admin() public virtual proxyCallIfNotAdmin returns (address) {
                return _getAdmin();
            }
            /**
             * @notice Queries the implementation address.
             *
             * @return Implementation address.
             */
            function implementation() public virtual proxyCallIfNotAdmin returns (address) {
                return _getImplementation();
            }
            /**
             * @notice Sets the implementation address.
             *
             * @param _implementation New implementation address.
             */
            function _setImplementation(address _implementation) internal {
                assembly {
                    sstore(IMPLEMENTATION_KEY, _implementation)
                }
                emit Upgraded(_implementation);
            }
            /**
             * @notice Changes the owner of the proxy contract.
             *
             * @param _admin New owner of the proxy contract.
             */
            function _changeAdmin(address _admin) internal {
                address previous = _getAdmin();
                assembly {
                    sstore(OWNER_KEY, _admin)
                }
                emit AdminChanged(previous, _admin);
            }
            /**
             * @notice Performs the proxy call via a delegatecall.
             */
            function _doProxyCall() internal {
                address impl = _getImplementation();
                require(impl != address(0), "Proxy: implementation not initialized");
                assembly {
                    // Copy calldata into memory at 0x0....calldatasize.
                    calldatacopy(0x0, 0x0, calldatasize())
                    // Perform the delegatecall, make sure to pass all available gas.
                    let success := delegatecall(gas(), impl, 0x0, calldatasize(), 0x0, 0x0)
                    // Copy returndata into memory at 0x0....returndatasize. Note that this *will*
                    // overwrite the calldata that we just copied into memory but that doesn't really
                    // matter because we'll be returning in a second anyway.
                    returndatacopy(0x0, 0x0, returndatasize())
                    // Success == 0 means a revert. We'll revert too and pass the data up.
                    if iszero(success) {
                        revert(0x0, returndatasize())
                    }
                    // Otherwise we'll just return and pass the data up.
                    return(0x0, returndatasize())
                }
            }
            /**
             * @notice Queries the implementation address.
             *
             * @return Implementation address.
             */
            function _getImplementation() internal view returns (address) {
                address impl;
                assembly {
                    impl := sload(IMPLEMENTATION_KEY)
                }
                return impl;
            }
            /**
             * @notice Queries the owner of the proxy contract.
             *
             * @return Owner address.
             */
            function _getAdmin() internal view returns (address) {
                address owner;
                assembly {
                    owner := sload(OWNER_KEY)
                }
                return owner;
            }
        }
        

        File 2 of 4: OptimismPortal2
        // SPDX-License-Identifier: MIT
        pragma solidity 0.8.15;
        import { Initializable } from "@openzeppelin/contracts/proxy/utils/Initializable.sol";
        import { SafeCall } from "src/libraries/SafeCall.sol";
        import { DisputeGameFactory, IDisputeGame } from "src/dispute/DisputeGameFactory.sol";
        import { SystemConfig } from "src/L1/SystemConfig.sol";
        import { SuperchainConfig } from "src/L1/SuperchainConfig.sol";
        import { Constants } from "src/libraries/Constants.sol";
        import { Types } from "src/libraries/Types.sol";
        import { Hashing } from "src/libraries/Hashing.sol";
        import { SecureMerkleTrie } from "src/libraries/trie/SecureMerkleTrie.sol";
        import { AddressAliasHelper } from "src/vendor/AddressAliasHelper.sol";
        import { ResourceMetering } from "src/L1/ResourceMetering.sol";
        import { ISemver } from "src/universal/ISemver.sol";
        import { Constants } from "src/libraries/Constants.sol";
        import "src/libraries/PortalErrors.sol";
        import "src/dispute/lib/Types.sol";
        /// @custom:proxied
        /// @title OptimismPortal2
        /// @notice The OptimismPortal is a low-level contract responsible for passing messages between L1
        ///         and L2. Messages sent directly to the OptimismPortal have no form of replayability.
        ///         Users are encouraged to use the L1CrossDomainMessenger for a higher-level interface.
        contract OptimismPortal2 is Initializable, ResourceMetering, ISemver {
            /// @notice Represents a proven withdrawal.
            /// @custom:field disputeGameProxy The address of the dispute game proxy that the withdrawal was proven against.
            /// @custom:field timestamp        Timestamp at whcih the withdrawal was proven.
            struct ProvenWithdrawal {
                IDisputeGame disputeGameProxy;
                uint64 timestamp;
            }
            /// @notice The delay between when a withdrawal transaction is proven and when it may be finalized.
            uint256 internal immutable PROOF_MATURITY_DELAY_SECONDS;
            /// @notice The delay between when a dispute game is resolved and when a withdrawal proven against it may be
            ///         finalized.
            uint256 internal immutable DISPUTE_GAME_FINALITY_DELAY_SECONDS;
            /// @notice Version of the deposit event.
            uint256 internal constant DEPOSIT_VERSION = 0;
            /// @notice The L2 gas limit set when eth is deposited using the receive() function.
            uint64 internal constant RECEIVE_DEFAULT_GAS_LIMIT = 100_000;
            /// @notice Address of the L2 account which initiated a withdrawal in this transaction.
            ///         If the of this variable is the default L2 sender address, then we are NOT inside of
            ///         a call to finalizeWithdrawalTransaction.
            address public l2Sender;
            /// @notice A list of withdrawal hashes which have been successfully finalized.
            mapping(bytes32 => bool) public finalizedWithdrawals;
            /// @custom:legacy
            /// @custom:spacer provenWithdrawals
            /// @notice Spacer taking up the legacy `provenWithdrawals` mapping slot.
            bytes32 private spacer_52_0_32;
            /// @custom:legacy
            /// @custom:spacer paused
            /// @notice Spacer for backwards compatibility.
            bool private spacer_53_0_1;
            /// @notice Contract of the Superchain Config.
            SuperchainConfig public superchainConfig;
            /// @custom:legacy
            /// @custom:spacer l2Oracle
            /// @notice Spacer taking up the legacy `l2Oracle` address slot.
            address private spacer_54_0_20;
            /// @notice Contract of the SystemConfig.
            /// @custom:network-specific
            SystemConfig public systemConfig;
            /// @notice Address of the DisputeGameFactory.
            /// @custom:network-specific
            DisputeGameFactory public disputeGameFactory;
            /// @notice A mapping of withdrawal hashes to proof submitters to `ProvenWithdrawal` data.
            mapping(bytes32 => mapping(address => ProvenWithdrawal)) public provenWithdrawals;
            /// @notice A mapping of dispute game addresses to whether or not they are blacklisted.
            mapping(IDisputeGame => bool) public disputeGameBlacklist;
            /// @notice The game type that the OptimismPortal consults for output proposals.
            GameType public respectedGameType;
            /// @notice The timestamp at which the respected game type was last updated.
            uint64 public respectedGameTypeUpdatedAt;
            /// @notice Mapping of withdrawal hashes to addresses that have submitted a proof for the withdrawal.
            mapping(bytes32 => address[]) public proofSubmitters;
            /// @custom:spacer _balance (custom gas token)
            /// @notice Spacer for forwards compatibility.
            bytes32 private spacer_61_0_32;
            /// @notice Emitted when a transaction is deposited from L1 to L2.
            ///         The parameters of this event are read by the rollup node and used to derive deposit
            ///         transactions on L2.
            /// @param from       Address that triggered the deposit transaction.
            /// @param to         Address that the deposit transaction is directed to.
            /// @param version    Version of this deposit transaction event.
            /// @param opaqueData ABI encoded deposit data to be parsed off-chain.
            event TransactionDeposited(address indexed from, address indexed to, uint256 indexed version, bytes opaqueData);
            /// @notice Emitted when a withdrawal transaction is proven.
            /// @param withdrawalHash Hash of the withdrawal transaction.
            /// @param from           Address that triggered the withdrawal transaction.
            /// @param to             Address that the withdrawal transaction is directed to.
            event WithdrawalProven(bytes32 indexed withdrawalHash, address indexed from, address indexed to);
            /// @notice Emitted when a withdrawal transaction is proven. Exists as a separate event to allow for backwards
            ///         compatibility for tooling that observes the `WithdrawalProven` event.
            /// @param withdrawalHash Hash of the withdrawal transaction.
            /// @param proofSubmitter Address of the proof submitter.
            event WithdrawalProvenExtension1(bytes32 indexed withdrawalHash, address indexed proofSubmitter);
            /// @notice Emitted when a withdrawal transaction is finalized.
            /// @param withdrawalHash Hash of the withdrawal transaction.
            /// @param success        Whether the withdrawal transaction was successful.
            event WithdrawalFinalized(bytes32 indexed withdrawalHash, bool success);
            /// @notice Emitted when a dispute game is blacklisted by the Guardian.
            /// @param disputeGame Address of the dispute game that was blacklisted.
            event DisputeGameBlacklisted(IDisputeGame indexed disputeGame);
            /// @notice Emitted when the Guardian changes the respected game type in the portal.
            /// @param newGameType The new respected game type.
            /// @param updatedAt   The timestamp at which the respected game type was updated.
            event RespectedGameTypeSet(GameType indexed newGameType, Timestamp indexed updatedAt);
            /// @notice Reverts when paused.
            modifier whenNotPaused() {
                if (paused()) revert CallPaused();
                _;
            }
            /// @notice Semantic version.
            /// @custom:semver 3.10.0
            string public constant version = "3.10.0";
            /// @notice Constructs the OptimismPortal contract.
            constructor(uint256 _proofMaturityDelaySeconds, uint256 _disputeGameFinalityDelaySeconds) {
                PROOF_MATURITY_DELAY_SECONDS = _proofMaturityDelaySeconds;
                DISPUTE_GAME_FINALITY_DELAY_SECONDS = _disputeGameFinalityDelaySeconds;
                initialize({
                    _disputeGameFactory: DisputeGameFactory(address(0)),
                    _systemConfig: SystemConfig(address(0)),
                    _superchainConfig: SuperchainConfig(address(0)),
                    _initialRespectedGameType: GameType.wrap(0)
                });
            }
            /// @notice Initializer.
            /// @param _disputeGameFactory Contract of the DisputeGameFactory.
            /// @param _systemConfig Contract of the SystemConfig.
            /// @param _superchainConfig Contract of the SuperchainConfig.
            function initialize(
                DisputeGameFactory _disputeGameFactory,
                SystemConfig _systemConfig,
                SuperchainConfig _superchainConfig,
                GameType _initialRespectedGameType
            )
                public
                initializer
            {
                disputeGameFactory = _disputeGameFactory;
                systemConfig = _systemConfig;
                superchainConfig = _superchainConfig;
                // Set the `l2Sender` slot, only if it is currently empty. This signals the first initialization of the
                // contract.
                if (l2Sender == address(0)) {
                    l2Sender = Constants.DEFAULT_L2_SENDER;
                    // Set the `respectedGameTypeUpdatedAt` timestamp, to ignore all games of the respected type prior
                    // to this operation.
                    respectedGameTypeUpdatedAt = uint64(block.timestamp);
                    // Set the initial respected game type
                    respectedGameType = _initialRespectedGameType;
                }
                __ResourceMetering_init();
            }
            /// @notice Getter function for the address of the guardian.
            ///         Public getter is legacy and will be removed in the future. Use `SuperchainConfig.guardian()` instead.
            /// @return Address of the guardian.
            /// @custom:legacy
            function guardian() public view returns (address) {
                return superchainConfig.guardian();
            }
            /// @notice Getter for the current paused status.
            function paused() public view returns (bool) {
                return superchainConfig.paused();
            }
            /// @notice Getter for the proof maturity delay.
            function proofMaturityDelaySeconds() public view returns (uint256) {
                return PROOF_MATURITY_DELAY_SECONDS;
            }
            /// @notice Getter for the dispute game finality delay.
            function disputeGameFinalityDelaySeconds() public view returns (uint256) {
                return DISPUTE_GAME_FINALITY_DELAY_SECONDS;
            }
            /// @notice Computes the minimum gas limit for a deposit.
            ///         The minimum gas limit linearly increases based on the size of the calldata.
            ///         This is to prevent users from creating L2 resource usage without paying for it.
            ///         This function can be used when interacting with the portal to ensure forwards
            ///         compatibility.
            /// @param _byteCount Number of bytes in the calldata.
            /// @return The minimum gas limit for a deposit.
            function minimumGasLimit(uint64 _byteCount) public pure returns (uint64) {
                return _byteCount * 16 + 21000;
            }
            /// @notice Accepts value so that users can send ETH directly to this contract and have the
            ///         funds be deposited to their address on L2. This is intended as a convenience
            ///         function for EOAs. Contracts should call the depositTransaction() function directly
            ///         otherwise any deposited funds will be lost due to address aliasing.
            receive() external payable {
                depositTransaction(msg.sender, msg.value, RECEIVE_DEFAULT_GAS_LIMIT, false, bytes(""));
            }
            /// @notice Accepts ETH value without triggering a deposit to L2.
            ///         This function mainly exists for the sake of the migration between the legacy
            ///         Optimism system and Bedrock.
            function donateETH() external payable {
                // Intentionally empty.
            }
            /// @notice Getter for the resource config.
            ///         Used internally by the ResourceMetering contract.
            ///         The SystemConfig is the source of truth for the resource config.
            /// @return ResourceMetering ResourceConfig
            function _resourceConfig() internal view override returns (ResourceMetering.ResourceConfig memory) {
                return systemConfig.resourceConfig();
            }
            /// @notice Proves a withdrawal transaction.
            /// @param _tx               Withdrawal transaction to finalize.
            /// @param _disputeGameIndex Index of the dispute game to prove the withdrawal against.
            /// @param _outputRootProof  Inclusion proof of the L2ToL1MessagePasser contract's storage root.
            /// @param _withdrawalProof  Inclusion proof of the withdrawal in L2ToL1MessagePasser contract.
            function proveWithdrawalTransaction(
                Types.WithdrawalTransaction memory _tx,
                uint256 _disputeGameIndex,
                Types.OutputRootProof calldata _outputRootProof,
                bytes[] calldata _withdrawalProof
            )
                external
                whenNotPaused
            {
                // Prevent users from creating a deposit transaction where this address is the message
                // sender on L2. Because this is checked here, we do not need to check again in
                // `finalizeWithdrawalTransaction`.
                require(_tx.target != address(this), "OptimismPortal: you cannot send messages to the portal contract");
                // Fetch the dispute game proxy from the `DisputeGameFactory` contract.
                (GameType gameType,, IDisputeGame gameProxy) = disputeGameFactory.gameAtIndex(_disputeGameIndex);
                Claim outputRoot = gameProxy.rootClaim();
                // The game type of the dispute game must be the respected game type.
                require(gameType.raw() == respectedGameType.raw(), "OptimismPortal: invalid game type");
                // Verify that the output root can be generated with the elements in the proof.
                require(
                    outputRoot.raw() == Hashing.hashOutputRootProof(_outputRootProof),
                    "OptimismPortal: invalid output root proof"
                );
                // Load the ProvenWithdrawal into memory, using the withdrawal hash as a unique identifier.
                bytes32 withdrawalHash = Hashing.hashWithdrawal(_tx);
                // We do not allow for proving withdrawals against dispute games that have resolved against the favor
                // of the root claim.
                require(
                    gameProxy.status() != GameStatus.CHALLENGER_WINS,
                    "OptimismPortal: cannot prove against invalid dispute games"
                );
                // Compute the storage slot of the withdrawal hash in the L2ToL1MessagePasser contract.
                // Refer to the Solidity documentation for more information on how storage layouts are
                // computed for mappings.
                bytes32 storageKey = keccak256(
                    abi.encode(
                        withdrawalHash,
                        uint256(0) // The withdrawals mapping is at the first slot in the layout.
                    )
                );
                // Verify that the hash of this withdrawal was stored in the L2toL1MessagePasser contract
                // on L2. If this is true, under the assumption that the SecureMerkleTrie does not have
                // bugs, then we know that this withdrawal was actually triggered on L2 and can therefore
                // be relayed on L1.
                require(
                    SecureMerkleTrie.verifyInclusionProof({
                        _key: abi.encode(storageKey),
                        _value: hex"01",
                        _proof: _withdrawalProof,
                        _root: _outputRootProof.messagePasserStorageRoot
                    }),
                    "OptimismPortal: invalid withdrawal inclusion proof"
                );
                // Designate the withdrawalHash as proven by storing the `disputeGameProxy` & `timestamp` in the
                // `provenWithdrawals` mapping. A `withdrawalHash` can only be proven once unless the dispute game it proved
                // against resolves against the favor of the root claim.
                provenWithdrawals[withdrawalHash][msg.sender] =
                    ProvenWithdrawal({ disputeGameProxy: gameProxy, timestamp: uint64(block.timestamp) });
                // Emit a `WithdrawalProven` event.
                emit WithdrawalProven(withdrawalHash, _tx.sender, _tx.target);
                // Emit a `WithdrawalProvenExtension1` event.
                emit WithdrawalProvenExtension1(withdrawalHash, msg.sender);
                // Add the proof submitter to the list of proof submitters for this withdrawal hash.
                proofSubmitters[withdrawalHash].push(msg.sender);
            }
            /// @notice Finalizes a withdrawal transaction.
            /// @param _tx Withdrawal transaction to finalize.
            function finalizeWithdrawalTransaction(Types.WithdrawalTransaction memory _tx) external whenNotPaused {
                finalizeWithdrawalTransactionExternalProof(_tx, msg.sender);
            }
            /// @notice Finalizes a withdrawal transaction, using an external proof submitter.
            /// @param _tx Withdrawal transaction to finalize.
            /// @param _proofSubmitter Address of the proof submitter.
            function finalizeWithdrawalTransactionExternalProof(
                Types.WithdrawalTransaction memory _tx,
                address _proofSubmitter
            )
                public
                whenNotPaused
            {
                // Make sure that the l2Sender has not yet been set. The l2Sender is set to a value other
                // than the default value when a withdrawal transaction is being finalized. This check is
                // a defacto reentrancy guard.
                require(
                    l2Sender == Constants.DEFAULT_L2_SENDER, "OptimismPortal: can only trigger one withdrawal per transaction"
                );
                // Compute the withdrawal hash.
                bytes32 withdrawalHash = Hashing.hashWithdrawal(_tx);
                // Check that the withdrawal can be finalized.
                checkWithdrawal(withdrawalHash, _proofSubmitter);
                // Mark the withdrawal as finalized so it can't be replayed.
                finalizedWithdrawals[withdrawalHash] = true;
                // Set the l2Sender so contracts know who triggered this withdrawal on L2.
                l2Sender = _tx.sender;
                // Trigger the call to the target contract. We use a custom low level method
                // SafeCall.callWithMinGas to ensure two key properties
                //   1. Target contracts cannot force this call to run out of gas by returning a very large
                //      amount of data (and this is OK because we don't care about the returndata here).
                //   2. The amount of gas provided to the execution context of the target is at least the
                //      gas limit specified by the user. If there is not enough gas in the current context
                //      to accomplish this, `callWithMinGas` will revert.
                bool success = SafeCall.callWithMinGas(_tx.target, _tx.gasLimit, _tx.value, _tx.data);
                // Reset the l2Sender back to the default value.
                l2Sender = Constants.DEFAULT_L2_SENDER;
                // All withdrawals are immediately finalized. Replayability can
                // be achieved through contracts built on top of this contract
                emit WithdrawalFinalized(withdrawalHash, success);
                // Reverting here is useful for determining the exact gas cost to successfully execute the
                // sub call to the target contract if the minimum gas limit specified by the user would not
                // be sufficient to execute the sub call.
                if (!success && tx.origin == Constants.ESTIMATION_ADDRESS) {
                    revert GasEstimation();
                }
            }
            /// @notice Accepts deposits of ETH and data, and emits a TransactionDeposited event for use in
            ///         deriving deposit transactions. Note that if a deposit is made by a contract, its
            ///         address will be aliased when retrieved using `tx.origin` or `msg.sender`. Consider
            ///         using the CrossDomainMessenger contracts for a simpler developer experience.
            /// @param _to         Target address on L2.
            /// @param _value      ETH value to send to the recipient.
            /// @param _gasLimit   Amount of L2 gas to purchase by burning gas on L1.
            /// @param _isCreation Whether or not the transaction is a contract creation.
            /// @param _data       Data to trigger the recipient with.
            function depositTransaction(
                address _to,
                uint256 _value,
                uint64 _gasLimit,
                bool _isCreation,
                bytes memory _data
            )
                public
                payable
                metered(_gasLimit)
            {
                // Just to be safe, make sure that people specify address(0) as the target when doing
                // contract creations.
                if (_isCreation && _to != address(0)) revert BadTarget();
                // Prevent depositing transactions that have too small of a gas limit. Users should pay
                // more for more resource usage.
                if (_gasLimit < minimumGasLimit(uint64(_data.length))) revert SmallGasLimit();
                // Prevent the creation of deposit transactions that have too much calldata. This gives an
                // upper limit on the size of unsafe blocks over the p2p network. 120kb is chosen to ensure
                // that the transaction can fit into the p2p network policy of 128kb even though deposit
                // transactions are not gossipped over the p2p network.
                if (_data.length > 120_000) revert LargeCalldata();
                // Transform the from-address to its alias if the caller is a contract.
                address from = msg.sender;
                if (msg.sender != tx.origin) {
                    from = AddressAliasHelper.applyL1ToL2Alias(msg.sender);
                }
                // Compute the opaque data that will be emitted as part of the TransactionDeposited event.
                // We use opaque data so that we can update the TransactionDeposited event in the future
                // without breaking the current interface.
                bytes memory opaqueData = abi.encodePacked(msg.value, _value, _gasLimit, _isCreation, _data);
                // Emit a TransactionDeposited event so that the rollup node can derive a deposit
                // transaction for this deposit.
                emit TransactionDeposited(from, _to, DEPOSIT_VERSION, opaqueData);
            }
            /// @notice Blacklists a dispute game. Should only be used in the event that a dispute game resolves incorrectly.
            /// @param _disputeGame Dispute game to blacklist.
            function blacklistDisputeGame(IDisputeGame _disputeGame) external {
                if (msg.sender != guardian()) revert Unauthorized();
                disputeGameBlacklist[_disputeGame] = true;
                emit DisputeGameBlacklisted(_disputeGame);
            }
            /// @notice Sets the respected game type. Changing this value can alter the security properties of the system,
            ///         depending on the new game's behavior.
            /// @param _gameType The game type to consult for output proposals.
            function setRespectedGameType(GameType _gameType) external {
                if (msg.sender != guardian()) revert Unauthorized();
                respectedGameType = _gameType;
                respectedGameTypeUpdatedAt = uint64(block.timestamp);
                emit RespectedGameTypeSet(_gameType, Timestamp.wrap(respectedGameTypeUpdatedAt));
            }
            /// @notice Checks if a withdrawal can be finalized. This function will revert if the withdrawal cannot be
            ///         finalized, and otherwise has no side-effects.
            /// @param _withdrawalHash Hash of the withdrawal to check.
            /// @param _proofSubmitter The submitter of the proof for the withdrawal hash
            function checkWithdrawal(bytes32 _withdrawalHash, address _proofSubmitter) public view {
                ProvenWithdrawal memory provenWithdrawal = provenWithdrawals[_withdrawalHash][_proofSubmitter];
                IDisputeGame disputeGameProxy = provenWithdrawal.disputeGameProxy;
                // The dispute game must not be blacklisted.
                require(!disputeGameBlacklist[disputeGameProxy], "OptimismPortal: dispute game has been blacklisted");
                // A withdrawal can only be finalized if it has been proven. We know that a withdrawal has
                // been proven at least once when its timestamp is non-zero. Unproven withdrawals will have
                // a timestamp of zero.
                require(
                    provenWithdrawal.timestamp != 0,
                    "OptimismPortal: withdrawal has not been proven by proof submitter address yet"
                );
                uint64 createdAt = disputeGameProxy.createdAt().raw();
                // As a sanity check, we make sure that the proven withdrawal's timestamp is greater than
                // starting timestamp inside the Dispute Game. Not strictly necessary but extra layer of
                // safety against weird bugs in the proving step.
                require(
                    provenWithdrawal.timestamp > createdAt,
                    "OptimismPortal: withdrawal timestamp less than dispute game creation timestamp"
                );
                // A proven withdrawal must wait at least `PROOF_MATURITY_DELAY_SECONDS` before finalizing.
                require(
                    block.timestamp - provenWithdrawal.timestamp > PROOF_MATURITY_DELAY_SECONDS,
                    "OptimismPortal: proven withdrawal has not matured yet"
                );
                // A proven withdrawal must wait until the dispute game it was proven against has been
                // resolved in favor of the root claim (the output proposal). This is to prevent users
                // from finalizing withdrawals proven against non-finalized output roots.
                require(
                    disputeGameProxy.status() == GameStatus.DEFENDER_WINS,
                    "OptimismPortal: output proposal has not been validated"
                );
                // The game type of the dispute game must be the respected game type. This was also checked in
                // `proveWithdrawalTransaction`, but we check it again in case the respected game type has changed since
                // the withdrawal was proven.
                require(disputeGameProxy.gameType().raw() == respectedGameType.raw(), "OptimismPortal: invalid game type");
                // The game must have been created after `respectedGameTypeUpdatedAt`. This is to prevent users from creating
                // invalid disputes against a deployed game type while the off-chain challenge agents are not watching.
                require(
                    createdAt >= respectedGameTypeUpdatedAt,
                    "OptimismPortal: dispute game created before respected game type was updated"
                );
                // Before a withdrawal can be finalized, the dispute game it was proven against must have been
                // resolved for at least `DISPUTE_GAME_FINALITY_DELAY_SECONDS`. This is to allow for manual
                // intervention in the event that a dispute game is resolved incorrectly.
                require(
                    block.timestamp - disputeGameProxy.resolvedAt().raw() > DISPUTE_GAME_FINALITY_DELAY_SECONDS,
                    "OptimismPortal: output proposal in air-gap"
                );
                // Check that this withdrawal has not already been finalized, this is replay protection.
                require(!finalizedWithdrawals[_withdrawalHash], "OptimismPortal: withdrawal has already been finalized");
            }
            /// @notice External getter for the number of proof submitters for a withdrawal hash.
            /// @param _withdrawalHash Hash of the withdrawal.
            /// @return The number of proof submitters for the withdrawal hash.
            function numProofSubmitters(bytes32 _withdrawalHash) external view returns (uint256) {
                return proofSubmitters[_withdrawalHash].length;
            }
        }
        // SPDX-License-Identifier: MIT
        // OpenZeppelin Contracts (last updated v4.7.0) (proxy/utils/Initializable.sol)
        pragma solidity ^0.8.2;
        import "../../utils/Address.sol";
        /**
         * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed
         * behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an
         * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer
         * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.
         *
         * The initialization functions use a version number. Once a version number is used, it is consumed and cannot be
         * reused. This mechanism prevents re-execution of each "step" but allows the creation of new initialization steps in
         * case an upgrade adds a module that needs to be initialized.
         *
         * For example:
         *
         * [.hljs-theme-light.nopadding]
         * ```
         * contract MyToken is ERC20Upgradeable {
         *     function initialize() initializer public {
         *         __ERC20_init("MyToken", "MTK");
         *     }
         * }
         * contract MyTokenV2 is MyToken, ERC20PermitUpgradeable {
         *     function initializeV2() reinitializer(2) public {
         *         __ERC20Permit_init("MyToken");
         *     }
         * }
         * ```
         *
         * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as
         * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.
         *
         * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure
         * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.
         *
         * [CAUTION]
         * ====
         * Avoid leaving a contract uninitialized.
         *
         * An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation
         * contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke
         * the {_disableInitializers} function in the constructor to automatically lock it when it is deployed:
         *
         * [.hljs-theme-light.nopadding]
         * ```
         * /// @custom:oz-upgrades-unsafe-allow constructor
         * constructor() {
         *     _disableInitializers();
         * }
         * ```
         * ====
         */
        abstract contract Initializable {
            /**
             * @dev Indicates that the contract has been initialized.
             * @custom:oz-retyped-from bool
             */
            uint8 private _initialized;
            /**
             * @dev Indicates that the contract is in the process of being initialized.
             */
            bool private _initializing;
            /**
             * @dev Triggered when the contract has been initialized or reinitialized.
             */
            event Initialized(uint8 version);
            /**
             * @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,
             * `onlyInitializing` functions can be used to initialize parent contracts. Equivalent to `reinitializer(1)`.
             */
            modifier initializer() {
                bool isTopLevelCall = !_initializing;
                require(
                    (isTopLevelCall && _initialized < 1) || (!Address.isContract(address(this)) && _initialized == 1),
                    "Initializable: contract is already initialized"
                );
                _initialized = 1;
                if (isTopLevelCall) {
                    _initializing = true;
                }
                _;
                if (isTopLevelCall) {
                    _initializing = false;
                    emit Initialized(1);
                }
            }
            /**
             * @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the
             * contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be
             * used to initialize parent contracts.
             *
             * `initializer` is equivalent to `reinitializer(1)`, so a reinitializer may be used after the original
             * initialization step. This is essential to configure modules that are added through upgrades and that require
             * initialization.
             *
             * Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in
             * a contract, executing them in the right order is up to the developer or operator.
             */
            modifier reinitializer(uint8 version) {
                require(!_initializing && _initialized < version, "Initializable: contract is already initialized");
                _initialized = version;
                _initializing = true;
                _;
                _initializing = false;
                emit Initialized(version);
            }
            /**
             * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the
             * {initializer} and {reinitializer} modifiers, directly or indirectly.
             */
            modifier onlyInitializing() {
                require(_initializing, "Initializable: contract is not initializing");
                _;
            }
            /**
             * @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.
             * Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized
             * to any version. It is recommended to use this to lock implementation contracts that are designed to be called
             * through proxies.
             */
            function _disableInitializers() internal virtual {
                require(!_initializing, "Initializable: contract is initializing");
                if (_initialized < type(uint8).max) {
                    _initialized = type(uint8).max;
                    emit Initialized(type(uint8).max);
                }
            }
        }
        // SPDX-License-Identifier: MIT
        pragma solidity 0.8.15;
        /// @title SafeCall
        /// @notice Perform low level safe calls
        library SafeCall {
            /// @notice Performs a low level call without copying any returndata.
            /// @dev Passes no calldata to the call context.
            /// @param _target   Address to call
            /// @param _gas      Amount of gas to pass to the call
            /// @param _value    Amount of value to pass to the call
            function send(address _target, uint256 _gas, uint256 _value) internal returns (bool) {
                bool _success;
                assembly {
                    _success :=
                        call(
                            _gas, // gas
                            _target, // recipient
                            _value, // ether value
                            0, // inloc
                            0, // inlen
                            0, // outloc
                            0 // outlen
                        )
                }
                return _success;
            }
            /// @notice Perform a low level call without copying any returndata
            /// @param _target   Address to call
            /// @param _gas      Amount of gas to pass to the call
            /// @param _value    Amount of value to pass to the call
            /// @param _calldata Calldata to pass to the call
            function call(address _target, uint256 _gas, uint256 _value, bytes memory _calldata) internal returns (bool) {
                bool _success;
                assembly {
                    _success :=
                        call(
                            _gas, // gas
                            _target, // recipient
                            _value, // ether value
                            add(_calldata, 32), // inloc
                            mload(_calldata), // inlen
                            0, // outloc
                            0 // outlen
                        )
                }
                return _success;
            }
            /// @notice Helper function to determine if there is sufficient gas remaining within the context
            ///         to guarantee that the minimum gas requirement for a call will be met as well as
            ///         optionally reserving a specified amount of gas for after the call has concluded.
            /// @param _minGas      The minimum amount of gas that may be passed to the target context.
            /// @param _reservedGas Optional amount of gas to reserve for the caller after the execution
            ///                     of the target context.
            /// @return `true` if there is enough gas remaining to safely supply `_minGas` to the target
            ///         context as well as reserve `_reservedGas` for the caller after the execution of
            ///         the target context.
            /// @dev !!!!! FOOTGUN ALERT !!!!!
            ///      1.) The 40_000 base buffer is to account for the worst case of the dynamic cost of the
            ///          `CALL` opcode's `address_access_cost`, `positive_value_cost`, and
            ///          `value_to_empty_account_cost` factors with an added buffer of 5,700 gas. It is
            ///          still possible to self-rekt by initiating a withdrawal with a minimum gas limit
            ///          that does not account for the `memory_expansion_cost` & `code_execution_cost`
            ///          factors of the dynamic cost of the `CALL` opcode.
            ///      2.) This function should *directly* precede the external call if possible. There is an
            ///          added buffer to account for gas consumed between this check and the call, but it
            ///          is only 5,700 gas.
            ///      3.) Because EIP-150 ensures that a maximum of 63/64ths of the remaining gas in the call
            ///          frame may be passed to a subcontext, we need to ensure that the gas will not be
            ///          truncated.
            ///      4.) Use wisely. This function is not a silver bullet.
            function hasMinGas(uint256 _minGas, uint256 _reservedGas) internal view returns (bool) {
                bool _hasMinGas;
                assembly {
                    // Equation: gas × 63 ≥ minGas × 64 + 63(40_000 + reservedGas)
                    _hasMinGas := iszero(lt(mul(gas(), 63), add(mul(_minGas, 64), mul(add(40000, _reservedGas), 63))))
                }
                return _hasMinGas;
            }
            /// @notice Perform a low level call without copying any returndata. This function
            ///         will revert if the call cannot be performed with the specified minimum
            ///         gas.
            /// @param _target   Address to call
            /// @param _minGas   The minimum amount of gas that may be passed to the call
            /// @param _value    Amount of value to pass to the call
            /// @param _calldata Calldata to pass to the call
            function callWithMinGas(
                address _target,
                uint256 _minGas,
                uint256 _value,
                bytes memory _calldata
            )
                internal
                returns (bool)
            {
                bool _success;
                bool _hasMinGas = hasMinGas(_minGas, 0);
                assembly {
                    // Assertion: gasleft() >= (_minGas * 64) / 63 + 40_000
                    if iszero(_hasMinGas) {
                        // Store the "Error(string)" selector in scratch space.
                        mstore(0, 0x08c379a0)
                        // Store the pointer to the string length in scratch space.
                        mstore(32, 32)
                        // Store the string.
                        //
                        // SAFETY:
                        // - We pad the beginning of the string with two zero bytes as well as the
                        // length (24) to ensure that we override the free memory pointer at offset
                        // 0x40. This is necessary because the free memory pointer is likely to
                        // be greater than 1 byte when this function is called, but it is incredibly
                        // unlikely that it will be greater than 3 bytes. As for the data within
                        // 0x60, it is ensured that it is 0 due to 0x60 being the zero offset.
                        // - It's fine to clobber the free memory pointer, we're reverting.
                        mstore(88, 0x0000185361666543616c6c3a204e6f7420656e6f75676820676173)
                        // Revert with 'Error("SafeCall: Not enough gas")'
                        revert(28, 100)
                    }
                    // The call will be supplied at least ((_minGas * 64) / 63) gas due to the
                    // above assertion. This ensures that, in all circumstances (except for when the
                    // `_minGas` does not account for the `memory_expansion_cost` and `code_execution_cost`
                    // factors of the dynamic cost of the `CALL` opcode), the call will receive at least
                    // the minimum amount of gas specified.
                    _success :=
                        call(
                            gas(), // gas
                            _target, // recipient
                            _value, // ether value
                            add(_calldata, 32), // inloc
                            mload(_calldata), // inlen
                            0x00, // outloc
                            0x00 // outlen
                        )
                }
                return _success;
            }
        }
        // SPDX-License-Identifier: MIT
        pragma solidity 0.8.15;
        import { LibClone } from "@solady/utils/LibClone.sol";
        import { OwnableUpgradeable } from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
        import { ISemver } from "src/universal/ISemver.sol";
        import { IDisputeGame } from "src/dispute/interfaces/IDisputeGame.sol";
        import { IDisputeGameFactory } from "src/dispute/interfaces/IDisputeGameFactory.sol";
        import "src/dispute/lib/Types.sol";
        import "src/dispute/lib/Errors.sol";
        /// @title DisputeGameFactory
        /// @notice A factory contract for creating `IDisputeGame` contracts. All created dispute games are stored in both a
        ///         mapping and an append only array. The timestamp of the creation time of the dispute game is packed tightly
        ///         into the storage slot with the address of the dispute game to make offchain discoverability of playable
        ///         dispute games easier.
        contract DisputeGameFactory is OwnableUpgradeable, IDisputeGameFactory, ISemver {
            /// @dev Allows for the creation of clone proxies with immutable arguments.
            using LibClone for address;
            /// @notice Semantic version.
            /// @custom:semver 1.0.0
            string public constant version = "1.0.0";
            /// @inheritdoc IDisputeGameFactory
            mapping(GameType => IDisputeGame) public gameImpls;
            /// @inheritdoc IDisputeGameFactory
            mapping(GameType => uint256) public initBonds;
            /// @notice Mapping of a hash of `gameType || rootClaim || extraData` to the deployed `IDisputeGame` clone (where
            //          `||` denotes concatenation).
            mapping(Hash => GameId) internal _disputeGames;
            /// @notice An append-only array of disputeGames that have been created. Used by offchain game solvers to
            ///         efficiently track dispute games.
            GameId[] internal _disputeGameList;
            /// @notice Constructs a new DisputeGameFactory contract.
            constructor() OwnableUpgradeable() {
                initialize(address(0));
            }
            /// @notice Initializes the contract.
            /// @param _owner The owner of the contract.
            function initialize(address _owner) public initializer {
                __Ownable_init();
                _transferOwnership(_owner);
            }
            /// @inheritdoc IDisputeGameFactory
            function gameCount() external view returns (uint256 gameCount_) {
                gameCount_ = _disputeGameList.length;
            }
            /// @inheritdoc IDisputeGameFactory
            function games(
                GameType _gameType,
                Claim _rootClaim,
                bytes calldata _extraData
            )
                external
                view
                returns (IDisputeGame proxy_, Timestamp timestamp_)
            {
                Hash uuid = getGameUUID(_gameType, _rootClaim, _extraData);
                (, Timestamp timestamp, address proxy) = _disputeGames[uuid].unpack();
                (proxy_, timestamp_) = (IDisputeGame(proxy), timestamp);
            }
            /// @inheritdoc IDisputeGameFactory
            function gameAtIndex(uint256 _index)
                external
                view
                returns (GameType gameType_, Timestamp timestamp_, IDisputeGame proxy_)
            {
                (GameType gameType, Timestamp timestamp, address proxy) = _disputeGameList[_index].unpack();
                (gameType_, timestamp_, proxy_) = (gameType, timestamp, IDisputeGame(proxy));
            }
            /// @inheritdoc IDisputeGameFactory
            function create(
                GameType _gameType,
                Claim _rootClaim,
                bytes calldata _extraData
            )
                external
                payable
                returns (IDisputeGame proxy_)
            {
                // Grab the implementation contract for the given `GameType`.
                IDisputeGame impl = gameImpls[_gameType];
                // If there is no implementation to clone for the given `GameType`, revert.
                if (address(impl) == address(0)) revert NoImplementation(_gameType);
                // If the required initialization bond is not met, revert.
                if (msg.value != initBonds[_gameType]) revert IncorrectBondAmount();
                // Get the hash of the parent block.
                bytes32 parentHash = blockhash(block.number - 1);
                // Clone the implementation contract and initialize it with the given parameters.
                //
                // CWIA Calldata Layout:
                // ┌──────────────┬────────────────────────────────────┐
                // │    Bytes     │            Description             │
                // ├──────────────┼────────────────────────────────────┤
                // │ [0, 20)      │ Game creator address               │
                // │ [20, 52)     │ Root claim                         │
                // │ [52, 84)     │ Parent block hash at creation time │
                // │ [84, 84 + n) │ Extra data (opaque)                │
                // └──────────────┴────────────────────────────────────┘
                proxy_ = IDisputeGame(address(impl).clone(abi.encodePacked(msg.sender, _rootClaim, parentHash, _extraData)));
                proxy_.initialize{ value: msg.value }();
                // Compute the unique identifier for the dispute game.
                Hash uuid = getGameUUID(_gameType, _rootClaim, _extraData);
                // If a dispute game with the same UUID already exists, revert.
                if (GameId.unwrap(_disputeGames[uuid]) != bytes32(0)) revert GameAlreadyExists(uuid);
                // Pack the game ID.
                GameId id = LibGameId.pack(_gameType, Timestamp.wrap(uint64(block.timestamp)), address(proxy_));
                // Store the dispute game id in the mapping & emit the `DisputeGameCreated` event.
                _disputeGames[uuid] = id;
                _disputeGameList.push(id);
                emit DisputeGameCreated(address(proxy_), _gameType, _rootClaim);
            }
            /// @inheritdoc IDisputeGameFactory
            function getGameUUID(
                GameType _gameType,
                Claim _rootClaim,
                bytes calldata _extraData
            )
                public
                pure
                returns (Hash uuid_)
            {
                uuid_ = Hash.wrap(keccak256(abi.encode(_gameType, _rootClaim, _extraData)));
            }
            /// @inheritdoc IDisputeGameFactory
            function findLatestGames(
                GameType _gameType,
                uint256 _start,
                uint256 _n
            )
                external
                view
                returns (GameSearchResult[] memory games_)
            {
                // If the `_start` index is greater than or equal to the game array length or `_n == 0`, return an empty array.
                if (_start >= _disputeGameList.length || _n == 0) return games_;
                // Allocate enough memory for the full array, but start the array's length at `0`. We may not use all of the
                // memory allocated, but we don't know ahead of time the final size of the array.
                assembly {
                    games_ := mload(0x40)
                    mstore(0x40, add(games_, add(0x20, shl(0x05, _n))))
                }
                // Perform a reverse linear search for the `_n` most recent games of type `_gameType`.
                for (uint256 i = _start; i >= 0 && i <= _start;) {
                    GameId id = _disputeGameList[i];
                    (GameType gameType, Timestamp timestamp, address proxy) = id.unpack();
                    if (gameType.raw() == _gameType.raw()) {
                        // Increase the size of the `games_` array by 1.
                        // SAFETY: We can safely lazily allocate memory here because we pre-allocated enough memory for the max
                        //         possible size of the array.
                        assembly {
                            mstore(games_, add(mload(games_), 0x01))
                        }
                        bytes memory extraData = IDisputeGame(proxy).extraData();
                        Claim rootClaim = IDisputeGame(proxy).rootClaim();
                        games_[games_.length - 1] = GameSearchResult({
                            index: i,
                            metadata: id,
                            timestamp: timestamp,
                            rootClaim: rootClaim,
                            extraData: extraData
                        });
                        if (games_.length >= _n) break;
                    }
                    unchecked {
                        i--;
                    }
                }
            }
            /// @inheritdoc IDisputeGameFactory
            function setImplementation(GameType _gameType, IDisputeGame _impl) external onlyOwner {
                gameImpls[_gameType] = _impl;
                emit ImplementationSet(address(_impl), _gameType);
            }
            /// @inheritdoc IDisputeGameFactory
            function setInitBond(GameType _gameType, uint256 _initBond) external onlyOwner {
                initBonds[_gameType] = _initBond;
                emit InitBondUpdated(_gameType, _initBond);
            }
        }
        // SPDX-License-Identifier: MIT
        pragma solidity 0.8.15;
        import { OwnableUpgradeable } from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
        import { ISemver } from "src/universal/ISemver.sol";
        import { ResourceMetering } from "src/L1/ResourceMetering.sol";
        import { Storage } from "src/libraries/Storage.sol";
        import { Constants } from "src/libraries/Constants.sol";
        /// @title SystemConfig
        /// @notice The SystemConfig contract is used to manage configuration of an Optimism network.
        ///         All configuration is stored on L1 and picked up by L2 as part of the derviation of
        ///         the L2 chain.
        contract SystemConfig is OwnableUpgradeable, ISemver {
            /// @notice Enum representing different types of updates.
            /// @custom:value BATCHER              Represents an update to the batcher hash.
            /// @custom:value GAS_CONFIG           Represents an update to txn fee config on L2.
            /// @custom:value GAS_LIMIT            Represents an update to gas limit on L2.
            /// @custom:value UNSAFE_BLOCK_SIGNER  Represents an update to the signer key for unsafe
            ///                                    block distrubution.
            enum UpdateType {
                BATCHER,
                GAS_CONFIG,
                GAS_LIMIT,
                UNSAFE_BLOCK_SIGNER
            }
            /// @notice Struct representing the addresses of L1 system contracts. These should be the
            ///         proxies and are network specific.
            struct Addresses {
                address l1CrossDomainMessenger;
                address l1ERC721Bridge;
                address l1StandardBridge;
                address disputeGameFactory;
                address optimismPortal;
                address optimismMintableERC20Factory;
            }
            /// @notice Version identifier, used for upgrades.
            uint256 public constant VERSION = 0;
            /// @notice Storage slot that the unsafe block signer is stored at.
            ///         Storing it at this deterministic storage slot allows for decoupling the storage
            ///         layout from the way that `solc` lays out storage. The `op-node` uses a storage
            ///         proof to fetch this value.
            /// @dev    NOTE: this value will be migrated to another storage slot in a future version.
            ///         User input should not be placed in storage in this contract until this migration
            ///         happens. It is unlikely that keccak second preimage resistance will be broken,
            ///         but it is better to be safe than sorry.
            bytes32 public constant UNSAFE_BLOCK_SIGNER_SLOT = keccak256("systemconfig.unsafeblocksigner");
            /// @notice Storage slot that the L1CrossDomainMessenger address is stored at.
            bytes32 public constant L1_CROSS_DOMAIN_MESSENGER_SLOT =
                bytes32(uint256(keccak256("systemconfig.l1crossdomainmessenger")) - 1);
            /// @notice Storage slot that the L1ERC721Bridge address is stored at.
            bytes32 public constant L1_ERC_721_BRIDGE_SLOT = bytes32(uint256(keccak256("systemconfig.l1erc721bridge")) - 1);
            /// @notice Storage slot that the L1StandardBridge address is stored at.
            bytes32 public constant L1_STANDARD_BRIDGE_SLOT = bytes32(uint256(keccak256("systemconfig.l1standardbridge")) - 1);
            /// @notice Storage slot that the OptimismPortal address is stored at.
            bytes32 public constant OPTIMISM_PORTAL_SLOT = bytes32(uint256(keccak256("systemconfig.optimismportal")) - 1);
            /// @notice Storage slot that the OptimismMintableERC20Factory address is stored at.
            bytes32 public constant OPTIMISM_MINTABLE_ERC20_FACTORY_SLOT =
                bytes32(uint256(keccak256("systemconfig.optimismmintableerc20factory")) - 1);
            /// @notice Storage slot that the batch inbox address is stored at.
            bytes32 public constant BATCH_INBOX_SLOT = bytes32(uint256(keccak256("systemconfig.batchinbox")) - 1);
            /// @notice Storage slot for block at which the op-node can start searching for logs from.
            bytes32 public constant START_BLOCK_SLOT = bytes32(uint256(keccak256("systemconfig.startBlock")) - 1);
            /// @notice Storage slot for the DisputeGameFactory address.
            bytes32 public constant DISPUTE_GAME_FACTORY_SLOT =
                bytes32(uint256(keccak256("systemconfig.disputegamefactory")) - 1);
            /// @notice The maximum gas limit that can be set for L2 blocks. This limit is used to enforce that the blocks
            ///         on L2 are not too large to process and prove. Over time, this value can be increased as various
            ///         optimizations and improvements are made to the system at large.
            uint64 internal constant MAX_GAS_LIMIT = 200_000_000;
            /// @notice Fixed L2 gas overhead. Used as part of the L2 fee calculation.
            uint256 public overhead;
            /// @notice Dynamic L2 gas overhead. Used as part of the L2 fee calculation.
            uint256 public scalar;
            /// @notice Identifier for the batcher.
            ///         For version 1 of this configuration, this is represented as an address left-padded
            ///         with zeros to 32 bytes.
            bytes32 public batcherHash;
            /// @notice L2 block gas limit.
            uint64 public gasLimit;
            /// @notice The configuration for the deposit fee market.
            ///         Used by the OptimismPortal to meter the cost of buying L2 gas on L1.
            ///         Set as internal with a getter so that the struct is returned instead of a tuple.
            ResourceMetering.ResourceConfig internal _resourceConfig;
            /// @notice Emitted when configuration is updated.
            /// @param version    SystemConfig version.
            /// @param updateType Type of update.
            /// @param data       Encoded update data.
            event ConfigUpdate(uint256 indexed version, UpdateType indexed updateType, bytes data);
            /// @notice Semantic version.
            /// @custom:semver 2.2.0
            string public constant version = "2.2.0";
            /// @notice Constructs the SystemConfig contract. Cannot set
            ///         the owner to `address(0)` due to the Ownable contract's
            ///         implementation, so set it to `address(0xdEaD)`
            /// @dev    START_BLOCK_SLOT is set to type(uint256).max here so that it will be a dead value
            ///         in the singleton and is skipped by initialize when setting the start block.
            constructor() {
                Storage.setUint(START_BLOCK_SLOT, type(uint256).max);
                initialize({
                    _owner: address(0xdEaD),
                    _overhead: 0,
                    _scalar: 0,
                    _batcherHash: bytes32(0),
                    _gasLimit: 1,
                    _unsafeBlockSigner: address(0),
                    _config: ResourceMetering.ResourceConfig({
                        maxResourceLimit: 1,
                        elasticityMultiplier: 1,
                        baseFeeMaxChangeDenominator: 2,
                        minimumBaseFee: 0,
                        systemTxMaxGas: 0,
                        maximumBaseFee: 0
                    }),
                    _batchInbox: address(0),
                    _addresses: SystemConfig.Addresses({
                        l1CrossDomainMessenger: address(0),
                        l1ERC721Bridge: address(0),
                        l1StandardBridge: address(0),
                        disputeGameFactory: address(0),
                        optimismPortal: address(0),
                        optimismMintableERC20Factory: address(0)
                    })
                });
            }
            /// @notice Initializer.
            ///         The resource config must be set before the require check.
            /// @param _owner             Initial owner of the contract.
            /// @param _overhead          Initial overhead value.
            /// @param _scalar            Initial scalar value.
            /// @param _batcherHash       Initial batcher hash.
            /// @param _gasLimit          Initial gas limit.
            /// @param _unsafeBlockSigner Initial unsafe block signer address.
            /// @param _config            Initial ResourceConfig.
            /// @param _batchInbox        Batch inbox address. An identifier for the op-node to find
            ///                           canonical data.
            /// @param _addresses         Set of L1 contract addresses. These should be the proxies.
            function initialize(
                address _owner,
                uint256 _overhead,
                uint256 _scalar,
                bytes32 _batcherHash,
                uint64 _gasLimit,
                address _unsafeBlockSigner,
                ResourceMetering.ResourceConfig memory _config,
                address _batchInbox,
                SystemConfig.Addresses memory _addresses
            )
                public
                initializer
            {
                __Ownable_init();
                transferOwnership(_owner);
                // These are set in ascending order of their UpdateTypes.
                _setBatcherHash(_batcherHash);
                _setGasConfig({ _overhead: _overhead, _scalar: _scalar });
                _setGasLimit(_gasLimit);
                Storage.setAddress(UNSAFE_BLOCK_SIGNER_SLOT, _unsafeBlockSigner);
                Storage.setAddress(BATCH_INBOX_SLOT, _batchInbox);
                Storage.setAddress(L1_CROSS_DOMAIN_MESSENGER_SLOT, _addresses.l1CrossDomainMessenger);
                Storage.setAddress(L1_ERC_721_BRIDGE_SLOT, _addresses.l1ERC721Bridge);
                Storage.setAddress(L1_STANDARD_BRIDGE_SLOT, _addresses.l1StandardBridge);
                Storage.setAddress(DISPUTE_GAME_FACTORY_SLOT, _addresses.disputeGameFactory);
                Storage.setAddress(OPTIMISM_PORTAL_SLOT, _addresses.optimismPortal);
                Storage.setAddress(OPTIMISM_MINTABLE_ERC20_FACTORY_SLOT, _addresses.optimismMintableERC20Factory);
                _setStartBlock();
                _setResourceConfig(_config);
                require(_gasLimit >= minimumGasLimit(), "SystemConfig: gas limit too low");
            }
            /// @notice Returns the minimum L2 gas limit that can be safely set for the system to
            ///         operate. The L2 gas limit must be larger than or equal to the amount of
            ///         gas that is allocated for deposits per block plus the amount of gas that
            ///         is allocated for the system transaction.
            ///         This function is used to determine if changes to parameters are safe.
            /// @return uint64 Minimum gas limit.
            function minimumGasLimit() public view returns (uint64) {
                return uint64(_resourceConfig.maxResourceLimit) + uint64(_resourceConfig.systemTxMaxGas);
            }
            /// @notice Returns the maximum L2 gas limit that can be safely set for the system to
            ///         operate. This bound is used to prevent the gas limit from being set too high
            ///         and causing the system to be unable to process and/or prove L2 blocks.
            /// @return uint64 Maximum gas limit.
            function maximumGasLimit() public pure returns (uint64) {
                return MAX_GAS_LIMIT;
            }
            /// @notice High level getter for the unsafe block signer address.
            ///         Unsafe blocks can be propagated across the p2p network if they are signed by the
            ///         key corresponding to this address.
            /// @return addr_ Address of the unsafe block signer.
            function unsafeBlockSigner() public view returns (address addr_) {
                addr_ = Storage.getAddress(UNSAFE_BLOCK_SIGNER_SLOT);
            }
            /// @notice Getter for the L1CrossDomainMessenger address.
            function l1CrossDomainMessenger() external view returns (address addr_) {
                addr_ = Storage.getAddress(L1_CROSS_DOMAIN_MESSENGER_SLOT);
            }
            /// @notice Getter for the L1ERC721Bridge address.
            function l1ERC721Bridge() external view returns (address addr_) {
                addr_ = Storage.getAddress(L1_ERC_721_BRIDGE_SLOT);
            }
            /// @notice Getter for the L1StandardBridge address.
            function l1StandardBridge() external view returns (address addr_) {
                addr_ = Storage.getAddress(L1_STANDARD_BRIDGE_SLOT);
            }
            /// @notice Getter for the DisputeGameFactory address.
            function disputeGameFactory() external view returns (address addr_) {
                addr_ = Storage.getAddress(DISPUTE_GAME_FACTORY_SLOT);
            }
            /// @notice Getter for the OptimismPortal address.
            function optimismPortal() external view returns (address addr_) {
                addr_ = Storage.getAddress(OPTIMISM_PORTAL_SLOT);
            }
            /// @notice Getter for the OptimismMintableERC20Factory address.
            function optimismMintableERC20Factory() external view returns (address addr_) {
                addr_ = Storage.getAddress(OPTIMISM_MINTABLE_ERC20_FACTORY_SLOT);
            }
            /// @notice Getter for the BatchInbox address.
            function batchInbox() external view returns (address addr_) {
                addr_ = Storage.getAddress(BATCH_INBOX_SLOT);
            }
            /// @notice Getter for the StartBlock number.
            function startBlock() external view returns (uint256 startBlock_) {
                startBlock_ = Storage.getUint(START_BLOCK_SLOT);
            }
            /// @notice Updates the unsafe block signer address. Can only be called by the owner.
            /// @param _unsafeBlockSigner New unsafe block signer address.
            function setUnsafeBlockSigner(address _unsafeBlockSigner) external onlyOwner {
                _setUnsafeBlockSigner(_unsafeBlockSigner);
            }
            /// @notice Updates the unsafe block signer address.
            /// @param _unsafeBlockSigner New unsafe block signer address.
            function _setUnsafeBlockSigner(address _unsafeBlockSigner) internal {
                Storage.setAddress(UNSAFE_BLOCK_SIGNER_SLOT, _unsafeBlockSigner);
                bytes memory data = abi.encode(_unsafeBlockSigner);
                emit ConfigUpdate(VERSION, UpdateType.UNSAFE_BLOCK_SIGNER, data);
            }
            /// @notice Updates the batcher hash. Can only be called by the owner.
            /// @param _batcherHash New batcher hash.
            function setBatcherHash(bytes32 _batcherHash) external onlyOwner {
                _setBatcherHash(_batcherHash);
            }
            /// @notice Internal function for updating the batcher hash.
            /// @param _batcherHash New batcher hash.
            function _setBatcherHash(bytes32 _batcherHash) internal {
                batcherHash = _batcherHash;
                bytes memory data = abi.encode(_batcherHash);
                emit ConfigUpdate(VERSION, UpdateType.BATCHER, data);
            }
            /// @notice Updates gas config. Can only be called by the owner.
            /// @param _overhead New overhead value.
            /// @param _scalar   New scalar value.
            function setGasConfig(uint256 _overhead, uint256 _scalar) external onlyOwner {
                _setGasConfig(_overhead, _scalar);
            }
            /// @notice Internal function for updating the gas config.
            /// @param _overhead New overhead value.
            /// @param _scalar   New scalar value.
            function _setGasConfig(uint256 _overhead, uint256 _scalar) internal {
                overhead = _overhead;
                scalar = _scalar;
                bytes memory data = abi.encode(_overhead, _scalar);
                emit ConfigUpdate(VERSION, UpdateType.GAS_CONFIG, data);
            }
            /// @notice Updates the L2 gas limit. Can only be called by the owner.
            /// @param _gasLimit New gas limit.
            function setGasLimit(uint64 _gasLimit) external onlyOwner {
                _setGasLimit(_gasLimit);
            }
            /// @notice Internal function for updating the L2 gas limit.
            /// @param _gasLimit New gas limit.
            function _setGasLimit(uint64 _gasLimit) internal {
                require(_gasLimit >= minimumGasLimit(), "SystemConfig: gas limit too low");
                require(_gasLimit <= maximumGasLimit(), "SystemConfig: gas limit too high");
                gasLimit = _gasLimit;
                bytes memory data = abi.encode(_gasLimit);
                emit ConfigUpdate(VERSION, UpdateType.GAS_LIMIT, data);
            }
            /// @notice Sets the start block in a backwards compatible way. Proxies
            ///         that were initialized before the startBlock existed in storage
            ///         can have their start block set by a user provided override.
            ///         A start block of 0 indicates that there is no override and the
            ///         start block will be set by `block.number`.
            /// @dev    This logic is used to patch legacy deployments with new storage values.
            ///         Use the override if it is provided as a non zero value and the value
            ///         has not already been set in storage. Use `block.number` if the value
            ///         has already been set in storage
            function _setStartBlock() internal {
                if (Storage.getUint(START_BLOCK_SLOT) == 0) {
                    Storage.setUint(START_BLOCK_SLOT, block.number);
                }
            }
            /// @notice A getter for the resource config.
            ///         Ensures that the struct is returned instead of a tuple.
            /// @return ResourceConfig
            function resourceConfig() external view returns (ResourceMetering.ResourceConfig memory) {
                return _resourceConfig;
            }
            /// @notice An internal setter for the resource config.
            ///         Ensures that the config is sane before storing it by checking for invariants.
            ///         In the future, this method may emit an event that the `op-node` picks up
            ///         for when the resource config is changed.
            /// @param _config The new resource config.
            function _setResourceConfig(ResourceMetering.ResourceConfig memory _config) internal {
                // Min base fee must be less than or equal to max base fee.
                require(
                    _config.minimumBaseFee <= _config.maximumBaseFee, "SystemConfig: min base fee must be less than max base"
                );
                // Base fee change denominator must be greater than 1.
                require(_config.baseFeeMaxChangeDenominator > 1, "SystemConfig: denominator must be larger than 1");
                // Max resource limit plus system tx gas must be less than or equal to the L2 gas limit.
                // The gas limit must be increased before these values can be increased.
                require(_config.maxResourceLimit + _config.systemTxMaxGas <= gasLimit, "SystemConfig: gas limit too low");
                // Elasticity multiplier must be greater than 0.
                require(_config.elasticityMultiplier > 0, "SystemConfig: elasticity multiplier cannot be 0");
                // No precision loss when computing target resource limit.
                require(
                    ((_config.maxResourceLimit / _config.elasticityMultiplier) * _config.elasticityMultiplier)
                        == _config.maxResourceLimit,
                    "SystemConfig: precision loss with target resource limit"
                );
                _resourceConfig = _config;
            }
        }
        // SPDX-License-Identifier: MIT
        pragma solidity 0.8.15;
        import { Initializable } from "@openzeppelin/contracts/proxy/utils/Initializable.sol";
        import { ISemver } from "src/universal/ISemver.sol";
        import { Storage } from "src/libraries/Storage.sol";
        /// @custom:audit none This contracts is not yet audited.
        /// @title SuperchainConfig
        /// @notice The SuperchainConfig contract is used to manage configuration of global superchain values.
        contract SuperchainConfig is Initializable, ISemver {
            /// @notice Enum representing different types of updates.
            /// @custom:value GUARDIAN            Represents an update to the guardian.
            enum UpdateType {
                GUARDIAN
            }
            /// @notice Whether or not the Superchain is paused.
            bytes32 public constant PAUSED_SLOT = bytes32(uint256(keccak256("superchainConfig.paused")) - 1);
            /// @notice The address of the guardian, which can pause withdrawals from the System.
            ///         It can only be modified by an upgrade.
            bytes32 public constant GUARDIAN_SLOT = bytes32(uint256(keccak256("superchainConfig.guardian")) - 1);
            /// @notice Emitted when the pause is triggered.
            /// @param identifier A string helping to identify provenance of the pause transaction.
            event Paused(string identifier);
            /// @notice Emitted when the pause is lifted.
            event Unpaused();
            /// @notice Emitted when configuration is updated.
            /// @param updateType Type of update.
            /// @param data       Encoded update data.
            event ConfigUpdate(UpdateType indexed updateType, bytes data);
            /// @notice Semantic version.
            /// @custom:semver 1.1.0
            string public constant version = "1.1.0";
            /// @notice Constructs the SuperchainConfig contract.
            constructor() {
                initialize({ _guardian: address(0), _paused: false });
            }
            /// @notice Initializer.
            /// @param _guardian    Address of the guardian, can pause the OptimismPortal.
            /// @param _paused      Initial paused status.
            function initialize(address _guardian, bool _paused) public initializer {
                _setGuardian(_guardian);
                if (_paused) {
                    _pause("Initializer paused");
                }
            }
            /// @notice Getter for the guardian address.
            function guardian() public view returns (address guardian_) {
                guardian_ = Storage.getAddress(GUARDIAN_SLOT);
            }
            /// @notice Getter for the current paused status.
            function paused() public view returns (bool paused_) {
                paused_ = Storage.getBool(PAUSED_SLOT);
            }
            /// @notice Pauses withdrawals.
            /// @param _identifier (Optional) A string to identify provenance of the pause transaction.
            function pause(string memory _identifier) external {
                require(msg.sender == guardian(), "SuperchainConfig: only guardian can pause");
                _pause(_identifier);
            }
            /// @notice Pauses withdrawals.
            /// @param _identifier (Optional) A string to identify provenance of the pause transaction.
            function _pause(string memory _identifier) internal {
                Storage.setBool(PAUSED_SLOT, true);
                emit Paused(_identifier);
            }
            /// @notice Unpauses withdrawals.
            function unpause() external {
                require(msg.sender == guardian(), "SuperchainConfig: only guardian can unpause");
                Storage.setBool(PAUSED_SLOT, false);
                emit Unpaused();
            }
            /// @notice Sets the guardian address. This is only callable during initialization, so an upgrade
            ///         will be required to change the guardian.
            /// @param _guardian The new guardian address.
            function _setGuardian(address _guardian) internal {
                Storage.setAddress(GUARDIAN_SLOT, _guardian);
                emit ConfigUpdate(UpdateType.GUARDIAN, abi.encode(_guardian));
            }
        }
        // SPDX-License-Identifier: MIT
        pragma solidity ^0.8.0;
        import { ResourceMetering } from "src/L1/ResourceMetering.sol";
        /// @title Constants
        /// @notice Constants is a library for storing constants. Simple! Don't put everything in here, just
        ///         the stuff used in multiple contracts. Constants that only apply to a single contract
        ///         should be defined in that contract instead.
        library Constants {
            /// @notice Special address to be used as the tx origin for gas estimation calls in the
            ///         OptimismPortal and CrossDomainMessenger calls. You only need to use this address if
            ///         the minimum gas limit specified by the user is not actually enough to execute the
            ///         given message and you're attempting to estimate the actual necessary gas limit. We
            ///         use address(1) because it's the ecrecover precompile and therefore guaranteed to
            ///         never have any code on any EVM chain.
            address internal constant ESTIMATION_ADDRESS = address(1);
            /// @notice Value used for the L2 sender storage slot in both the OptimismPortal and the
            ///         CrossDomainMessenger contracts before an actual sender is set. This value is
            ///         non-zero to reduce the gas cost of message passing transactions.
            address internal constant DEFAULT_L2_SENDER = 0x000000000000000000000000000000000000dEaD;
            /// @notice The storage slot that holds the address of a proxy implementation.
            /// @dev `bytes32(uint256(keccak256('eip1967.proxy.implementation')) - 1)`
            bytes32 internal constant PROXY_IMPLEMENTATION_ADDRESS =
                0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
            /// @notice The storage slot that holds the address of the owner.
            /// @dev `bytes32(uint256(keccak256('eip1967.proxy.admin')) - 1)`
            bytes32 internal constant PROXY_OWNER_ADDRESS = 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103;
            /// @notice Returns the default values for the ResourceConfig. These are the recommended values
            ///         for a production network.
            function DEFAULT_RESOURCE_CONFIG() internal pure returns (ResourceMetering.ResourceConfig memory) {
                ResourceMetering.ResourceConfig memory config = ResourceMetering.ResourceConfig({
                    maxResourceLimit: 20_000_000,
                    elasticityMultiplier: 10,
                    baseFeeMaxChangeDenominator: 8,
                    minimumBaseFee: 1 gwei,
                    systemTxMaxGas: 1_000_000,
                    maximumBaseFee: type(uint128).max
                });
                return config;
            }
        }
        // SPDX-License-Identifier: MIT
        pragma solidity ^0.8.0;
        /// @title Types
        /// @notice Contains various types used throughout the Optimism contract system.
        library Types {
            /// @notice OutputProposal represents a commitment to the L2 state. The timestamp is the L1
            ///         timestamp that the output root is posted. This timestamp is used to verify that the
            ///         finalization period has passed since the output root was submitted.
            /// @custom:field outputRoot    Hash of the L2 output.
            /// @custom:field timestamp     Timestamp of the L1 block that the output root was submitted in.
            /// @custom:field l2BlockNumber L2 block number that the output corresponds to.
            struct OutputProposal {
                bytes32 outputRoot;
                uint128 timestamp;
                uint128 l2BlockNumber;
            }
            /// @notice Struct representing the elements that are hashed together to generate an output root
            ///         which itself represents a snapshot of the L2 state.
            /// @custom:field version                  Version of the output root.
            /// @custom:field stateRoot                Root of the state trie at the block of this output.
            /// @custom:field messagePasserStorageRoot Root of the message passer storage trie.
            /// @custom:field latestBlockhash          Hash of the block this output was generated from.
            struct OutputRootProof {
                bytes32 version;
                bytes32 stateRoot;
                bytes32 messagePasserStorageRoot;
                bytes32 latestBlockhash;
            }
            /// @notice Struct representing a deposit transaction (L1 => L2 transaction) created by an end
            ///         user (as opposed to a system deposit transaction generated by the system).
            /// @custom:field from        Address of the sender of the transaction.
            /// @custom:field to          Address of the recipient of the transaction.
            /// @custom:field isCreation  True if the transaction is a contract creation.
            /// @custom:field value       Value to send to the recipient.
            /// @custom:field mint        Amount of ETH to mint.
            /// @custom:field gasLimit    Gas limit of the transaction.
            /// @custom:field data        Data of the transaction.
            /// @custom:field l1BlockHash Hash of the block the transaction was submitted in.
            /// @custom:field logIndex    Index of the log in the block the transaction was submitted in.
            struct UserDepositTransaction {
                address from;
                address to;
                bool isCreation;
                uint256 value;
                uint256 mint;
                uint64 gasLimit;
                bytes data;
                bytes32 l1BlockHash;
                uint256 logIndex;
            }
            /// @notice Struct representing a withdrawal transaction.
            /// @custom:field nonce    Nonce of the withdrawal transaction
            /// @custom:field sender   Address of the sender of the transaction.
            /// @custom:field target   Address of the recipient of the transaction.
            /// @custom:field value    Value to send to the recipient.
            /// @custom:field gasLimit Gas limit of the transaction.
            /// @custom:field data     Data of the transaction.
            struct WithdrawalTransaction {
                uint256 nonce;
                address sender;
                address target;
                uint256 value;
                uint256 gasLimit;
                bytes data;
            }
        }
        // SPDX-License-Identifier: MIT
        pragma solidity ^0.8.0;
        import { Types } from "src/libraries/Types.sol";
        import { Encoding } from "src/libraries/Encoding.sol";
        /// @title Hashing
        /// @notice Hashing handles Optimism's various different hashing schemes.
        library Hashing {
            /// @notice Computes the hash of the RLP encoded L2 transaction that would be generated when a
            ///         given deposit is sent to the L2 system. Useful for searching for a deposit in the L2
            ///         system.
            /// @param _tx User deposit transaction to hash.
            /// @return Hash of the RLP encoded L2 deposit transaction.
            function hashDepositTransaction(Types.UserDepositTransaction memory _tx) internal pure returns (bytes32) {
                return keccak256(Encoding.encodeDepositTransaction(_tx));
            }
            /// @notice Computes the deposit transaction's "source hash", a value that guarantees the hash
            ///         of the L2 transaction that corresponds to a deposit is unique and is
            ///         deterministically generated from L1 transaction data.
            /// @param _l1BlockHash Hash of the L1 block where the deposit was included.
            /// @param _logIndex    The index of the log that created the deposit transaction.
            /// @return Hash of the deposit transaction's "source hash".
            function hashDepositSource(bytes32 _l1BlockHash, uint256 _logIndex) internal pure returns (bytes32) {
                bytes32 depositId = keccak256(abi.encode(_l1BlockHash, _logIndex));
                return keccak256(abi.encode(bytes32(0), depositId));
            }
            /// @notice Hashes the cross domain message based on the version that is encoded into the
            ///         message nonce.
            /// @param _nonce    Message nonce with version encoded into the first two bytes.
            /// @param _sender   Address of the sender of the message.
            /// @param _target   Address of the target of the message.
            /// @param _value    ETH value to send to the target.
            /// @param _gasLimit Gas limit to use for the message.
            /// @param _data     Data to send with the message.
            /// @return Hashed cross domain message.
            function hashCrossDomainMessage(
                uint256 _nonce,
                address _sender,
                address _target,
                uint256 _value,
                uint256 _gasLimit,
                bytes memory _data
            )
                internal
                pure
                returns (bytes32)
            {
                (, uint16 version) = Encoding.decodeVersionedNonce(_nonce);
                if (version == 0) {
                    return hashCrossDomainMessageV0(_target, _sender, _data, _nonce);
                } else if (version == 1) {
                    return hashCrossDomainMessageV1(_nonce, _sender, _target, _value, _gasLimit, _data);
                } else {
                    revert("Hashing: unknown cross domain message version");
                }
            }
            /// @notice Hashes a cross domain message based on the V0 (legacy) encoding.
            /// @param _target Address of the target of the message.
            /// @param _sender Address of the sender of the message.
            /// @param _data   Data to send with the message.
            /// @param _nonce  Message nonce.
            /// @return Hashed cross domain message.
            function hashCrossDomainMessageV0(
                address _target,
                address _sender,
                bytes memory _data,
                uint256 _nonce
            )
                internal
                pure
                returns (bytes32)
            {
                return keccak256(Encoding.encodeCrossDomainMessageV0(_target, _sender, _data, _nonce));
            }
            /// @notice Hashes a cross domain message based on the V1 (current) encoding.
            /// @param _nonce    Message nonce.
            /// @param _sender   Address of the sender of the message.
            /// @param _target   Address of the target of the message.
            /// @param _value    ETH value to send to the target.
            /// @param _gasLimit Gas limit to use for the message.
            /// @param _data     Data to send with the message.
            /// @return Hashed cross domain message.
            function hashCrossDomainMessageV1(
                uint256 _nonce,
                address _sender,
                address _target,
                uint256 _value,
                uint256 _gasLimit,
                bytes memory _data
            )
                internal
                pure
                returns (bytes32)
            {
                return keccak256(Encoding.encodeCrossDomainMessageV1(_nonce, _sender, _target, _value, _gasLimit, _data));
            }
            /// @notice Derives the withdrawal hash according to the encoding in the L2 Withdrawer contract
            /// @param _tx Withdrawal transaction to hash.
            /// @return Hashed withdrawal transaction.
            function hashWithdrawal(Types.WithdrawalTransaction memory _tx) internal pure returns (bytes32) {
                return keccak256(abi.encode(_tx.nonce, _tx.sender, _tx.target, _tx.value, _tx.gasLimit, _tx.data));
            }
            /// @notice Hashes the various elements of an output root proof into an output root hash which
            ///         can be used to check if the proof is valid.
            /// @param _outputRootProof Output root proof which should hash to an output root.
            /// @return Hashed output root proof.
            function hashOutputRootProof(Types.OutputRootProof memory _outputRootProof) internal pure returns (bytes32) {
                return keccak256(
                    abi.encode(
                        _outputRootProof.version,
                        _outputRootProof.stateRoot,
                        _outputRootProof.messagePasserStorageRoot,
                        _outputRootProof.latestBlockhash
                    )
                );
            }
        }
        // SPDX-License-Identifier: MIT
        pragma solidity ^0.8.0;
        import { MerkleTrie } from "./MerkleTrie.sol";
        /// @title SecureMerkleTrie
        /// @notice SecureMerkleTrie is a thin wrapper around the MerkleTrie library that hashes the input
        ///         keys. Ethereum's state trie hashes input keys before storing them.
        library SecureMerkleTrie {
            /// @notice Verifies a proof that a given key/value pair is present in the Merkle trie.
            /// @param _key   Key of the node to search for, as a hex string.
            /// @param _value Value of the node to search for, as a hex string.
            /// @param _proof Merkle trie inclusion proof for the desired node. Unlike traditional Merkle
            ///               trees, this proof is executed top-down and consists of a list of RLP-encoded
            ///               nodes that make a path down to the target node.
            /// @param _root  Known root of the Merkle trie. Used to verify that the included proof is
            ///               correctly constructed.
            /// @return valid_ Whether or not the proof is valid.
            function verifyInclusionProof(
                bytes memory _key,
                bytes memory _value,
                bytes[] memory _proof,
                bytes32 _root
            )
                internal
                pure
                returns (bool valid_)
            {
                bytes memory key = _getSecureKey(_key);
                valid_ = MerkleTrie.verifyInclusionProof(key, _value, _proof, _root);
            }
            /// @notice Retrieves the value associated with a given key.
            /// @param _key   Key to search for, as hex bytes.
            /// @param _proof Merkle trie inclusion proof for the key.
            /// @param _root  Known root of the Merkle trie.
            /// @return value_ Value of the key if it exists.
            function get(bytes memory _key, bytes[] memory _proof, bytes32 _root) internal pure returns (bytes memory value_) {
                bytes memory key = _getSecureKey(_key);
                value_ = MerkleTrie.get(key, _proof, _root);
            }
            /// @notice Computes the hashed version of the input key.
            /// @param _key Key to hash.
            /// @return hash_ Hashed version of the key.
            function _getSecureKey(bytes memory _key) private pure returns (bytes memory hash_) {
                hash_ = abi.encodePacked(keccak256(_key));
            }
        }
        // SPDX-License-Identifier: Apache-2.0
        /*
         * Copyright 2019-2021, Offchain Labs, Inc.
         *
         * Licensed under the Apache License, Version 2.0 (the "License");
         * you may not use this file except in compliance with the License.
         * You may obtain a copy of the License at
         *
         *    http://www.apache.org/licenses/LICENSE-2.0
         *
         * Unless required by applicable law or agreed to in writing, software
         * distributed under the License is distributed on an "AS IS" BASIS,
         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
         * See the License for the specific language governing permissions and
         * limitations under the License.
         */
        pragma solidity ^0.8.0;
        library AddressAliasHelper {
            uint160 constant offset = uint160(0x1111000000000000000000000000000000001111);
            /// @notice Utility function that converts the address in the L1 that submitted a tx to
            /// the inbox to the msg.sender viewed in the L2
            /// @param l1Address the address in the L1 that triggered the tx to L2
            /// @return l2Address L2 address as viewed in msg.sender
            function applyL1ToL2Alias(address l1Address) internal pure returns (address l2Address) {
                unchecked {
                    l2Address = address(uint160(l1Address) + offset);
                }
            }
            /// @notice Utility function that converts the msg.sender viewed in the L2 to the
            /// address in the L1 that submitted a tx to the inbox
            /// @param l2Address L2 address as viewed in msg.sender
            /// @return l1Address the address in the L1 that triggered the tx to L2
            function undoL1ToL2Alias(address l2Address) internal pure returns (address l1Address) {
                unchecked {
                    l1Address = address(uint160(l2Address) - offset);
                }
            }
        }
        // SPDX-License-Identifier: MIT
        pragma solidity 0.8.15;
        import { Initializable } from "@openzeppelin/contracts/proxy/utils/Initializable.sol";
        import { Math } from "@openzeppelin/contracts/utils/math/Math.sol";
        import { Burn } from "src/libraries/Burn.sol";
        import { Arithmetic } from "src/libraries/Arithmetic.sol";
        /// @custom:upgradeable
        /// @title ResourceMetering
        /// @notice ResourceMetering implements an EIP-1559 style resource metering system where pricing
        ///         updates automatically based on current demand.
        abstract contract ResourceMetering is Initializable {
            /// @notice Error returned when too much gas resource is consumed.
            error OutOfGas();
            /// @notice Represents the various parameters that control the way in which resources are
            ///         metered. Corresponds to the EIP-1559 resource metering system.
            /// @custom:field prevBaseFee   Base fee from the previous block(s).
            /// @custom:field prevBoughtGas Amount of gas bought so far in the current block.
            /// @custom:field prevBlockNum  Last block number that the base fee was updated.
            struct ResourceParams {
                uint128 prevBaseFee;
                uint64 prevBoughtGas;
                uint64 prevBlockNum;
            }
            /// @notice Represents the configuration for the EIP-1559 based curve for the deposit gas
            ///         market. These values should be set with care as it is possible to set them in
            ///         a way that breaks the deposit gas market. The target resource limit is defined as
            ///         maxResourceLimit / elasticityMultiplier. This struct was designed to fit within a
            ///         single word. There is additional space for additions in the future.
            /// @custom:field maxResourceLimit             Represents the maximum amount of deposit gas that
            ///                                            can be purchased per block.
            /// @custom:field elasticityMultiplier         Determines the target resource limit along with
            ///                                            the resource limit.
            /// @custom:field baseFeeMaxChangeDenominator  Determines max change on fee per block.
            /// @custom:field minimumBaseFee               The min deposit base fee, it is clamped to this
            ///                                            value.
            /// @custom:field systemTxMaxGas               The amount of gas supplied to the system
            ///                                            transaction. This should be set to the same
            ///                                            number that the op-node sets as the gas limit
            ///                                            for the system transaction.
            /// @custom:field maximumBaseFee               The max deposit base fee, it is clamped to this
            ///                                            value.
            struct ResourceConfig {
                uint32 maxResourceLimit;
                uint8 elasticityMultiplier;
                uint8 baseFeeMaxChangeDenominator;
                uint32 minimumBaseFee;
                uint32 systemTxMaxGas;
                uint128 maximumBaseFee;
            }
            /// @notice EIP-1559 style gas parameters.
            ResourceParams public params;
            /// @notice Reserve extra slots (to a total of 50) in the storage layout for future upgrades.
            uint256[48] private __gap;
            /// @notice Meters access to a function based an amount of a requested resource.
            /// @param _amount Amount of the resource requested.
            modifier metered(uint64 _amount) {
                // Record initial gas amount so we can refund for it later.
                uint256 initialGas = gasleft();
                // Run the underlying function.
                _;
                // Run the metering function.
                _metered(_amount, initialGas);
            }
            /// @notice An internal function that holds all of the logic for metering a resource.
            /// @param _amount     Amount of the resource requested.
            /// @param _initialGas The amount of gas before any modifier execution.
            function _metered(uint64 _amount, uint256 _initialGas) internal {
                // Update block number and base fee if necessary.
                uint256 blockDiff = block.number - params.prevBlockNum;
                ResourceConfig memory config = _resourceConfig();
                int256 targetResourceLimit =
                    int256(uint256(config.maxResourceLimit)) / int256(uint256(config.elasticityMultiplier));
                if (blockDiff > 0) {
                    // Handle updating EIP-1559 style gas parameters. We use EIP-1559 to restrict the rate
                    // at which deposits can be created and therefore limit the potential for deposits to
                    // spam the L2 system. Fee scheme is very similar to EIP-1559 with minor changes.
                    int256 gasUsedDelta = int256(uint256(params.prevBoughtGas)) - targetResourceLimit;
                    int256 baseFeeDelta = (int256(uint256(params.prevBaseFee)) * gasUsedDelta)
                        / (targetResourceLimit * int256(uint256(config.baseFeeMaxChangeDenominator)));
                    // Update base fee by adding the base fee delta and clamp the resulting value between
                    // min and max.
                    int256 newBaseFee = Arithmetic.clamp({
                        _value: int256(uint256(params.prevBaseFee)) + baseFeeDelta,
                        _min: int256(uint256(config.minimumBaseFee)),
                        _max: int256(uint256(config.maximumBaseFee))
                    });
                    // If we skipped more than one block, we also need to account for every empty block.
                    // Empty block means there was no demand for deposits in that block, so we should
                    // reflect this lack of demand in the fee.
                    if (blockDiff > 1) {
                        // Update the base fee by repeatedly applying the exponent 1-(1/change_denominator)
                        // blockDiff - 1 times. Simulates multiple empty blocks. Clamp the resulting value
                        // between min and max.
                        newBaseFee = Arithmetic.clamp({
                            _value: Arithmetic.cdexp({
                                _coefficient: newBaseFee,
                                _denominator: int256(uint256(config.baseFeeMaxChangeDenominator)),
                                _exponent: int256(blockDiff - 1)
                            }),
                            _min: int256(uint256(config.minimumBaseFee)),
                            _max: int256(uint256(config.maximumBaseFee))
                        });
                    }
                    // Update new base fee, reset bought gas, and update block number.
                    params.prevBaseFee = uint128(uint256(newBaseFee));
                    params.prevBoughtGas = 0;
                    params.prevBlockNum = uint64(block.number);
                }
                // Make sure we can actually buy the resource amount requested by the user.
                params.prevBoughtGas += _amount;
                if (int256(uint256(params.prevBoughtGas)) > int256(uint256(config.maxResourceLimit))) {
                    revert OutOfGas();
                }
                // Determine the amount of ETH to be paid.
                uint256 resourceCost = uint256(_amount) * uint256(params.prevBaseFee);
                // We currently charge for this ETH amount as an L1 gas burn, so we convert the ETH amount
                // into gas by dividing by the L1 base fee. We assume a minimum base fee of 1 gwei to avoid
                // division by zero for L1s that don't support 1559 or to avoid excessive gas burns during
                // periods of extremely low L1 demand. One-day average gas fee hasn't dipped below 1 gwei
                // during any 1 day period in the last 5 years, so should be fine.
                uint256 gasCost = resourceCost / Math.max(block.basefee, 1 gwei);
                // Give the user a refund based on the amount of gas they used to do all of the work up to
                // this point. Since we're at the end of the modifier, this should be pretty accurate. Acts
                // effectively like a dynamic stipend (with a minimum value).
                uint256 usedGas = _initialGas - gasleft();
                if (gasCost > usedGas) {
                    Burn.gas(gasCost - usedGas);
                }
            }
            /// @notice Virtual function that returns the resource config.
            ///         Contracts that inherit this contract must implement this function.
            /// @return ResourceConfig
            function _resourceConfig() internal virtual returns (ResourceConfig memory);
            /// @notice Sets initial resource parameter values.
            ///         This function must either be called by the initializer function of an upgradeable
            ///         child contract.
            function __ResourceMetering_init() internal onlyInitializing {
                if (params.prevBlockNum == 0) {
                    params = ResourceParams({ prevBaseFee: 1 gwei, prevBoughtGas: 0, prevBlockNum: uint64(block.number) });
                }
            }
        }
        // SPDX-License-Identifier: MIT
        pragma solidity ^0.8.0;
        /// @title ISemver
        /// @notice ISemver is a simple contract for ensuring that contracts are
        ///         versioned using semantic versioning.
        interface ISemver {
            /// @notice Getter for the semantic version of the contract. This is not
            ///         meant to be used onchain but instead meant to be used by offchain
            ///         tooling.
            /// @return Semver contract version as a string.
            function version() external view returns (string memory);
        }
        // SPDX-License-Identifier: MIT
        pragma solidity ^0.8.0;
        /// @notice Error for when a deposit or withdrawal is to a bad target.
        error BadTarget();
        /// @notice Error for when a deposit has too much calldata.
        error LargeCalldata();
        /// @notice Error for when a deposit has too small of a gas limit.
        error SmallGasLimit();
        /// @notice Error for when a withdrawal transfer fails.
        error TransferFailed();
        /// @notice Error for when a method is called that only works when using a custom gas token.
        error OnlyCustomGasToken();
        /// @notice Error for when a method cannot be called with non zero CALLVALUE.
        error NoValue();
        /// @notice Error for an unauthorized CALLER.
        error Unauthorized();
        /// @notice Error for when a method cannot be called when paused. This could be renamed
        ///         to `Paused` in the future, but it collides with the `Paused` event.
        error CallPaused();
        /// @notice Error for special gas estimation.
        error GasEstimation();
        // SPDX-License-Identifier: MIT
        pragma solidity ^0.8.15;
        import "src/dispute/lib/LibUDT.sol";
        /// @notice The current status of the dispute game.
        enum GameStatus {
            // The game is currently in progress, and has not been resolved.
            IN_PROGRESS,
            // The game has concluded, and the `rootClaim` was challenged successfully.
            CHALLENGER_WINS,
            // The game has concluded, and the `rootClaim` could not be contested.
            DEFENDER_WINS
        }
        /// @notice Represents an L2 output root and the L2 block number at which it was generated.
        /// @custom:field root The output root.
        /// @custom:field l2BlockNumber The L2 block number at which the output root was generated.
        struct OutputRoot {
            Hash root;
            uint256 l2BlockNumber;
        }
        /// @title GameTypes
        /// @notice A library that defines the IDs of games that can be played.
        library GameTypes {
            /// @dev A dispute game type the uses the cannon vm.
            GameType internal constant CANNON = GameType.wrap(0);
            /// @dev A permissioned dispute game type the uses the cannon vm.
            GameType internal constant PERMISSIONED_CANNON = GameType.wrap(1);
            /// @notice A dispute game type the uses the asterisc VM
            GameType internal constant ASTERISC = GameType.wrap(2);
            /// @notice A dispute game type that uses an alphabet vm.
            ///         Not intended for production use.
            GameType internal constant ALPHABET = GameType.wrap(255);
        }
        /// @title VMStatuses
        /// @notice Named type aliases for the various valid VM status bytes.
        library VMStatuses {
            /// @notice The VM has executed successfully and the outcome is valid.
            VMStatus internal constant VALID = VMStatus.wrap(0);
            /// @notice The VM has executed successfully and the outcome is invalid.
            VMStatus internal constant INVALID = VMStatus.wrap(1);
            /// @notice The VM has paniced.
            VMStatus internal constant PANIC = VMStatus.wrap(2);
            /// @notice The VM execution is still in progress.
            VMStatus internal constant UNFINISHED = VMStatus.wrap(3);
        }
        /// @title LocalPreimageKey
        /// @notice Named type aliases for local `PreimageOracle` key identifiers.
        library LocalPreimageKey {
            /// @notice The identifier for the L1 head hash.
            uint256 internal constant L1_HEAD_HASH = 0x01;
            /// @notice The identifier for the starting output root.
            uint256 internal constant STARTING_OUTPUT_ROOT = 0x02;
            /// @notice The identifier for the disputed output root.
            uint256 internal constant DISPUTED_OUTPUT_ROOT = 0x03;
            /// @notice The identifier for the disputed L2 block number.
            uint256 internal constant DISPUTED_L2_BLOCK_NUMBER = 0x04;
            /// @notice The identifier for the chain ID.
            uint256 internal constant CHAIN_ID = 0x05;
        }
        // SPDX-License-Identifier: MIT
        // OpenZeppelin Contracts (last updated v4.7.0) (utils/Address.sol)
        pragma solidity ^0.8.1;
        /**
         * @dev Collection of functions related to the address type
         */
        library Address {
            /**
             * @dev Returns true if `account` is a contract.
             *
             * [IMPORTANT]
             * ====
             * It is unsafe to assume that an address for which this function returns
             * false is an externally-owned account (EOA) and not a contract.
             *
             * Among others, `isContract` will return false for the following
             * types of addresses:
             *
             *  - an externally-owned account
             *  - a contract in construction
             *  - an address where a contract will be created
             *  - an address where a contract lived, but was destroyed
             * ====
             *
             * [IMPORTANT]
             * ====
             * You shouldn't rely on `isContract` to protect against flash loan attacks!
             *
             * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
             * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
             * constructor.
             * ====
             */
            function isContract(address account) internal view returns (bool) {
                // This method relies on extcodesize/address.code.length, which returns 0
                // for contracts in construction, since the code is only stored at the end
                // of the constructor execution.
                return account.code.length > 0;
            }
            /**
             * @dev Replacement for Solidity's `transfer`: sends `amount` wei to
             * `recipient`, forwarding all available gas and reverting on errors.
             *
             * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
             * of certain opcodes, possibly making contracts go over the 2300 gas limit
             * imposed by `transfer`, making them unable to receive funds via
             * `transfer`. {sendValue} removes this limitation.
             *
             * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
             *
             * IMPORTANT: because control is transferred to `recipient`, care must be
             * taken to not create reentrancy vulnerabilities. Consider using
             * {ReentrancyGuard} or the
             * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
             */
            function sendValue(address payable recipient, uint256 amount) internal {
                require(address(this).balance >= amount, "Address: insufficient balance");
                (bool success, ) = recipient.call{value: amount}("");
                require(success, "Address: unable to send value, recipient may have reverted");
            }
            /**
             * @dev Performs a Solidity function call using a low level `call`. A
             * plain `call` is an unsafe replacement for a function call: use this
             * function instead.
             *
             * If `target` reverts with a revert reason, it is bubbled up by this
             * function (like regular Solidity function calls).
             *
             * Returns the raw returned data. To convert to the expected return value,
             * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
             *
             * Requirements:
             *
             * - `target` must be a contract.
             * - calling `target` with `data` must not revert.
             *
             * _Available since v3.1._
             */
            function functionCall(address target, bytes memory data) internal returns (bytes memory) {
                return functionCall(target, data, "Address: low-level call failed");
            }
            /**
             * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
             * `errorMessage` as a fallback revert reason when `target` reverts.
             *
             * _Available since v3.1._
             */
            function functionCall(
                address target,
                bytes memory data,
                string memory errorMessage
            ) internal returns (bytes memory) {
                return functionCallWithValue(target, data, 0, errorMessage);
            }
            /**
             * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
             * but also transferring `value` wei to `target`.
             *
             * Requirements:
             *
             * - the calling contract must have an ETH balance of at least `value`.
             * - the called Solidity function must be `payable`.
             *
             * _Available since v3.1._
             */
            function functionCallWithValue(
                address target,
                bytes memory data,
                uint256 value
            ) internal returns (bytes memory) {
                return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
            }
            /**
             * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
             * with `errorMessage` as a fallback revert reason when `target` reverts.
             *
             * _Available since v3.1._
             */
            function functionCallWithValue(
                address target,
                bytes memory data,
                uint256 value,
                string memory errorMessage
            ) internal returns (bytes memory) {
                require(address(this).balance >= value, "Address: insufficient balance for call");
                require(isContract(target), "Address: call to non-contract");
                (bool success, bytes memory returndata) = target.call{value: value}(data);
                return verifyCallResult(success, returndata, errorMessage);
            }
            /**
             * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
             * but performing a static call.
             *
             * _Available since v3.3._
             */
            function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
                return functionStaticCall(target, data, "Address: low-level static call failed");
            }
            /**
             * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
             * but performing a static call.
             *
             * _Available since v3.3._
             */
            function functionStaticCall(
                address target,
                bytes memory data,
                string memory errorMessage
            ) internal view returns (bytes memory) {
                require(isContract(target), "Address: static call to non-contract");
                (bool success, bytes memory returndata) = target.staticcall(data);
                return verifyCallResult(success, returndata, errorMessage);
            }
            /**
             * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
             * but performing a delegate call.
             *
             * _Available since v3.4._
             */
            function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
                return functionDelegateCall(target, data, "Address: low-level delegate call failed");
            }
            /**
             * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
             * but performing a delegate call.
             *
             * _Available since v3.4._
             */
            function functionDelegateCall(
                address target,
                bytes memory data,
                string memory errorMessage
            ) internal returns (bytes memory) {
                require(isContract(target), "Address: delegate call to non-contract");
                (bool success, bytes memory returndata) = target.delegatecall(data);
                return verifyCallResult(success, returndata, errorMessage);
            }
            /**
             * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the
             * revert reason using the provided one.
             *
             * _Available since v4.3._
             */
            function verifyCallResult(
                bool success,
                bytes memory returndata,
                string memory errorMessage
            ) internal pure returns (bytes memory) {
                if (success) {
                    return returndata;
                } else {
                    // Look for revert reason and bubble it up if present
                    if (returndata.length > 0) {
                        // The easiest way to bubble the revert reason is using memory via assembly
                        /// @solidity memory-safe-assembly
                        assembly {
                            let returndata_size := mload(returndata)
                            revert(add(32, returndata), returndata_size)
                        }
                    } else {
                        revert(errorMessage);
                    }
                }
            }
        }
        // SPDX-License-Identifier: MIT
        pragma solidity ^0.8.4;
        /// @notice Minimal proxy library.
        /// @author Solady (https://github.com/vectorized/solady/blob/main/src/utils/LibClone.sol)
        /// @author Minimal proxy by 0age (https://github.com/0age)
        /// @author Clones with immutable args by wighawag, zefram.eth, Saw-mon & Natalie
        /// (https://github.com/Saw-mon-and-Natalie/clones-with-immutable-args)
        /// @author Minimal ERC1967 proxy by jtriley-eth (https://github.com/jtriley-eth/minimum-viable-proxy)
        ///
        /// @dev Minimal proxy:
        /// Although the sw0nt pattern saves 5 gas over the erc-1167 pattern during runtime,
        /// it is not supported out-of-the-box on Etherscan. Hence, we choose to use the 0age pattern,
        /// which saves 4 gas over the erc-1167 pattern during runtime, and has the smallest bytecode.
        ///
        /// @dev Minimal proxy (PUSH0 variant):
        /// This is a new minimal proxy that uses the PUSH0 opcode introduced during Shanghai.
        /// It is optimized first for minimal runtime gas, then for minimal bytecode.
        /// The PUSH0 clone functions are intentionally postfixed with a jarring "_PUSH0" as
        /// many EVM chains may not support the PUSH0 opcode in the early months after Shanghai.
        /// Please use with caution.
        ///
        /// @dev Clones with immutable args (CWIA):
        /// The implementation of CWIA here implements a `receive()` method that emits the
        /// `ReceiveETH(uint256)` event. This skips the `DELEGATECALL` when there is no calldata,
        /// enabling us to accept hard gas-capped `sends` & `transfers` for maximum backwards
        /// composability. The minimal proxy implementation does not offer this feature.
        ///
        /// @dev Minimal ERC1967 proxy:
        /// An minimal ERC1967 proxy, intended to be upgraded with UUPS.
        /// This is NOT the same as ERC1967Factory's transparent proxy, which includes admin logic.
        library LibClone {
            /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
            /*                       CUSTOM ERRORS                        */
            /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
            /// @dev Unable to deploy the clone.
            error DeploymentFailed();
            /// @dev The salt must start with either the zero address or `by`.
            error SaltDoesNotStartWith();
            /// @dev The ETH transfer has failed.
            error ETHTransferFailed();
            /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
            /*                  MINIMAL PROXY OPERATIONS                  */
            /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
            /// @dev Deploys a clone of `implementation`.
            function clone(address implementation) internal returns (address instance) {
                instance = clone(0, implementation);
            }
            /// @dev Deploys a clone of `implementation`.
            function clone(uint256 value, address implementation) internal returns (address instance) {
                /// @solidity memory-safe-assembly
                assembly {
                    /**
                     * --------------------------------------------------------------------------+
                     * CREATION (9 bytes)                                                        |
                     * --------------------------------------------------------------------------|
                     * Opcode     | Mnemonic          | Stack     | Memory                       |
                     * --------------------------------------------------------------------------|
                     * 60 runSize | PUSH1 runSize     | r         |                              |
                     * 3d         | RETURNDATASIZE    | 0 r       |                              |
                     * 81         | DUP2              | r 0 r     |                              |
                     * 60 offset  | PUSH1 offset      | o r 0 r   |                              |
                     * 3d         | RETURNDATASIZE    | 0 o r 0 r |                              |
                     * 39         | CODECOPY          | 0 r       | [0..runSize): runtime code   |
                     * f3         | RETURN            |           | [0..runSize): runtime code   |
                     * --------------------------------------------------------------------------|
                     * RUNTIME (44 bytes)                                                        |
                     * --------------------------------------------------------------------------|
                     * Opcode  | Mnemonic       | Stack                  | Memory                |
                     * --------------------------------------------------------------------------|
                     *                                                                           |
                     * ::: keep some values in stack ::::::::::::::::::::::::::::::::::::::::::: |
                     * 3d      | RETURNDATASIZE | 0                      |                       |
                     * 3d      | RETURNDATASIZE | 0 0                    |                       |
                     * 3d      | RETURNDATASIZE | 0 0 0                  |                       |
                     * 3d      | RETURNDATASIZE | 0 0 0 0                |                       |
                     *                                                                           |
                     * ::: copy calldata to memory ::::::::::::::::::::::::::::::::::::::::::::: |
                     * 36      | CALLDATASIZE   | cds 0 0 0 0            |                       |
                     * 3d      | RETURNDATASIZE | 0 cds 0 0 0 0          |                       |
                     * 3d      | RETURNDATASIZE | 0 0 cds 0 0 0 0        |                       |
                     * 37      | CALLDATACOPY   | 0 0 0 0                | [0..cds): calldata    |
                     *                                                                           |
                     * ::: delegate call to the implementation contract :::::::::::::::::::::::: |
                     * 36      | CALLDATASIZE   | cds 0 0 0 0            | [0..cds): calldata    |
                     * 3d      | RETURNDATASIZE | 0 cds 0 0 0 0          | [0..cds): calldata    |
                     * 73 addr | PUSH20 addr    | addr 0 cds 0 0 0 0     | [0..cds): calldata    |
                     * 5a      | GAS            | gas addr 0 cds 0 0 0 0 | [0..cds): calldata    |
                     * f4      | DELEGATECALL   | success 0 0            | [0..cds): calldata    |
                     *                                                                           |
                     * ::: copy return data to memory :::::::::::::::::::::::::::::::::::::::::: |
                     * 3d      | RETURNDATASIZE | rds success 0 0        | [0..cds): calldata    |
                     * 3d      | RETURNDATASIZE | rds rds success 0 0    | [0..cds): calldata    |
                     * 93      | SWAP4          | 0 rds success 0 rds    | [0..cds): calldata    |
                     * 80      | DUP1           | 0 0 rds success 0 rds  | [0..cds): calldata    |
                     * 3e      | RETURNDATACOPY | success 0 rds          | [0..rds): returndata  |
                     *                                                                           |
                     * 60 0x2a | PUSH1 0x2a     | 0x2a success 0 rds     | [0..rds): returndata  |
                     * 57      | JUMPI          | 0 rds                  | [0..rds): returndata  |
                     *                                                                           |
                     * ::: revert :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: |
                     * fd      | REVERT         |                        | [0..rds): returndata  |
                     *                                                                           |
                     * ::: return :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: |
                     * 5b      | JUMPDEST       | 0 rds                  | [0..rds): returndata  |
                     * f3      | RETURN         |                        | [0..rds): returndata  |
                     * --------------------------------------------------------------------------+
                     */
                    mstore(0x21, 0x5af43d3d93803e602a57fd5bf3)
                    mstore(0x14, implementation)
                    mstore(0x00, 0x602c3d8160093d39f33d3d3d3d363d3d37363d73)
                    instance := create(value, 0x0c, 0x35)
                    if iszero(instance) {
                        mstore(0x00, 0x30116425) // `DeploymentFailed()`.
                        revert(0x1c, 0x04)
                    }
                    mstore(0x21, 0) // Restore the overwritten part of the free memory pointer.
                }
            }
            /// @dev Deploys a deterministic clone of `implementation` with `salt`.
            function cloneDeterministic(address implementation, bytes32 salt)
                internal
                returns (address instance)
            {
                instance = cloneDeterministic(0, implementation, salt);
            }
            /// @dev Deploys a deterministic clone of `implementation` with `salt`.
            function cloneDeterministic(uint256 value, address implementation, bytes32 salt)
                internal
                returns (address instance)
            {
                /// @solidity memory-safe-assembly
                assembly {
                    mstore(0x21, 0x5af43d3d93803e602a57fd5bf3)
                    mstore(0x14, implementation)
                    mstore(0x00, 0x602c3d8160093d39f33d3d3d3d363d3d37363d73)
                    instance := create2(value, 0x0c, 0x35, salt)
                    if iszero(instance) {
                        mstore(0x00, 0x30116425) // `DeploymentFailed()`.
                        revert(0x1c, 0x04)
                    }
                    mstore(0x21, 0) // Restore the overwritten part of the free memory pointer.
                }
            }
            /// @dev Returns the initialization code hash of the clone of `implementation`.
            /// Used for mining vanity addresses with create2crunch.
            function initCodeHash(address implementation) internal pure returns (bytes32 hash) {
                /// @solidity memory-safe-assembly
                assembly {
                    mstore(0x21, 0x5af43d3d93803e602a57fd5bf3)
                    mstore(0x14, implementation)
                    mstore(0x00, 0x602c3d8160093d39f33d3d3d3d363d3d37363d73)
                    hash := keccak256(0x0c, 0x35)
                    mstore(0x21, 0) // Restore the overwritten part of the free memory pointer.
                }
            }
            /// @dev Returns the address of the deterministic clone of `implementation`,
            /// with `salt` by `deployer`.
            /// Note: The returned result has dirty upper 96 bits. Please clean if used in assembly.
            function predictDeterministicAddress(address implementation, bytes32 salt, address deployer)
                internal
                pure
                returns (address predicted)
            {
                bytes32 hash = initCodeHash(implementation);
                predicted = predictDeterministicAddress(hash, salt, deployer);
            }
            /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
            /*          MINIMAL PROXY OPERATIONS (PUSH0 VARIANT)          */
            /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
            /// @dev Deploys a PUSH0 clone of `implementation`.
            function clone_PUSH0(address implementation) internal returns (address instance) {
                instance = clone_PUSH0(0, implementation);
            }
            /// @dev Deploys a PUSH0 clone of `implementation`.
            function clone_PUSH0(uint256 value, address implementation)
                internal
                returns (address instance)
            {
                /// @solidity memory-safe-assembly
                assembly {
                    /**
                     * --------------------------------------------------------------------------+
                     * CREATION (9 bytes)                                                        |
                     * --------------------------------------------------------------------------|
                     * Opcode     | Mnemonic          | Stack     | Memory                       |
                     * --------------------------------------------------------------------------|
                     * 60 runSize | PUSH1 runSize     | r         |                              |
                     * 5f         | PUSH0             | 0 r       |                              |
                     * 81         | DUP2              | r 0 r     |                              |
                     * 60 offset  | PUSH1 offset      | o r 0 r   |                              |
                     * 5f         | PUSH0             | 0 o r 0 r |                              |
                     * 39         | CODECOPY          | 0 r       | [0..runSize): runtime code   |
                     * f3         | RETURN            |           | [0..runSize): runtime code   |
                     * --------------------------------------------------------------------------|
                     * RUNTIME (45 bytes)                                                        |
                     * --------------------------------------------------------------------------|
                     * Opcode  | Mnemonic       | Stack                  | Memory                |
                     * --------------------------------------------------------------------------|
                     *                                                                           |
                     * ::: keep some values in stack ::::::::::::::::::::::::::::::::::::::::::: |
                     * 5f      | PUSH0          | 0                      |                       |
                     * 5f      | PUSH0          | 0 0                    |                       |
                     *                                                                           |
                     * ::: copy calldata to memory ::::::::::::::::::::::::::::::::::::::::::::: |
                     * 36      | CALLDATASIZE   | cds 0 0                |                       |
                     * 5f      | PUSH0          | 0 cds 0 0              |                       |
                     * 5f      | PUSH0          | 0 0 cds 0 0            |                       |
                     * 37      | CALLDATACOPY   | 0 0                    | [0..cds): calldata    |
                     *                                                                           |
                     * ::: delegate call to the implementation contract :::::::::::::::::::::::: |
                     * 36      | CALLDATASIZE   | cds 0 0                | [0..cds): calldata    |
                     * 5f      | PUSH0          | 0 cds 0 0              | [0..cds): calldata    |
                     * 73 addr | PUSH20 addr    | addr 0 cds 0 0         | [0..cds): calldata    |
                     * 5a      | GAS            | gas addr 0 cds 0 0     | [0..cds): calldata    |
                     * f4      | DELEGATECALL   | success                | [0..cds): calldata    |
                     *                                                                           |
                     * ::: copy return data to memory :::::::::::::::::::::::::::::::::::::::::: |
                     * 3d      | RETURNDATASIZE | rds success            | [0..cds): calldata    |
                     * 5f      | PUSH0          | 0 rds success          | [0..cds): calldata    |
                     * 5f      | PUSH0          | 0 0 rds success        | [0..cds): calldata    |
                     * 3e      | RETURNDATACOPY | success                | [0..rds): returndata  |
                     *                                                                           |
                     * 60 0x29 | PUSH1 0x29     | 0x29 success           | [0..rds): returndata  |
                     * 57      | JUMPI          |                        | [0..rds): returndata  |
                     *                                                                           |
                     * ::: revert :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: |
                     * 3d      | RETURNDATASIZE | rds                    | [0..rds): returndata  |
                     * 5f      | PUSH0          | 0 rds                  | [0..rds): returndata  |
                     * fd      | REVERT         |                        | [0..rds): returndata  |
                     *                                                                           |
                     * ::: return :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: |
                     * 5b      | JUMPDEST       |                        | [0..rds): returndata  |
                     * 3d      | RETURNDATASIZE | rds                    | [0..rds): returndata  |
                     * 5f      | PUSH0          | 0 rds                  | [0..rds): returndata  |
                     * f3      | RETURN         |                        | [0..rds): returndata  |
                     * --------------------------------------------------------------------------+
                     */
                    mstore(0x24, 0x5af43d5f5f3e6029573d5ffd5b3d5ff3) // 16
                    mstore(0x14, implementation) // 20
                    mstore(0x00, 0x602d5f8160095f39f35f5f365f5f37365f73) // 9 + 9
                    instance := create(value, 0x0e, 0x36)
                    if iszero(instance) {
                        mstore(0x00, 0x30116425) // `DeploymentFailed()`.
                        revert(0x1c, 0x04)
                    }
                    mstore(0x24, 0) // Restore the overwritten part of the free memory pointer.
                }
            }
            /// @dev Deploys a deterministic PUSH0 clone of `implementation` with `salt`.
            function cloneDeterministic_PUSH0(address implementation, bytes32 salt)
                internal
                returns (address instance)
            {
                instance = cloneDeterministic_PUSH0(0, implementation, salt);
            }
            /// @dev Deploys a deterministic PUSH0 clone of `implementation` with `salt`.
            function cloneDeterministic_PUSH0(uint256 value, address implementation, bytes32 salt)
                internal
                returns (address instance)
            {
                /// @solidity memory-safe-assembly
                assembly {
                    mstore(0x24, 0x5af43d5f5f3e6029573d5ffd5b3d5ff3) // 16
                    mstore(0x14, implementation) // 20
                    mstore(0x00, 0x602d5f8160095f39f35f5f365f5f37365f73) // 9 + 9
                    instance := create2(value, 0x0e, 0x36, salt)
                    if iszero(instance) {
                        mstore(0x00, 0x30116425) // `DeploymentFailed()`.
                        revert(0x1c, 0x04)
                    }
                    mstore(0x24, 0) // Restore the overwritten part of the free memory pointer.
                }
            }
            /// @dev Returns the initialization code hash of the PUSH0 clone of `implementation`.
            /// Used for mining vanity addresses with create2crunch.
            function initCodeHash_PUSH0(address implementation) internal pure returns (bytes32 hash) {
                /// @solidity memory-safe-assembly
                assembly {
                    mstore(0x24, 0x5af43d5f5f3e6029573d5ffd5b3d5ff3) // 16
                    mstore(0x14, implementation) // 20
                    mstore(0x00, 0x602d5f8160095f39f35f5f365f5f37365f73) // 9 + 9
                    hash := keccak256(0x0e, 0x36)
                    mstore(0x24, 0) // Restore the overwritten part of the free memory pointer.
                }
            }
            /// @dev Returns the address of the deterministic PUSH0 clone of `implementation`,
            /// with `salt` by `deployer`.
            /// Note: The returned result has dirty upper 96 bits. Please clean if used in assembly.
            function predictDeterministicAddress_PUSH0(
                address implementation,
                bytes32 salt,
                address deployer
            ) internal pure returns (address predicted) {
                bytes32 hash = initCodeHash_PUSH0(implementation);
                predicted = predictDeterministicAddress(hash, salt, deployer);
            }
            /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
            /*           CLONES WITH IMMUTABLE ARGS OPERATIONS            */
            /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
            // Note: This implementation of CWIA differs from the original implementation.
            // If the calldata is empty, it will emit a `ReceiveETH(uint256)` event and skip the `DELEGATECALL`.
            /// @dev Deploys a clone of `implementation` with immutable arguments encoded in `data`.
            function clone(address implementation, bytes memory data) internal returns (address instance) {
                instance = clone(0, implementation, data);
            }
            /// @dev Deploys a clone of `implementation` with immutable arguments encoded in `data`.
            function clone(uint256 value, address implementation, bytes memory data)
                internal
                returns (address instance)
            {
                assembly {
                    // Compute the boundaries of the data and cache the memory slots around it.
                    let mBefore3 := mload(sub(data, 0x60))
                    let mBefore2 := mload(sub(data, 0x40))
                    let mBefore1 := mload(sub(data, 0x20))
                    let dataLength := mload(data)
                    let dataEnd := add(add(data, 0x20), dataLength)
                    let mAfter1 := mload(dataEnd)
                    // +2 bytes for telling how much data there is appended to the call.
                    let extraLength := add(dataLength, 2)
                    // The `creationSize` is `extraLength + 108`
                    // The `runSize` is `creationSize - 10`.
                    /**
                     * ---------------------------------------------------------------------------------------------------+
                     * CREATION (10 bytes)                                                                                |
                     * ---------------------------------------------------------------------------------------------------|
                     * Opcode     | Mnemonic          | Stack     | Memory                                                |
                     * ---------------------------------------------------------------------------------------------------|
                     * 61 runSize | PUSH2 runSize     | r         |                                                       |
                     * 3d         | RETURNDATASIZE    | 0 r       |                                                       |
                     * 81         | DUP2              | r 0 r     |                                                       |
                     * 60 offset  | PUSH1 offset      | o r 0 r   |                                                       |
                     * 3d         | RETURNDATASIZE    | 0 o r 0 r |                                                       |
                     * 39         | CODECOPY          | 0 r       | [0..runSize): runtime code                            |
                     * f3         | RETURN            |           | [0..runSize): runtime code                            |
                     * ---------------------------------------------------------------------------------------------------|
                     * RUNTIME (98 bytes + extraLength)                                                                   |
                     * ---------------------------------------------------------------------------------------------------|
                     * Opcode   | Mnemonic       | Stack                    | Memory                                      |
                     * ---------------------------------------------------------------------------------------------------|
                     *                                                                                                    |
                     * ::: if no calldata, emit event & return w/o `DELEGATECALL` ::::::::::::::::::::::::::::::::::::::: |
                     * 36       | CALLDATASIZE   | cds                      |                                             |
                     * 60 0x2c  | PUSH1 0x2c     | 0x2c cds                 |                                             |
                     * 57       | JUMPI          |                          |                                             |
                     * 34       | CALLVALUE      | cv                       |                                             |
                     * 3d       | RETURNDATASIZE | 0 cv                     |                                             |
                     * 52       | MSTORE         |                          | [0..0x20): callvalue                        |
                     * 7f sig   | PUSH32 0x9e..  | sig                      | [0..0x20): callvalue                        |
                     * 59       | MSIZE          | 0x20 sig                 | [0..0x20): callvalue                        |
                     * 3d       | RETURNDATASIZE | 0 0x20 sig               | [0..0x20): callvalue                        |
                     * a1       | LOG1           |                          | [0..0x20): callvalue                        |
                     * 00       | STOP           |                          | [0..0x20): callvalue                        |
                     * 5b       | JUMPDEST       |                          |                                             |
                     *                                                                                                    |
                     * ::: copy calldata to memory :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: |
                     * 36       | CALLDATASIZE   | cds                      |                                             |
                     * 3d       | RETURNDATASIZE | 0 cds                    |                                             |
                     * 3d       | RETURNDATASIZE | 0 0 cds                  |                                             |
                     * 37       | CALLDATACOPY   |                          | [0..cds): calldata                          |
                     *                                                                                                    |
                     * ::: keep some values in stack :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: |
                     * 3d       | RETURNDATASIZE | 0                        | [0..cds): calldata                          |
                     * 3d       | RETURNDATASIZE | 0 0                      | [0..cds): calldata                          |
                     * 3d       | RETURNDATASIZE | 0 0 0                    | [0..cds): calldata                          |
                     * 3d       | RETURNDATASIZE | 0 0 0 0                  | [0..cds): calldata                          |
                     * 61 extra | PUSH2 extra    | e 0 0 0 0                | [0..cds): calldata                          |
                     *                                                                                                    |
                     * ::: copy extra data to memory :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: |
                     * 80       | DUP1           | e e 0 0 0 0              | [0..cds): calldata                          |
                     * 60 0x62  | PUSH1 0x62     | 0x62 e e 0 0 0 0         | [0..cds): calldata                          |
                     * 36       | CALLDATASIZE   | cds 0x62 e e 0 0 0 0     | [0..cds): calldata                          |
                     * 39       | CODECOPY       | e 0 0 0 0                | [0..cds): calldata, [cds..cds+e): extraData |
                     *                                                                                                    |
                     * ::: delegate call to the implementation contract ::::::::::::::::::::::::::::::::::::::::::::::::: |
                     * 36       | CALLDATASIZE   | cds e 0 0 0 0            | [0..cds): calldata, [cds..cds+e): extraData |
                     * 01       | ADD            | cds+e 0 0 0 0            | [0..cds): calldata, [cds..cds+e): extraData |
                     * 3d       | RETURNDATASIZE | 0 cds+e 0 0 0 0          | [0..cds): calldata, [cds..cds+e): extraData |
                     * 73 addr  | PUSH20 addr    | addr 0 cds+e 0 0 0 0     | [0..cds): calldata, [cds..cds+e): extraData |
                     * 5a       | GAS            | gas addr 0 cds+e 0 0 0 0 | [0..cds): calldata, [cds..cds+e): extraData |
                     * f4       | DELEGATECALL   | success 0 0              | [0..cds): calldata, [cds..cds+e): extraData |
                     *                                                                                                    |
                     * ::: copy return data to memory ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: |
                     * 3d       | RETURNDATASIZE | rds success 0 0          | [0..cds): calldata, [cds..cds+e): extraData |
                     * 3d       | RETURNDATASIZE | rds rds success 0 0      | [0..cds): calldata, [cds..cds+e): extraData |
                     * 93       | SWAP4          | 0 rds success 0 rds      | [0..cds): calldata, [cds..cds+e): extraData |
                     * 80       | DUP1           | 0 0 rds success 0 rds    | [0..cds): calldata, [cds..cds+e): extraData |
                     * 3e       | RETURNDATACOPY | success 0 rds            | [0..rds): returndata                        |
                     *                                                                                                    |
                     * 60 0x60  | PUSH1 0x60     | 0x60 success 0 rds       | [0..rds): returndata                        |
                     * 57       | JUMPI          | 0 rds                    | [0..rds): returndata                        |
                     *                                                                                                    |
                     * ::: revert ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: |
                     * fd       | REVERT         |                          | [0..rds): returndata                        |
                     *                                                                                                    |
                     * ::: return ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: |
                     * 5b       | JUMPDEST       | 0 rds                    | [0..rds): returndata                        |
                     * f3       | RETURN         |                          | [0..rds): returndata                        |
                     * ---------------------------------------------------------------------------------------------------+
                     */
                    mstore(data, 0x5af43d3d93803e606057fd5bf3) // Write the bytecode before the data.
                    mstore(sub(data, 0x0d), implementation) // Write the address of the implementation.
                    // Write the rest of the bytecode.
                    mstore(
                        sub(data, 0x21),
                        or(shl(0x48, extraLength), 0x593da1005b363d3d373d3d3d3d610000806062363936013d73)
                    )
                    // `keccak256("ReceiveETH(uint256)")`
                    mstore(
                        sub(data, 0x3a), 0x9e4ac34f21c619cefc926c8bd93b54bf5a39c7ab2127a895af1cc0691d7e3dff
                    )
                    mstore(
                        // Do a out-of-gas revert if `extraLength` is too big. 0xffff - 0x62 + 0x01 = 0xff9e.
                        // The actual EVM limit may be smaller and may change over time.
                        sub(data, add(0x59, lt(extraLength, 0xff9e))),
                        or(shl(0x78, add(extraLength, 0x62)), 0xfd6100003d81600a3d39f336602c57343d527f)
                    )
                    mstore(dataEnd, shl(0xf0, extraLength))
                    instance := create(value, sub(data, 0x4c), add(extraLength, 0x6c))
                    if iszero(instance) {
                        mstore(0x00, 0x30116425) // `DeploymentFailed()`.
                        revert(0x1c, 0x04)
                    }
                    // Restore the overwritten memory surrounding `data`.
                    mstore(dataEnd, mAfter1)
                    mstore(data, dataLength)
                    mstore(sub(data, 0x20), mBefore1)
                    mstore(sub(data, 0x40), mBefore2)
                    mstore(sub(data, 0x60), mBefore3)
                }
            }
            /// @dev Deploys a deterministic clone of `implementation`
            /// with immutable arguments encoded in `data` and `salt`.
            function cloneDeterministic(address implementation, bytes memory data, bytes32 salt)
                internal
                returns (address instance)
            {
                instance = cloneDeterministic(0, implementation, data, salt);
            }
            /// @dev Deploys a deterministic clone of `implementation`
            /// with immutable arguments encoded in `data` and `salt`.
            function cloneDeterministic(
                uint256 value,
                address implementation,
                bytes memory data,
                bytes32 salt
            ) internal returns (address instance) {
                assembly {
                    // Compute the boundaries of the data and cache the memory slots around it.
                    let mBefore3 := mload(sub(data, 0x60))
                    let mBefore2 := mload(sub(data, 0x40))
                    let mBefore1 := mload(sub(data, 0x20))
                    let dataLength := mload(data)
                    let dataEnd := add(add(data, 0x20), dataLength)
                    let mAfter1 := mload(dataEnd)
                    // +2 bytes for telling how much data there is appended to the call.
                    let extraLength := add(dataLength, 2)
                    mstore(data, 0x5af43d3d93803e606057fd5bf3) // Write the bytecode before the data.
                    mstore(sub(data, 0x0d), implementation) // Write the address of the implementation.
                    // Write the rest of the bytecode.
                    mstore(
                        sub(data, 0x21),
                        or(shl(0x48, extraLength), 0x593da1005b363d3d373d3d3d3d610000806062363936013d73)
                    )
                    // `keccak256("ReceiveETH(uint256)")`
                    mstore(
                        sub(data, 0x3a), 0x9e4ac34f21c619cefc926c8bd93b54bf5a39c7ab2127a895af1cc0691d7e3dff
                    )
                    mstore(
                        // Do a out-of-gas revert if `extraLength` is too big. 0xffff - 0x62 + 0x01 = 0xff9e.
                        // The actual EVM limit may be smaller and may change over time.
                        sub(data, add(0x59, lt(extraLength, 0xff9e))),
                        or(shl(0x78, add(extraLength, 0x62)), 0xfd6100003d81600a3d39f336602c57343d527f)
                    )
                    mstore(dataEnd, shl(0xf0, extraLength))
                    instance := create2(value, sub(data, 0x4c), add(extraLength, 0x6c), salt)
                    if iszero(instance) {
                        mstore(0x00, 0x30116425) // `DeploymentFailed()`.
                        revert(0x1c, 0x04)
                    }
                    // Restore the overwritten memory surrounding `data`.
                    mstore(dataEnd, mAfter1)
                    mstore(data, dataLength)
                    mstore(sub(data, 0x20), mBefore1)
                    mstore(sub(data, 0x40), mBefore2)
                    mstore(sub(data, 0x60), mBefore3)
                }
            }
            /// @dev Returns the initialization code hash of the clone of `implementation`
            /// using immutable arguments encoded in `data`.
            /// Used for mining vanity addresses with create2crunch.
            function initCodeHash(address implementation, bytes memory data)
                internal
                pure
                returns (bytes32 hash)
            {
                assembly {
                    // Compute the boundaries of the data and cache the memory slots around it.
                    let mBefore3 := mload(sub(data, 0x60))
                    let mBefore2 := mload(sub(data, 0x40))
                    let mBefore1 := mload(sub(data, 0x20))
                    let dataLength := mload(data)
                    let dataEnd := add(add(data, 0x20), dataLength)
                    let mAfter1 := mload(dataEnd)
                    // Do a out-of-gas revert if `dataLength` is too big. 0xffff - 0x02 - 0x62 = 0xff9b.
                    // The actual EVM limit may be smaller and may change over time.
                    returndatacopy(returndatasize(), returndatasize(), gt(dataLength, 0xff9b))
                    // +2 bytes for telling how much data there is appended to the call.
                    let extraLength := add(dataLength, 2)
                    mstore(data, 0x5af43d3d93803e606057fd5bf3) // Write the bytecode before the data.
                    mstore(sub(data, 0x0d), implementation) // Write the address of the implementation.
                    // Write the rest of the bytecode.
                    mstore(
                        sub(data, 0x21),
                        or(shl(0x48, extraLength), 0x593da1005b363d3d373d3d3d3d610000806062363936013d73)
                    )
                    // `keccak256("ReceiveETH(uint256)")`
                    mstore(
                        sub(data, 0x3a), 0x9e4ac34f21c619cefc926c8bd93b54bf5a39c7ab2127a895af1cc0691d7e3dff
                    )
                    mstore(
                        sub(data, 0x5a),
                        or(shl(0x78, add(extraLength, 0x62)), 0x6100003d81600a3d39f336602c57343d527f)
                    )
                    mstore(dataEnd, shl(0xf0, extraLength))
                    hash := keccak256(sub(data, 0x4c), add(extraLength, 0x6c))
                    // Restore the overwritten memory surrounding `data`.
                    mstore(dataEnd, mAfter1)
                    mstore(data, dataLength)
                    mstore(sub(data, 0x20), mBefore1)
                    mstore(sub(data, 0x40), mBefore2)
                    mstore(sub(data, 0x60), mBefore3)
                }
            }
            /// @dev Returns the address of the deterministic clone of
            /// `implementation` using immutable arguments encoded in `data`, with `salt`, by `deployer`.
            /// Note: The returned result has dirty upper 96 bits. Please clean if used in assembly.
            function predictDeterministicAddress(
                address implementation,
                bytes memory data,
                bytes32 salt,
                address deployer
            ) internal pure returns (address predicted) {
                bytes32 hash = initCodeHash(implementation, data);
                predicted = predictDeterministicAddress(hash, salt, deployer);
            }
            /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
            /*              MINIMAL ERC1967 PROXY OPERATIONS              */
            /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
            // Note: The ERC1967 proxy here is intended to be upgraded with UUPS.
            // This is NOT the same as ERC1967Factory's transparent proxy, which includes admin logic.
            /// @dev Deploys a minimal ERC1967 proxy with `implementation`.
            function deployERC1967(address implementation) internal returns (address instance) {
                instance = deployERC1967(0, implementation);
            }
            /// @dev Deploys a minimal ERC1967 proxy with `implementation`.
            function deployERC1967(uint256 value, address implementation)
                internal
                returns (address instance)
            {
                /// @solidity memory-safe-assembly
                assembly {
                    /**
                     * ---------------------------------------------------------------------------------+
                     * CREATION (34 bytes)                                                              |
                     * ---------------------------------------------------------------------------------|
                     * Opcode     | Mnemonic       | Stack            | Memory                          |
                     * ---------------------------------------------------------------------------------|
                     * 60 runSize | PUSH1 runSize  | r                |                                 |
                     * 3d         | RETURNDATASIZE | 0 r              |                                 |
                     * 81         | DUP2           | r 0 r            |                                 |
                     * 60 offset  | PUSH1 offset   | o r 0 r          |                                 |
                     * 3d         | RETURNDATASIZE | 0 o r 0 r        |                                 |
                     * 39         | CODECOPY       | 0 r              | [0..runSize): runtime code      |
                     * 73 impl    | PUSH20 impl    | impl 0 r         | [0..runSize): runtime code      |
                     * 60 slotPos | PUSH1 slotPos  | slotPos impl 0 r | [0..runSize): runtime code      |
                     * 51         | MLOAD          | slot impl 0 r    | [0..runSize): runtime code      |
                     * 55         | SSTORE         | 0 r              | [0..runSize): runtime code      |
                     * f3         | RETURN         |                  | [0..runSize): runtime code      |
                     * ---------------------------------------------------------------------------------|
                     * RUNTIME (62 bytes)                                                               |
                     * ---------------------------------------------------------------------------------|
                     * Opcode     | Mnemonic       | Stack            | Memory                          |
                     * ---------------------------------------------------------------------------------|
                     *                                                                                  |
                     * ::: copy calldata to memory :::::::::::::::::::::::::::::::::::::::::::::::::::: |
                     * 36         | CALLDATASIZE   | cds              |                                 |
                     * 3d         | RETURNDATASIZE | 0 cds            |                                 |
                     * 3d         | RETURNDATASIZE | 0 0 cds          |                                 |
                     * 37         | CALLDATACOPY   |                  | [0..calldatasize): calldata     |
                     *                                                                                  |
                     * ::: delegatecall to implementation ::::::::::::::::::::::::::::::::::::::::::::: |
                     * 3d         | RETURNDATASIZE | 0                |                                 |
                     * 3d         | RETURNDATASIZE | 0 0              |                                 |
                     * 36         | CALLDATASIZE   | cds 0 0          | [0..calldatasize): calldata     |
                     * 3d         | RETURNDATASIZE | 0 cds 0 0        | [0..calldatasize): calldata     |
                     * 7f slot    | PUSH32 slot    | s 0 cds 0 0      | [0..calldatasize): calldata     |
                     * 54         | SLOAD          | i 0 cds 0 0      | [0..calldatasize): calldata     |
                     * 5a         | GAS            | g i 0 cds 0 0    | [0..calldatasize): calldata     |
                     * f4         | DELEGATECALL   | succ             | [0..calldatasize): calldata     |
                     *                                                                                  |
                     * ::: copy returndata to memory :::::::::::::::::::::::::::::::::::::::::::::::::: |
                     * 3d         | RETURNDATASIZE | rds succ         | [0..calldatasize): calldata     |
                     * 60 0x00    | PUSH1 0x00     | 0 rds succ       | [0..calldatasize): calldata     |
                     * 80         | DUP1           | 0 0 rds succ     | [0..calldatasize): calldata     |
                     * 3e         | RETURNDATACOPY | succ             | [0..returndatasize): returndata |
                     *                                                                                  |
                     * ::: branch on delegatecall status :::::::::::::::::::::::::::::::::::::::::::::: |
                     * 60 0x38    | PUSH1 0x38     | dest succ        | [0..returndatasize): returndata |
                     * 57         | JUMPI          |                  | [0..returndatasize): returndata |
                     *                                                                                  |
                     * ::: delegatecall failed, revert :::::::::::::::::::::::::::::::::::::::::::::::: |
                     * 3d         | RETURNDATASIZE | rds              | [0..returndatasize): returndata |
                     * 60 0x00    | PUSH1 0x00     | 0 rds            | [0..returndatasize): returndata |
                     * fd         | REVERT         |                  | [0..returndatasize): returndata |
                     *                                                                                  |
                     * ::: delegatecall succeeded, return ::::::::::::::::::::::::::::::::::::::::::::: |
                     * 5b         | JUMPDEST       |                  | [0..returndatasize): returndata |
                     * 3d         | RETURNDATASIZE | rds              | [0..returndatasize): returndata |
                     * 60 0x00    | PUSH1 0x00     | 0 rds            | [0..returndatasize): returndata |
                     * f3         | RETURN         |                  | [0..returndatasize): returndata |
                     * ---------------------------------------------------------------------------------+
                     */
                    let m := mload(0x40) // Cache the free memory pointer.
                    mstore(0x60, 0xcc3735a920a3ca505d382bbc545af43d6000803e6038573d6000fd5b3d6000f3)
                    mstore(0x40, 0x5155f3363d3d373d3d363d7f360894a13ba1a3210667c828492db98dca3e2076)
                    mstore(0x20, 0x6009)
                    mstore(0x1e, implementation)
                    mstore(0x0a, 0x603d3d8160223d3973)
                    instance := create(value, 0x21, 0x5f)
                    if iszero(instance) {
                        mstore(0x00, 0x30116425) // `DeploymentFailed()`.
                        revert(0x1c, 0x04)
                    }
                    mstore(0x40, m) // Restore the free memory pointer.
                    mstore(0x60, 0) // Restore the zero slot.
                }
            }
            /// @dev Deploys a deterministic minimal ERC1967 proxy with `implementation` and `salt`.
            function deployDeterministicERC1967(address implementation, bytes32 salt)
                internal
                returns (address instance)
            {
                instance = deployDeterministicERC1967(0, implementation, salt);
            }
            /// @dev Deploys a deterministic minimal ERC1967 proxy with `implementation` and `salt`.
            function deployDeterministicERC1967(uint256 value, address implementation, bytes32 salt)
                internal
                returns (address instance)
            {
                /// @solidity memory-safe-assembly
                assembly {
                    let m := mload(0x40) // Cache the free memory pointer.
                    mstore(0x60, 0xcc3735a920a3ca505d382bbc545af43d6000803e6038573d6000fd5b3d6000f3)
                    mstore(0x40, 0x5155f3363d3d373d3d363d7f360894a13ba1a3210667c828492db98dca3e2076)
                    mstore(0x20, 0x6009)
                    mstore(0x1e, implementation)
                    mstore(0x0a, 0x603d3d8160223d3973)
                    instance := create2(value, 0x21, 0x5f, salt)
                    if iszero(instance) {
                        mstore(0x00, 0x30116425) // `DeploymentFailed()`.
                        revert(0x1c, 0x04)
                    }
                    mstore(0x40, m) // Restore the free memory pointer.
                    mstore(0x60, 0) // Restore the zero slot.
                }
            }
            /// @dev Creates a deterministic minimal ERC1967 proxy with `implementation` and `salt`.
            /// Note: This method is intended for use in ERC4337 factories,
            /// which are expected to NOT revert if the proxy is already deployed.
            function createDeterministicERC1967(address implementation, bytes32 salt)
                internal
                returns (bool alreadyDeployed, address instance)
            {
                return createDeterministicERC1967(0, implementation, salt);
            }
            /// @dev Creates a deterministic minimal ERC1967 proxy with `implementation` and `salt`.
            /// Note: This method is intended for use in ERC4337 factories,
            /// which are expected to NOT revert if the proxy is already deployed.
            function createDeterministicERC1967(uint256 value, address implementation, bytes32 salt)
                internal
                returns (bool alreadyDeployed, address instance)
            {
                /// @solidity memory-safe-assembly
                assembly {
                    let m := mload(0x40) // Cache the free memory pointer.
                    mstore(0x60, 0xcc3735a920a3ca505d382bbc545af43d6000803e6038573d6000fd5b3d6000f3)
                    mstore(0x40, 0x5155f3363d3d373d3d363d7f360894a13ba1a3210667c828492db98dca3e2076)
                    mstore(0x20, 0x6009)
                    mstore(0x1e, implementation)
                    mstore(0x0a, 0x603d3d8160223d3973)
                    // Compute and store the bytecode hash.
                    mstore(add(m, 0x35), keccak256(0x21, 0x5f))
                    mstore(m, shl(88, address()))
                    mstore8(m, 0xff) // Write the prefix.
                    mstore(add(m, 0x15), salt)
                    instance := keccak256(m, 0x55)
                    for {} 1 {} {
                        if iszero(extcodesize(instance)) {
                            instance := create2(value, 0x21, 0x5f, salt)
                            if iszero(instance) {
                                mstore(0x00, 0x30116425) // `DeploymentFailed()`.
                                revert(0x1c, 0x04)
                            }
                            break
                        }
                        alreadyDeployed := 1
                        if iszero(value) { break }
                        if iszero(call(gas(), instance, value, codesize(), 0x00, codesize(), 0x00)) {
                            mstore(0x00, 0xb12d13eb) // `ETHTransferFailed()`.
                            revert(0x1c, 0x04)
                        }
                        break
                    }
                    mstore(0x40, m) // Restore the free memory pointer.
                    mstore(0x60, 0) // Restore the zero slot.
                }
            }
            /// @dev Returns the initialization code hash of the clone of `implementation`
            /// using immutable arguments encoded in `data`.
            /// Used for mining vanity addresses with create2crunch.
            function initCodeHashERC1967(address implementation) internal pure returns (bytes32 hash) {
                /// @solidity memory-safe-assembly
                assembly {
                    let m := mload(0x40) // Cache the free memory pointer.
                    mstore(0x60, 0xcc3735a920a3ca505d382bbc545af43d6000803e6038573d6000fd5b3d6000f3)
                    mstore(0x40, 0x5155f3363d3d373d3d363d7f360894a13ba1a3210667c828492db98dca3e2076)
                    mstore(0x20, 0x6009)
                    mstore(0x1e, implementation)
                    mstore(0x0a, 0x603d3d8160223d3973)
                    hash := keccak256(0x21, 0x5f)
                    mstore(0x40, m) // Restore the free memory pointer.
                    mstore(0x60, 0) // Restore the zero slot.
                }
            }
            /// @dev Returns the address of the deterministic clone of
            /// `implementation` using immutable arguments encoded in `data`, with `salt`, by `deployer`.
            /// Note: The returned result has dirty upper 96 bits. Please clean if used in assembly.
            function predictDeterministicAddressERC1967(
                address implementation,
                bytes32 salt,
                address deployer
            ) internal pure returns (address predicted) {
                bytes32 hash = initCodeHashERC1967(implementation);
                predicted = predictDeterministicAddress(hash, salt, deployer);
            }
            /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
            /*                      OTHER OPERATIONS                      */
            /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
            /// @dev Returns the address when a contract with initialization code hash,
            /// `hash`, is deployed with `salt`, by `deployer`.
            /// Note: The returned result has dirty upper 96 bits. Please clean if used in assembly.
            function predictDeterministicAddress(bytes32 hash, bytes32 salt, address deployer)
                internal
                pure
                returns (address predicted)
            {
                /// @solidity memory-safe-assembly
                assembly {
                    // Compute and store the bytecode hash.
                    mstore8(0x00, 0xff) // Write the prefix.
                    mstore(0x35, hash)
                    mstore(0x01, shl(96, deployer))
                    mstore(0x15, salt)
                    predicted := keccak256(0x00, 0x55)
                    mstore(0x35, 0) // Restore the overwritten part of the free memory pointer.
                }
            }
            /// @dev Requires that `salt` starts with either the zero address or `by`.
            function checkStartsWith(bytes32 salt, address by) internal pure {
                /// @solidity memory-safe-assembly
                assembly {
                    // If the salt does not start with the zero address or `by`.
                    if iszero(or(iszero(shr(96, salt)), eq(shr(96, shl(96, by)), shr(96, salt)))) {
                        mstore(0x00, 0x0c4549ef) // `SaltDoesNotStartWith()`.
                        revert(0x1c, 0x04)
                    }
                }
            }
        }
        // SPDX-License-Identifier: MIT
        // OpenZeppelin Contracts (last updated v4.7.0) (access/Ownable.sol)
        pragma solidity ^0.8.0;
        import "../utils/ContextUpgradeable.sol";
        import "../proxy/utils/Initializable.sol";
        /**
         * @dev Contract module which provides a basic access control mechanism, where
         * there is an account (an owner) that can be granted exclusive access to
         * specific functions.
         *
         * By default, the owner account will be the one that deploys the contract. This
         * can later be changed with {transferOwnership}.
         *
         * This module is used through inheritance. It will make available the modifier
         * `onlyOwner`, which can be applied to your functions to restrict their use to
         * the owner.
         */
        abstract contract OwnableUpgradeable is Initializable, ContextUpgradeable {
            address private _owner;
            event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
            /**
             * @dev Initializes the contract setting the deployer as the initial owner.
             */
            function __Ownable_init() internal onlyInitializing {
                __Ownable_init_unchained();
            }
            function __Ownable_init_unchained() internal onlyInitializing {
                _transferOwnership(_msgSender());
            }
            /**
             * @dev Throws if called by any account other than the owner.
             */
            modifier onlyOwner() {
                _checkOwner();
                _;
            }
            /**
             * @dev Returns the address of the current owner.
             */
            function owner() public view virtual returns (address) {
                return _owner;
            }
            /**
             * @dev Throws if the sender is not the owner.
             */
            function _checkOwner() internal view virtual {
                require(owner() == _msgSender(), "Ownable: caller is not the owner");
            }
            /**
             * @dev Leaves the contract without owner. It will not be possible to call
             * `onlyOwner` functions anymore. Can only be called by the current owner.
             *
             * NOTE: Renouncing ownership will leave the contract without an owner,
             * thereby removing any functionality that is only available to the owner.
             */
            function renounceOwnership() public virtual onlyOwner {
                _transferOwnership(address(0));
            }
            /**
             * @dev Transfers ownership of the contract to a new account (`newOwner`).
             * Can only be called by the current owner.
             */
            function transferOwnership(address newOwner) public virtual onlyOwner {
                require(newOwner != address(0), "Ownable: new owner is the zero address");
                _transferOwnership(newOwner);
            }
            /**
             * @dev Transfers ownership of the contract to a new account (`newOwner`).
             * Internal function without access restriction.
             */
            function _transferOwnership(address newOwner) internal virtual {
                address oldOwner = _owner;
                _owner = newOwner;
                emit OwnershipTransferred(oldOwner, newOwner);
            }
            /**
             * @dev This empty reserved space is put in place to allow future versions to add new
             * variables without shifting down storage in the inheritance chain.
             * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
             */
            uint256[49] private __gap;
        }
        // SPDX-License-Identifier: MIT
        pragma solidity ^0.8.0;
        import { IInitializable } from "src/dispute/interfaces/IInitializable.sol";
        import "src/dispute/lib/Types.sol";
        /// @title IDisputeGame
        /// @notice The generic interface for a DisputeGame contract.
        interface IDisputeGame is IInitializable {
            /// @notice Emitted when the game is resolved.
            /// @param status The status of the game after resolution.
            event Resolved(GameStatus indexed status);
            /// @notice Returns the timestamp that the DisputeGame contract was created at.
            /// @return createdAt_ The timestamp that the DisputeGame contract was created at.
            function createdAt() external view returns (Timestamp createdAt_);
            /// @notice Returns the timestamp that the DisputeGame contract was resolved at.
            /// @return resolvedAt_ The timestamp that the DisputeGame contract was resolved at.
            function resolvedAt() external view returns (Timestamp resolvedAt_);
            /// @notice Returns the current status of the game.
            /// @return status_ The current status of the game.
            function status() external view returns (GameStatus status_);
            /// @notice Getter for the game type.
            /// @dev The reference impl should be entirely different depending on the type (fault, validity)
            ///      i.e. The game type should indicate the security model.
            /// @return gameType_ The type of proof system being used.
            function gameType() external view returns (GameType gameType_);
            /// @notice Getter for the creator of the dispute game.
            /// @dev `clones-with-immutable-args` argument #1
            /// @return creator_ The creator of the dispute game.
            function gameCreator() external pure returns (address creator_);
            /// @notice Getter for the root claim.
            /// @dev `clones-with-immutable-args` argument #2
            /// @return rootClaim_ The root claim of the DisputeGame.
            function rootClaim() external pure returns (Claim rootClaim_);
            /// @notice Getter for the parent hash of the L1 block when the dispute game was created.
            /// @dev `clones-with-immutable-args` argument #3
            /// @return l1Head_ The parent hash of the L1 block when the dispute game was created.
            function l1Head() external pure returns (Hash l1Head_);
            /// @notice Getter for the extra data.
            /// @dev `clones-with-immutable-args` argument #4
            /// @return extraData_ Any extra data supplied to the dispute game contract by the creator.
            function extraData() external pure returns (bytes memory extraData_);
            /// @notice If all necessary information has been gathered, this function should mark the game
            ///         status as either `CHALLENGER_WINS` or `DEFENDER_WINS` and return the status of
            ///         the resolved game. It is at this stage that the bonds should be awarded to the
            ///         necessary parties.
            /// @dev May only be called if the `status` is `IN_PROGRESS`.
            /// @return status_ The status of the game after resolution.
            function resolve() external returns (GameStatus status_);
            /// @notice A compliant implementation of this interface should return the components of the
            ///         game UUID's preimage provided in the cwia payload. The preimage of the UUID is
            ///         constructed as `keccak256(gameType . rootClaim . extraData)` where `.` denotes
            ///         concatenation.
            /// @return gameType_ The type of proof system being used.
            /// @return rootClaim_ The root claim of the DisputeGame.
            /// @return extraData_ Any extra data supplied to the dispute game contract by the creator.
            function gameData() external view returns (GameType gameType_, Claim rootClaim_, bytes memory extraData_);
        }
        // SPDX-License-Identifier: MIT
        pragma solidity ^0.8.0;
        import { IDisputeGame } from "./IDisputeGame.sol";
        import "src/dispute/lib/Types.sol";
        /// @title IDisputeGameFactory
        /// @notice The interface for a DisputeGameFactory contract.
        interface IDisputeGameFactory {
            /// @notice Emitted when a new dispute game is created
            /// @param disputeProxy The address of the dispute game proxy
            /// @param gameType The type of the dispute game proxy's implementation
            /// @param rootClaim The root claim of the dispute game
            event DisputeGameCreated(address indexed disputeProxy, GameType indexed gameType, Claim indexed rootClaim);
            /// @notice Emitted when a new game implementation added to the factory
            /// @param impl The implementation contract for the given `GameType`.
            /// @param gameType The type of the DisputeGame.
            event ImplementationSet(address indexed impl, GameType indexed gameType);
            /// @notice Emitted when a game type's initialization bond is updated
            /// @param gameType The type of the DisputeGame.
            /// @param newBond The new bond (in wei) for initializing the game type.
            event InitBondUpdated(GameType indexed gameType, uint256 indexed newBond);
            /// @notice Information about a dispute game found in a `findLatestGames` search.
            struct GameSearchResult {
                uint256 index;
                GameId metadata;
                Timestamp timestamp;
                Claim rootClaim;
                bytes extraData;
            }
            /// @notice The total number of dispute games created by this factory.
            /// @return gameCount_ The total number of dispute games created by this factory.
            function gameCount() external view returns (uint256 gameCount_);
            /// @notice `games` queries an internal mapping that maps the hash of
            ///         `gameType ++ rootClaim ++ extraData` to the deployed `DisputeGame` clone.
            /// @dev `++` equates to concatenation.
            /// @param _gameType The type of the DisputeGame - used to decide the proxy implementation
            /// @param _rootClaim The root claim of the DisputeGame.
            /// @param _extraData Any extra data that should be provided to the created dispute game.
            /// @return proxy_ The clone of the `DisputeGame` created with the given parameters.
            ///         Returns `address(0)` if nonexistent.
            /// @return timestamp_ The timestamp of the creation of the dispute game.
            function games(
                GameType _gameType,
                Claim _rootClaim,
                bytes calldata _extraData
            )
                external
                view
                returns (IDisputeGame proxy_, Timestamp timestamp_);
            /// @notice `gameAtIndex` returns the dispute game contract address and its creation timestamp
            ///          at the given index. Each created dispute game increments the underlying index.
            /// @param _index The index of the dispute game.
            /// @return gameType_ The type of the DisputeGame - used to decide the proxy implementation.
            /// @return timestamp_ The timestamp of the creation of the dispute game.
            /// @return proxy_ The clone of the `DisputeGame` created with the given parameters.
            ///         Returns `address(0)` if nonexistent.
            function gameAtIndex(uint256 _index)
                external
                view
                returns (GameType gameType_, Timestamp timestamp_, IDisputeGame proxy_);
            /// @notice `gameImpls` is a mapping that maps `GameType`s to their respective
            ///         `IDisputeGame` implementations.
            /// @param _gameType The type of the dispute game.
            /// @return impl_ The address of the implementation of the game type.
            ///         Will be cloned on creation of a new dispute game with the given `gameType`.
            function gameImpls(GameType _gameType) external view returns (IDisputeGame impl_);
            /// @notice Returns the required bonds for initializing a dispute game of the given type.
            /// @param _gameType The type of the dispute game.
            /// @return bond_ The required bond for initializing a dispute game of the given type.
            function initBonds(GameType _gameType) external view returns (uint256 bond_);
            /// @notice Creates a new DisputeGame proxy contract.
            /// @param _gameType The type of the DisputeGame - used to decide the proxy implementation.
            /// @param _rootClaim The root claim of the DisputeGame.
            /// @param _extraData Any extra data that should be provided to the created dispute game.
            /// @return proxy_ The address of the created DisputeGame proxy.
            function create(
                GameType _gameType,
                Claim _rootClaim,
                bytes calldata _extraData
            )
                external
                payable
                returns (IDisputeGame proxy_);
            /// @notice Sets the implementation contract for a specific `GameType`.
            /// @dev May only be called by the `owner`.
            /// @param _gameType The type of the DisputeGame.
            /// @param _impl The implementation contract for the given `GameType`.
            function setImplementation(GameType _gameType, IDisputeGame _impl) external;
            /// @notice Sets the bond (in wei) for initializing a game type.
            /// @dev May only be called by the `owner`.
            /// @param _gameType The type of the DisputeGame.
            /// @param _initBond The bond (in wei) for initializing a game type.
            function setInitBond(GameType _gameType, uint256 _initBond) external;
            /// @notice Returns a unique identifier for the given dispute game parameters.
            /// @dev Hashes the concatenation of `gameType . rootClaim . extraData`
            ///      without expanding memory.
            /// @param _gameType The type of the DisputeGame.
            /// @param _rootClaim The root claim of the DisputeGame.
            /// @param _extraData Any extra data that should be provided to the created dispute game.
            /// @return uuid_ The unique identifier for the given dispute game parameters.
            function getGameUUID(
                GameType _gameType,
                Claim _rootClaim,
                bytes memory _extraData
            )
                external
                pure
                returns (Hash uuid_);
            /// @notice Finds the `_n` most recent `GameId`'s of type `_gameType` starting at `_start`. If there are less than
            ///         `_n` games of type `_gameType` starting at `_start`, then the returned array will be shorter than `_n`.
            /// @param _gameType The type of game to find.
            /// @param _start The index to start the reverse search from.
            /// @param _n The number of games to find.
            function findLatestGames(
                GameType _gameType,
                uint256 _start,
                uint256 _n
            )
                external
                view
                returns (GameSearchResult[] memory games_);
        }
        // SPDX-License-Identifier: MIT
        pragma solidity ^0.8.15;
        import "src/dispute/lib/LibUDT.sol";
        ////////////////////////////////////////////////////////////////
        //                `DisputeGameFactory` Errors                 //
        ////////////////////////////////////////////////////////////////
        /// @notice Thrown when a dispute game is attempted to be created with an unsupported game type.
        /// @param gameType The unsupported game type.
        error NoImplementation(GameType gameType);
        /// @notice Thrown when a dispute game that already exists is attempted to be created.
        /// @param uuid The UUID of the dispute game that already exists.
        error GameAlreadyExists(Hash uuid);
        /// @notice Thrown when the root claim has an unexpected VM status.
        ///         Some games can only start with a root-claim with a specific status.
        /// @param rootClaim is the claim that was unexpected.
        error UnexpectedRootClaim(Claim rootClaim);
        ////////////////////////////////////////////////////////////////
        //                 `FaultDisputeGame` Errors                  //
        ////////////////////////////////////////////////////////////////
        /// @notice Thrown when a dispute game has already been initialized.
        error AlreadyInitialized();
        /// @notice Thrown when a supplied bond is not equal to the required bond amount to cover the cost of the interaction.
        error IncorrectBondAmount();
        /// @notice Thrown when a credit claim is attempted for a value of 0.
        error NoCreditToClaim();
        /// @notice Thrown when the transfer of credit to a recipient account reverts.
        error BondTransferFailed();
        /// @notice Thrown when the `extraData` passed to the CWIA proxy is of improper length, or contains invalid information.
        error BadExtraData();
        /// @notice Thrown when a defense against the root claim is attempted.
        error CannotDefendRootClaim();
        /// @notice Thrown when a claim is attempting to be made that already exists.
        error ClaimAlreadyExists();
        /// @notice Thrown when a disputed claim does not match its index in the game.
        error InvalidDisputedClaimIndex();
        /// @notice Thrown when an action that requires the game to be `IN_PROGRESS` is invoked when
        ///         the game is not in progress.
        error GameNotInProgress();
        /// @notice Thrown when a move is attempted to be made after the clock has timed out.
        error ClockTimeExceeded();
        /// @notice Thrown when the game is attempted to be resolved too early.
        error ClockNotExpired();
        /// @notice Thrown when a move is attempted to be made at or greater than the max depth of the game.
        error GameDepthExceeded();
        /// @notice Thrown when a step is attempted above the maximum game depth.
        error InvalidParent();
        /// @notice Thrown when an invalid prestate is supplied to `step`.
        error InvalidPrestate();
        /// @notice Thrown when a step is made that computes the expected post state correctly.
        error ValidStep();
        /// @notice Thrown when a game is attempted to be initialized with an L1 head that does
        ///         not contain the disputed output root.
        error L1HeadTooOld();
        /// @notice Thrown when an invalid local identifier is passed to the `addLocalData` function.
        error InvalidLocalIdent();
        /// @notice Thrown when resolving claims out of order.
        error OutOfOrderResolution();
        /// @notice Thrown when resolving a claim that has already been resolved.
        error ClaimAlreadyResolved();
        /// @notice Thrown when a parent output root is attempted to be found on a claim that is in
        ///         the output root portion of the tree.
        error ClaimAboveSplit();
        /// @notice Thrown on deployment if the split depth is greater than or equal to the max
        ///         depth of the game.
        error InvalidSplitDepth();
        /// @notice Thrown on deployment if the max clock duration is less than or equal to the clock extension.
        error InvalidClockExtension();
        /// @notice Thrown on deployment if the max depth is greater than `LibPosition.`
        error MaxDepthTooLarge();
        /// @notice Thrown when trying to step against a claim for a second time, after it has already been countered with
        ///         an instruction step.
        error DuplicateStep();
        /// @notice Thrown when an anchor root is not found for a given game type.
        error AnchorRootNotFound();
        /// @notice Thrown when an output root proof is invalid.
        error InvalidOutputRootProof();
        /// @notice Thrown when header RLP is invalid with respect to the block hash in an output root proof.
        error InvalidHeaderRLP();
        /// @notice Thrown when there is a match between the block number in the output root proof and the block number
        ///         claimed in the dispute game.
        error BlockNumberMatches();
        /// @notice Thrown when the L2 block number claim has already been challenged.
        error L2BlockNumberChallenged();
        ////////////////////////////////////////////////////////////////
        //              `PermissionedDisputeGame` Errors              //
        ////////////////////////////////////////////////////////////////
        /// @notice Thrown when an unauthorized address attempts to interact with the game.
        error BadAuth();
        // SPDX-License-Identifier: MIT
        pragma solidity ^0.8.0;
        /// @title Storage
        /// @notice Storage handles reading and writing to arbitary storage locations
        library Storage {
            /// @notice Returns an address stored in an arbitrary storage slot.
            ///         These storage slots decouple the storage layout from
            ///         solc's automation.
            /// @param _slot The storage slot to retrieve the address from.
            function getAddress(bytes32 _slot) internal view returns (address addr_) {
                assembly {
                    addr_ := sload(_slot)
                }
            }
            /// @notice Stores an address in an arbitrary storage slot, `_slot`.
            /// @param _slot The storage slot to store the address in.
            /// @param _address The protocol version to store
            /// @dev WARNING! This function must be used cautiously, as it allows for overwriting addresses
            ///      in arbitrary storage slots.
            function setAddress(bytes32 _slot, address _address) internal {
                assembly {
                    sstore(_slot, _address)
                }
            }
            /// @notice Returns a uint256 stored in an arbitrary storage slot.
            ///         These storage slots decouple the storage layout from
            ///         solc's automation.
            /// @param _slot The storage slot to retrieve the address from.
            function getUint(bytes32 _slot) internal view returns (uint256 value_) {
                assembly {
                    value_ := sload(_slot)
                }
            }
            /// @notice Stores a value in an arbitrary storage slot, `_slot`.
            /// @param _slot The storage slot to store the address in.
            /// @param _value The protocol version to store
            /// @dev WARNING! This function must be used cautiously, as it allows for overwriting values
            ///      in arbitrary storage slots.
            function setUint(bytes32 _slot, uint256 _value) internal {
                assembly {
                    sstore(_slot, _value)
                }
            }
            /// @notice Returns a bytes32 stored in an arbitrary storage slot.
            ///         These storage slots decouple the storage layout from
            ///         solc's automation.
            /// @param _slot The storage slot to retrieve the address from.
            function getBytes32(bytes32 _slot) internal view returns (bytes32 value_) {
                assembly {
                    value_ := sload(_slot)
                }
            }
            /// @notice Stores a bytes32 value in an arbitrary storage slot, `_slot`.
            /// @param _slot The storage slot to store the address in.
            /// @param _value The bytes32 value to store.
            /// @dev WARNING! This function must be used cautiously, as it allows for overwriting values
            ///      in arbitrary storage slots.
            function setBytes32(bytes32 _slot, bytes32 _value) internal {
                assembly {
                    sstore(_slot, _value)
                }
            }
            /// @notice Stores a bool value in an arbitrary storage slot, `_slot`.
            /// @param _slot The storage slot to store the bool in.
            /// @param _value The bool value to store
            /// @dev WARNING! This function must be used cautiously, as it allows for overwriting values
            ///      in arbitrary storage slots.
            function setBool(bytes32 _slot, bool _value) internal {
                assembly {
                    sstore(_slot, _value)
                }
            }
            /// @notice Returns a bool stored in an arbitrary storage slot.
            /// @param _slot The storage slot to retrieve the bool from.
            function getBool(bytes32 _slot) internal view returns (bool value_) {
                assembly {
                    value_ := sload(_slot)
                }
            }
        }
        // SPDX-License-Identifier: MIT
        pragma solidity ^0.8.0;
        import { Types } from "src/libraries/Types.sol";
        import { Hashing } from "src/libraries/Hashing.sol";
        import { RLPWriter } from "src/libraries/rlp/RLPWriter.sol";
        /// @title Encoding
        /// @notice Encoding handles Optimism's various different encoding schemes.
        library Encoding {
            /// @notice RLP encodes the L2 transaction that would be generated when a given deposit is sent
            ///         to the L2 system. Useful for searching for a deposit in the L2 system. The
            ///         transaction is prefixed with 0x7e to identify its EIP-2718 type.
            /// @param _tx User deposit transaction to encode.
            /// @return RLP encoded L2 deposit transaction.
            function encodeDepositTransaction(Types.UserDepositTransaction memory _tx) internal pure returns (bytes memory) {
                bytes32 source = Hashing.hashDepositSource(_tx.l1BlockHash, _tx.logIndex);
                bytes[] memory raw = new bytes[](8);
                raw[0] = RLPWriter.writeBytes(abi.encodePacked(source));
                raw[1] = RLPWriter.writeAddress(_tx.from);
                raw[2] = _tx.isCreation ? RLPWriter.writeBytes("") : RLPWriter.writeAddress(_tx.to);
                raw[3] = RLPWriter.writeUint(_tx.mint);
                raw[4] = RLPWriter.writeUint(_tx.value);
                raw[5] = RLPWriter.writeUint(uint256(_tx.gasLimit));
                raw[6] = RLPWriter.writeBool(false);
                raw[7] = RLPWriter.writeBytes(_tx.data);
                return abi.encodePacked(uint8(0x7e), RLPWriter.writeList(raw));
            }
            /// @notice Encodes the cross domain message based on the version that is encoded into the
            ///         message nonce.
            /// @param _nonce    Message nonce with version encoded into the first two bytes.
            /// @param _sender   Address of the sender of the message.
            /// @param _target   Address of the target of the message.
            /// @param _value    ETH value to send to the target.
            /// @param _gasLimit Gas limit to use for the message.
            /// @param _data     Data to send with the message.
            /// @return Encoded cross domain message.
            function encodeCrossDomainMessage(
                uint256 _nonce,
                address _sender,
                address _target,
                uint256 _value,
                uint256 _gasLimit,
                bytes memory _data
            )
                internal
                pure
                returns (bytes memory)
            {
                (, uint16 version) = decodeVersionedNonce(_nonce);
                if (version == 0) {
                    return encodeCrossDomainMessageV0(_target, _sender, _data, _nonce);
                } else if (version == 1) {
                    return encodeCrossDomainMessageV1(_nonce, _sender, _target, _value, _gasLimit, _data);
                } else {
                    revert("Encoding: unknown cross domain message version");
                }
            }
            /// @notice Encodes a cross domain message based on the V0 (legacy) encoding.
            /// @param _target Address of the target of the message.
            /// @param _sender Address of the sender of the message.
            /// @param _data   Data to send with the message.
            /// @param _nonce  Message nonce.
            /// @return Encoded cross domain message.
            function encodeCrossDomainMessageV0(
                address _target,
                address _sender,
                bytes memory _data,
                uint256 _nonce
            )
                internal
                pure
                returns (bytes memory)
            {
                return abi.encodeWithSignature("relayMessage(address,address,bytes,uint256)", _target, _sender, _data, _nonce);
            }
            /// @notice Encodes a cross domain message based on the V1 (current) encoding.
            /// @param _nonce    Message nonce.
            /// @param _sender   Address of the sender of the message.
            /// @param _target   Address of the target of the message.
            /// @param _value    ETH value to send to the target.
            /// @param _gasLimit Gas limit to use for the message.
            /// @param _data     Data to send with the message.
            /// @return Encoded cross domain message.
            function encodeCrossDomainMessageV1(
                uint256 _nonce,
                address _sender,
                address _target,
                uint256 _value,
                uint256 _gasLimit,
                bytes memory _data
            )
                internal
                pure
                returns (bytes memory)
            {
                return abi.encodeWithSignature(
                    "relayMessage(uint256,address,address,uint256,uint256,bytes)",
                    _nonce,
                    _sender,
                    _target,
                    _value,
                    _gasLimit,
                    _data
                );
            }
            /// @notice Adds a version number into the first two bytes of a message nonce.
            /// @param _nonce   Message nonce to encode into.
            /// @param _version Version number to encode into the message nonce.
            /// @return Message nonce with version encoded into the first two bytes.
            function encodeVersionedNonce(uint240 _nonce, uint16 _version) internal pure returns (uint256) {
                uint256 nonce;
                assembly {
                    nonce := or(shl(240, _version), _nonce)
                }
                return nonce;
            }
            /// @notice Pulls the version out of a version-encoded nonce.
            /// @param _nonce Message nonce with version encoded into the first two bytes.
            /// @return Nonce without encoded version.
            /// @return Version of the message.
            function decodeVersionedNonce(uint256 _nonce) internal pure returns (uint240, uint16) {
                uint240 nonce;
                uint16 version;
                assembly {
                    nonce := and(_nonce, 0x0000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff)
                    version := shr(240, _nonce)
                }
                return (nonce, version);
            }
            /// @notice Returns an appropriately encoded call to L1Block.setL1BlockValuesEcotone
            /// @param baseFeeScalar       L1 base fee Scalar
            /// @param blobBaseFeeScalar   L1 blob base fee Scalar
            /// @param sequenceNumber      Number of L2 blocks since epoch start.
            /// @param timestamp           L1 timestamp.
            /// @param number              L1 blocknumber.
            /// @param baseFee             L1 base fee.
            /// @param blobBaseFee         L1 blob base fee.
            /// @param hash                L1 blockhash.
            /// @param batcherHash         Versioned hash to authenticate batcher by.
            function encodeSetL1BlockValuesEcotone(
                uint32 baseFeeScalar,
                uint32 blobBaseFeeScalar,
                uint64 sequenceNumber,
                uint64 timestamp,
                uint64 number,
                uint256 baseFee,
                uint256 blobBaseFee,
                bytes32 hash,
                bytes32 batcherHash
            )
                internal
                pure
                returns (bytes memory)
            {
                bytes4 functionSignature = bytes4(keccak256("setL1BlockValuesEcotone()"));
                return abi.encodePacked(
                    functionSignature,
                    baseFeeScalar,
                    blobBaseFeeScalar,
                    sequenceNumber,
                    timestamp,
                    number,
                    baseFee,
                    blobBaseFee,
                    hash,
                    batcherHash
                );
            }
            /// @notice Returns an appropriately encoded call to L1Block.setL1BlockValuesInterop
            /// @param _baseFeeScalar       L1 base fee Scalar
            /// @param _blobBaseFeeScalar   L1 blob base fee Scalar
            /// @param _sequenceNumber      Number of L2 blocks since epoch start.
            /// @param _timestamp           L1 timestamp.
            /// @param _number              L1 blocknumber.
            /// @param _baseFee             L1 base fee.
            /// @param _blobBaseFee         L1 blob base fee.
            /// @param _hash                L1 blockhash.
            /// @param _batcherHash         Versioned hash to authenticate batcher by.
            /// @param _dependencySet       Array of the chain IDs in the interop dependency set.
            function encodeSetL1BlockValuesInterop(
                uint32 _baseFeeScalar,
                uint32 _blobBaseFeeScalar,
                uint64 _sequenceNumber,
                uint64 _timestamp,
                uint64 _number,
                uint256 _baseFee,
                uint256 _blobBaseFee,
                bytes32 _hash,
                bytes32 _batcherHash,
                uint256[] memory _dependencySet
            )
                internal
                pure
                returns (bytes memory)
            {
                require(_dependencySet.length <= type(uint8).max, "Encoding: dependency set length is too large");
                // Check that the batcher hash is just the address with 0 padding to the left for version 0.
                require(uint160(uint256(_batcherHash)) == uint256(_batcherHash), "Encoding: invalid batcher hash");
                bytes4 functionSignature = bytes4(keccak256("setL1BlockValuesInterop()"));
                return abi.encodePacked(
                    functionSignature,
                    _baseFeeScalar,
                    _blobBaseFeeScalar,
                    _sequenceNumber,
                    _timestamp,
                    _number,
                    _baseFee,
                    _blobBaseFee,
                    _hash,
                    _batcherHash,
                    uint8(_dependencySet.length),
                    _dependencySet
                );
            }
        }
        // SPDX-License-Identifier: MIT
        pragma solidity ^0.8.0;
        import { Bytes } from "../Bytes.sol";
        import { RLPReader } from "../rlp/RLPReader.sol";
        /// @title MerkleTrie
        /// @notice MerkleTrie is a small library for verifying standard Ethereum Merkle-Patricia trie
        ///         inclusion proofs. By default, this library assumes a hexary trie. One can change the
        ///         trie radix constant to support other trie radixes.
        library MerkleTrie {
            /// @notice Struct representing a node in the trie.
            /// @custom:field encoded The RLP-encoded node.
            /// @custom:field decoded The RLP-decoded node.
            struct TrieNode {
                bytes encoded;
                RLPReader.RLPItem[] decoded;
            }
            /// @notice Determines the number of elements per branch node.
            uint256 internal constant TREE_RADIX = 16;
            /// @notice Branch nodes have TREE_RADIX elements and one value element.
            uint256 internal constant BRANCH_NODE_LENGTH = TREE_RADIX + 1;
            /// @notice Leaf nodes and extension nodes have two elements, a `path` and a `value`.
            uint256 internal constant LEAF_OR_EXTENSION_NODE_LENGTH = 2;
            /// @notice Prefix for even-nibbled extension node paths.
            uint8 internal constant PREFIX_EXTENSION_EVEN = 0;
            /// @notice Prefix for odd-nibbled extension node paths.
            uint8 internal constant PREFIX_EXTENSION_ODD = 1;
            /// @notice Prefix for even-nibbled leaf node paths.
            uint8 internal constant PREFIX_LEAF_EVEN = 2;
            /// @notice Prefix for odd-nibbled leaf node paths.
            uint8 internal constant PREFIX_LEAF_ODD = 3;
            /// @notice Verifies a proof that a given key/value pair is present in the trie.
            /// @param _key   Key of the node to search for, as a hex string.
            /// @param _value Value of the node to search for, as a hex string.
            /// @param _proof Merkle trie inclusion proof for the desired node. Unlike traditional Merkle
            ///               trees, this proof is executed top-down and consists of a list of RLP-encoded
            ///               nodes that make a path down to the target node.
            /// @param _root  Known root of the Merkle trie. Used to verify that the included proof is
            ///               correctly constructed.
            /// @return valid_ Whether or not the proof is valid.
            function verifyInclusionProof(
                bytes memory _key,
                bytes memory _value,
                bytes[] memory _proof,
                bytes32 _root
            )
                internal
                pure
                returns (bool valid_)
            {
                valid_ = Bytes.equal(_value, get(_key, _proof, _root));
            }
            /// @notice Retrieves the value associated with a given key.
            /// @param _key   Key to search for, as hex bytes.
            /// @param _proof Merkle trie inclusion proof for the key.
            /// @param _root  Known root of the Merkle trie.
            /// @return value_ Value of the key if it exists.
            function get(bytes memory _key, bytes[] memory _proof, bytes32 _root) internal pure returns (bytes memory value_) {
                require(_key.length > 0, "MerkleTrie: empty key");
                TrieNode[] memory proof = _parseProof(_proof);
                bytes memory key = Bytes.toNibbles(_key);
                bytes memory currentNodeID = abi.encodePacked(_root);
                uint256 currentKeyIndex = 0;
                // Proof is top-down, so we start at the first element (root).
                for (uint256 i = 0; i < proof.length; i++) {
                    TrieNode memory currentNode = proof[i];
                    // Key index should never exceed total key length or we'll be out of bounds.
                    require(currentKeyIndex <= key.length, "MerkleTrie: key index exceeds total key length");
                    if (currentKeyIndex == 0) {
                        // First proof element is always the root node.
                        require(
                            Bytes.equal(abi.encodePacked(keccak256(currentNode.encoded)), currentNodeID),
                            "MerkleTrie: invalid root hash"
                        );
                    } else if (currentNode.encoded.length >= 32) {
                        // Nodes 32 bytes or larger are hashed inside branch nodes.
                        require(
                            Bytes.equal(abi.encodePacked(keccak256(currentNode.encoded)), currentNodeID),
                            "MerkleTrie: invalid large internal hash"
                        );
                    } else {
                        // Nodes smaller than 32 bytes aren't hashed.
                        require(Bytes.equal(currentNode.encoded, currentNodeID), "MerkleTrie: invalid internal node hash");
                    }
                    if (currentNode.decoded.length == BRANCH_NODE_LENGTH) {
                        if (currentKeyIndex == key.length) {
                            // Value is the last element of the decoded list (for branch nodes). There's
                            // some ambiguity in the Merkle trie specification because bytes(0) is a
                            // valid value to place into the trie, but for branch nodes bytes(0) can exist
                            // even when the value wasn't explicitly placed there. Geth treats a value of
                            // bytes(0) as "key does not exist" and so we do the same.
                            value_ = RLPReader.readBytes(currentNode.decoded[TREE_RADIX]);
                            require(value_.length > 0, "MerkleTrie: value length must be greater than zero (branch)");
                            // Extra proof elements are not allowed.
                            require(i == proof.length - 1, "MerkleTrie: value node must be last node in proof (branch)");
                            return value_;
                        } else {
                            // We're not at the end of the key yet.
                            // Figure out what the next node ID should be and continue.
                            uint8 branchKey = uint8(key[currentKeyIndex]);
                            RLPReader.RLPItem memory nextNode = currentNode.decoded[branchKey];
                            currentNodeID = _getNodeID(nextNode);
                            currentKeyIndex += 1;
                        }
                    } else if (currentNode.decoded.length == LEAF_OR_EXTENSION_NODE_LENGTH) {
                        bytes memory path = _getNodePath(currentNode);
                        uint8 prefix = uint8(path[0]);
                        uint8 offset = 2 - (prefix % 2);
                        bytes memory pathRemainder = Bytes.slice(path, offset);
                        bytes memory keyRemainder = Bytes.slice(key, currentKeyIndex);
                        uint256 sharedNibbleLength = _getSharedNibbleLength(pathRemainder, keyRemainder);
                        // Whether this is a leaf node or an extension node, the path remainder MUST be a
                        // prefix of the key remainder (or be equal to the key remainder) or the proof is
                        // considered invalid.
                        require(
                            pathRemainder.length == sharedNibbleLength,
                            "MerkleTrie: path remainder must share all nibbles with key"
                        );
                        if (prefix == PREFIX_LEAF_EVEN || prefix == PREFIX_LEAF_ODD) {
                            // Prefix of 2 or 3 means this is a leaf node. For the leaf node to be valid,
                            // the key remainder must be exactly equal to the path remainder. We already
                            // did the necessary byte comparison, so it's more efficient here to check that
                            // the key remainder length equals the shared nibble length, which implies
                            // equality with the path remainder (since we already did the same check with
                            // the path remainder and the shared nibble length).
                            require(
                                keyRemainder.length == sharedNibbleLength,
                                "MerkleTrie: key remainder must be identical to path remainder"
                            );
                            // Our Merkle Trie is designed specifically for the purposes of the Ethereum
                            // state trie. Empty values are not allowed in the state trie, so we can safely
                            // say that if the value is empty, the key should not exist and the proof is
                            // invalid.
                            value_ = RLPReader.readBytes(currentNode.decoded[1]);
                            require(value_.length > 0, "MerkleTrie: value length must be greater than zero (leaf)");
                            // Extra proof elements are not allowed.
                            require(i == proof.length - 1, "MerkleTrie: value node must be last node in proof (leaf)");
                            return value_;
                        } else if (prefix == PREFIX_EXTENSION_EVEN || prefix == PREFIX_EXTENSION_ODD) {
                            // Prefix of 0 or 1 means this is an extension node. We move onto the next node
                            // in the proof and increment the key index by the length of the path remainder
                            // which is equal to the shared nibble length.
                            currentNodeID = _getNodeID(currentNode.decoded[1]);
                            currentKeyIndex += sharedNibbleLength;
                        } else {
                            revert("MerkleTrie: received a node with an unknown prefix");
                        }
                    } else {
                        revert("MerkleTrie: received an unparseable node");
                    }
                }
                revert("MerkleTrie: ran out of proof elements");
            }
            /// @notice Parses an array of proof elements into a new array that contains both the original
            ///         encoded element and the RLP-decoded element.
            /// @param _proof Array of proof elements to parse.
            /// @return proof_ Proof parsed into easily accessible structs.
            function _parseProof(bytes[] memory _proof) private pure returns (TrieNode[] memory proof_) {
                uint256 length = _proof.length;
                proof_ = new TrieNode[](length);
                for (uint256 i = 0; i < length;) {
                    proof_[i] = TrieNode({ encoded: _proof[i], decoded: RLPReader.readList(_proof[i]) });
                    unchecked {
                        ++i;
                    }
                }
            }
            /// @notice Picks out the ID for a node. Node ID is referred to as the "hash" within the
            ///         specification, but nodes < 32 bytes are not actually hashed.
            /// @param _node Node to pull an ID for.
            /// @return id_ ID for the node, depending on the size of its contents.
            function _getNodeID(RLPReader.RLPItem memory _node) private pure returns (bytes memory id_) {
                id_ = _node.length < 32 ? RLPReader.readRawBytes(_node) : RLPReader.readBytes(_node);
            }
            /// @notice Gets the path for a leaf or extension node.
            /// @param _node Node to get a path for.
            /// @return nibbles_ Node path, converted to an array of nibbles.
            function _getNodePath(TrieNode memory _node) private pure returns (bytes memory nibbles_) {
                nibbles_ = Bytes.toNibbles(RLPReader.readBytes(_node.decoded[0]));
            }
            /// @notice Utility; determines the number of nibbles shared between two nibble arrays.
            /// @param _a First nibble array.
            /// @param _b Second nibble array.
            /// @return shared_ Number of shared nibbles.
            function _getSharedNibbleLength(bytes memory _a, bytes memory _b) private pure returns (uint256 shared_) {
                uint256 max = (_a.length < _b.length) ? _a.length : _b.length;
                for (; shared_ < max && _a[shared_] == _b[shared_];) {
                    unchecked {
                        ++shared_;
                    }
                }
            }
        }
        // SPDX-License-Identifier: MIT
        // OpenZeppelin Contracts (last updated v4.7.0) (utils/math/Math.sol)
        pragma solidity ^0.8.0;
        /**
         * @dev Standard math utilities missing in the Solidity language.
         */
        library Math {
            enum Rounding {
                Down, // Toward negative infinity
                Up, // Toward infinity
                Zero // Toward zero
            }
            /**
             * @dev Returns the largest of two numbers.
             */
            function max(uint256 a, uint256 b) internal pure returns (uint256) {
                return a >= b ? a : b;
            }
            /**
             * @dev Returns the smallest of two numbers.
             */
            function min(uint256 a, uint256 b) internal pure returns (uint256) {
                return a < b ? a : b;
            }
            /**
             * @dev Returns the average of two numbers. The result is rounded towards
             * zero.
             */
            function average(uint256 a, uint256 b) internal pure returns (uint256) {
                // (a + b) / 2 can overflow.
                return (a & b) + (a ^ b) / 2;
            }
            /**
             * @dev Returns the ceiling of the division of two numbers.
             *
             * This differs from standard division with `/` in that it rounds up instead
             * of rounding down.
             */
            function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
                // (a + b - 1) / b can overflow on addition, so we distribute.
                return a == 0 ? 0 : (a - 1) / b + 1;
            }
            /**
             * @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or denominator == 0
             * @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv)
             * with further edits by Uniswap Labs also under MIT license.
             */
            function mulDiv(
                uint256 x,
                uint256 y,
                uint256 denominator
            ) internal pure returns (uint256 result) {
                unchecked {
                    // 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use
                    // use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256
                    // variables such that product = prod1 * 2^256 + prod0.
                    uint256 prod0; // Least significant 256 bits of the product
                    uint256 prod1; // Most significant 256 bits of the product
                    assembly {
                        let mm := mulmod(x, y, not(0))
                        prod0 := mul(x, y)
                        prod1 := sub(sub(mm, prod0), lt(mm, prod0))
                    }
                    // Handle non-overflow cases, 256 by 256 division.
                    if (prod1 == 0) {
                        return prod0 / denominator;
                    }
                    // Make sure the result is less than 2^256. Also prevents denominator == 0.
                    require(denominator > prod1);
                    ///////////////////////////////////////////////
                    // 512 by 256 division.
                    ///////////////////////////////////////////////
                    // Make division exact by subtracting the remainder from [prod1 prod0].
                    uint256 remainder;
                    assembly {
                        // Compute remainder using mulmod.
                        remainder := mulmod(x, y, denominator)
                        // Subtract 256 bit number from 512 bit number.
                        prod1 := sub(prod1, gt(remainder, prod0))
                        prod0 := sub(prod0, remainder)
                    }
                    // Factor powers of two out of denominator and compute largest power of two divisor of denominator. Always >= 1.
                    // See https://cs.stackexchange.com/q/138556/92363.
                    // Does not overflow because the denominator cannot be zero at this stage in the function.
                    uint256 twos = denominator & (~denominator + 1);
                    assembly {
                        // Divide denominator by twos.
                        denominator := div(denominator, twos)
                        // Divide [prod1 prod0] by twos.
                        prod0 := div(prod0, twos)
                        // Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one.
                        twos := add(div(sub(0, twos), twos), 1)
                    }
                    // Shift in bits from prod1 into prod0.
                    prod0 |= prod1 * twos;
                    // Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such
                    // that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for
                    // four bits. That is, denominator * inv = 1 mod 2^4.
                    uint256 inverse = (3 * denominator) ^ 2;
                    // Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also works
                    // in modular arithmetic, doubling the correct bits in each step.
                    inverse *= 2 - denominator * inverse; // inverse mod 2^8
                    inverse *= 2 - denominator * inverse; // inverse mod 2^16
                    inverse *= 2 - denominator * inverse; // inverse mod 2^32
                    inverse *= 2 - denominator * inverse; // inverse mod 2^64
                    inverse *= 2 - denominator * inverse; // inverse mod 2^128
                    inverse *= 2 - denominator * inverse; // inverse mod 2^256
                    // Because the division is now exact we can divide by multiplying with the modular inverse of denominator.
                    // This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is
                    // less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1
                    // is no longer required.
                    result = prod0 * inverse;
                    return result;
                }
            }
            /**
             * @notice Calculates x * y / denominator with full precision, following the selected rounding direction.
             */
            function mulDiv(
                uint256 x,
                uint256 y,
                uint256 denominator,
                Rounding rounding
            ) internal pure returns (uint256) {
                uint256 result = mulDiv(x, y, denominator);
                if (rounding == Rounding.Up && mulmod(x, y, denominator) > 0) {
                    result += 1;
                }
                return result;
            }
            /**
             * @dev Returns the square root of a number. It the number is not a perfect square, the value is rounded down.
             *
             * Inspired by Henry S. Warren, Jr.'s "Hacker's Delight" (Chapter 11).
             */
            function sqrt(uint256 a) internal pure returns (uint256) {
                if (a == 0) {
                    return 0;
                }
                // For our first guess, we get the biggest power of 2 which is smaller than the square root of the target.
                // We know that the "msb" (most significant bit) of our target number `a` is a power of 2 such that we have
                // `msb(a) <= a < 2*msb(a)`.
                // We also know that `k`, the position of the most significant bit, is such that `msb(a) = 2**k`.
                // This gives `2**k < a <= 2**(k+1)` → `2**(k/2) <= sqrt(a) < 2 ** (k/2+1)`.
                // Using an algorithm similar to the msb conmputation, we are able to compute `result = 2**(k/2)` which is a
                // good first aproximation of `sqrt(a)` with at least 1 correct bit.
                uint256 result = 1;
                uint256 x = a;
                if (x >> 128 > 0) {
                    x >>= 128;
                    result <<= 64;
                }
                if (x >> 64 > 0) {
                    x >>= 64;
                    result <<= 32;
                }
                if (x >> 32 > 0) {
                    x >>= 32;
                    result <<= 16;
                }
                if (x >> 16 > 0) {
                    x >>= 16;
                    result <<= 8;
                }
                if (x >> 8 > 0) {
                    x >>= 8;
                    result <<= 4;
                }
                if (x >> 4 > 0) {
                    x >>= 4;
                    result <<= 2;
                }
                if (x >> 2 > 0) {
                    result <<= 1;
                }
                // At this point `result` is an estimation with one bit of precision. We know the true value is a uint128,
                // since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at
                // every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision
                // into the expected uint128 result.
                unchecked {
                    result = (result + a / result) >> 1;
                    result = (result + a / result) >> 1;
                    result = (result + a / result) >> 1;
                    result = (result + a / result) >> 1;
                    result = (result + a / result) >> 1;
                    result = (result + a / result) >> 1;
                    result = (result + a / result) >> 1;
                    return min(result, a / result);
                }
            }
            /**
             * @notice Calculates sqrt(a), following the selected rounding direction.
             */
            function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {
                uint256 result = sqrt(a);
                if (rounding == Rounding.Up && result * result < a) {
                    result += 1;
                }
                return result;
            }
        }
        // SPDX-License-Identifier: MIT
        pragma solidity 0.8.15;
        /// @title Burn
        /// @notice Utilities for burning stuff.
        library Burn {
            /// @notice Burns a given amount of ETH.
            /// @param _amount Amount of ETH to burn.
            function eth(uint256 _amount) internal {
                new Burner{ value: _amount }();
            }
            /// @notice Burns a given amount of gas.
            /// @param _amount Amount of gas to burn.
            function gas(uint256 _amount) internal view {
                uint256 i = 0;
                uint256 initialGas = gasleft();
                while (initialGas - gasleft() < _amount) {
                    ++i;
                }
            }
        }
        /// @title Burner
        /// @notice Burner self-destructs on creation and sends all ETH to itself, removing all ETH given to
        ///         the contract from the circulating supply. Self-destructing is the only way to remove ETH
        ///         from the circulating supply.
        contract Burner {
            constructor() payable {
                selfdestruct(payable(address(this)));
            }
        }
        // SPDX-License-Identifier: MIT
        pragma solidity ^0.8.0;
        import { SignedMath } from "@openzeppelin/contracts/utils/math/SignedMath.sol";
        import { FixedPointMathLib } from "@rari-capital/solmate/src/utils/FixedPointMathLib.sol";
        /// @title Arithmetic
        /// @notice Even more math than before.
        library Arithmetic {
            /// @notice Clamps a value between a minimum and maximum.
            /// @param _value The value to clamp.
            /// @param _min   The minimum value.
            /// @param _max   The maximum value.
            /// @return The clamped value.
            function clamp(int256 _value, int256 _min, int256 _max) internal pure returns (int256) {
                return SignedMath.min(SignedMath.max(_value, _min), _max);
            }
            /// @notice (c)oefficient (d)enominator (exp)onentiation function.
            ///         Returns the result of: c * (1 - 1/d)^exp.
            /// @param _coefficient Coefficient of the function.
            /// @param _denominator Fractional denominator.
            /// @param _exponent    Power function exponent.
            /// @return Result of c * (1 - 1/d)^exp.
            function cdexp(int256 _coefficient, int256 _denominator, int256 _exponent) internal pure returns (int256) {
                return (_coefficient * (FixedPointMathLib.powWad(1e18 - (1e18 / _denominator), _exponent * 1e18))) / 1e18;
            }
        }
        // SPDX-License-Identifier: MIT
        pragma solidity ^0.8.15;
        import "src/dispute/lib/LibPosition.sol";
        using LibClaim for Claim global;
        using LibHash for Hash global;
        using LibDuration for Duration global;
        using LibClock for Clock global;
        using LibGameId for GameId global;
        using LibTimestamp for Timestamp global;
        using LibVMStatus for VMStatus global;
        using LibGameType for GameType global;
        /// @notice A `Clock` represents a packed `Duration` and `Timestamp`
        /// @dev The packed layout of this type is as follows:
        /// ┌────────────┬────────────────┐
        /// │    Bits    │     Value      │
        /// ├────────────┼────────────────┤
        /// │ [0, 64)    │ Duration       │
        /// │ [64, 128)  │ Timestamp      │
        /// └────────────┴────────────────┘
        type Clock is uint128;
        /// @title LibClock
        /// @notice This library contains helper functions for working with the `Clock` type.
        library LibClock {
            /// @notice Packs a `Duration` and `Timestamp` into a `Clock` type.
            /// @param _duration The `Duration` to pack into the `Clock` type.
            /// @param _timestamp The `Timestamp` to pack into the `Clock` type.
            /// @return clock_ The `Clock` containing the `_duration` and `_timestamp`.
            function wrap(Duration _duration, Timestamp _timestamp) internal pure returns (Clock clock_) {
                assembly {
                    clock_ := or(shl(0x40, _duration), _timestamp)
                }
            }
            /// @notice Pull the `Duration` out of a `Clock` type.
            /// @param _clock The `Clock` type to pull the `Duration` out of.
            /// @return duration_ The `Duration` pulled out of `_clock`.
            function duration(Clock _clock) internal pure returns (Duration duration_) {
                // Shift the high-order 64 bits into the low-order 64 bits, leaving only the `duration`.
                assembly {
                    duration_ := shr(0x40, _clock)
                }
            }
            /// @notice Pull the `Timestamp` out of a `Clock` type.
            /// @param _clock The `Clock` type to pull the `Timestamp` out of.
            /// @return timestamp_ The `Timestamp` pulled out of `_clock`.
            function timestamp(Clock _clock) internal pure returns (Timestamp timestamp_) {
                // Clean the high-order 192 bits by shifting the clock left and then right again, leaving
                // only the `timestamp`.
                assembly {
                    timestamp_ := shr(0xC0, shl(0xC0, _clock))
                }
            }
            /// @notice Get the value of a `Clock` type in the form of the underlying uint128.
            /// @param _clock The `Clock` type to get the value of.
            /// @return clock_ The value of the `Clock` type as a uint128 type.
            function raw(Clock _clock) internal pure returns (uint128 clock_) {
                assembly {
                    clock_ := _clock
                }
            }
        }
        /// @notice A `GameId` represents a packed 4 byte game ID, a 8 byte timestamp, and a 20 byte address.
        /// @dev The packed layout of this type is as follows:
        /// ┌───────────┬───────────┐
        /// │   Bits    │   Value   │
        /// ├───────────┼───────────┤
        /// │ [0, 32)   │ Game Type │
        /// │ [32, 96)  │ Timestamp │
        /// │ [96, 256) │ Address   │
        /// └───────────┴───────────┘
        type GameId is bytes32;
        /// @title LibGameId
        /// @notice Utility functions for packing and unpacking GameIds.
        library LibGameId {
            /// @notice Packs values into a 32 byte GameId type.
            /// @param _gameType The game type.
            /// @param _timestamp The timestamp of the game's creation.
            /// @param _gameProxy The game proxy address.
            /// @return gameId_ The packed GameId.
            function pack(
                GameType _gameType,
                Timestamp _timestamp,
                address _gameProxy
            )
                internal
                pure
                returns (GameId gameId_)
            {
                assembly {
                    gameId_ := or(or(shl(224, _gameType), shl(160, _timestamp)), _gameProxy)
                }
            }
            /// @notice Unpacks values from a 32 byte GameId type.
            /// @param _gameId The packed GameId.
            /// @return gameType_ The game type.
            /// @return timestamp_ The timestamp of the game's creation.
            /// @return gameProxy_ The game proxy address.
            function unpack(GameId _gameId)
                internal
                pure
                returns (GameType gameType_, Timestamp timestamp_, address gameProxy_)
            {
                assembly {
                    gameType_ := shr(224, _gameId)
                    timestamp_ := and(shr(160, _gameId), 0xFFFFFFFFFFFFFFFF)
                    gameProxy_ := and(_gameId, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)
                }
            }
        }
        /// @notice A claim represents an MPT root representing the state of the fault proof program.
        type Claim is bytes32;
        /// @title LibClaim
        /// @notice This library contains helper functions for working with the `Claim` type.
        library LibClaim {
            /// @notice Get the value of a `Claim` type in the form of the underlying bytes32.
            /// @param _claim The `Claim` type to get the value of.
            /// @return claim_ The value of the `Claim` type as a bytes32 type.
            function raw(Claim _claim) internal pure returns (bytes32 claim_) {
                assembly {
                    claim_ := _claim
                }
            }
            /// @notice Hashes a claim and a position together.
            /// @param _claim A Claim type.
            /// @param _position The position of `claim`.
            /// @param _challengeIndex The index of the claim being moved against.
            /// @return claimHash_ A hash of abi.encodePacked(claim, position|challengeIndex);
            function hashClaimPos(
                Claim _claim,
                Position _position,
                uint256 _challengeIndex
            )
                internal
                pure
                returns (Hash claimHash_)
            {
                assembly {
                    mstore(0x00, _claim)
                    mstore(0x20, or(shl(128, _position), and(0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF, _challengeIndex)))
                    claimHash_ := keccak256(0x00, 0x40)
                }
            }
        }
        /// @notice A dedicated duration type.
        /// @dev Unit: seconds
        type Duration is uint64;
        /// @title LibDuration
        /// @notice This library contains helper functions for working with the `Duration` type.
        library LibDuration {
            /// @notice Get the value of a `Duration` type in the form of the underlying uint64.
            /// @param _duration The `Duration` type to get the value of.
            /// @return duration_ The value of the `Duration` type as a uint64 type.
            function raw(Duration _duration) internal pure returns (uint64 duration_) {
                assembly {
                    duration_ := _duration
                }
            }
        }
        /// @notice A custom type for a generic hash.
        type Hash is bytes32;
        /// @title LibHash
        /// @notice This library contains helper functions for working with the `Hash` type.
        library LibHash {
            /// @notice Get the value of a `Hash` type in the form of the underlying bytes32.
            /// @param _hash The `Hash` type to get the value of.
            /// @return hash_ The value of the `Hash` type as a bytes32 type.
            function raw(Hash _hash) internal pure returns (bytes32 hash_) {
                assembly {
                    hash_ := _hash
                }
            }
        }
        /// @notice A dedicated timestamp type.
        type Timestamp is uint64;
        /// @title LibTimestamp
        /// @notice This library contains helper functions for working with the `Timestamp` type.
        library LibTimestamp {
            /// @notice Get the value of a `Timestamp` type in the form of the underlying uint64.
            /// @param _timestamp The `Timestamp` type to get the value of.
            /// @return timestamp_ The value of the `Timestamp` type as a uint64 type.
            function raw(Timestamp _timestamp) internal pure returns (uint64 timestamp_) {
                assembly {
                    timestamp_ := _timestamp
                }
            }
        }
        /// @notice A `VMStatus` represents the status of a VM execution.
        type VMStatus is uint8;
        /// @title LibVMStatus
        /// @notice This library contains helper functions for working with the `VMStatus` type.
        library LibVMStatus {
            /// @notice Get the value of a `VMStatus` type in the form of the underlying uint8.
            /// @param _vmstatus The `VMStatus` type to get the value of.
            /// @return vmstatus_ The value of the `VMStatus` type as a uint8 type.
            function raw(VMStatus _vmstatus) internal pure returns (uint8 vmstatus_) {
                assembly {
                    vmstatus_ := _vmstatus
                }
            }
        }
        /// @notice A `GameType` represents the type of game being played.
        type GameType is uint32;
        /// @title LibGameType
        /// @notice This library contains helper functions for working with the `GameType` type.
        library LibGameType {
            /// @notice Get the value of a `GameType` type in the form of the underlying uint32.
            /// @param _gametype The `GameType` type to get the value of.
            /// @return gametype_ The value of the `GameType` type as a uint32 type.
            function raw(GameType _gametype) internal pure returns (uint32 gametype_) {
                assembly {
                    gametype_ := _gametype
                }
            }
        }
        // SPDX-License-Identifier: MIT
        // OpenZeppelin Contracts v4.4.1 (utils/Context.sol)
        pragma solidity ^0.8.0;
        import "../proxy/utils/Initializable.sol";
        /**
         * @dev Provides information about the current execution context, including the
         * sender of the transaction and its data. While these are generally available
         * via msg.sender and msg.data, they should not be accessed in such a direct
         * manner, since when dealing with meta-transactions the account sending and
         * paying for execution may not be the actual sender (as far as an application
         * is concerned).
         *
         * This contract is only required for intermediate, library-like contracts.
         */
        abstract contract ContextUpgradeable is Initializable {
            function __Context_init() internal onlyInitializing {
            }
            function __Context_init_unchained() internal onlyInitializing {
            }
            function _msgSender() internal view virtual returns (address) {
                return msg.sender;
            }
            function _msgData() internal view virtual returns (bytes calldata) {
                return msg.data;
            }
            /**
             * @dev This empty reserved space is put in place to allow future versions to add new
             * variables without shifting down storage in the inheritance chain.
             * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
             */
            uint256[50] private __gap;
        }
        // SPDX-License-Identifier: MIT
        // OpenZeppelin Contracts (last updated v4.7.0) (proxy/utils/Initializable.sol)
        pragma solidity ^0.8.2;
        import "../../utils/AddressUpgradeable.sol";
        /**
         * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed
         * behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an
         * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer
         * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.
         *
         * The initialization functions use a version number. Once a version number is used, it is consumed and cannot be
         * reused. This mechanism prevents re-execution of each "step" but allows the creation of new initialization steps in
         * case an upgrade adds a module that needs to be initialized.
         *
         * For example:
         *
         * [.hljs-theme-light.nopadding]
         * ```
         * contract MyToken is ERC20Upgradeable {
         *     function initialize() initializer public {
         *         __ERC20_init("MyToken", "MTK");
         *     }
         * }
         * contract MyTokenV2 is MyToken, ERC20PermitUpgradeable {
         *     function initializeV2() reinitializer(2) public {
         *         __ERC20Permit_init("MyToken");
         *     }
         * }
         * ```
         *
         * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as
         * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.
         *
         * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure
         * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.
         *
         * [CAUTION]
         * ====
         * Avoid leaving a contract uninitialized.
         *
         * An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation
         * contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke
         * the {_disableInitializers} function in the constructor to automatically lock it when it is deployed:
         *
         * [.hljs-theme-light.nopadding]
         * ```
         * /// @custom:oz-upgrades-unsafe-allow constructor
         * constructor() {
         *     _disableInitializers();
         * }
         * ```
         * ====
         */
        abstract contract Initializable {
            /**
             * @dev Indicates that the contract has been initialized.
             * @custom:oz-retyped-from bool
             */
            uint8 private _initialized;
            /**
             * @dev Indicates that the contract is in the process of being initialized.
             */
            bool private _initializing;
            /**
             * @dev Triggered when the contract has been initialized or reinitialized.
             */
            event Initialized(uint8 version);
            /**
             * @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,
             * `onlyInitializing` functions can be used to initialize parent contracts. Equivalent to `reinitializer(1)`.
             */
            modifier initializer() {
                bool isTopLevelCall = !_initializing;
                require(
                    (isTopLevelCall && _initialized < 1) || (!AddressUpgradeable.isContract(address(this)) && _initialized == 1),
                    "Initializable: contract is already initialized"
                );
                _initialized = 1;
                if (isTopLevelCall) {
                    _initializing = true;
                }
                _;
                if (isTopLevelCall) {
                    _initializing = false;
                    emit Initialized(1);
                }
            }
            /**
             * @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the
             * contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be
             * used to initialize parent contracts.
             *
             * `initializer` is equivalent to `reinitializer(1)`, so a reinitializer may be used after the original
             * initialization step. This is essential to configure modules that are added through upgrades and that require
             * initialization.
             *
             * Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in
             * a contract, executing them in the right order is up to the developer or operator.
             */
            modifier reinitializer(uint8 version) {
                require(!_initializing && _initialized < version, "Initializable: contract is already initialized");
                _initialized = version;
                _initializing = true;
                _;
                _initializing = false;
                emit Initialized(version);
            }
            /**
             * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the
             * {initializer} and {reinitializer} modifiers, directly or indirectly.
             */
            modifier onlyInitializing() {
                require(_initializing, "Initializable: contract is not initializing");
                _;
            }
            /**
             * @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.
             * Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized
             * to any version. It is recommended to use this to lock implementation contracts that are designed to be called
             * through proxies.
             */
            function _disableInitializers() internal virtual {
                require(!_initializing, "Initializable: contract is initializing");
                if (_initialized < type(uint8).max) {
                    _initialized = type(uint8).max;
                    emit Initialized(type(uint8).max);
                }
            }
        }
        // SPDX-License-Identifier: MIT
        pragma solidity ^0.8.0;
        /// @title IInitializable
        /// @notice An interface for initializable contracts.
        interface IInitializable {
            /// @notice Initializes the contract.
            /// @dev This function may only be called once.
            function initialize() external payable;
        }
        // SPDX-License-Identifier: MIT
        pragma solidity ^0.8.0;
        /// @custom:attribution https://github.com/bakaoh/solidity-rlp-encode
        /// @title RLPWriter
        /// @author RLPWriter is a library for encoding Solidity types to RLP bytes. Adapted from Bakaoh's
        ///         RLPEncode library (https://github.com/bakaoh/solidity-rlp-encode) with minor
        ///         modifications to improve legibility.
        library RLPWriter {
            /// @notice RLP encodes a byte string.
            /// @param _in The byte string to encode.
            /// @return out_ The RLP encoded string in bytes.
            function writeBytes(bytes memory _in) internal pure returns (bytes memory out_) {
                if (_in.length == 1 && uint8(_in[0]) < 128) {
                    out_ = _in;
                } else {
                    out_ = abi.encodePacked(_writeLength(_in.length, 128), _in);
                }
            }
            /// @notice RLP encodes a list of RLP encoded byte byte strings.
            /// @param _in The list of RLP encoded byte strings.
            /// @return list_ The RLP encoded list of items in bytes.
            function writeList(bytes[] memory _in) internal pure returns (bytes memory list_) {
                list_ = _flatten(_in);
                list_ = abi.encodePacked(_writeLength(list_.length, 192), list_);
            }
            /// @notice RLP encodes a string.
            /// @param _in The string to encode.
            /// @return out_ The RLP encoded string in bytes.
            function writeString(string memory _in) internal pure returns (bytes memory out_) {
                out_ = writeBytes(bytes(_in));
            }
            /// @notice RLP encodes an address.
            /// @param _in The address to encode.
            /// @return out_ The RLP encoded address in bytes.
            function writeAddress(address _in) internal pure returns (bytes memory out_) {
                out_ = writeBytes(abi.encodePacked(_in));
            }
            /// @notice RLP encodes a uint.
            /// @param _in The uint256 to encode.
            /// @return out_ The RLP encoded uint256 in bytes.
            function writeUint(uint256 _in) internal pure returns (bytes memory out_) {
                out_ = writeBytes(_toBinary(_in));
            }
            /// @notice RLP encodes a bool.
            /// @param _in The bool to encode.
            /// @return out_ The RLP encoded bool in bytes.
            function writeBool(bool _in) internal pure returns (bytes memory out_) {
                out_ = new bytes(1);
                out_[0] = (_in ? bytes1(0x01) : bytes1(0x80));
            }
            /// @notice Encode the first byte and then the `len` in binary form if `length` is more than 55.
            /// @param _len    The length of the string or the payload.
            /// @param _offset 128 if item is string, 192 if item is list.
            /// @return out_ RLP encoded bytes.
            function _writeLength(uint256 _len, uint256 _offset) private pure returns (bytes memory out_) {
                if (_len < 56) {
                    out_ = new bytes(1);
                    out_[0] = bytes1(uint8(_len) + uint8(_offset));
                } else {
                    uint256 lenLen;
                    uint256 i = 1;
                    while (_len / i != 0) {
                        lenLen++;
                        i *= 256;
                    }
                    out_ = new bytes(lenLen + 1);
                    out_[0] = bytes1(uint8(lenLen) + uint8(_offset) + 55);
                    for (i = 1; i <= lenLen; i++) {
                        out_[i] = bytes1(uint8((_len / (256 ** (lenLen - i))) % 256));
                    }
                }
            }
            /// @notice Encode integer in big endian binary form with no leading zeroes.
            /// @param _x The integer to encode.
            /// @return out_ RLP encoded bytes.
            function _toBinary(uint256 _x) private pure returns (bytes memory out_) {
                bytes memory b = abi.encodePacked(_x);
                uint256 i = 0;
                for (; i < 32; i++) {
                    if (b[i] != 0) {
                        break;
                    }
                }
                out_ = new bytes(32 - i);
                for (uint256 j = 0; j < out_.length; j++) {
                    out_[j] = b[i++];
                }
            }
            /// @custom:attribution https://github.com/Arachnid/solidity-stringutils
            /// @notice Copies a piece of memory to another location.
            /// @param _dest Destination location.
            /// @param _src  Source location.
            /// @param _len  Length of memory to copy.
            function _memcpy(uint256 _dest, uint256 _src, uint256 _len) private pure {
                uint256 dest = _dest;
                uint256 src = _src;
                uint256 len = _len;
                for (; len >= 32; len -= 32) {
                    assembly {
                        mstore(dest, mload(src))
                    }
                    dest += 32;
                    src += 32;
                }
                uint256 mask;
                unchecked {
                    mask = 256 ** (32 - len) - 1;
                }
                assembly {
                    let srcpart := and(mload(src), not(mask))
                    let destpart := and(mload(dest), mask)
                    mstore(dest, or(destpart, srcpart))
                }
            }
            /// @custom:attribution https://github.com/sammayo/solidity-rlp-encoder
            /// @notice Flattens a list of byte strings into one byte string.
            /// @param _list List of byte strings to flatten.
            /// @return out_ The flattened byte string.
            function _flatten(bytes[] memory _list) private pure returns (bytes memory out_) {
                if (_list.length == 0) {
                    return new bytes(0);
                }
                uint256 len;
                uint256 i = 0;
                for (; i < _list.length; i++) {
                    len += _list[i].length;
                }
                out_ = new bytes(len);
                uint256 flattenedPtr;
                assembly {
                    flattenedPtr := add(out_, 0x20)
                }
                for (i = 0; i < _list.length; i++) {
                    bytes memory item = _list[i];
                    uint256 listPtr;
                    assembly {
                        listPtr := add(item, 0x20)
                    }
                    _memcpy(flattenedPtr, listPtr, item.length);
                    flattenedPtr += _list[i].length;
                }
            }
        }
        // SPDX-License-Identifier: MIT
        pragma solidity ^0.8.0;
        /// @title Bytes
        /// @notice Bytes is a library for manipulating byte arrays.
        library Bytes {
            /// @custom:attribution https://github.com/GNSPS/solidity-bytes-utils
            /// @notice Slices a byte array with a given starting index and length. Returns a new byte array
            ///         as opposed to a pointer to the original array. Will throw if trying to slice more
            ///         bytes than exist in the array.
            /// @param _bytes Byte array to slice.
            /// @param _start Starting index of the slice.
            /// @param _length Length of the slice.
            /// @return Slice of the input byte array.
            function slice(bytes memory _bytes, uint256 _start, uint256 _length) internal pure returns (bytes memory) {
                unchecked {
                    require(_length + 31 >= _length, "slice_overflow");
                    require(_start + _length >= _start, "slice_overflow");
                    require(_bytes.length >= _start + _length, "slice_outOfBounds");
                }
                bytes memory tempBytes;
                assembly {
                    switch iszero(_length)
                    case 0 {
                        // Get a location of some free memory and store it in tempBytes as
                        // Solidity does for memory variables.
                        tempBytes := mload(0x40)
                        // The first word of the slice result is potentially a partial
                        // word read from the original array. To read it, we calculate
                        // the length of that partial word and start copying that many
                        // bytes into the array. The first word we copy will start with
                        // data we don't care about, but the last `lengthmod` bytes will
                        // land at the beginning of the contents of the new array. When
                        // we're done copying, we overwrite the full first word with
                        // the actual length of the slice.
                        let lengthmod := and(_length, 31)
                        // The multiplication in the next line is necessary
                        // because when slicing multiples of 32 bytes (lengthmod == 0)
                        // the following copy loop was copying the origin's length
                        // and then ending prematurely not copying everything it should.
                        let mc := add(add(tempBytes, lengthmod), mul(0x20, iszero(lengthmod)))
                        let end := add(mc, _length)
                        for {
                            // The multiplication in the next line has the same exact purpose
                            // as the one above.
                            let cc := add(add(add(_bytes, lengthmod), mul(0x20, iszero(lengthmod))), _start)
                        } lt(mc, end) {
                            mc := add(mc, 0x20)
                            cc := add(cc, 0x20)
                        } { mstore(mc, mload(cc)) }
                        mstore(tempBytes, _length)
                        //update free-memory pointer
                        //allocating the array padded to 32 bytes like the compiler does now
                        mstore(0x40, and(add(mc, 31), not(31)))
                    }
                    //if we want a zero-length slice let's just return a zero-length array
                    default {
                        tempBytes := mload(0x40)
                        //zero out the 32 bytes slice we are about to return
                        //we need to do it because Solidity does not garbage collect
                        mstore(tempBytes, 0)
                        mstore(0x40, add(tempBytes, 0x20))
                    }
                }
                return tempBytes;
            }
            /// @notice Slices a byte array with a given starting index up to the end of the original byte
            ///         array. Returns a new array rathern than a pointer to the original.
            /// @param _bytes Byte array to slice.
            /// @param _start Starting index of the slice.
            /// @return Slice of the input byte array.
            function slice(bytes memory _bytes, uint256 _start) internal pure returns (bytes memory) {
                if (_start >= _bytes.length) {
                    return bytes("");
                }
                return slice(_bytes, _start, _bytes.length - _start);
            }
            /// @notice Converts a byte array into a nibble array by splitting each byte into two nibbles.
            ///         Resulting nibble array will be exactly twice as long as the input byte array.
            /// @param _bytes Input byte array to convert.
            /// @return Resulting nibble array.
            function toNibbles(bytes memory _bytes) internal pure returns (bytes memory) {
                bytes memory _nibbles;
                assembly {
                    // Grab a free memory offset for the new array
                    _nibbles := mload(0x40)
                    // Load the length of the passed bytes array from memory
                    let bytesLength := mload(_bytes)
                    // Calculate the length of the new nibble array
                    // This is the length of the input array times 2
                    let nibblesLength := shl(0x01, bytesLength)
                    // Update the free memory pointer to allocate memory for the new array.
                    // To do this, we add the length of the new array + 32 bytes for the array length
                    // rounded up to the nearest 32 byte boundary to the current free memory pointer.
                    mstore(0x40, add(_nibbles, and(not(0x1F), add(nibblesLength, 0x3F))))
                    // Store the length of the new array in memory
                    mstore(_nibbles, nibblesLength)
                    // Store the memory offset of the _bytes array's contents on the stack
                    let bytesStart := add(_bytes, 0x20)
                    // Store the memory offset of the nibbles array's contents on the stack
                    let nibblesStart := add(_nibbles, 0x20)
                    // Loop through each byte in the input array
                    for { let i := 0x00 } lt(i, bytesLength) { i := add(i, 0x01) } {
                        // Get the starting offset of the next 2 bytes in the nibbles array
                        let offset := add(nibblesStart, shl(0x01, i))
                        // Load the byte at the current index within the `_bytes` array
                        let b := byte(0x00, mload(add(bytesStart, i)))
                        // Pull out the first nibble and store it in the new array
                        mstore8(offset, shr(0x04, b))
                        // Pull out the second nibble and store it in the new array
                        mstore8(add(offset, 0x01), and(b, 0x0F))
                    }
                }
                return _nibbles;
            }
            /// @notice Compares two byte arrays by comparing their keccak256 hashes.
            /// @param _bytes First byte array to compare.
            /// @param _other Second byte array to compare.
            /// @return True if the two byte arrays are equal, false otherwise.
            function equal(bytes memory _bytes, bytes memory _other) internal pure returns (bool) {
                return keccak256(_bytes) == keccak256(_other);
            }
        }
        // SPDX-License-Identifier: MIT
        pragma solidity ^0.8.8;
        import "./RLPErrors.sol";
        /// @custom:attribution https://github.com/hamdiallam/Solidity-RLP
        /// @title RLPReader
        /// @notice RLPReader is a library for parsing RLP-encoded byte arrays into Solidity types. Adapted
        ///         from Solidity-RLP (https://github.com/hamdiallam/Solidity-RLP) by Hamdi Allam with
        ///         various tweaks to improve readability.
        library RLPReader {
            /// @notice Custom pointer type to avoid confusion between pointers and uint256s.
            type MemoryPointer is uint256;
            /// @notice RLP item types.
            /// @custom:value DATA_ITEM Represents an RLP data item (NOT a list).
            /// @custom:value LIST_ITEM Represents an RLP list item.
            enum RLPItemType {
                DATA_ITEM,
                LIST_ITEM
            }
            /// @notice Struct representing an RLP item.
            /// @custom:field length Length of the RLP item.
            /// @custom:field ptr    Pointer to the RLP item in memory.
            struct RLPItem {
                uint256 length;
                MemoryPointer ptr;
            }
            /// @notice Max list length that this library will accept.
            uint256 internal constant MAX_LIST_LENGTH = 32;
            /// @notice Converts bytes to a reference to memory position and length.
            /// @param _in Input bytes to convert.
            /// @return out_ Output memory reference.
            function toRLPItem(bytes memory _in) internal pure returns (RLPItem memory out_) {
                // Empty arrays are not RLP items.
                if (_in.length == 0) revert EmptyItem();
                MemoryPointer ptr;
                assembly {
                    ptr := add(_in, 32)
                }
                out_ = RLPItem({ length: _in.length, ptr: ptr });
            }
            /// @notice Reads an RLP list value into a list of RLP items.
            /// @param _in RLP list value.
            /// @return out_ Decoded RLP list items.
            function readList(RLPItem memory _in) internal pure returns (RLPItem[] memory out_) {
                (uint256 listOffset, uint256 listLength, RLPItemType itemType) = _decodeLength(_in);
                if (itemType != RLPItemType.LIST_ITEM) revert UnexpectedString();
                if (listOffset + listLength != _in.length) revert InvalidDataRemainder();
                // Solidity in-memory arrays can't be increased in size, but *can* be decreased in size by
                // writing to the length. Since we can't know the number of RLP items without looping over
                // the entire input, we'd have to loop twice to accurately size this array. It's easier to
                // simply set a reasonable maximum list length and decrease the size before we finish.
                out_ = new RLPItem[](MAX_LIST_LENGTH);
                uint256 itemCount = 0;
                uint256 offset = listOffset;
                while (offset < _in.length) {
                    (uint256 itemOffset, uint256 itemLength,) = _decodeLength(
                        RLPItem({ length: _in.length - offset, ptr: MemoryPointer.wrap(MemoryPointer.unwrap(_in.ptr) + offset) })
                    );
                    // We don't need to check itemCount < out.length explicitly because Solidity already
                    // handles this check on our behalf, we'd just be wasting gas.
                    out_[itemCount] = RLPItem({
                        length: itemLength + itemOffset,
                        ptr: MemoryPointer.wrap(MemoryPointer.unwrap(_in.ptr) + offset)
                    });
                    itemCount += 1;
                    offset += itemOffset + itemLength;
                }
                // Decrease the array size to match the actual item count.
                assembly {
                    mstore(out_, itemCount)
                }
            }
            /// @notice Reads an RLP list value into a list of RLP items.
            /// @param _in RLP list value.
            /// @return out_ Decoded RLP list items.
            function readList(bytes memory _in) internal pure returns (RLPItem[] memory out_) {
                out_ = readList(toRLPItem(_in));
            }
            /// @notice Reads an RLP bytes value into bytes.
            /// @param _in RLP bytes value.
            /// @return out_ Decoded bytes.
            function readBytes(RLPItem memory _in) internal pure returns (bytes memory out_) {
                (uint256 itemOffset, uint256 itemLength, RLPItemType itemType) = _decodeLength(_in);
                if (itemType != RLPItemType.DATA_ITEM) revert UnexpectedList();
                if (_in.length != itemOffset + itemLength) revert InvalidDataRemainder();
                out_ = _copy(_in.ptr, itemOffset, itemLength);
            }
            /// @notice Reads an RLP bytes value into bytes.
            /// @param _in RLP bytes value.
            /// @return out_ Decoded bytes.
            function readBytes(bytes memory _in) internal pure returns (bytes memory out_) {
                out_ = readBytes(toRLPItem(_in));
            }
            /// @notice Reads the raw bytes of an RLP item.
            /// @param _in RLP item to read.
            /// @return out_ Raw RLP bytes.
            function readRawBytes(RLPItem memory _in) internal pure returns (bytes memory out_) {
                out_ = _copy(_in.ptr, 0, _in.length);
            }
            /// @notice Decodes the length of an RLP item.
            /// @param _in RLP item to decode.
            /// @return offset_ Offset of the encoded data.
            /// @return length_ Length of the encoded data.
            /// @return type_ RLP item type (LIST_ITEM or DATA_ITEM).
            function _decodeLength(RLPItem memory _in)
                private
                pure
                returns (uint256 offset_, uint256 length_, RLPItemType type_)
            {
                // Short-circuit if there's nothing to decode, note that we perform this check when
                // the user creates an RLP item via toRLPItem, but it's always possible for them to bypass
                // that function and create an RLP item directly. So we need to check this anyway.
                if (_in.length == 0) revert EmptyItem();
                MemoryPointer ptr = _in.ptr;
                uint256 prefix;
                assembly {
                    prefix := byte(0, mload(ptr))
                }
                if (prefix <= 0x7f) {
                    // Single byte.
                    return (0, 1, RLPItemType.DATA_ITEM);
                } else if (prefix <= 0xb7) {
                    // Short string.
                    // slither-disable-next-line variable-scope
                    uint256 strLen = prefix - 0x80;
                    if (_in.length <= strLen) revert ContentLengthMismatch();
                    bytes1 firstByteOfContent;
                    assembly {
                        firstByteOfContent := and(mload(add(ptr, 1)), shl(248, 0xff))
                    }
                    if (strLen == 1 && firstByteOfContent < 0x80) revert InvalidHeader();
                    return (1, strLen, RLPItemType.DATA_ITEM);
                } else if (prefix <= 0xbf) {
                    // Long string.
                    uint256 lenOfStrLen = prefix - 0xb7;
                    if (_in.length <= lenOfStrLen) revert ContentLengthMismatch();
                    bytes1 firstByteOfContent;
                    assembly {
                        firstByteOfContent := and(mload(add(ptr, 1)), shl(248, 0xff))
                    }
                    if (firstByteOfContent == 0x00) revert InvalidHeader();
                    uint256 strLen;
                    assembly {
                        strLen := shr(sub(256, mul(8, lenOfStrLen)), mload(add(ptr, 1)))
                    }
                    if (strLen <= 55) revert InvalidHeader();
                    if (_in.length <= lenOfStrLen + strLen) revert ContentLengthMismatch();
                    return (1 + lenOfStrLen, strLen, RLPItemType.DATA_ITEM);
                } else if (prefix <= 0xf7) {
                    // Short list.
                    // slither-disable-next-line variable-scope
                    uint256 listLen = prefix - 0xc0;
                    if (_in.length <= listLen) revert ContentLengthMismatch();
                    return (1, listLen, RLPItemType.LIST_ITEM);
                } else {
                    // Long list.
                    uint256 lenOfListLen = prefix - 0xf7;
                    if (_in.length <= lenOfListLen) revert ContentLengthMismatch();
                    bytes1 firstByteOfContent;
                    assembly {
                        firstByteOfContent := and(mload(add(ptr, 1)), shl(248, 0xff))
                    }
                    if (firstByteOfContent == 0x00) revert InvalidHeader();
                    uint256 listLen;
                    assembly {
                        listLen := shr(sub(256, mul(8, lenOfListLen)), mload(add(ptr, 1)))
                    }
                    if (listLen <= 55) revert InvalidHeader();
                    if (_in.length <= lenOfListLen + listLen) revert ContentLengthMismatch();
                    return (1 + lenOfListLen, listLen, RLPItemType.LIST_ITEM);
                }
            }
            /// @notice Copies the bytes from a memory location.
            /// @param _src    Pointer to the location to read from.
            /// @param _offset Offset to start reading from.
            /// @param _length Number of bytes to read.
            /// @return out_ Copied bytes.
            function _copy(MemoryPointer _src, uint256 _offset, uint256 _length) private pure returns (bytes memory out_) {
                out_ = new bytes(_length);
                if (_length == 0) {
                    return out_;
                }
                // Mostly based on Solidity's copy_memory_to_memory:
                // https://github.com/ethereum/solidity/blob/34dd30d71b4da730488be72ff6af7083cf2a91f6/libsolidity/codegen/YulUtilFunctions.cpp#L102-L114
                uint256 src = MemoryPointer.unwrap(_src) + _offset;
                assembly {
                    let dest := add(out_, 32)
                    let i := 0
                    for { } lt(i, _length) { i := add(i, 32) } { mstore(add(dest, i), mload(add(src, i))) }
                    if gt(i, _length) { mstore(add(dest, _length), 0) }
                }
            }
        }
        // SPDX-License-Identifier: MIT
        // OpenZeppelin Contracts (last updated v4.5.0) (utils/math/SignedMath.sol)
        pragma solidity ^0.8.0;
        /**
         * @dev Standard signed math utilities missing in the Solidity language.
         */
        library SignedMath {
            /**
             * @dev Returns the largest of two signed numbers.
             */
            function max(int256 a, int256 b) internal pure returns (int256) {
                return a >= b ? a : b;
            }
            /**
             * @dev Returns the smallest of two signed numbers.
             */
            function min(int256 a, int256 b) internal pure returns (int256) {
                return a < b ? a : b;
            }
            /**
             * @dev Returns the average of two signed numbers without overflow.
             * The result is rounded towards zero.
             */
            function average(int256 a, int256 b) internal pure returns (int256) {
                // Formula from the book "Hacker's Delight"
                int256 x = (a & b) + ((a ^ b) >> 1);
                return x + (int256(uint256(x) >> 255) & (a ^ b));
            }
            /**
             * @dev Returns the absolute unsigned value of a signed value.
             */
            function abs(int256 n) internal pure returns (uint256) {
                unchecked {
                    // must be unchecked in order to support `n = type(int256).min`
                    return uint256(n >= 0 ? n : -n);
                }
            }
        }
        // SPDX-License-Identifier: MIT
        pragma solidity >=0.8.0;
        /// @notice Arithmetic library with operations for fixed-point numbers.
        /// @author Solmate (https://github.com/Rari-Capital/solmate/blob/main/src/utils/FixedPointMathLib.sol)
        library FixedPointMathLib {
            /*//////////////////////////////////////////////////////////////
                            SIMPLIFIED FIXED POINT OPERATIONS
            //////////////////////////////////////////////////////////////*/
            uint256 internal constant WAD = 1e18; // The scalar of ETH and most ERC20s.
            function mulWadDown(uint256 x, uint256 y) internal pure returns (uint256) {
                return mulDivDown(x, y, WAD); // Equivalent to (x * y) / WAD rounded down.
            }
            function mulWadUp(uint256 x, uint256 y) internal pure returns (uint256) {
                return mulDivUp(x, y, WAD); // Equivalent to (x * y) / WAD rounded up.
            }
            function divWadDown(uint256 x, uint256 y) internal pure returns (uint256) {
                return mulDivDown(x, WAD, y); // Equivalent to (x * WAD) / y rounded down.
            }
            function divWadUp(uint256 x, uint256 y) internal pure returns (uint256) {
                return mulDivUp(x, WAD, y); // Equivalent to (x * WAD) / y rounded up.
            }
            function powWad(int256 x, int256 y) internal pure returns (int256) {
                // Equivalent to x to the power of y because x ** y = (e ** ln(x)) ** y = e ** (ln(x) * y)
                return expWad((lnWad(x) * y) / int256(WAD)); // Using ln(x) means x must be greater than 0.
            }
            function expWad(int256 x) internal pure returns (int256 r) {
                unchecked {
                    // When the result is < 0.5 we return zero. This happens when
                    // x <= floor(log(0.5e18) * 1e18) ~ -42e18
                    if (x <= -42139678854452767551) return 0;
                    // When the result is > (2**255 - 1) / 1e18 we can not represent it as an
                    // int. This happens when x >= floor(log((2**255 - 1) / 1e18) * 1e18) ~ 135.
                    if (x >= 135305999368893231589) revert("EXP_OVERFLOW");
                    // x is now in the range (-42, 136) * 1e18. Convert to (-42, 136) * 2**96
                    // for more intermediate precision and a binary basis. This base conversion
                    // is a multiplication by 1e18 / 2**96 = 5**18 / 2**78.
                    x = (x << 78) / 5**18;
                    // Reduce range of x to (-½ ln 2, ½ ln 2) * 2**96 by factoring out powers
                    // of two such that exp(x) = exp(x') * 2**k, where k is an integer.
                    // Solving this gives k = round(x / log(2)) and x' = x - k * log(2).
                    int256 k = ((x << 96) / 54916777467707473351141471128 + 2**95) >> 96;
                    x = x - k * 54916777467707473351141471128;
                    // k is in the range [-61, 195].
                    // Evaluate using a (6, 7)-term rational approximation.
                    // p is made monic, we'll multiply by a scale factor later.
                    int256 y = x + 1346386616545796478920950773328;
                    y = ((y * x) >> 96) + 57155421227552351082224309758442;
                    int256 p = y + x - 94201549194550492254356042504812;
                    p = ((p * y) >> 96) + 28719021644029726153956944680412240;
                    p = p * x + (4385272521454847904659076985693276 << 96);
                    // We leave p in 2**192 basis so we don't need to scale it back up for the division.
                    int256 q = x - 2855989394907223263936484059900;
                    q = ((q * x) >> 96) + 50020603652535783019961831881945;
                    q = ((q * x) >> 96) - 533845033583426703283633433725380;
                    q = ((q * x) >> 96) + 3604857256930695427073651918091429;
                    q = ((q * x) >> 96) - 14423608567350463180887372962807573;
                    q = ((q * x) >> 96) + 26449188498355588339934803723976023;
                    assembly {
                        // Div in assembly because solidity adds a zero check despite the unchecked.
                        // The q polynomial won't have zeros in the domain as all its roots are complex.
                        // No scaling is necessary because p is already 2**96 too large.
                        r := sdiv(p, q)
                    }
                    // r should be in the range (0.09, 0.25) * 2**96.
                    // We now need to multiply r by:
                    // * the scale factor s = ~6.031367120.
                    // * the 2**k factor from the range reduction.
                    // * the 1e18 / 2**96 factor for base conversion.
                    // We do this all at once, with an intermediate result in 2**213
                    // basis, so the final right shift is always by a positive amount.
                    r = int256((uint256(r) * 3822833074963236453042738258902158003155416615667) >> uint256(195 - k));
                }
            }
            function lnWad(int256 x) internal pure returns (int256 r) {
                unchecked {
                    require(x > 0, "UNDEFINED");
                    // We want to convert x from 10**18 fixed point to 2**96 fixed point.
                    // We do this by multiplying by 2**96 / 10**18. But since
                    // ln(x * C) = ln(x) + ln(C), we can simply do nothing here
                    // and add ln(2**96 / 10**18) at the end.
                    // Reduce range of x to (1, 2) * 2**96
                    // ln(2^k * x) = k * ln(2) + ln(x)
                    int256 k = int256(log2(uint256(x))) - 96;
                    x <<= uint256(159 - k);
                    x = int256(uint256(x) >> 159);
                    // Evaluate using a (8, 8)-term rational approximation.
                    // p is made monic, we will multiply by a scale factor later.
                    int256 p = x + 3273285459638523848632254066296;
                    p = ((p * x) >> 96) + 24828157081833163892658089445524;
                    p = ((p * x) >> 96) + 43456485725739037958740375743393;
                    p = ((p * x) >> 96) - 11111509109440967052023855526967;
                    p = ((p * x) >> 96) - 45023709667254063763336534515857;
                    p = ((p * x) >> 96) - 14706773417378608786704636184526;
                    p = p * x - (795164235651350426258249787498 << 96);
                    // We leave p in 2**192 basis so we don't need to scale it back up for the division.
                    // q is monic by convention.
                    int256 q = x + 5573035233440673466300451813936;
                    q = ((q * x) >> 96) + 71694874799317883764090561454958;
                    q = ((q * x) >> 96) + 283447036172924575727196451306956;
                    q = ((q * x) >> 96) + 401686690394027663651624208769553;
                    q = ((q * x) >> 96) + 204048457590392012362485061816622;
                    q = ((q * x) >> 96) + 31853899698501571402653359427138;
                    q = ((q * x) >> 96) + 909429971244387300277376558375;
                    assembly {
                        // Div in assembly because solidity adds a zero check despite the unchecked.
                        // The q polynomial is known not to have zeros in the domain.
                        // No scaling required because p is already 2**96 too large.
                        r := sdiv(p, q)
                    }
                    // r is in the range (0, 0.125) * 2**96
                    // Finalization, we need to:
                    // * multiply by the scale factor s = 5.549…
                    // * add ln(2**96 / 10**18)
                    // * add k * ln(2)
                    // * multiply by 10**18 / 2**96 = 5**18 >> 78
                    // mul s * 5e18 * 2**96, base is now 5**18 * 2**192
                    r *= 1677202110996718588342820967067443963516166;
                    // add ln(2) * k * 5e18 * 2**192
                    r += 16597577552685614221487285958193947469193820559219878177908093499208371 * k;
                    // add ln(2**96 / 10**18) * 5e18 * 2**192
                    r += 600920179829731861736702779321621459595472258049074101567377883020018308;
                    // base conversion: mul 2**18 / 2**192
                    r >>= 174;
                }
            }
            /*//////////////////////////////////////////////////////////////
                            LOW LEVEL FIXED POINT OPERATIONS
            //////////////////////////////////////////////////////////////*/
            function mulDivDown(
                uint256 x,
                uint256 y,
                uint256 denominator
            ) internal pure returns (uint256 z) {
                assembly {
                    // Store x * y in z for now.
                    z := mul(x, y)
                    // Equivalent to require(denominator != 0 && (x == 0 || (x * y) / x == y))
                    if iszero(and(iszero(iszero(denominator)), or(iszero(x), eq(div(z, x), y)))) {
                        revert(0, 0)
                    }
                    // Divide z by the denominator.
                    z := div(z, denominator)
                }
            }
            function mulDivUp(
                uint256 x,
                uint256 y,
                uint256 denominator
            ) internal pure returns (uint256 z) {
                assembly {
                    // Store x * y in z for now.
                    z := mul(x, y)
                    // Equivalent to require(denominator != 0 && (x == 0 || (x * y) / x == y))
                    if iszero(and(iszero(iszero(denominator)), or(iszero(x), eq(div(z, x), y)))) {
                        revert(0, 0)
                    }
                    // First, divide z - 1 by the denominator and add 1.
                    // We allow z - 1 to underflow if z is 0, because we multiply the
                    // end result by 0 if z is zero, ensuring we return 0 if z is zero.
                    z := mul(iszero(iszero(z)), add(div(sub(z, 1), denominator), 1))
                }
            }
            function rpow(
                uint256 x,
                uint256 n,
                uint256 scalar
            ) internal pure returns (uint256 z) {
                assembly {
                    switch x
                    case 0 {
                        switch n
                        case 0 {
                            // 0 ** 0 = 1
                            z := scalar
                        }
                        default {
                            // 0 ** n = 0
                            z := 0
                        }
                    }
                    default {
                        switch mod(n, 2)
                        case 0 {
                            // If n is even, store scalar in z for now.
                            z := scalar
                        }
                        default {
                            // If n is odd, store x in z for now.
                            z := x
                        }
                        // Shifting right by 1 is like dividing by 2.
                        let half := shr(1, scalar)
                        for {
                            // Shift n right by 1 before looping to halve it.
                            n := shr(1, n)
                        } n {
                            // Shift n right by 1 each iteration to halve it.
                            n := shr(1, n)
                        } {
                            // Revert immediately if x ** 2 would overflow.
                            // Equivalent to iszero(eq(div(xx, x), x)) here.
                            if shr(128, x) {
                                revert(0, 0)
                            }
                            // Store x squared.
                            let xx := mul(x, x)
                            // Round to the nearest number.
                            let xxRound := add(xx, half)
                            // Revert if xx + half overflowed.
                            if lt(xxRound, xx) {
                                revert(0, 0)
                            }
                            // Set x to scaled xxRound.
                            x := div(xxRound, scalar)
                            // If n is even:
                            if mod(n, 2) {
                                // Compute z * x.
                                let zx := mul(z, x)
                                // If z * x overflowed:
                                if iszero(eq(div(zx, x), z)) {
                                    // Revert if x is non-zero.
                                    if iszero(iszero(x)) {
                                        revert(0, 0)
                                    }
                                }
                                // Round to the nearest number.
                                let zxRound := add(zx, half)
                                // Revert if zx + half overflowed.
                                if lt(zxRound, zx) {
                                    revert(0, 0)
                                }
                                // Return properly scaled zxRound.
                                z := div(zxRound, scalar)
                            }
                        }
                    }
                }
            }
            /*//////////////////////////////////////////////////////////////
                                GENERAL NUMBER UTILITIES
            //////////////////////////////////////////////////////////////*/
            function sqrt(uint256 x) internal pure returns (uint256 z) {
                assembly {
                    let y := x // We start y at x, which will help us make our initial estimate.
                    z := 181 // The "correct" value is 1, but this saves a multiplication later.
                    // This segment is to get a reasonable initial estimate for the Babylonian method. With a bad
                    // start, the correct # of bits increases ~linearly each iteration instead of ~quadratically.
                    // We check y >= 2^(k + 8) but shift right by k bits
                    // each branch to ensure that if x >= 256, then y >= 256.
                    if iszero(lt(y, 0x10000000000000000000000000000000000)) {
                        y := shr(128, y)
                        z := shl(64, z)
                    }
                    if iszero(lt(y, 0x1000000000000000000)) {
                        y := shr(64, y)
                        z := shl(32, z)
                    }
                    if iszero(lt(y, 0x10000000000)) {
                        y := shr(32, y)
                        z := shl(16, z)
                    }
                    if iszero(lt(y, 0x1000000)) {
                        y := shr(16, y)
                        z := shl(8, z)
                    }
                    // Goal was to get z*z*y within a small factor of x. More iterations could
                    // get y in a tighter range. Currently, we will have y in [256, 256*2^16).
                    // We ensured y >= 256 so that the relative difference between y and y+1 is small.
                    // That's not possible if x < 256 but we can just verify those cases exhaustively.
                    // Now, z*z*y <= x < z*z*(y+1), and y <= 2^(16+8), and either y >= 256, or x < 256.
                    // Correctness can be checked exhaustively for x < 256, so we assume y >= 256.
                    // Then z*sqrt(y) is within sqrt(257)/sqrt(256) of sqrt(x), or about 20bps.
                    // For s in the range [1/256, 256], the estimate f(s) = (181/1024) * (s+1) is in the range
                    // (1/2.84 * sqrt(s), 2.84 * sqrt(s)), with largest error when s = 1 and when s = 256 or 1/256.
                    // Since y is in [256, 256*2^16), let a = y/65536, so that a is in [1/256, 256). Then we can estimate
                    // sqrt(y) using sqrt(65536) * 181/1024 * (a + 1) = 181/4 * (y + 65536)/65536 = 181 * (y + 65536)/2^18.
                    // There is no overflow risk here since y < 2^136 after the first branch above.
                    z := shr(18, mul(z, add(y, 65536))) // A mul() is saved from starting z at 181.
                    // Given the worst case multiplicative error of 2.84 above, 7 iterations should be enough.
                    z := shr(1, add(z, div(x, z)))
                    z := shr(1, add(z, div(x, z)))
                    z := shr(1, add(z, div(x, z)))
                    z := shr(1, add(z, div(x, z)))
                    z := shr(1, add(z, div(x, z)))
                    z := shr(1, add(z, div(x, z)))
                    z := shr(1, add(z, div(x, z)))
                    // If x+1 is a perfect square, the Babylonian method cycles between
                    // floor(sqrt(x)) and ceil(sqrt(x)). This statement ensures we return floor.
                    // See: https://en.wikipedia.org/wiki/Integer_square_root#Using_only_integer_division
                    // Since the ceil is rare, we save gas on the assignment and repeat division in the rare case.
                    // If you don't care whether the floor or ceil square root is returned, you can remove this statement.
                    z := sub(z, lt(div(x, z), z))
                }
            }
            function log2(uint256 x) internal pure returns (uint256 r) {
                require(x > 0, "UNDEFINED");
                assembly {
                    r := shl(7, lt(0xffffffffffffffffffffffffffffffff, x))
                    r := or(r, shl(6, lt(0xffffffffffffffff, shr(r, x))))
                    r := or(r, shl(5, lt(0xffffffff, shr(r, x))))
                    r := or(r, shl(4, lt(0xffff, shr(r, x))))
                    r := or(r, shl(3, lt(0xff, shr(r, x))))
                    r := or(r, shl(2, lt(0xf, shr(r, x))))
                    r := or(r, shl(1, lt(0x3, shr(r, x))))
                    r := or(r, lt(0x1, shr(r, x)))
                }
            }
        }
        // SPDX-License-Identifier: MIT
        pragma solidity ^0.8.15;
        using LibPosition for Position global;
        /// @notice A `Position` represents a position of a claim within the game tree.
        /// @dev This is represented as a "generalized index" where the high-order bit
        /// is the level in the tree and the remaining bits is a unique bit pattern, allowing
        /// a unique identifier for each node in the tree. Mathematically, it is calculated
        /// as 2^{depth} + indexAtDepth.
        type Position is uint128;
        /// @title LibPosition
        /// @notice This library contains helper functions for working with the `Position` type.
        library LibPosition {
            /// @notice the `MAX_POSITION_BITLEN` is the number of bits that the `Position` type, and the implementation of
            ///         its behavior within this library, can safely support.
            uint8 internal constant MAX_POSITION_BITLEN = 126;
            /// @notice Computes a generalized index (2^{depth} + indexAtDepth).
            /// @param _depth The depth of the position.
            /// @param _indexAtDepth The index at the depth of the position.
            /// @return position_ The computed generalized index.
            function wrap(uint8 _depth, uint128 _indexAtDepth) internal pure returns (Position position_) {
                assembly {
                    // gindex = 2^{_depth} + _indexAtDepth
                    position_ := add(shl(_depth, 1), _indexAtDepth)
                }
            }
            /// @notice Pulls the `depth` out of a `Position` type.
            /// @param _position The generalized index to get the `depth` of.
            /// @return depth_ The `depth` of the `position` gindex.
            /// @custom:attribution Solady <https://github.com/Vectorized/Solady>
            function depth(Position _position) internal pure returns (uint8 depth_) {
                // Return the most significant bit offset, which signifies the depth of the gindex.
                assembly {
                    depth_ := or(depth_, shl(6, lt(0xffffffffffffffff, shr(depth_, _position))))
                    depth_ := or(depth_, shl(5, lt(0xffffffff, shr(depth_, _position))))
                    // For the remaining 32 bits, use a De Bruijn lookup.
                    _position := shr(depth_, _position)
                    _position := or(_position, shr(1, _position))
                    _position := or(_position, shr(2, _position))
                    _position := or(_position, shr(4, _position))
                    _position := or(_position, shr(8, _position))
                    _position := or(_position, shr(16, _position))
                    depth_ :=
                        or(
                            depth_,
                            byte(
                                shr(251, mul(_position, shl(224, 0x07c4acdd))),
                                0x0009010a0d15021d0b0e10121619031e080c141c0f111807131b17061a05041f
                            )
                        )
                }
            }
            /// @notice Pulls the `indexAtDepth` out of a `Position` type.
            ///         The `indexAtDepth` is the left/right index of a position at a specific depth within
            ///         the binary tree, starting from index 0. For example, at gindex 2, the `depth` = 1
            ///         and the `indexAtDepth` = 0.
            /// @param _position The generalized index to get the `indexAtDepth` of.
            /// @return indexAtDepth_ The `indexAtDepth` of the `position` gindex.
            function indexAtDepth(Position _position) internal pure returns (uint128 indexAtDepth_) {
                // Return bits p_{msb-1}...p_{0}. This effectively pulls the 2^{depth} out of the gindex,
                // leaving only the `indexAtDepth`.
                uint256 msb = depth(_position);
                assembly {
                    indexAtDepth_ := sub(_position, shl(msb, 1))
                }
            }
            /// @notice Get the left child of `_position`.
            /// @param _position The position to get the left position of.
            /// @return left_ The position to the left of `position`.
            function left(Position _position) internal pure returns (Position left_) {
                assembly {
                    left_ := shl(1, _position)
                }
            }
            /// @notice Get the right child of `_position`
            /// @param _position The position to get the right position of.
            /// @return right_ The position to the right of `position`.
            function right(Position _position) internal pure returns (Position right_) {
                assembly {
                    right_ := or(1, shl(1, _position))
                }
            }
            /// @notice Get the parent position of `_position`.
            /// @param _position The position to get the parent position of.
            /// @return parent_ The parent position of `position`.
            function parent(Position _position) internal pure returns (Position parent_) {
                assembly {
                    parent_ := shr(1, _position)
                }
            }
            /// @notice Get the deepest, right most gindex relative to the `position`. This is equivalent to
            ///         calling `right` on a position until the maximum depth is reached.
            /// @param _position The position to get the relative deepest, right most gindex of.
            /// @param _maxDepth The maximum depth of the game.
            /// @return rightIndex_ The deepest, right most gindex relative to the `position`.
            function rightIndex(Position _position, uint256 _maxDepth) internal pure returns (Position rightIndex_) {
                uint256 msb = depth(_position);
                assembly {
                    let remaining := sub(_maxDepth, msb)
                    rightIndex_ := or(shl(remaining, _position), sub(shl(remaining, 1), 1))
                }
            }
            /// @notice Get the deepest, right most trace index relative to the `position`. This is
            ///         equivalent to calling `right` on a position until the maximum depth is reached and
            ///         then finding its index at depth.
            /// @param _position The position to get the relative trace index of.
            /// @param _maxDepth The maximum depth of the game.
            /// @return traceIndex_ The trace index relative to the `position`.
            function traceIndex(Position _position, uint256 _maxDepth) internal pure returns (uint256 traceIndex_) {
                uint256 msb = depth(_position);
                assembly {
                    let remaining := sub(_maxDepth, msb)
                    traceIndex_ := sub(or(shl(remaining, _position), sub(shl(remaining, 1), 1)), shl(_maxDepth, 1))
                }
            }
            /// @notice Gets the position of the highest ancestor of `_position` that commits to the same
            ///         trace index.
            /// @param _position The position to get the highest ancestor of.
            /// @return ancestor_ The highest ancestor of `position` that commits to the same trace index.
            function traceAncestor(Position _position) internal pure returns (Position ancestor_) {
                // Create a field with only the lowest unset bit of `_position` set.
                Position lsb;
                assembly {
                    lsb := and(not(_position), add(_position, 1))
                }
                // Find the index of the lowest unset bit within the field.
                uint256 msb = depth(lsb);
                // The highest ancestor that commits to the same trace index is the original position
                // shifted right by the index of the lowest unset bit.
                assembly {
                    let a := shr(msb, _position)
                    // Bound the ancestor to the minimum gindex, 1.
                    ancestor_ := or(a, iszero(a))
                }
            }
            /// @notice Gets the position of the highest ancestor of `_position` that commits to the same
            ///         trace index, while still being below `_upperBoundExclusive`.
            /// @param _position The position to get the highest ancestor of.
            /// @param _upperBoundExclusive The exclusive upper depth bound, used to inform where to stop in order
            ///                             to not escape a sub-tree.
            /// @return ancestor_ The highest ancestor of `position` that commits to the same trace index.
            function traceAncestorBounded(
                Position _position,
                uint256 _upperBoundExclusive
            )
                internal
                pure
                returns (Position ancestor_)
            {
                // This function only works for positions that are below the upper bound.
                if (_position.depth() <= _upperBoundExclusive) {
                    assembly {
                        // Revert with `ClaimAboveSplit()`
                        mstore(0x00, 0xb34b5c22)
                        revert(0x1C, 0x04)
                    }
                }
                // Grab the global trace ancestor.
                ancestor_ = traceAncestor(_position);
                // If the ancestor is above or at the upper bound, shift it to be below the upper bound.
                // This should be a special case that only covers positions that commit to the final leaf
                // in a sub-tree.
                if (ancestor_.depth() <= _upperBoundExclusive) {
                    ancestor_ = ancestor_.rightIndex(_upperBoundExclusive + 1);
                }
            }
            /// @notice Get the move position of `_position`, which is the left child of:
            ///         1. `_position` if `_isAttack` is true.
            ///         2. `_position | 1` if `_isAttack` is false.
            /// @param _position The position to get the relative attack/defense position of.
            /// @param _isAttack Whether or not the move is an attack move.
            /// @return move_ The move position relative to `position`.
            function move(Position _position, bool _isAttack) internal pure returns (Position move_) {
                assembly {
                    move_ := shl(1, or(iszero(_isAttack), _position))
                }
            }
            /// @notice Get the value of a `Position` type in the form of the underlying uint128.
            /// @param _position The position to get the value of.
            /// @return raw_ The value of the `position` as a uint128 type.
            function raw(Position _position) internal pure returns (uint128 raw_) {
                assembly {
                    raw_ := _position
                }
            }
        }
        // SPDX-License-Identifier: MIT
        // OpenZeppelin Contracts (last updated v4.7.0) (utils/Address.sol)
        pragma solidity ^0.8.1;
        /**
         * @dev Collection of functions related to the address type
         */
        library AddressUpgradeable {
            /**
             * @dev Returns true if `account` is a contract.
             *
             * [IMPORTANT]
             * ====
             * It is unsafe to assume that an address for which this function returns
             * false is an externally-owned account (EOA) and not a contract.
             *
             * Among others, `isContract` will return false for the following
             * types of addresses:
             *
             *  - an externally-owned account
             *  - a contract in construction
             *  - an address where a contract will be created
             *  - an address where a contract lived, but was destroyed
             * ====
             *
             * [IMPORTANT]
             * ====
             * You shouldn't rely on `isContract` to protect against flash loan attacks!
             *
             * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
             * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
             * constructor.
             * ====
             */
            function isContract(address account) internal view returns (bool) {
                // This method relies on extcodesize/address.code.length, which returns 0
                // for contracts in construction, since the code is only stored at the end
                // of the constructor execution.
                return account.code.length > 0;
            }
            /**
             * @dev Replacement for Solidity's `transfer`: sends `amount` wei to
             * `recipient`, forwarding all available gas and reverting on errors.
             *
             * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
             * of certain opcodes, possibly making contracts go over the 2300 gas limit
             * imposed by `transfer`, making them unable to receive funds via
             * `transfer`. {sendValue} removes this limitation.
             *
             * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
             *
             * IMPORTANT: because control is transferred to `recipient`, care must be
             * taken to not create reentrancy vulnerabilities. Consider using
             * {ReentrancyGuard} or the
             * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
             */
            function sendValue(address payable recipient, uint256 amount) internal {
                require(address(this).balance >= amount, "Address: insufficient balance");
                (bool success, ) = recipient.call{value: amount}("");
                require(success, "Address: unable to send value, recipient may have reverted");
            }
            /**
             * @dev Performs a Solidity function call using a low level `call`. A
             * plain `call` is an unsafe replacement for a function call: use this
             * function instead.
             *
             * If `target` reverts with a revert reason, it is bubbled up by this
             * function (like regular Solidity function calls).
             *
             * Returns the raw returned data. To convert to the expected return value,
             * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
             *
             * Requirements:
             *
             * - `target` must be a contract.
             * - calling `target` with `data` must not revert.
             *
             * _Available since v3.1._
             */
            function functionCall(address target, bytes memory data) internal returns (bytes memory) {
                return functionCall(target, data, "Address: low-level call failed");
            }
            /**
             * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
             * `errorMessage` as a fallback revert reason when `target` reverts.
             *
             * _Available since v3.1._
             */
            function functionCall(
                address target,
                bytes memory data,
                string memory errorMessage
            ) internal returns (bytes memory) {
                return functionCallWithValue(target, data, 0, errorMessage);
            }
            /**
             * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
             * but also transferring `value` wei to `target`.
             *
             * Requirements:
             *
             * - the calling contract must have an ETH balance of at least `value`.
             * - the called Solidity function must be `payable`.
             *
             * _Available since v3.1._
             */
            function functionCallWithValue(
                address target,
                bytes memory data,
                uint256 value
            ) internal returns (bytes memory) {
                return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
            }
            /**
             * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
             * with `errorMessage` as a fallback revert reason when `target` reverts.
             *
             * _Available since v3.1._
             */
            function functionCallWithValue(
                address target,
                bytes memory data,
                uint256 value,
                string memory errorMessage
            ) internal returns (bytes memory) {
                require(address(this).balance >= value, "Address: insufficient balance for call");
                require(isContract(target), "Address: call to non-contract");
                (bool success, bytes memory returndata) = target.call{value: value}(data);
                return verifyCallResult(success, returndata, errorMessage);
            }
            /**
             * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
             * but performing a static call.
             *
             * _Available since v3.3._
             */
            function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
                return functionStaticCall(target, data, "Address: low-level static call failed");
            }
            /**
             * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
             * but performing a static call.
             *
             * _Available since v3.3._
             */
            function functionStaticCall(
                address target,
                bytes memory data,
                string memory errorMessage
            ) internal view returns (bytes memory) {
                require(isContract(target), "Address: static call to non-contract");
                (bool success, bytes memory returndata) = target.staticcall(data);
                return verifyCallResult(success, returndata, errorMessage);
            }
            /**
             * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the
             * revert reason using the provided one.
             *
             * _Available since v4.3._
             */
            function verifyCallResult(
                bool success,
                bytes memory returndata,
                string memory errorMessage
            ) internal pure returns (bytes memory) {
                if (success) {
                    return returndata;
                } else {
                    // Look for revert reason and bubble it up if present
                    if (returndata.length > 0) {
                        // The easiest way to bubble the revert reason is using memory via assembly
                        /// @solidity memory-safe-assembly
                        assembly {
                            let returndata_size := mload(returndata)
                            revert(add(32, returndata), returndata_size)
                        }
                    } else {
                        revert(errorMessage);
                    }
                }
            }
        }
        // SPDX-License-Identifier: MIT
        pragma solidity 0.8.15;
        /// @notice The length of an RLP item must be greater than zero to be decodable
        error EmptyItem();
        /// @notice The decoded item type for list is not a list item
        error UnexpectedString();
        /// @notice The RLP item has an invalid data remainder
        error InvalidDataRemainder();
        /// @notice Decoded item type for bytes is not a string item
        error UnexpectedList();
        /// @notice The length of the content must be greater than the RLP item length
        error ContentLengthMismatch();
        /// @notice Invalid RLP header for RLP item
        error InvalidHeader();
        

        File 3 of 4: Proxy
        // SPDX-License-Identifier: MIT
        pragma solidity 0.8.15;
        /**
         * @title Proxy
         * @notice Proxy is a transparent proxy that passes through the call if the caller is the owner or
         *         if the caller is address(0), meaning that the call originated from an off-chain
         *         simulation.
         */
        contract Proxy {
            /**
             * @notice The storage slot that holds the address of the implementation.
             *         bytes32(uint256(keccak256('eip1967.proxy.implementation')) - 1)
             */
            bytes32 internal constant IMPLEMENTATION_KEY =
                0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
            /**
             * @notice The storage slot that holds the address of the owner.
             *         bytes32(uint256(keccak256('eip1967.proxy.admin')) - 1)
             */
            bytes32 internal constant OWNER_KEY =
                0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103;
            /**
             * @notice An event that is emitted each time the implementation is changed. This event is part
             *         of the EIP-1967 specification.
             *
             * @param implementation The address of the implementation contract
             */
            event Upgraded(address indexed implementation);
            /**
             * @notice An event that is emitted each time the owner is upgraded. This event is part of the
             *         EIP-1967 specification.
             *
             * @param previousAdmin The previous owner of the contract
             * @param newAdmin      The new owner of the contract
             */
            event AdminChanged(address previousAdmin, address newAdmin);
            /**
             * @notice A modifier that reverts if not called by the owner or by address(0) to allow
             *         eth_call to interact with this proxy without needing to use low-level storage
             *         inspection. We assume that nobody is able to trigger calls from address(0) during
             *         normal EVM execution.
             */
            modifier proxyCallIfNotAdmin() {
                if (msg.sender == _getAdmin() || msg.sender == address(0)) {
                    _;
                } else {
                    // This WILL halt the call frame on completion.
                    _doProxyCall();
                }
            }
            /**
             * @notice Sets the initial admin during contract deployment. Admin address is stored at the
             *         EIP-1967 admin storage slot so that accidental storage collision with the
             *         implementation is not possible.
             *
             * @param _admin Address of the initial contract admin. Admin as the ability to access the
             *               transparent proxy interface.
             */
            constructor(address _admin) {
                _changeAdmin(_admin);
            }
            // slither-disable-next-line locked-ether
            receive() external payable {
                // Proxy call by default.
                _doProxyCall();
            }
            // slither-disable-next-line locked-ether
            fallback() external payable {
                // Proxy call by default.
                _doProxyCall();
            }
            /**
             * @notice Set the implementation contract address. The code at the given address will execute
             *         when this contract is called.
             *
             * @param _implementation Address of the implementation contract.
             */
            function upgradeTo(address _implementation) public virtual proxyCallIfNotAdmin {
                _setImplementation(_implementation);
            }
            /**
             * @notice Set the implementation and call a function in a single transaction. Useful to ensure
             *         atomic execution of initialization-based upgrades.
             *
             * @param _implementation Address of the implementation contract.
             * @param _data           Calldata to delegatecall the new implementation with.
             */
            function upgradeToAndCall(address _implementation, bytes calldata _data)
                public
                payable
                virtual
                proxyCallIfNotAdmin
                returns (bytes memory)
            {
                _setImplementation(_implementation);
                (bool success, bytes memory returndata) = _implementation.delegatecall(_data);
                require(success, "Proxy: delegatecall to new implementation contract failed");
                return returndata;
            }
            /**
             * @notice Changes the owner of the proxy contract. Only callable by the owner.
             *
             * @param _admin New owner of the proxy contract.
             */
            function changeAdmin(address _admin) public virtual proxyCallIfNotAdmin {
                _changeAdmin(_admin);
            }
            /**
             * @notice Gets the owner of the proxy contract.
             *
             * @return Owner address.
             */
            function admin() public virtual proxyCallIfNotAdmin returns (address) {
                return _getAdmin();
            }
            /**
             * @notice Queries the implementation address.
             *
             * @return Implementation address.
             */
            function implementation() public virtual proxyCallIfNotAdmin returns (address) {
                return _getImplementation();
            }
            /**
             * @notice Sets the implementation address.
             *
             * @param _implementation New implementation address.
             */
            function _setImplementation(address _implementation) internal {
                assembly {
                    sstore(IMPLEMENTATION_KEY, _implementation)
                }
                emit Upgraded(_implementation);
            }
            /**
             * @notice Changes the owner of the proxy contract.
             *
             * @param _admin New owner of the proxy contract.
             */
            function _changeAdmin(address _admin) internal {
                address previous = _getAdmin();
                assembly {
                    sstore(OWNER_KEY, _admin)
                }
                emit AdminChanged(previous, _admin);
            }
            /**
             * @notice Performs the proxy call via a delegatecall.
             */
            function _doProxyCall() internal {
                address impl = _getImplementation();
                require(impl != address(0), "Proxy: implementation not initialized");
                assembly {
                    // Copy calldata into memory at 0x0....calldatasize.
                    calldatacopy(0x0, 0x0, calldatasize())
                    // Perform the delegatecall, make sure to pass all available gas.
                    let success := delegatecall(gas(), impl, 0x0, calldatasize(), 0x0, 0x0)
                    // Copy returndata into memory at 0x0....returndatasize. Note that this *will*
                    // overwrite the calldata that we just copied into memory but that doesn't really
                    // matter because we'll be returning in a second anyway.
                    returndatacopy(0x0, 0x0, returndatasize())
                    // Success == 0 means a revert. We'll revert too and pass the data up.
                    if iszero(success) {
                        revert(0x0, returndatasize())
                    }
                    // Otherwise we'll just return and pass the data up.
                    return(0x0, returndatasize())
                }
            }
            /**
             * @notice Queries the implementation address.
             *
             * @return Implementation address.
             */
            function _getImplementation() internal view returns (address) {
                address impl;
                assembly {
                    impl := sload(IMPLEMENTATION_KEY)
                }
                return impl;
            }
            /**
             * @notice Queries the owner of the proxy contract.
             *
             * @return Owner address.
             */
            function _getAdmin() internal view returns (address) {
                address owner;
                assembly {
                    owner := sload(OWNER_KEY)
                }
                return owner;
            }
        }
        

        File 4 of 4: SystemConfig
        // SPDX-License-Identifier: MIT
        pragma solidity 0.8.15;
        // Contracts
        import { OwnableUpgradeable } from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
        import { ERC20 } from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
        // Libraries
        import { Storage } from "src/libraries/Storage.sol";
        import { Constants } from "src/libraries/Constants.sol";
        import { GasPayingToken, IGasToken } from "src/libraries/GasPayingToken.sol";
        // Interfaces
        import { ISemver } from "src/universal/interfaces/ISemver.sol";
        import { IOptimismPortal } from "src/L1/interfaces/IOptimismPortal.sol";
        import { IResourceMetering } from "src/L1/interfaces/IResourceMetering.sol";
        /// @custom:proxied true
        /// @title SystemConfig
        /// @notice The SystemConfig contract is used to manage configuration of an Optimism network.
        ///         All configuration is stored on L1 and picked up by L2 as part of the derviation of
        ///         the L2 chain.
        contract SystemConfig is OwnableUpgradeable, ISemver, IGasToken {
            /// @notice Enum representing different types of updates.
            /// @custom:value BATCHER              Represents an update to the batcher hash.
            /// @custom:value FEE_SCALARS          Represents an update to l1 data fee scalars.
            /// @custom:value GAS_LIMIT            Represents an update to gas limit on L2.
            /// @custom:value UNSAFE_BLOCK_SIGNER  Represents an update to the signer key for unsafe
            ///                                    block distrubution.
            enum UpdateType {
                BATCHER,
                FEE_SCALARS,
                GAS_LIMIT,
                UNSAFE_BLOCK_SIGNER,
                EIP_1559_PARAMS
            }
            /// @notice Struct representing the addresses of L1 system contracts. These should be the
            ///         contracts that users interact with (not implementations for proxied contracts)
            ///         and are network specific.
            struct Addresses {
                address l1CrossDomainMessenger;
                address l1ERC721Bridge;
                address l1StandardBridge;
                address disputeGameFactory;
                address optimismPortal;
                address optimismMintableERC20Factory;
                address gasPayingToken;
            }
            /// @notice Version identifier, used for upgrades.
            uint256 public constant VERSION = 0;
            /// @notice Storage slot that the unsafe block signer is stored at.
            ///         Storing it at this deterministic storage slot allows for decoupling the storage
            ///         layout from the way that `solc` lays out storage. The `op-node` uses a storage
            ///         proof to fetch this value.
            /// @dev    NOTE: this value will be migrated to another storage slot in a future version.
            ///         User input should not be placed in storage in this contract until this migration
            ///         happens. It is unlikely that keccak second preimage resistance will be broken,
            ///         but it is better to be safe than sorry.
            bytes32 public constant UNSAFE_BLOCK_SIGNER_SLOT = keccak256("systemconfig.unsafeblocksigner");
            /// @notice Storage slot that the L1CrossDomainMessenger address is stored at.
            bytes32 public constant L1_CROSS_DOMAIN_MESSENGER_SLOT =
                bytes32(uint256(keccak256("systemconfig.l1crossdomainmessenger")) - 1);
            /// @notice Storage slot that the L1ERC721Bridge address is stored at.
            bytes32 public constant L1_ERC_721_BRIDGE_SLOT = bytes32(uint256(keccak256("systemconfig.l1erc721bridge")) - 1);
            /// @notice Storage slot that the L1StandardBridge address is stored at.
            bytes32 public constant L1_STANDARD_BRIDGE_SLOT = bytes32(uint256(keccak256("systemconfig.l1standardbridge")) - 1);
            /// @notice Storage slot that the OptimismPortal address is stored at.
            bytes32 public constant OPTIMISM_PORTAL_SLOT = bytes32(uint256(keccak256("systemconfig.optimismportal")) - 1);
            /// @notice Storage slot that the OptimismMintableERC20Factory address is stored at.
            bytes32 public constant OPTIMISM_MINTABLE_ERC20_FACTORY_SLOT =
                bytes32(uint256(keccak256("systemconfig.optimismmintableerc20factory")) - 1);
            /// @notice Storage slot that the batch inbox address is stored at.
            bytes32 public constant BATCH_INBOX_SLOT = bytes32(uint256(keccak256("systemconfig.batchinbox")) - 1);
            /// @notice Storage slot for block at which the op-node can start searching for logs from.
            bytes32 public constant START_BLOCK_SLOT = bytes32(uint256(keccak256("systemconfig.startBlock")) - 1);
            /// @notice Storage slot for the DisputeGameFactory address.
            bytes32 public constant DISPUTE_GAME_FACTORY_SLOT =
                bytes32(uint256(keccak256("systemconfig.disputegamefactory")) - 1);
            /// @notice The number of decimals that the gas paying token has.
            uint8 internal constant GAS_PAYING_TOKEN_DECIMALS = 18;
            /// @notice The maximum gas limit that can be set for L2 blocks. This limit is used to enforce that the blocks
            ///         on L2 are not too large to process and prove. Over time, this value can be increased as various
            ///         optimizations and improvements are made to the system at large.
            uint64 internal constant MAX_GAS_LIMIT = 200_000_000;
            /// @notice Fixed L2 gas overhead. Used as part of the L2 fee calculation.
            ///         Deprecated since the Ecotone network upgrade
            uint256 public overhead;
            /// @notice Dynamic L2 gas overhead. Used as part of the L2 fee calculation.
            ///         The most significant byte is used to determine the version since the
            ///         Ecotone network upgrade.
            uint256 public scalar;
            /// @notice Identifier for the batcher.
            ///         For version 1 of this configuration, this is represented as an address left-padded
            ///         with zeros to 32 bytes.
            bytes32 public batcherHash;
            /// @notice L2 block gas limit.
            uint64 public gasLimit;
            /// @notice Basefee scalar value. Part of the L2 fee calculation since the Ecotone network upgrade.
            uint32 public basefeeScalar;
            /// @notice Blobbasefee scalar value. Part of the L2 fee calculation since the Ecotone network upgrade.
            uint32 public blobbasefeeScalar;
            /// @notice The configuration for the deposit fee market.
            ///         Used by the OptimismPortal to meter the cost of buying L2 gas on L1.
            ///         Set as internal with a getter so that the struct is returned instead of a tuple.
            IResourceMetering.ResourceConfig internal _resourceConfig;
            /// @notice The EIP-1559 base fee max change denominator.
            uint32 public eip1559Denominator;
            /// @notice The EIP-1559 elasticity multiplier.
            uint32 public eip1559Elasticity;
            /// @notice Emitted when configuration is updated.
            /// @param version    SystemConfig version.
            /// @param updateType Type of update.
            /// @param data       Encoded update data.
            event ConfigUpdate(uint256 indexed version, UpdateType indexed updateType, bytes data);
            /// @notice Semantic version.
            /// @custom:semver 2.3.0
            function version() public pure virtual returns (string memory) {
                return "2.3.0";
            }
            /// @notice Constructs the SystemConfig contract. Cannot set
            ///         the owner to `address(0)` due to the Ownable contract's
            ///         implementation, so set it to `address(0xdEaD)`
            /// @dev    START_BLOCK_SLOT is set to type(uint256).max here so that it will be a dead value
            ///         in the singleton and is skipped by initialize when setting the start block.
            constructor() {
                Storage.setUint(START_BLOCK_SLOT, type(uint256).max);
                initialize({
                    _owner: address(0xdEaD),
                    _basefeeScalar: 0,
                    _blobbasefeeScalar: 0,
                    _batcherHash: bytes32(0),
                    _gasLimit: 1,
                    _unsafeBlockSigner: address(0),
                    _config: IResourceMetering.ResourceConfig({
                        maxResourceLimit: 1,
                        elasticityMultiplier: 1,
                        baseFeeMaxChangeDenominator: 2,
                        minimumBaseFee: 0,
                        systemTxMaxGas: 0,
                        maximumBaseFee: 0
                    }),
                    _batchInbox: address(0),
                    _addresses: SystemConfig.Addresses({
                        l1CrossDomainMessenger: address(0),
                        l1ERC721Bridge: address(0),
                        l1StandardBridge: address(0),
                        disputeGameFactory: address(0),
                        optimismPortal: address(0),
                        optimismMintableERC20Factory: address(0),
                        gasPayingToken: address(0)
                    })
                });
            }
            /// @notice Initializer.
            ///         The resource config must be set before the require check.
            /// @param _owner             Initial owner of the contract.
            /// @param _basefeeScalar     Initial basefee scalar value.
            /// @param _blobbasefeeScalar Initial blobbasefee scalar value.
            /// @param _batcherHash       Initial batcher hash.
            /// @param _gasLimit          Initial gas limit.
            /// @param _unsafeBlockSigner Initial unsafe block signer address.
            /// @param _config            Initial ResourceConfig.
            /// @param _batchInbox        Batch inbox address. An identifier for the op-node to find
            ///                           canonical data.
            /// @param _addresses         Set of L1 contract addresses. These should be the proxies.
            function initialize(
                address _owner,
                uint32 _basefeeScalar,
                uint32 _blobbasefeeScalar,
                bytes32 _batcherHash,
                uint64 _gasLimit,
                address _unsafeBlockSigner,
                IResourceMetering.ResourceConfig memory _config,
                address _batchInbox,
                SystemConfig.Addresses memory _addresses
            )
                public
                initializer
            {
                __Ownable_init();
                transferOwnership(_owner);
                // These are set in ascending order of their UpdateTypes.
                _setBatcherHash(_batcherHash);
                _setGasConfigEcotone({ _basefeeScalar: _basefeeScalar, _blobbasefeeScalar: _blobbasefeeScalar });
                _setGasLimit(_gasLimit);
                Storage.setAddress(UNSAFE_BLOCK_SIGNER_SLOT, _unsafeBlockSigner);
                Storage.setAddress(BATCH_INBOX_SLOT, _batchInbox);
                Storage.setAddress(L1_CROSS_DOMAIN_MESSENGER_SLOT, _addresses.l1CrossDomainMessenger);
                Storage.setAddress(L1_ERC_721_BRIDGE_SLOT, _addresses.l1ERC721Bridge);
                Storage.setAddress(L1_STANDARD_BRIDGE_SLOT, _addresses.l1StandardBridge);
                Storage.setAddress(DISPUTE_GAME_FACTORY_SLOT, _addresses.disputeGameFactory);
                Storage.setAddress(OPTIMISM_PORTAL_SLOT, _addresses.optimismPortal);
                Storage.setAddress(OPTIMISM_MINTABLE_ERC20_FACTORY_SLOT, _addresses.optimismMintableERC20Factory);
                _setStartBlock();
                _setGasPayingToken(_addresses.gasPayingToken);
                _setResourceConfig(_config);
                require(_gasLimit >= minimumGasLimit(), "SystemConfig: gas limit too low");
            }
            /// @notice Returns the minimum L2 gas limit that can be safely set for the system to
            ///         operate. The L2 gas limit must be larger than or equal to the amount of
            ///         gas that is allocated for deposits per block plus the amount of gas that
            ///         is allocated for the system transaction.
            ///         This function is used to determine if changes to parameters are safe.
            /// @return uint64 Minimum gas limit.
            function minimumGasLimit() public view returns (uint64) {
                return uint64(_resourceConfig.maxResourceLimit) + uint64(_resourceConfig.systemTxMaxGas);
            }
            /// @notice Returns the maximum L2 gas limit that can be safely set for the system to
            ///         operate. This bound is used to prevent the gas limit from being set too high
            ///         and causing the system to be unable to process and/or prove L2 blocks.
            /// @return uint64 Maximum gas limit.
            function maximumGasLimit() public pure returns (uint64) {
                return MAX_GAS_LIMIT;
            }
            /// @notice High level getter for the unsafe block signer address.
            ///         Unsafe blocks can be propagated across the p2p network if they are signed by the
            ///         key corresponding to this address.
            /// @return addr_ Address of the unsafe block signer.
            function unsafeBlockSigner() public view returns (address addr_) {
                addr_ = Storage.getAddress(UNSAFE_BLOCK_SIGNER_SLOT);
            }
            /// @notice Getter for the L1CrossDomainMessenger address.
            function l1CrossDomainMessenger() external view returns (address addr_) {
                addr_ = Storage.getAddress(L1_CROSS_DOMAIN_MESSENGER_SLOT);
            }
            /// @notice Getter for the L1ERC721Bridge address.
            function l1ERC721Bridge() external view returns (address addr_) {
                addr_ = Storage.getAddress(L1_ERC_721_BRIDGE_SLOT);
            }
            /// @notice Getter for the L1StandardBridge address.
            function l1StandardBridge() external view returns (address addr_) {
                addr_ = Storage.getAddress(L1_STANDARD_BRIDGE_SLOT);
            }
            /// @notice Getter for the DisputeGameFactory address.
            function disputeGameFactory() external view returns (address addr_) {
                addr_ = Storage.getAddress(DISPUTE_GAME_FACTORY_SLOT);
            }
            /// @notice Getter for the OptimismPortal address.
            function optimismPortal() public view returns (address addr_) {
                addr_ = Storage.getAddress(OPTIMISM_PORTAL_SLOT);
            }
            /// @notice Getter for the OptimismMintableERC20Factory address.
            function optimismMintableERC20Factory() external view returns (address addr_) {
                addr_ = Storage.getAddress(OPTIMISM_MINTABLE_ERC20_FACTORY_SLOT);
            }
            /// @notice Getter for the BatchInbox address.
            function batchInbox() external view returns (address addr_) {
                addr_ = Storage.getAddress(BATCH_INBOX_SLOT);
            }
            /// @notice Getter for the StartBlock number.
            function startBlock() external view returns (uint256 startBlock_) {
                startBlock_ = Storage.getUint(START_BLOCK_SLOT);
            }
            /// @notice Getter for the gas paying asset address.
            function gasPayingToken() public view returns (address addr_, uint8 decimals_) {
                (addr_, decimals_) = GasPayingToken.getToken();
            }
            /// @notice Getter for custom gas token paying networks. Returns true if the
            ///         network uses a custom gas token.
            function isCustomGasToken() public view returns (bool) {
                (address token,) = gasPayingToken();
                return token != Constants.ETHER;
            }
            /// @notice Getter for the gas paying token name.
            function gasPayingTokenName() external view returns (string memory name_) {
                name_ = GasPayingToken.getName();
            }
            /// @notice Getter for the gas paying token symbol.
            function gasPayingTokenSymbol() external view returns (string memory symbol_) {
                symbol_ = GasPayingToken.getSymbol();
            }
            /// @notice Internal setter for the gas paying token address, includes validation.
            ///         The token must not already be set and must be non zero and not the ether address
            ///         to set the token address. This prevents the token address from being changed
            ///         and makes it explicitly opt-in to use custom gas token.
            /// @param _token Address of the gas paying token.
            function _setGasPayingToken(address _token) internal virtual {
                if (_token != address(0) && _token != Constants.ETHER && !isCustomGasToken()) {
                    require(
                        ERC20(_token).decimals() == GAS_PAYING_TOKEN_DECIMALS, "SystemConfig: bad decimals of gas paying token"
                    );
                    bytes32 name = GasPayingToken.sanitize(ERC20(_token).name());
                    bytes32 symbol = GasPayingToken.sanitize(ERC20(_token).symbol());
                    // Set the gas paying token in storage and in the OptimismPortal.
                    GasPayingToken.set({ _token: _token, _decimals: GAS_PAYING_TOKEN_DECIMALS, _name: name, _symbol: symbol });
                    IOptimismPortal(payable(optimismPortal())).setGasPayingToken({
                        _token: _token,
                        _decimals: GAS_PAYING_TOKEN_DECIMALS,
                        _name: name,
                        _symbol: symbol
                    });
                }
            }
            /// @notice Updates the unsafe block signer address. Can only be called by the owner.
            /// @param _unsafeBlockSigner New unsafe block signer address.
            function setUnsafeBlockSigner(address _unsafeBlockSigner) external onlyOwner {
                _setUnsafeBlockSigner(_unsafeBlockSigner);
            }
            /// @notice Updates the unsafe block signer address.
            /// @param _unsafeBlockSigner New unsafe block signer address.
            function _setUnsafeBlockSigner(address _unsafeBlockSigner) internal {
                Storage.setAddress(UNSAFE_BLOCK_SIGNER_SLOT, _unsafeBlockSigner);
                bytes memory data = abi.encode(_unsafeBlockSigner);
                emit ConfigUpdate(VERSION, UpdateType.UNSAFE_BLOCK_SIGNER, data);
            }
            /// @notice Updates the batcher hash. Can only be called by the owner.
            /// @param _batcherHash New batcher hash.
            function setBatcherHash(bytes32 _batcherHash) external onlyOwner {
                _setBatcherHash(_batcherHash);
            }
            /// @notice Internal function for updating the batcher hash.
            /// @param _batcherHash New batcher hash.
            function _setBatcherHash(bytes32 _batcherHash) internal {
                batcherHash = _batcherHash;
                bytes memory data = abi.encode(_batcherHash);
                emit ConfigUpdate(VERSION, UpdateType.BATCHER, data);
            }
            /// @notice Updates gas config. Can only be called by the owner.
            ///         Deprecated in favor of setGasConfigEcotone since the Ecotone upgrade.
            /// @param _overhead New overhead value.
            /// @param _scalar   New scalar value.
            function setGasConfig(uint256 _overhead, uint256 _scalar) external onlyOwner {
                _setGasConfig(_overhead, _scalar);
            }
            /// @notice Internal function for updating the gas config.
            /// @param _overhead New overhead value.
            /// @param _scalar   New scalar value.
            function _setGasConfig(uint256 _overhead, uint256 _scalar) internal {
                require((uint256(0xff) << 248) & _scalar == 0, "SystemConfig: scalar exceeds max.");
                overhead = _overhead;
                scalar = _scalar;
                bytes memory data = abi.encode(_overhead, _scalar);
                emit ConfigUpdate(VERSION, UpdateType.FEE_SCALARS, data);
            }
            /// @notice Updates gas config as of the Ecotone upgrade. Can only be called by the owner.
            /// @param _basefeeScalar     New basefeeScalar value.
            /// @param _blobbasefeeScalar New blobbasefeeScalar value.
            function setGasConfigEcotone(uint32 _basefeeScalar, uint32 _blobbasefeeScalar) external onlyOwner {
                _setGasConfigEcotone(_basefeeScalar, _blobbasefeeScalar);
            }
            /// @notice Internal function for updating the fee scalars as of the Ecotone upgrade.
            /// @param _basefeeScalar     New basefeeScalar value.
            /// @param _blobbasefeeScalar New blobbasefeeScalar value.
            function _setGasConfigEcotone(uint32 _basefeeScalar, uint32 _blobbasefeeScalar) internal {
                basefeeScalar = _basefeeScalar;
                blobbasefeeScalar = _blobbasefeeScalar;
                scalar = (uint256(0x01) << 248) | (uint256(_blobbasefeeScalar) << 32) | _basefeeScalar;
                bytes memory data = abi.encode(overhead, scalar);
                emit ConfigUpdate(VERSION, UpdateType.FEE_SCALARS, data);
            }
            /// @notice Updates the L2 gas limit. Can only be called by the owner.
            /// @param _gasLimit New gas limit.
            function setGasLimit(uint64 _gasLimit) external onlyOwner {
                _setGasLimit(_gasLimit);
            }
            /// @notice Internal function for updating the L2 gas limit.
            /// @param _gasLimit New gas limit.
            function _setGasLimit(uint64 _gasLimit) internal {
                require(_gasLimit >= minimumGasLimit(), "SystemConfig: gas limit too low");
                require(_gasLimit <= maximumGasLimit(), "SystemConfig: gas limit too high");
                gasLimit = _gasLimit;
                bytes memory data = abi.encode(_gasLimit);
                emit ConfigUpdate(VERSION, UpdateType.GAS_LIMIT, data);
            }
            /// @notice Updates the EIP-1559 parameters of the chain. Can only be called by the owner.
            /// @param _denominator EIP-1559 base fee max change denominator.
            /// @param _elasticity  EIP-1559 elasticity multiplier.
            function setEIP1559Params(uint32 _denominator, uint32 _elasticity) external onlyOwner {
                _setEIP1559Params(_denominator, _elasticity);
            }
            /// @notice Internal function for updating the EIP-1559 parameters.
            function _setEIP1559Params(uint32 _denominator, uint32 _elasticity) internal {
                // require the parameters have sane values:
                require(_denominator >= 1, "SystemConfig: denominator must be >= 1");
                require(_elasticity >= 1, "SystemConfig: elasticity must be >= 1");
                eip1559Denominator = _denominator;
                eip1559Elasticity = _elasticity;
                bytes memory data = abi.encode(uint256(_denominator) << 32 | uint64(_elasticity));
                emit ConfigUpdate(VERSION, UpdateType.EIP_1559_PARAMS, data);
            }
            /// @notice Sets the start block in a backwards compatible way. Proxies
            ///         that were initialized before the startBlock existed in storage
            ///         can have their start block set by a user provided override.
            ///         A start block of 0 indicates that there is no override and the
            ///         start block will be set by `block.number`.
            /// @dev    This logic is used to patch legacy deployments with new storage values.
            ///         Use the override if it is provided as a non zero value and the value
            ///         has not already been set in storage. Use `block.number` if the value
            ///         has already been set in storage
            function _setStartBlock() internal {
                if (Storage.getUint(START_BLOCK_SLOT) == 0) {
                    Storage.setUint(START_BLOCK_SLOT, block.number);
                }
            }
            /// @notice A getter for the resource config.
            ///         Ensures that the struct is returned instead of a tuple.
            /// @return ResourceConfig
            function resourceConfig() external view returns (IResourceMetering.ResourceConfig memory) {
                return _resourceConfig;
            }
            /// @notice An internal setter for the resource config.
            ///         Ensures that the config is sane before storing it by checking for invariants.
            ///         In the future, this method may emit an event that the `op-node` picks up
            ///         for when the resource config is changed.
            /// @param _config The new resource config.
            function _setResourceConfig(IResourceMetering.ResourceConfig memory _config) internal {
                // Min base fee must be less than or equal to max base fee.
                require(
                    _config.minimumBaseFee <= _config.maximumBaseFee, "SystemConfig: min base fee must be less than max base"
                );
                // Base fee change denominator must be greater than 1.
                require(_config.baseFeeMaxChangeDenominator > 1, "SystemConfig: denominator must be larger than 1");
                // Max resource limit plus system tx gas must be less than or equal to the L2 gas limit.
                // The gas limit must be increased before these values can be increased.
                require(_config.maxResourceLimit + _config.systemTxMaxGas <= gasLimit, "SystemConfig: gas limit too low");
                // Elasticity multiplier must be greater than 0.
                require(_config.elasticityMultiplier > 0, "SystemConfig: elasticity multiplier cannot be 0");
                // No precision loss when computing target resource limit.
                require(
                    ((_config.maxResourceLimit / _config.elasticityMultiplier) * _config.elasticityMultiplier)
                        == _config.maxResourceLimit,
                    "SystemConfig: precision loss with target resource limit"
                );
                _resourceConfig = _config;
            }
        }
        // SPDX-License-Identifier: MIT
        // OpenZeppelin Contracts (last updated v4.7.0) (access/Ownable.sol)
        pragma solidity ^0.8.0;
        import "../utils/ContextUpgradeable.sol";
        import "../proxy/utils/Initializable.sol";
        /**
         * @dev Contract module which provides a basic access control mechanism, where
         * there is an account (an owner) that can be granted exclusive access to
         * specific functions.
         *
         * By default, the owner account will be the one that deploys the contract. This
         * can later be changed with {transferOwnership}.
         *
         * This module is used through inheritance. It will make available the modifier
         * `onlyOwner`, which can be applied to your functions to restrict their use to
         * the owner.
         */
        abstract contract OwnableUpgradeable is Initializable, ContextUpgradeable {
            address private _owner;
            event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
            /**
             * @dev Initializes the contract setting the deployer as the initial owner.
             */
            function __Ownable_init() internal onlyInitializing {
                __Ownable_init_unchained();
            }
            function __Ownable_init_unchained() internal onlyInitializing {
                _transferOwnership(_msgSender());
            }
            /**
             * @dev Throws if called by any account other than the owner.
             */
            modifier onlyOwner() {
                _checkOwner();
                _;
            }
            /**
             * @dev Returns the address of the current owner.
             */
            function owner() public view virtual returns (address) {
                return _owner;
            }
            /**
             * @dev Throws if the sender is not the owner.
             */
            function _checkOwner() internal view virtual {
                require(owner() == _msgSender(), "Ownable: caller is not the owner");
            }
            /**
             * @dev Leaves the contract without owner. It will not be possible to call
             * `onlyOwner` functions anymore. Can only be called by the current owner.
             *
             * NOTE: Renouncing ownership will leave the contract without an owner,
             * thereby removing any functionality that is only available to the owner.
             */
            function renounceOwnership() public virtual onlyOwner {
                _transferOwnership(address(0));
            }
            /**
             * @dev Transfers ownership of the contract to a new account (`newOwner`).
             * Can only be called by the current owner.
             */
            function transferOwnership(address newOwner) public virtual onlyOwner {
                require(newOwner != address(0), "Ownable: new owner is the zero address");
                _transferOwnership(newOwner);
            }
            /**
             * @dev Transfers ownership of the contract to a new account (`newOwner`).
             * Internal function without access restriction.
             */
            function _transferOwnership(address newOwner) internal virtual {
                address oldOwner = _owner;
                _owner = newOwner;
                emit OwnershipTransferred(oldOwner, newOwner);
            }
            /**
             * @dev This empty reserved space is put in place to allow future versions to add new
             * variables without shifting down storage in the inheritance chain.
             * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
             */
            uint256[49] private __gap;
        }
        // SPDX-License-Identifier: MIT
        // OpenZeppelin Contracts (last updated v4.7.0) (token/ERC20/ERC20.sol)
        pragma solidity ^0.8.0;
        import "./IERC20.sol";
        import "./extensions/IERC20Metadata.sol";
        import "../../utils/Context.sol";
        /**
         * @dev Implementation of the {IERC20} interface.
         *
         * This implementation is agnostic to the way tokens are created. This means
         * that a supply mechanism has to be added in a derived contract using {_mint}.
         * For a generic mechanism see {ERC20PresetMinterPauser}.
         *
         * TIP: For a detailed writeup see our guide
         * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How
         * to implement supply mechanisms].
         *
         * We have followed general OpenZeppelin Contracts guidelines: functions revert
         * instead returning `false` on failure. This behavior is nonetheless
         * conventional and does not conflict with the expectations of ERC20
         * applications.
         *
         * Additionally, an {Approval} event is emitted on calls to {transferFrom}.
         * This allows applications to reconstruct the allowance for all accounts just
         * by listening to said events. Other implementations of the EIP may not emit
         * these events, as it isn't required by the specification.
         *
         * Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
         * functions have been added to mitigate the well-known issues around setting
         * allowances. See {IERC20-approve}.
         */
        contract ERC20 is Context, IERC20, IERC20Metadata {
            mapping(address => uint256) private _balances;
            mapping(address => mapping(address => uint256)) private _allowances;
            uint256 private _totalSupply;
            string private _name;
            string private _symbol;
            /**
             * @dev Sets the values for {name} and {symbol}.
             *
             * The default value of {decimals} is 18. To select a different value for
             * {decimals} you should overload it.
             *
             * All two of these values are immutable: they can only be set once during
             * construction.
             */
            constructor(string memory name_, string memory symbol_) {
                _name = name_;
                _symbol = symbol_;
            }
            /**
             * @dev Returns the name of the token.
             */
            function name() public view virtual override returns (string memory) {
                return _name;
            }
            /**
             * @dev Returns the symbol of the token, usually a shorter version of the
             * name.
             */
            function symbol() public view virtual override returns (string memory) {
                return _symbol;
            }
            /**
             * @dev Returns the number of decimals used to get its user representation.
             * For example, if `decimals` equals `2`, a balance of `505` tokens should
             * be displayed to a user as `5.05` (`505 / 10 ** 2`).
             *
             * Tokens usually opt for a value of 18, imitating the relationship between
             * Ether and Wei. This is the value {ERC20} uses, unless this function is
             * overridden;
             *
             * NOTE: This information is only used for _display_ purposes: it in
             * no way affects any of the arithmetic of the contract, including
             * {IERC20-balanceOf} and {IERC20-transfer}.
             */
            function decimals() public view virtual override returns (uint8) {
                return 18;
            }
            /**
             * @dev See {IERC20-totalSupply}.
             */
            function totalSupply() public view virtual override returns (uint256) {
                return _totalSupply;
            }
            /**
             * @dev See {IERC20-balanceOf}.
             */
            function balanceOf(address account) public view virtual override returns (uint256) {
                return _balances[account];
            }
            /**
             * @dev See {IERC20-transfer}.
             *
             * Requirements:
             *
             * - `to` cannot be the zero address.
             * - the caller must have a balance of at least `amount`.
             */
            function transfer(address to, uint256 amount) public virtual override returns (bool) {
                address owner = _msgSender();
                _transfer(owner, to, amount);
                return true;
            }
            /**
             * @dev See {IERC20-allowance}.
             */
            function allowance(address owner, address spender) public view virtual override returns (uint256) {
                return _allowances[owner][spender];
            }
            /**
             * @dev See {IERC20-approve}.
             *
             * NOTE: If `amount` is the maximum `uint256`, the allowance is not updated on
             * `transferFrom`. This is semantically equivalent to an infinite approval.
             *
             * Requirements:
             *
             * - `spender` cannot be the zero address.
             */
            function approve(address spender, uint256 amount) public virtual override returns (bool) {
                address owner = _msgSender();
                _approve(owner, spender, amount);
                return true;
            }
            /**
             * @dev See {IERC20-transferFrom}.
             *
             * Emits an {Approval} event indicating the updated allowance. This is not
             * required by the EIP. See the note at the beginning of {ERC20}.
             *
             * NOTE: Does not update the allowance if the current allowance
             * is the maximum `uint256`.
             *
             * Requirements:
             *
             * - `from` and `to` cannot be the zero address.
             * - `from` must have a balance of at least `amount`.
             * - the caller must have allowance for ``from``'s tokens of at least
             * `amount`.
             */
            function transferFrom(
                address from,
                address to,
                uint256 amount
            ) public virtual override returns (bool) {
                address spender = _msgSender();
                _spendAllowance(from, spender, amount);
                _transfer(from, to, amount);
                return true;
            }
            /**
             * @dev Atomically increases the allowance granted to `spender` by the caller.
             *
             * This is an alternative to {approve} that can be used as a mitigation for
             * problems described in {IERC20-approve}.
             *
             * Emits an {Approval} event indicating the updated allowance.
             *
             * Requirements:
             *
             * - `spender` cannot be the zero address.
             */
            function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
                address owner = _msgSender();
                _approve(owner, spender, allowance(owner, spender) + addedValue);
                return true;
            }
            /**
             * @dev Atomically decreases the allowance granted to `spender` by the caller.
             *
             * This is an alternative to {approve} that can be used as a mitigation for
             * problems described in {IERC20-approve}.
             *
             * Emits an {Approval} event indicating the updated allowance.
             *
             * Requirements:
             *
             * - `spender` cannot be the zero address.
             * - `spender` must have allowance for the caller of at least
             * `subtractedValue`.
             */
            function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
                address owner = _msgSender();
                uint256 currentAllowance = allowance(owner, spender);
                require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero");
                unchecked {
                    _approve(owner, spender, currentAllowance - subtractedValue);
                }
                return true;
            }
            /**
             * @dev Moves `amount` of tokens from `from` to `to`.
             *
             * This internal function is equivalent to {transfer}, and can be used to
             * e.g. implement automatic token fees, slashing mechanisms, etc.
             *
             * Emits a {Transfer} event.
             *
             * Requirements:
             *
             * - `from` cannot be the zero address.
             * - `to` cannot be the zero address.
             * - `from` must have a balance of at least `amount`.
             */
            function _transfer(
                address from,
                address to,
                uint256 amount
            ) internal virtual {
                require(from != address(0), "ERC20: transfer from the zero address");
                require(to != address(0), "ERC20: transfer to the zero address");
                _beforeTokenTransfer(from, to, amount);
                uint256 fromBalance = _balances[from];
                require(fromBalance >= amount, "ERC20: transfer amount exceeds balance");
                unchecked {
                    _balances[from] = fromBalance - amount;
                }
                _balances[to] += amount;
                emit Transfer(from, to, amount);
                _afterTokenTransfer(from, to, amount);
            }
            /** @dev Creates `amount` tokens and assigns them to `account`, increasing
             * the total supply.
             *
             * Emits a {Transfer} event with `from` set to the zero address.
             *
             * Requirements:
             *
             * - `account` cannot be the zero address.
             */
            function _mint(address account, uint256 amount) internal virtual {
                require(account != address(0), "ERC20: mint to the zero address");
                _beforeTokenTransfer(address(0), account, amount);
                _totalSupply += amount;
                _balances[account] += amount;
                emit Transfer(address(0), account, amount);
                _afterTokenTransfer(address(0), account, amount);
            }
            /**
             * @dev Destroys `amount` tokens from `account`, reducing the
             * total supply.
             *
             * Emits a {Transfer} event with `to` set to the zero address.
             *
             * Requirements:
             *
             * - `account` cannot be the zero address.
             * - `account` must have at least `amount` tokens.
             */
            function _burn(address account, uint256 amount) internal virtual {
                require(account != address(0), "ERC20: burn from the zero address");
                _beforeTokenTransfer(account, address(0), amount);
                uint256 accountBalance = _balances[account];
                require(accountBalance >= amount, "ERC20: burn amount exceeds balance");
                unchecked {
                    _balances[account] = accountBalance - amount;
                }
                _totalSupply -= amount;
                emit Transfer(account, address(0), amount);
                _afterTokenTransfer(account, address(0), amount);
            }
            /**
             * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens.
             *
             * This internal function is equivalent to `approve`, and can be used to
             * e.g. set automatic allowances for certain subsystems, etc.
             *
             * Emits an {Approval} event.
             *
             * Requirements:
             *
             * - `owner` cannot be the zero address.
             * - `spender` cannot be the zero address.
             */
            function _approve(
                address owner,
                address spender,
                uint256 amount
            ) internal virtual {
                require(owner != address(0), "ERC20: approve from the zero address");
                require(spender != address(0), "ERC20: approve to the zero address");
                _allowances[owner][spender] = amount;
                emit Approval(owner, spender, amount);
            }
            /**
             * @dev Updates `owner` s allowance for `spender` based on spent `amount`.
             *
             * Does not update the allowance amount in case of infinite allowance.
             * Revert if not enough allowance is available.
             *
             * Might emit an {Approval} event.
             */
            function _spendAllowance(
                address owner,
                address spender,
                uint256 amount
            ) internal virtual {
                uint256 currentAllowance = allowance(owner, spender);
                if (currentAllowance != type(uint256).max) {
                    require(currentAllowance >= amount, "ERC20: insufficient allowance");
                    unchecked {
                        _approve(owner, spender, currentAllowance - amount);
                    }
                }
            }
            /**
             * @dev Hook that is called before any transfer of tokens. This includes
             * minting and burning.
             *
             * Calling conditions:
             *
             * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
             * will be transferred to `to`.
             * - when `from` is zero, `amount` tokens will be minted for `to`.
             * - when `to` is zero, `amount` of ``from``'s tokens will be burned.
             * - `from` and `to` are never both zero.
             *
             * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
             */
            function _beforeTokenTransfer(
                address from,
                address to,
                uint256 amount
            ) internal virtual {}
            /**
             * @dev Hook that is called after any transfer of tokens. This includes
             * minting and burning.
             *
             * Calling conditions:
             *
             * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
             * has been transferred to `to`.
             * - when `from` is zero, `amount` tokens have been minted for `to`.
             * - when `to` is zero, `amount` of ``from``'s tokens have been burned.
             * - `from` and `to` are never both zero.
             *
             * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
             */
            function _afterTokenTransfer(
                address from,
                address to,
                uint256 amount
            ) internal virtual {}
        }
        // SPDX-License-Identifier: MIT
        pragma solidity ^0.8.0;
        /// @title Storage
        /// @notice Storage handles reading and writing to arbitary storage locations
        library Storage {
            /// @notice Returns an address stored in an arbitrary storage slot.
            ///         These storage slots decouple the storage layout from
            ///         solc's automation.
            /// @param _slot The storage slot to retrieve the address from.
            function getAddress(bytes32 _slot) internal view returns (address addr_) {
                assembly {
                    addr_ := sload(_slot)
                }
            }
            /// @notice Stores an address in an arbitrary storage slot, `_slot`.
            /// @param _slot The storage slot to store the address in.
            /// @param _address The protocol version to store
            /// @dev WARNING! This function must be used cautiously, as it allows for overwriting addresses
            ///      in arbitrary storage slots.
            function setAddress(bytes32 _slot, address _address) internal {
                assembly {
                    sstore(_slot, _address)
                }
            }
            /// @notice Returns a uint256 stored in an arbitrary storage slot.
            ///         These storage slots decouple the storage layout from
            ///         solc's automation.
            /// @param _slot The storage slot to retrieve the address from.
            function getUint(bytes32 _slot) internal view returns (uint256 value_) {
                assembly {
                    value_ := sload(_slot)
                }
            }
            /// @notice Stores a value in an arbitrary storage slot, `_slot`.
            /// @param _slot The storage slot to store the address in.
            /// @param _value The protocol version to store
            /// @dev WARNING! This function must be used cautiously, as it allows for overwriting values
            ///      in arbitrary storage slots.
            function setUint(bytes32 _slot, uint256 _value) internal {
                assembly {
                    sstore(_slot, _value)
                }
            }
            /// @notice Returns a bytes32 stored in an arbitrary storage slot.
            ///         These storage slots decouple the storage layout from
            ///         solc's automation.
            /// @param _slot The storage slot to retrieve the address from.
            function getBytes32(bytes32 _slot) internal view returns (bytes32 value_) {
                assembly {
                    value_ := sload(_slot)
                }
            }
            /// @notice Stores a bytes32 value in an arbitrary storage slot, `_slot`.
            /// @param _slot The storage slot to store the address in.
            /// @param _value The bytes32 value to store.
            /// @dev WARNING! This function must be used cautiously, as it allows for overwriting values
            ///      in arbitrary storage slots.
            function setBytes32(bytes32 _slot, bytes32 _value) internal {
                assembly {
                    sstore(_slot, _value)
                }
            }
            /// @notice Stores a bool value in an arbitrary storage slot, `_slot`.
            /// @param _slot The storage slot to store the bool in.
            /// @param _value The bool value to store
            /// @dev WARNING! This function must be used cautiously, as it allows for overwriting values
            ///      in arbitrary storage slots.
            function setBool(bytes32 _slot, bool _value) internal {
                assembly {
                    sstore(_slot, _value)
                }
            }
            /// @notice Returns a bool stored in an arbitrary storage slot.
            /// @param _slot The storage slot to retrieve the bool from.
            function getBool(bytes32 _slot) internal view returns (bool value_) {
                assembly {
                    value_ := sload(_slot)
                }
            }
        }
        // SPDX-License-Identifier: MIT
        pragma solidity ^0.8.0;
        import { IResourceMetering } from "src/L1/interfaces/IResourceMetering.sol";
        /// @title Constants
        /// @notice Constants is a library for storing constants. Simple! Don't put everything in here, just
        ///         the stuff used in multiple contracts. Constants that only apply to a single contract
        ///         should be defined in that contract instead.
        library Constants {
            /// @notice Special address to be used as the tx origin for gas estimation calls in the
            ///         OptimismPortal and CrossDomainMessenger calls. You only need to use this address if
            ///         the minimum gas limit specified by the user is not actually enough to execute the
            ///         given message and you're attempting to estimate the actual necessary gas limit. We
            ///         use address(1) because it's the ecrecover precompile and therefore guaranteed to
            ///         never have any code on any EVM chain.
            address internal constant ESTIMATION_ADDRESS = address(1);
            /// @notice Value used for the L2 sender storage slot in both the OptimismPortal and the
            ///         CrossDomainMessenger contracts before an actual sender is set. This value is
            ///         non-zero to reduce the gas cost of message passing transactions.
            address internal constant DEFAULT_L2_SENDER = 0x000000000000000000000000000000000000dEaD;
            /// @notice The storage slot that holds the address of a proxy implementation.
            /// @dev `bytes32(uint256(keccak256('eip1967.proxy.implementation')) - 1)`
            bytes32 internal constant PROXY_IMPLEMENTATION_ADDRESS =
                0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
            /// @notice The storage slot that holds the address of the owner.
            /// @dev `bytes32(uint256(keccak256('eip1967.proxy.admin')) - 1)`
            bytes32 internal constant PROXY_OWNER_ADDRESS = 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103;
            /// @notice The address that represents ether when dealing with ERC20 token addresses.
            address internal constant ETHER = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;
            /// @notice The address that represents the system caller responsible for L1 attributes
            ///         transactions.
            address internal constant DEPOSITOR_ACCOUNT = 0xDeaDDEaDDeAdDeAdDEAdDEaddeAddEAdDEAd0001;
            /// @notice Returns the default values for the ResourceConfig. These are the recommended values
            ///         for a production network.
            function DEFAULT_RESOURCE_CONFIG() internal pure returns (IResourceMetering.ResourceConfig memory) {
                IResourceMetering.ResourceConfig memory config = IResourceMetering.ResourceConfig({
                    maxResourceLimit: 20_000_000,
                    elasticityMultiplier: 10,
                    baseFeeMaxChangeDenominator: 8,
                    minimumBaseFee: 1 gwei,
                    systemTxMaxGas: 1_000_000,
                    maximumBaseFee: type(uint128).max
                });
                return config;
            }
        }
        // SPDX-License-Identifier: MIT
        pragma solidity ^0.8.0;
        import { Storage } from "src/libraries/Storage.sol";
        import { Constants } from "src/libraries/Constants.sol";
        import { LibString } from "@solady/utils/LibString.sol";
        /// @title IGasToken
        /// @notice Implemented by contracts that are aware of the custom gas token used
        ///         by the L2 network.
        interface IGasToken {
            /// @notice Getter for the ERC20 token address that is used to pay for gas and its decimals.
            function gasPayingToken() external view returns (address, uint8);
            /// @notice Returns the gas token name.
            function gasPayingTokenName() external view returns (string memory);
            /// @notice Returns the gas token symbol.
            function gasPayingTokenSymbol() external view returns (string memory);
            /// @notice Returns true if the network uses a custom gas token.
            function isCustomGasToken() external view returns (bool);
        }
        /// @title GasPayingToken
        /// @notice Handles reading and writing the custom gas token to storage.
        ///         To be used in any place where gas token information is read or
        ///         written to state. If multiple contracts use this library, the
        ///         values in storage should be kept in sync between them.
        library GasPayingToken {
            /// @notice The storage slot that contains the address and decimals of the gas paying token
            bytes32 internal constant GAS_PAYING_TOKEN_SLOT = bytes32(uint256(keccak256("opstack.gaspayingtoken")) - 1);
            /// @notice The storage slot that contains the ERC20 `name()` of the gas paying token
            bytes32 internal constant GAS_PAYING_TOKEN_NAME_SLOT = bytes32(uint256(keccak256("opstack.gaspayingtokenname")) - 1);
            /// @notice the storage slot that contains the ERC20 `symbol()` of the gas paying token
            bytes32 internal constant GAS_PAYING_TOKEN_SYMBOL_SLOT =
                bytes32(uint256(keccak256("opstack.gaspayingtokensymbol")) - 1);
            /// @notice Reads the gas paying token and its decimals from the magic
            ///         storage slot. If nothing is set in storage, then the ether
            ///         address is returned instead.
            function getToken() internal view returns (address addr_, uint8 decimals_) {
                bytes32 slot = Storage.getBytes32(GAS_PAYING_TOKEN_SLOT);
                addr_ = address(uint160(uint256(slot) & uint256(type(uint160).max)));
                if (addr_ == address(0)) {
                    addr_ = Constants.ETHER;
                    decimals_ = 18;
                } else {
                    decimals_ = uint8(uint256(slot) >> 160);
                }
            }
            /// @notice Reads the gas paying token's name from the magic storage slot.
            ///         If nothing is set in storage, then the ether name, 'Ether', is returned instead.
            function getName() internal view returns (string memory name_) {
                (address addr,) = getToken();
                if (addr == Constants.ETHER) {
                    name_ = "Ether";
                } else {
                    name_ = LibString.fromSmallString(Storage.getBytes32(GAS_PAYING_TOKEN_NAME_SLOT));
                }
            }
            /// @notice Reads the gas paying token's symbol from the magic storage slot.
            ///         If nothing is set in storage, then the ether symbol, 'ETH', is returned instead.
            function getSymbol() internal view returns (string memory symbol_) {
                (address addr,) = getToken();
                if (addr == Constants.ETHER) {
                    symbol_ = "ETH";
                } else {
                    symbol_ = LibString.fromSmallString(Storage.getBytes32(GAS_PAYING_TOKEN_SYMBOL_SLOT));
                }
            }
            /// @notice Writes the gas paying token, its decimals, name and symbol to the magic storage slot.
            function set(address _token, uint8 _decimals, bytes32 _name, bytes32 _symbol) internal {
                Storage.setBytes32(GAS_PAYING_TOKEN_SLOT, bytes32(uint256(_decimals) << 160 | uint256(uint160(_token))));
                Storage.setBytes32(GAS_PAYING_TOKEN_NAME_SLOT, _name);
                Storage.setBytes32(GAS_PAYING_TOKEN_SYMBOL_SLOT, _symbol);
            }
            /// @notice Maps a string to a normalized null-terminated small string.
            function sanitize(string memory _str) internal pure returns (bytes32) {
                require(bytes(_str).length <= 32, "GasPayingToken: string cannot be greater than 32 bytes");
                return LibString.toSmallString(_str);
            }
        }
        // SPDX-License-Identifier: MIT
        pragma solidity ^0.8.0;
        /// @title ISemver
        /// @notice ISemver is a simple contract for ensuring that contracts are
        ///         versioned using semantic versioning.
        interface ISemver {
            /// @notice Getter for the semantic version of the contract. This is not
            ///         meant to be used onchain but instead meant to be used by offchain
            ///         tooling.
            /// @return Semver contract version as a string.
            function version() external view returns (string memory);
        }
        // SPDX-License-Identifier: MIT
        pragma solidity ^0.8.0;
        import { Types } from "src/libraries/Types.sol";
        import { ISystemConfig } from "src/L1/interfaces/ISystemConfig.sol";
        import { ISuperchainConfig } from "src/L1/interfaces/ISuperchainConfig.sol";
        import { IL2OutputOracle } from "src/L1/interfaces/IL2OutputOracle.sol";
        interface IOptimismPortal {
            error BadTarget();
            error CallPaused();
            error ContentLengthMismatch();
            error EmptyItem();
            error GasEstimation();
            error InvalidDataRemainder();
            error InvalidHeader();
            error LargeCalldata();
            error NoValue();
            error NonReentrant();
            error OnlyCustomGasToken();
            error OutOfGas();
            error SmallGasLimit();
            error TransferFailed();
            error Unauthorized();
            error UnexpectedList();
            error UnexpectedString();
            event Initialized(uint8 version);
            event TransactionDeposited(address indexed from, address indexed to, uint256 indexed version, bytes opaqueData);
            event WithdrawalFinalized(bytes32 indexed withdrawalHash, bool success);
            event WithdrawalProven(bytes32 indexed withdrawalHash, address indexed from, address indexed to);
            receive() external payable;
            function balance() external view returns (uint256);
            function depositERC20Transaction(
                address _to,
                uint256 _mint,
                uint256 _value,
                uint64 _gasLimit,
                bool _isCreation,
                bytes memory _data
            )
                external;
            function depositTransaction(
                address _to,
                uint256 _value,
                uint64 _gasLimit,
                bool _isCreation,
                bytes memory _data
            )
                external
                payable;
            function donateETH() external payable;
            function finalizeWithdrawalTransaction(Types.WithdrawalTransaction memory _tx) external;
            function finalizedWithdrawals(bytes32) external view returns (bool);
            function guardian() external view returns (address);
            function initialize(
                IL2OutputOracle _l2Oracle,
                ISystemConfig _systemConfig,
                ISuperchainConfig _superchainConfig
            )
                external;
            function isOutputFinalized(uint256 _l2OutputIndex) external view returns (bool);
            function l2Oracle() external view returns (IL2OutputOracle);
            function l2Sender() external view returns (address);
            function minimumGasLimit(uint64 _byteCount) external pure returns (uint64);
            function params() external view returns (uint128 prevBaseFee, uint64 prevBoughtGas, uint64 prevBlockNum); // nosemgrep
            function paused() external view returns (bool paused_);
            function proveWithdrawalTransaction(
                Types.WithdrawalTransaction memory _tx,
                uint256 _l2OutputIndex,
                Types.OutputRootProof memory _outputRootProof,
                bytes[] memory _withdrawalProof
            )
                external;
            function provenWithdrawals(bytes32)
                external
                view
                returns (bytes32 outputRoot, uint128 timestamp, uint128 l2OutputIndex); // nosemgrep
            function setGasPayingToken(address _token, uint8 _decimals, bytes32 _name, bytes32 _symbol) external;
            function superchainConfig() external view returns (ISuperchainConfig);
            function systemConfig() external view returns (ISystemConfig);
            function version() external pure returns (string memory);
            function __constructor__() external;
        }
        // SPDX-License-Identifier: MIT
        pragma solidity ^0.8.0;
        interface IResourceMetering {
            struct ResourceParams {
                uint128 prevBaseFee;
                uint64 prevBoughtGas;
                uint64 prevBlockNum;
            }
            struct ResourceConfig {
                uint32 maxResourceLimit;
                uint8 elasticityMultiplier;
                uint8 baseFeeMaxChangeDenominator;
                uint32 minimumBaseFee;
                uint32 systemTxMaxGas;
                uint128 maximumBaseFee;
            }
            error OutOfGas();
            event Initialized(uint8 version);
            function params() external view returns (uint128 prevBaseFee, uint64 prevBoughtGas, uint64 prevBlockNum); // nosemgrep
            function __constructor__() external;
        }
        // SPDX-License-Identifier: MIT
        // OpenZeppelin Contracts v4.4.1 (utils/Context.sol)
        pragma solidity ^0.8.0;
        import "../proxy/utils/Initializable.sol";
        /**
         * @dev Provides information about the current execution context, including the
         * sender of the transaction and its data. While these are generally available
         * via msg.sender and msg.data, they should not be accessed in such a direct
         * manner, since when dealing with meta-transactions the account sending and
         * paying for execution may not be the actual sender (as far as an application
         * is concerned).
         *
         * This contract is only required for intermediate, library-like contracts.
         */
        abstract contract ContextUpgradeable is Initializable {
            function __Context_init() internal onlyInitializing {
            }
            function __Context_init_unchained() internal onlyInitializing {
            }
            function _msgSender() internal view virtual returns (address) {
                return msg.sender;
            }
            function _msgData() internal view virtual returns (bytes calldata) {
                return msg.data;
            }
            /**
             * @dev This empty reserved space is put in place to allow future versions to add new
             * variables without shifting down storage in the inheritance chain.
             * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
             */
            uint256[50] private __gap;
        }
        // SPDX-License-Identifier: MIT
        // OpenZeppelin Contracts (last updated v4.7.0) (proxy/utils/Initializable.sol)
        pragma solidity ^0.8.2;
        import "../../utils/AddressUpgradeable.sol";
        /**
         * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed
         * behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an
         * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer
         * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.
         *
         * The initialization functions use a version number. Once a version number is used, it is consumed and cannot be
         * reused. This mechanism prevents re-execution of each "step" but allows the creation of new initialization steps in
         * case an upgrade adds a module that needs to be initialized.
         *
         * For example:
         *
         * [.hljs-theme-light.nopadding]
         * ```
         * contract MyToken is ERC20Upgradeable {
         *     function initialize() initializer public {
         *         __ERC20_init("MyToken", "MTK");
         *     }
         * }
         * contract MyTokenV2 is MyToken, ERC20PermitUpgradeable {
         *     function initializeV2() reinitializer(2) public {
         *         __ERC20Permit_init("MyToken");
         *     }
         * }
         * ```
         *
         * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as
         * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.
         *
         * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure
         * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.
         *
         * [CAUTION]
         * ====
         * Avoid leaving a contract uninitialized.
         *
         * An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation
         * contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke
         * the {_disableInitializers} function in the constructor to automatically lock it when it is deployed:
         *
         * [.hljs-theme-light.nopadding]
         * ```
         * /// @custom:oz-upgrades-unsafe-allow constructor
         * constructor() {
         *     _disableInitializers();
         * }
         * ```
         * ====
         */
        abstract contract Initializable {
            /**
             * @dev Indicates that the contract has been initialized.
             * @custom:oz-retyped-from bool
             */
            uint8 private _initialized;
            /**
             * @dev Indicates that the contract is in the process of being initialized.
             */
            bool private _initializing;
            /**
             * @dev Triggered when the contract has been initialized or reinitialized.
             */
            event Initialized(uint8 version);
            /**
             * @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,
             * `onlyInitializing` functions can be used to initialize parent contracts. Equivalent to `reinitializer(1)`.
             */
            modifier initializer() {
                bool isTopLevelCall = !_initializing;
                require(
                    (isTopLevelCall && _initialized < 1) || (!AddressUpgradeable.isContract(address(this)) && _initialized == 1),
                    "Initializable: contract is already initialized"
                );
                _initialized = 1;
                if (isTopLevelCall) {
                    _initializing = true;
                }
                _;
                if (isTopLevelCall) {
                    _initializing = false;
                    emit Initialized(1);
                }
            }
            /**
             * @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the
             * contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be
             * used to initialize parent contracts.
             *
             * `initializer` is equivalent to `reinitializer(1)`, so a reinitializer may be used after the original
             * initialization step. This is essential to configure modules that are added through upgrades and that require
             * initialization.
             *
             * Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in
             * a contract, executing them in the right order is up to the developer or operator.
             */
            modifier reinitializer(uint8 version) {
                require(!_initializing && _initialized < version, "Initializable: contract is already initialized");
                _initialized = version;
                _initializing = true;
                _;
                _initializing = false;
                emit Initialized(version);
            }
            /**
             * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the
             * {initializer} and {reinitializer} modifiers, directly or indirectly.
             */
            modifier onlyInitializing() {
                require(_initializing, "Initializable: contract is not initializing");
                _;
            }
            /**
             * @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.
             * Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized
             * to any version. It is recommended to use this to lock implementation contracts that are designed to be called
             * through proxies.
             */
            function _disableInitializers() internal virtual {
                require(!_initializing, "Initializable: contract is initializing");
                if (_initialized < type(uint8).max) {
                    _initialized = type(uint8).max;
                    emit Initialized(type(uint8).max);
                }
            }
        }
        // SPDX-License-Identifier: MIT
        // OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/IERC20.sol)
        pragma solidity ^0.8.0;
        /**
         * @dev Interface of the ERC20 standard as defined in the EIP.
         */
        interface IERC20 {
            /**
             * @dev Emitted when `value` tokens are moved from one account (`from`) to
             * another (`to`).
             *
             * Note that `value` may be zero.
             */
            event Transfer(address indexed from, address indexed to, uint256 value);
            /**
             * @dev Emitted when the allowance of a `spender` for an `owner` is set by
             * a call to {approve}. `value` is the new allowance.
             */
            event Approval(address indexed owner, address indexed spender, uint256 value);
            /**
             * @dev Returns the amount of tokens in existence.
             */
            function totalSupply() external view returns (uint256);
            /**
             * @dev Returns the amount of tokens owned by `account`.
             */
            function balanceOf(address account) external view returns (uint256);
            /**
             * @dev Moves `amount` tokens from the caller's account to `to`.
             *
             * Returns a boolean value indicating whether the operation succeeded.
             *
             * Emits a {Transfer} event.
             */
            function transfer(address to, uint256 amount) external returns (bool);
            /**
             * @dev Returns the remaining number of tokens that `spender` will be
             * allowed to spend on behalf of `owner` through {transferFrom}. This is
             * zero by default.
             *
             * This value changes when {approve} or {transferFrom} are called.
             */
            function allowance(address owner, address spender) external view returns (uint256);
            /**
             * @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
             *
             * Returns a boolean value indicating whether the operation succeeded.
             *
             * IMPORTANT: Beware that changing an allowance with this method brings the risk
             * that someone may use both the old and the new allowance by unfortunate
             * transaction ordering. One possible solution to mitigate this race
             * condition is to first reduce the spender's allowance to 0 and set the
             * desired value afterwards:
             * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
             *
             * Emits an {Approval} event.
             */
            function approve(address spender, uint256 amount) external returns (bool);
            /**
             * @dev Moves `amount` tokens from `from` to `to` using the
             * allowance mechanism. `amount` is then deducted from the caller's
             * allowance.
             *
             * Returns a boolean value indicating whether the operation succeeded.
             *
             * Emits a {Transfer} event.
             */
            function transferFrom(
                address from,
                address to,
                uint256 amount
            ) external returns (bool);
        }
        // SPDX-License-Identifier: MIT
        // OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol)
        pragma solidity ^0.8.0;
        import "../IERC20.sol";
        /**
         * @dev Interface for the optional metadata functions from the ERC20 standard.
         *
         * _Available since v4.1._
         */
        interface IERC20Metadata is IERC20 {
            /**
             * @dev Returns the name of the token.
             */
            function name() external view returns (string memory);
            /**
             * @dev Returns the symbol of the token.
             */
            function symbol() external view returns (string memory);
            /**
             * @dev Returns the decimals places of the token.
             */
            function decimals() external view returns (uint8);
        }
        // SPDX-License-Identifier: MIT
        // OpenZeppelin Contracts v4.4.1 (utils/Context.sol)
        pragma solidity ^0.8.0;
        /**
         * @dev Provides information about the current execution context, including the
         * sender of the transaction and its data. While these are generally available
         * via msg.sender and msg.data, they should not be accessed in such a direct
         * manner, since when dealing with meta-transactions the account sending and
         * paying for execution may not be the actual sender (as far as an application
         * is concerned).
         *
         * This contract is only required for intermediate, library-like contracts.
         */
        abstract contract Context {
            function _msgSender() internal view virtual returns (address) {
                return msg.sender;
            }
            function _msgData() internal view virtual returns (bytes calldata) {
                return msg.data;
            }
        }
        // SPDX-License-Identifier: MIT
        pragma solidity ^0.8.4;
        /// @notice Library for converting numbers into strings and other string operations.
        /// @author Solady (https://github.com/vectorized/solady/blob/main/src/utils/LibString.sol)
        /// @author Modified from Solmate (https://github.com/transmissions11/solmate/blob/main/src/utils/LibString.sol)
        ///
        /// Note:
        /// For performance and bytecode compactness, most of the string operations are restricted to
        /// byte strings (7-bit ASCII), except where otherwise specified.
        /// Usage of byte string operations on charsets with runes spanning two or more bytes
        /// can lead to undefined behavior.
        library LibString {
            /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
            /*                        CUSTOM ERRORS                       */
            /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
            /// @dev The length of the output is too small to contain all the hex digits.
            error HexLengthInsufficient();
            /// @dev The length of the string is more than 32 bytes.
            error TooBigForSmallString();
            /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
            /*                         CONSTANTS                          */
            /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
            /// @dev The constant returned when the `search` is not found in the string.
            uint256 internal constant NOT_FOUND = type(uint256).max;
            /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
            /*                     DECIMAL OPERATIONS                     */
            /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
            /// @dev Returns the base 10 decimal representation of `value`.
            function toString(uint256 value) internal pure returns (string memory str) {
                /// @solidity memory-safe-assembly
                assembly {
                    // The maximum value of a uint256 contains 78 digits (1 byte per digit), but
                    // we allocate 0xa0 bytes to keep the free memory pointer 32-byte word aligned.
                    // We will need 1 word for the trailing zeros padding, 1 word for the length,
                    // and 3 words for a maximum of 78 digits.
                    str := add(mload(0x40), 0x80)
                    // Update the free memory pointer to allocate.
                    mstore(0x40, add(str, 0x20))
                    // Zeroize the slot after the string.
                    mstore(str, 0)
                    // Cache the end of the memory to calculate the length later.
                    let end := str
                    let w := not(0) // Tsk.
                    // We write the string from rightmost digit to leftmost digit.
                    // The following is essentially a do-while loop that also handles the zero case.
                    for { let temp := value } 1 {} {
                        str := add(str, w) // `sub(str, 1)`.
                        // Write the character to the pointer.
                        // The ASCII index of the '0' character is 48.
                        mstore8(str, add(48, mod(temp, 10)))
                        // Keep dividing `temp` until zero.
                        temp := div(temp, 10)
                        if iszero(temp) { break }
                    }
                    let length := sub(end, str)
                    // Move the pointer 32 bytes leftwards to make room for the length.
                    str := sub(str, 0x20)
                    // Store the length.
                    mstore(str, length)
                }
            }
            /// @dev Returns the base 10 decimal representation of `value`.
            function toString(int256 value) internal pure returns (string memory str) {
                if (value >= 0) {
                    return toString(uint256(value));
                }
                unchecked {
                    str = toString(uint256(-value));
                }
                /// @solidity memory-safe-assembly
                assembly {
                    // We still have some spare memory space on the left,
                    // as we have allocated 3 words (96 bytes) for up to 78 digits.
                    let length := mload(str) // Load the string length.
                    mstore(str, 0x2d) // Store the '-' character.
                    str := sub(str, 1) // Move back the string pointer by a byte.
                    mstore(str, add(length, 1)) // Update the string length.
                }
            }
            /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
            /*                   HEXADECIMAL OPERATIONS                   */
            /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
            /// @dev Returns the hexadecimal representation of `value`,
            /// left-padded to an input length of `length` bytes.
            /// The output is prefixed with "0x" encoded using 2 hexadecimal digits per byte,
            /// giving a total length of `length * 2 + 2` bytes.
            /// Reverts if `length` is too small for the output to contain all the digits.
            function toHexString(uint256 value, uint256 length) internal pure returns (string memory str) {
                str = toHexStringNoPrefix(value, length);
                /// @solidity memory-safe-assembly
                assembly {
                    let strLength := add(mload(str), 2) // Compute the length.
                    mstore(str, 0x3078) // Write the "0x" prefix.
                    str := sub(str, 2) // Move the pointer.
                    mstore(str, strLength) // Write the length.
                }
            }
            /// @dev Returns the hexadecimal representation of `value`,
            /// left-padded to an input length of `length` bytes.
            /// The output is prefixed with "0x" encoded using 2 hexadecimal digits per byte,
            /// giving a total length of `length * 2` bytes.
            /// Reverts if `length` is too small for the output to contain all the digits.
            function toHexStringNoPrefix(uint256 value, uint256 length)
                internal
                pure
                returns (string memory str)
            {
                /// @solidity memory-safe-assembly
                assembly {
                    // We need 0x20 bytes for the trailing zeros padding, `length * 2` bytes
                    // for the digits, 0x02 bytes for the prefix, and 0x20 bytes for the length.
                    // We add 0x20 to the total and round down to a multiple of 0x20.
                    // (0x20 + 0x20 + 0x02 + 0x20) = 0x62.
                    str := add(mload(0x40), and(add(shl(1, length), 0x42), not(0x1f)))
                    // Allocate the memory.
                    mstore(0x40, add(str, 0x20))
                    // Zeroize the slot after the string.
                    mstore(str, 0)
                    // Cache the end to calculate the length later.
                    let end := str
                    // Store "0123456789abcdef" in scratch space.
                    mstore(0x0f, 0x30313233343536373839616263646566)
                    let start := sub(str, add(length, length))
                    let w := not(1) // Tsk.
                    let temp := value
                    // We write the string from rightmost digit to leftmost digit.
                    // The following is essentially a do-while loop that also handles the zero case.
                    for {} 1 {} {
                        str := add(str, w) // `sub(str, 2)`.
                        mstore8(add(str, 1), mload(and(temp, 15)))
                        mstore8(str, mload(and(shr(4, temp), 15)))
                        temp := shr(8, temp)
                        if iszero(xor(str, start)) { break }
                    }
                    if temp {
                        mstore(0x00, 0x2194895a) // `HexLengthInsufficient()`.
                        revert(0x1c, 0x04)
                    }
                    // Compute the string's length.
                    let strLength := sub(end, str)
                    // Move the pointer and write the length.
                    str := sub(str, 0x20)
                    mstore(str, strLength)
                }
            }
            /// @dev Returns the hexadecimal representation of `value`.
            /// The output is prefixed with "0x" and encoded using 2 hexadecimal digits per byte.
            /// As address are 20 bytes long, the output will left-padded to have
            /// a length of `20 * 2 + 2` bytes.
            function toHexString(uint256 value) internal pure returns (string memory str) {
                str = toHexStringNoPrefix(value);
                /// @solidity memory-safe-assembly
                assembly {
                    let strLength := add(mload(str), 2) // Compute the length.
                    mstore(str, 0x3078) // Write the "0x" prefix.
                    str := sub(str, 2) // Move the pointer.
                    mstore(str, strLength) // Write the length.
                }
            }
            /// @dev Returns the hexadecimal representation of `value`.
            /// The output is prefixed with "0x".
            /// The output excludes leading "0" from the `toHexString` output.
            /// `0x00: "0x0", 0x01: "0x1", 0x12: "0x12", 0x123: "0x123"`.
            function toMinimalHexString(uint256 value) internal pure returns (string memory str) {
                str = toHexStringNoPrefix(value);
                /// @solidity memory-safe-assembly
                assembly {
                    let o := eq(byte(0, mload(add(str, 0x20))), 0x30) // Whether leading zero is present.
                    let strLength := add(mload(str), 2) // Compute the length.
                    mstore(add(str, o), 0x3078) // Write the "0x" prefix, accounting for leading zero.
                    str := sub(add(str, o), 2) // Move the pointer, accounting for leading zero.
                    mstore(str, sub(strLength, o)) // Write the length, accounting for leading zero.
                }
            }
            /// @dev Returns the hexadecimal representation of `value`.
            /// The output excludes leading "0" from the `toHexStringNoPrefix` output.
            /// `0x00: "0", 0x01: "1", 0x12: "12", 0x123: "123"`.
            function toMinimalHexStringNoPrefix(uint256 value) internal pure returns (string memory str) {
                str = toHexStringNoPrefix(value);
                /// @solidity memory-safe-assembly
                assembly {
                    let o := eq(byte(0, mload(add(str, 0x20))), 0x30) // Whether leading zero is present.
                    let strLength := mload(str) // Get the length.
                    str := add(str, o) // Move the pointer, accounting for leading zero.
                    mstore(str, sub(strLength, o)) // Write the length, accounting for leading zero.
                }
            }
            /// @dev Returns the hexadecimal representation of `value`.
            /// The output is encoded using 2 hexadecimal digits per byte.
            /// As address are 20 bytes long, the output will left-padded to have
            /// a length of `20 * 2` bytes.
            function toHexStringNoPrefix(uint256 value) internal pure returns (string memory str) {
                /// @solidity memory-safe-assembly
                assembly {
                    // We need 0x20 bytes for the trailing zeros padding, 0x20 bytes for the length,
                    // 0x02 bytes for the prefix, and 0x40 bytes for the digits.
                    // The next multiple of 0x20 above (0x20 + 0x20 + 0x02 + 0x40) is 0xa0.
                    str := add(mload(0x40), 0x80)
                    // Allocate the memory.
                    mstore(0x40, add(str, 0x20))
                    // Zeroize the slot after the string.
                    mstore(str, 0)
                    // Cache the end to calculate the length later.
                    let end := str
                    // Store "0123456789abcdef" in scratch space.
                    mstore(0x0f, 0x30313233343536373839616263646566)
                    let w := not(1) // Tsk.
                    // We write the string from rightmost digit to leftmost digit.
                    // The following is essentially a do-while loop that also handles the zero case.
                    for { let temp := value } 1 {} {
                        str := add(str, w) // `sub(str, 2)`.
                        mstore8(add(str, 1), mload(and(temp, 15)))
                        mstore8(str, mload(and(shr(4, temp), 15)))
                        temp := shr(8, temp)
                        if iszero(temp) { break }
                    }
                    // Compute the string's length.
                    let strLength := sub(end, str)
                    // Move the pointer and write the length.
                    str := sub(str, 0x20)
                    mstore(str, strLength)
                }
            }
            /// @dev Returns the hexadecimal representation of `value`.
            /// The output is prefixed with "0x", encoded using 2 hexadecimal digits per byte,
            /// and the alphabets are capitalized conditionally according to
            /// https://eips.ethereum.org/EIPS/eip-55
            function toHexStringChecksummed(address value) internal pure returns (string memory str) {
                str = toHexString(value);
                /// @solidity memory-safe-assembly
                assembly {
                    let mask := shl(6, div(not(0), 255)) // `0b010000000100000000 ...`
                    let o := add(str, 0x22)
                    let hashed := and(keccak256(o, 40), mul(34, mask)) // `0b10001000 ... `
                    let t := shl(240, 136) // `0b10001000 << 240`
                    for { let i := 0 } 1 {} {
                        mstore(add(i, i), mul(t, byte(i, hashed)))
                        i := add(i, 1)
                        if eq(i, 20) { break }
                    }
                    mstore(o, xor(mload(o), shr(1, and(mload(0x00), and(mload(o), mask)))))
                    o := add(o, 0x20)
                    mstore(o, xor(mload(o), shr(1, and(mload(0x20), and(mload(o), mask)))))
                }
            }
            /// @dev Returns the hexadecimal representation of `value`.
            /// The output is prefixed with "0x" and encoded using 2 hexadecimal digits per byte.
            function toHexString(address value) internal pure returns (string memory str) {
                str = toHexStringNoPrefix(value);
                /// @solidity memory-safe-assembly
                assembly {
                    let strLength := add(mload(str), 2) // Compute the length.
                    mstore(str, 0x3078) // Write the "0x" prefix.
                    str := sub(str, 2) // Move the pointer.
                    mstore(str, strLength) // Write the length.
                }
            }
            /// @dev Returns the hexadecimal representation of `value`.
            /// The output is encoded using 2 hexadecimal digits per byte.
            function toHexStringNoPrefix(address value) internal pure returns (string memory str) {
                /// @solidity memory-safe-assembly
                assembly {
                    str := mload(0x40)
                    // Allocate the memory.
                    // We need 0x20 bytes for the trailing zeros padding, 0x20 bytes for the length,
                    // 0x02 bytes for the prefix, and 0x28 bytes for the digits.
                    // The next multiple of 0x20 above (0x20 + 0x20 + 0x02 + 0x28) is 0x80.
                    mstore(0x40, add(str, 0x80))
                    // Store "0123456789abcdef" in scratch space.
                    mstore(0x0f, 0x30313233343536373839616263646566)
                    str := add(str, 2)
                    mstore(str, 40)
                    let o := add(str, 0x20)
                    mstore(add(o, 40), 0)
                    value := shl(96, value)
                    // We write the string from rightmost digit to leftmost digit.
                    // The following is essentially a do-while loop that also handles the zero case.
                    for { let i := 0 } 1 {} {
                        let p := add(o, add(i, i))
                        let temp := byte(i, value)
                        mstore8(add(p, 1), mload(and(temp, 15)))
                        mstore8(p, mload(shr(4, temp)))
                        i := add(i, 1)
                        if eq(i, 20) { break }
                    }
                }
            }
            /// @dev Returns the hex encoded string from the raw bytes.
            /// The output is encoded using 2 hexadecimal digits per byte.
            function toHexString(bytes memory raw) internal pure returns (string memory str) {
                str = toHexStringNoPrefix(raw);
                /// @solidity memory-safe-assembly
                assembly {
                    let strLength := add(mload(str), 2) // Compute the length.
                    mstore(str, 0x3078) // Write the "0x" prefix.
                    str := sub(str, 2) // Move the pointer.
                    mstore(str, strLength) // Write the length.
                }
            }
            /// @dev Returns the hex encoded string from the raw bytes.
            /// The output is encoded using 2 hexadecimal digits per byte.
            function toHexStringNoPrefix(bytes memory raw) internal pure returns (string memory str) {
                /// @solidity memory-safe-assembly
                assembly {
                    let length := mload(raw)
                    str := add(mload(0x40), 2) // Skip 2 bytes for the optional prefix.
                    mstore(str, add(length, length)) // Store the length of the output.
                    // Store "0123456789abcdef" in scratch space.
                    mstore(0x0f, 0x30313233343536373839616263646566)
                    let o := add(str, 0x20)
                    let end := add(raw, length)
                    for {} iszero(eq(raw, end)) {} {
                        raw := add(raw, 1)
                        mstore8(add(o, 1), mload(and(mload(raw), 15)))
                        mstore8(o, mload(and(shr(4, mload(raw)), 15)))
                        o := add(o, 2)
                    }
                    mstore(o, 0) // Zeroize the slot after the string.
                    mstore(0x40, add(o, 0x20)) // Allocate the memory.
                }
            }
            /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
            /*                   RUNE STRING OPERATIONS                   */
            /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
            /// @dev Returns the number of UTF characters in the string.
            function runeCount(string memory s) internal pure returns (uint256 result) {
                /// @solidity memory-safe-assembly
                assembly {
                    if mload(s) {
                        mstore(0x00, div(not(0), 255))
                        mstore(0x20, 0x0202020202020202020202020202020202020202020202020303030304040506)
                        let o := add(s, 0x20)
                        let end := add(o, mload(s))
                        for { result := 1 } 1 { result := add(result, 1) } {
                            o := add(o, byte(0, mload(shr(250, mload(o)))))
                            if iszero(lt(o, end)) { break }
                        }
                    }
                }
            }
            /// @dev Returns if this string is a 7-bit ASCII string.
            /// (i.e. all characters codes are in [0..127])
            function is7BitASCII(string memory s) internal pure returns (bool result) {
                /// @solidity memory-safe-assembly
                assembly {
                    let mask := shl(7, div(not(0), 255))
                    result := 1
                    let n := mload(s)
                    if n {
                        let o := add(s, 0x20)
                        let end := add(o, n)
                        let last := mload(end)
                        mstore(end, 0)
                        for {} 1 {} {
                            if and(mask, mload(o)) {
                                result := 0
                                break
                            }
                            o := add(o, 0x20)
                            if iszero(lt(o, end)) { break }
                        }
                        mstore(end, last)
                    }
                }
            }
            /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
            /*                   BYTE STRING OPERATIONS                   */
            /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
            // For performance and bytecode compactness, byte string operations are restricted
            // to 7-bit ASCII strings. All offsets are byte offsets, not UTF character offsets.
            // Usage of byte string operations on charsets with runes spanning two or more bytes
            // can lead to undefined behavior.
            /// @dev Returns `subject` all occurrences of `search` replaced with `replacement`.
            function replace(string memory subject, string memory search, string memory replacement)
                internal
                pure
                returns (string memory result)
            {
                /// @solidity memory-safe-assembly
                assembly {
                    let subjectLength := mload(subject)
                    let searchLength := mload(search)
                    let replacementLength := mload(replacement)
                    subject := add(subject, 0x20)
                    search := add(search, 0x20)
                    replacement := add(replacement, 0x20)
                    result := add(mload(0x40), 0x20)
                    let subjectEnd := add(subject, subjectLength)
                    if iszero(gt(searchLength, subjectLength)) {
                        let subjectSearchEnd := add(sub(subjectEnd, searchLength), 1)
                        let h := 0
                        if iszero(lt(searchLength, 0x20)) { h := keccak256(search, searchLength) }
                        let m := shl(3, sub(0x20, and(searchLength, 0x1f)))
                        let s := mload(search)
                        for {} 1 {} {
                            let t := mload(subject)
                            // Whether the first `searchLength % 32` bytes of
                            // `subject` and `search` matches.
                            if iszero(shr(m, xor(t, s))) {
                                if h {
                                    if iszero(eq(keccak256(subject, searchLength), h)) {
                                        mstore(result, t)
                                        result := add(result, 1)
                                        subject := add(subject, 1)
                                        if iszero(lt(subject, subjectSearchEnd)) { break }
                                        continue
                                    }
                                }
                                // Copy the `replacement` one word at a time.
                                for { let o := 0 } 1 {} {
                                    mstore(add(result, o), mload(add(replacement, o)))
                                    o := add(o, 0x20)
                                    if iszero(lt(o, replacementLength)) { break }
                                }
                                result := add(result, replacementLength)
                                subject := add(subject, searchLength)
                                if searchLength {
                                    if iszero(lt(subject, subjectSearchEnd)) { break }
                                    continue
                                }
                            }
                            mstore(result, t)
                            result := add(result, 1)
                            subject := add(subject, 1)
                            if iszero(lt(subject, subjectSearchEnd)) { break }
                        }
                    }
                    let resultRemainder := result
                    result := add(mload(0x40), 0x20)
                    let k := add(sub(resultRemainder, result), sub(subjectEnd, subject))
                    // Copy the rest of the string one word at a time.
                    for {} lt(subject, subjectEnd) {} {
                        mstore(resultRemainder, mload(subject))
                        resultRemainder := add(resultRemainder, 0x20)
                        subject := add(subject, 0x20)
                    }
                    result := sub(result, 0x20)
                    let last := add(add(result, 0x20), k) // Zeroize the slot after the string.
                    mstore(last, 0)
                    mstore(0x40, add(last, 0x20)) // Allocate the memory.
                    mstore(result, k) // Store the length.
                }
            }
            /// @dev Returns the byte index of the first location of `search` in `subject`,
            /// searching from left to right, starting from `from`.
            /// Returns `NOT_FOUND` (i.e. `type(uint256).max`) if the `search` is not found.
            function indexOf(string memory subject, string memory search, uint256 from)
                internal
                pure
                returns (uint256 result)
            {
                /// @solidity memory-safe-assembly
                assembly {
                    for { let subjectLength := mload(subject) } 1 {} {
                        if iszero(mload(search)) {
                            if iszero(gt(from, subjectLength)) {
                                result := from
                                break
                            }
                            result := subjectLength
                            break
                        }
                        let searchLength := mload(search)
                        let subjectStart := add(subject, 0x20)
                        result := not(0) // Initialize to `NOT_FOUND`.
                        subject := add(subjectStart, from)
                        let end := add(sub(add(subjectStart, subjectLength), searchLength), 1)
                        let m := shl(3, sub(0x20, and(searchLength, 0x1f)))
                        let s := mload(add(search, 0x20))
                        if iszero(and(lt(subject, end), lt(from, subjectLength))) { break }
                        if iszero(lt(searchLength, 0x20)) {
                            for { let h := keccak256(add(search, 0x20), searchLength) } 1 {} {
                                if iszero(shr(m, xor(mload(subject), s))) {
                                    if eq(keccak256(subject, searchLength), h) {
                                        result := sub(subject, subjectStart)
                                        break
                                    }
                                }
                                subject := add(subject, 1)
                                if iszero(lt(subject, end)) { break }
                            }
                            break
                        }
                        for {} 1 {} {
                            if iszero(shr(m, xor(mload(subject), s))) {
                                result := sub(subject, subjectStart)
                                break
                            }
                            subject := add(subject, 1)
                            if iszero(lt(subject, end)) { break }
                        }
                        break
                    }
                }
            }
            /// @dev Returns the byte index of the first location of `search` in `subject`,
            /// searching from left to right.
            /// Returns `NOT_FOUND` (i.e. `type(uint256).max`) if the `search` is not found.
            function indexOf(string memory subject, string memory search)
                internal
                pure
                returns (uint256 result)
            {
                result = indexOf(subject, search, 0);
            }
            /// @dev Returns the byte index of the first location of `search` in `subject`,
            /// searching from right to left, starting from `from`.
            /// Returns `NOT_FOUND` (i.e. `type(uint256).max`) if the `search` is not found.
            function lastIndexOf(string memory subject, string memory search, uint256 from)
                internal
                pure
                returns (uint256 result)
            {
                /// @solidity memory-safe-assembly
                assembly {
                    for {} 1 {} {
                        result := not(0) // Initialize to `NOT_FOUND`.
                        let searchLength := mload(search)
                        if gt(searchLength, mload(subject)) { break }
                        let w := result
                        let fromMax := sub(mload(subject), searchLength)
                        if iszero(gt(fromMax, from)) { from := fromMax }
                        let end := add(add(subject, 0x20), w)
                        subject := add(add(subject, 0x20), from)
                        if iszero(gt(subject, end)) { break }
                        // As this function is not too often used,
                        // we shall simply use keccak256 for smaller bytecode size.
                        for { let h := keccak256(add(search, 0x20), searchLength) } 1 {} {
                            if eq(keccak256(subject, searchLength), h) {
                                result := sub(subject, add(end, 1))
                                break
                            }
                            subject := add(subject, w) // `sub(subject, 1)`.
                            if iszero(gt(subject, end)) { break }
                        }
                        break
                    }
                }
            }
            /// @dev Returns the byte index of the first location of `search` in `subject`,
            /// searching from right to left.
            /// Returns `NOT_FOUND` (i.e. `type(uint256).max`) if the `search` is not found.
            function lastIndexOf(string memory subject, string memory search)
                internal
                pure
                returns (uint256 result)
            {
                result = lastIndexOf(subject, search, uint256(int256(-1)));
            }
            /// @dev Returns true if `search` is found in `subject`, false otherwise.
            function contains(string memory subject, string memory search) internal pure returns (bool) {
                return indexOf(subject, search) != NOT_FOUND;
            }
            /// @dev Returns whether `subject` starts with `search`.
            function startsWith(string memory subject, string memory search)
                internal
                pure
                returns (bool result)
            {
                /// @solidity memory-safe-assembly
                assembly {
                    let searchLength := mload(search)
                    // Just using keccak256 directly is actually cheaper.
                    // forgefmt: disable-next-item
                    result := and(
                        iszero(gt(searchLength, mload(subject))),
                        eq(
                            keccak256(add(subject, 0x20), searchLength),
                            keccak256(add(search, 0x20), searchLength)
                        )
                    )
                }
            }
            /// @dev Returns whether `subject` ends with `search`.
            function endsWith(string memory subject, string memory search)
                internal
                pure
                returns (bool result)
            {
                /// @solidity memory-safe-assembly
                assembly {
                    let searchLength := mload(search)
                    let subjectLength := mload(subject)
                    // Whether `search` is not longer than `subject`.
                    let withinRange := iszero(gt(searchLength, subjectLength))
                    // Just using keccak256 directly is actually cheaper.
                    // forgefmt: disable-next-item
                    result := and(
                        withinRange,
                        eq(
                            keccak256(
                                // `subject + 0x20 + max(subjectLength - searchLength, 0)`.
                                add(add(subject, 0x20), mul(withinRange, sub(subjectLength, searchLength))),
                                searchLength
                            ),
                            keccak256(add(search, 0x20), searchLength)
                        )
                    )
                }
            }
            /// @dev Returns `subject` repeated `times`.
            function repeat(string memory subject, uint256 times)
                internal
                pure
                returns (string memory result)
            {
                /// @solidity memory-safe-assembly
                assembly {
                    let subjectLength := mload(subject)
                    if iszero(or(iszero(times), iszero(subjectLength))) {
                        subject := add(subject, 0x20)
                        result := mload(0x40)
                        let output := add(result, 0x20)
                        for {} 1 {} {
                            // Copy the `subject` one word at a time.
                            for { let o := 0 } 1 {} {
                                mstore(add(output, o), mload(add(subject, o)))
                                o := add(o, 0x20)
                                if iszero(lt(o, subjectLength)) { break }
                            }
                            output := add(output, subjectLength)
                            times := sub(times, 1)
                            if iszero(times) { break }
                        }
                        mstore(output, 0) // Zeroize the slot after the string.
                        let resultLength := sub(output, add(result, 0x20))
                        mstore(result, resultLength) // Store the length.
                        // Allocate the memory.
                        mstore(0x40, add(result, add(resultLength, 0x20)))
                    }
                }
            }
            /// @dev Returns a copy of `subject` sliced from `start` to `end` (exclusive).
            /// `start` and `end` are byte offsets.
            function slice(string memory subject, uint256 start, uint256 end)
                internal
                pure
                returns (string memory result)
            {
                /// @solidity memory-safe-assembly
                assembly {
                    let subjectLength := mload(subject)
                    if iszero(gt(subjectLength, end)) { end := subjectLength }
                    if iszero(gt(subjectLength, start)) { start := subjectLength }
                    if lt(start, end) {
                        result := mload(0x40)
                        let resultLength := sub(end, start)
                        mstore(result, resultLength)
                        subject := add(subject, start)
                        let w := not(0x1f)
                        // Copy the `subject` one word at a time, backwards.
                        for { let o := and(add(resultLength, 0x1f), w) } 1 {} {
                            mstore(add(result, o), mload(add(subject, o)))
                            o := add(o, w) // `sub(o, 0x20)`.
                            if iszero(o) { break }
                        }
                        // Zeroize the slot after the string.
                        mstore(add(add(result, 0x20), resultLength), 0)
                        // Allocate memory for the length and the bytes,
                        // rounded up to a multiple of 32.
                        mstore(0x40, add(result, and(add(resultLength, 0x3f), w)))
                    }
                }
            }
            /// @dev Returns a copy of `subject` sliced from `start` to the end of the string.
            /// `start` is a byte offset.
            function slice(string memory subject, uint256 start)
                internal
                pure
                returns (string memory result)
            {
                result = slice(subject, start, uint256(int256(-1)));
            }
            /// @dev Returns all the indices of `search` in `subject`.
            /// The indices are byte offsets.
            function indicesOf(string memory subject, string memory search)
                internal
                pure
                returns (uint256[] memory result)
            {
                /// @solidity memory-safe-assembly
                assembly {
                    let subjectLength := mload(subject)
                    let searchLength := mload(search)
                    if iszero(gt(searchLength, subjectLength)) {
                        subject := add(subject, 0x20)
                        search := add(search, 0x20)
                        result := add(mload(0x40), 0x20)
                        let subjectStart := subject
                        let subjectSearchEnd := add(sub(add(subject, subjectLength), searchLength), 1)
                        let h := 0
                        if iszero(lt(searchLength, 0x20)) { h := keccak256(search, searchLength) }
                        let m := shl(3, sub(0x20, and(searchLength, 0x1f)))
                        let s := mload(search)
                        for {} 1 {} {
                            let t := mload(subject)
                            // Whether the first `searchLength % 32` bytes of
                            // `subject` and `search` matches.
                            if iszero(shr(m, xor(t, s))) {
                                if h {
                                    if iszero(eq(keccak256(subject, searchLength), h)) {
                                        subject := add(subject, 1)
                                        if iszero(lt(subject, subjectSearchEnd)) { break }
                                        continue
                                    }
                                }
                                // Append to `result`.
                                mstore(result, sub(subject, subjectStart))
                                result := add(result, 0x20)
                                // Advance `subject` by `searchLength`.
                                subject := add(subject, searchLength)
                                if searchLength {
                                    if iszero(lt(subject, subjectSearchEnd)) { break }
                                    continue
                                }
                            }
                            subject := add(subject, 1)
                            if iszero(lt(subject, subjectSearchEnd)) { break }
                        }
                        let resultEnd := result
                        // Assign `result` to the free memory pointer.
                        result := mload(0x40)
                        // Store the length of `result`.
                        mstore(result, shr(5, sub(resultEnd, add(result, 0x20))))
                        // Allocate memory for result.
                        // We allocate one more word, so this array can be recycled for {split}.
                        mstore(0x40, add(resultEnd, 0x20))
                    }
                }
            }
            /// @dev Returns a arrays of strings based on the `delimiter` inside of the `subject` string.
            function split(string memory subject, string memory delimiter)
                internal
                pure
                returns (string[] memory result)
            {
                uint256[] memory indices = indicesOf(subject, delimiter);
                /// @solidity memory-safe-assembly
                assembly {
                    let w := not(0x1f)
                    let indexPtr := add(indices, 0x20)
                    let indicesEnd := add(indexPtr, shl(5, add(mload(indices), 1)))
                    mstore(add(indicesEnd, w), mload(subject))
                    mstore(indices, add(mload(indices), 1))
                    let prevIndex := 0
                    for {} 1 {} {
                        let index := mload(indexPtr)
                        mstore(indexPtr, 0x60)
                        if iszero(eq(index, prevIndex)) {
                            let element := mload(0x40)
                            let elementLength := sub(index, prevIndex)
                            mstore(element, elementLength)
                            // Copy the `subject` one word at a time, backwards.
                            for { let o := and(add(elementLength, 0x1f), w) } 1 {} {
                                mstore(add(element, o), mload(add(add(subject, prevIndex), o)))
                                o := add(o, w) // `sub(o, 0x20)`.
                                if iszero(o) { break }
                            }
                            // Zeroize the slot after the string.
                            mstore(add(add(element, 0x20), elementLength), 0)
                            // Allocate memory for the length and the bytes,
                            // rounded up to a multiple of 32.
                            mstore(0x40, add(element, and(add(elementLength, 0x3f), w)))
                            // Store the `element` into the array.
                            mstore(indexPtr, element)
                        }
                        prevIndex := add(index, mload(delimiter))
                        indexPtr := add(indexPtr, 0x20)
                        if iszero(lt(indexPtr, indicesEnd)) { break }
                    }
                    result := indices
                    if iszero(mload(delimiter)) {
                        result := add(indices, 0x20)
                        mstore(result, sub(mload(indices), 2))
                    }
                }
            }
            /// @dev Returns a concatenated string of `a` and `b`.
            /// Cheaper than `string.concat()` and does not de-align the free memory pointer.
            function concat(string memory a, string memory b)
                internal
                pure
                returns (string memory result)
            {
                /// @solidity memory-safe-assembly
                assembly {
                    let w := not(0x1f)
                    result := mload(0x40)
                    let aLength := mload(a)
                    // Copy `a` one word at a time, backwards.
                    for { let o := and(add(aLength, 0x20), w) } 1 {} {
                        mstore(add(result, o), mload(add(a, o)))
                        o := add(o, w) // `sub(o, 0x20)`.
                        if iszero(o) { break }
                    }
                    let bLength := mload(b)
                    let output := add(result, aLength)
                    // Copy `b` one word at a time, backwards.
                    for { let o := and(add(bLength, 0x20), w) } 1 {} {
                        mstore(add(output, o), mload(add(b, o)))
                        o := add(o, w) // `sub(o, 0x20)`.
                        if iszero(o) { break }
                    }
                    let totalLength := add(aLength, bLength)
                    let last := add(add(result, 0x20), totalLength)
                    // Zeroize the slot after the string.
                    mstore(last, 0)
                    // Stores the length.
                    mstore(result, totalLength)
                    // Allocate memory for the length and the bytes,
                    // rounded up to a multiple of 32.
                    mstore(0x40, and(add(last, 0x1f), w))
                }
            }
            /// @dev Returns a copy of the string in either lowercase or UPPERCASE.
            /// WARNING! This function is only compatible with 7-bit ASCII strings.
            function toCase(string memory subject, bool toUpper)
                internal
                pure
                returns (string memory result)
            {
                /// @solidity memory-safe-assembly
                assembly {
                    let length := mload(subject)
                    if length {
                        result := add(mload(0x40), 0x20)
                        subject := add(subject, 1)
                        let flags := shl(add(70, shl(5, toUpper)), 0x3ffffff)
                        let w := not(0)
                        for { let o := length } 1 {} {
                            o := add(o, w)
                            let b := and(0xff, mload(add(subject, o)))
                            mstore8(add(result, o), xor(b, and(shr(b, flags), 0x20)))
                            if iszero(o) { break }
                        }
                        result := mload(0x40)
                        mstore(result, length) // Store the length.
                        let last := add(add(result, 0x20), length)
                        mstore(last, 0) // Zeroize the slot after the string.
                        mstore(0x40, add(last, 0x20)) // Allocate the memory.
                    }
                }
            }
            /// @dev Returns a string from a small bytes32 string.
            /// `s` must be null-terminated, or behavior will be undefined.
            function fromSmallString(bytes32 s) internal pure returns (string memory result) {
                /// @solidity memory-safe-assembly
                assembly {
                    result := mload(0x40)
                    let n := 0
                    for {} byte(n, s) { n := add(n, 1) } {} // Scan for '\\0'.
                    mstore(result, n)
                    let o := add(result, 0x20)
                    mstore(o, s)
                    mstore(add(o, n), 0)
                    mstore(0x40, add(result, 0x40))
                }
            }
            /// @dev Returns the small string, with all bytes after the first null byte zeroized.
            function normalizeSmallString(bytes32 s) internal pure returns (bytes32 result) {
                /// @solidity memory-safe-assembly
                assembly {
                    for {} byte(result, s) { result := add(result, 1) } {} // Scan for '\\0'.
                    mstore(0x00, s)
                    mstore(result, 0x00)
                    result := mload(0x00)
                }
            }
            /// @dev Returns the string as a normalized null-terminated small string.
            function toSmallString(string memory s) internal pure returns (bytes32 result) {
                /// @solidity memory-safe-assembly
                assembly {
                    result := mload(s)
                    if iszero(lt(result, 33)) {
                        mstore(0x00, 0xec92f9a3) // `TooBigForSmallString()`.
                        revert(0x1c, 0x04)
                    }
                    result := shl(shl(3, sub(32, result)), mload(add(s, result)))
                }
            }
            /// @dev Returns a lowercased copy of the string.
            /// WARNING! This function is only compatible with 7-bit ASCII strings.
            function lower(string memory subject) internal pure returns (string memory result) {
                result = toCase(subject, false);
            }
            /// @dev Returns an UPPERCASED copy of the string.
            /// WARNING! This function is only compatible with 7-bit ASCII strings.
            function upper(string memory subject) internal pure returns (string memory result) {
                result = toCase(subject, true);
            }
            /// @dev Escapes the string to be used within HTML tags.
            function escapeHTML(string memory s) internal pure returns (string memory result) {
                /// @solidity memory-safe-assembly
                assembly {
                    let end := add(s, mload(s))
                    result := add(mload(0x40), 0x20)
                    // Store the bytes of the packed offsets and strides into the scratch space.
                    // `packed = (stride << 5) | offset`. Max offset is 20. Max stride is 6.
                    mstore(0x1f, 0x900094)
                    mstore(0x08, 0xc0000000a6ab)
                    // Store "&quot;&amp;&#39;&lt;&gt;" into the scratch space.
                    mstore(0x00, shl(64, 0x2671756f743b26616d703b262333393b266c743b2667743b))
                    for {} iszero(eq(s, end)) {} {
                        s := add(s, 1)
                        let c := and(mload(s), 0xff)
                        // Not in `["\\"","'","&","<",">"]`.
                        if iszero(and(shl(c, 1), 0x500000c400000000)) {
                            mstore8(result, c)
                            result := add(result, 1)
                            continue
                        }
                        let t := shr(248, mload(c))
                        mstore(result, mload(and(t, 0x1f)))
                        result := add(result, shr(5, t))
                    }
                    let last := result
                    mstore(last, 0) // Zeroize the slot after the string.
                    result := mload(0x40)
                    mstore(result, sub(last, add(result, 0x20))) // Store the length.
                    mstore(0x40, add(last, 0x20)) // Allocate the memory.
                }
            }
            /// @dev Escapes the string to be used within double-quotes in a JSON.
            /// If `addDoubleQuotes` is true, the result will be enclosed in double-quotes.
            function escapeJSON(string memory s, bool addDoubleQuotes)
                internal
                pure
                returns (string memory result)
            {
                /// @solidity memory-safe-assembly
                assembly {
                    let end := add(s, mload(s))
                    result := add(mload(0x40), 0x20)
                    if addDoubleQuotes {
                        mstore8(result, 34)
                        result := add(1, result)
                    }
                    // Store "\\\\u0000" in scratch space.
                    // Store "0123456789abcdef" in scratch space.
                    // Also, store `{0x08:"b", 0x09:"t", 0x0a:"n", 0x0c:"f", 0x0d:"r"}`.
                    // into the scratch space.
                    mstore(0x15, 0x5c75303030303031323334353637383961626364656662746e006672)
                    // Bitmask for detecting `["\\"","\\\\"]`.
                    let e := or(shl(0x22, 1), shl(0x5c, 1))
                    for {} iszero(eq(s, end)) {} {
                        s := add(s, 1)
                        let c := and(mload(s), 0xff)
                        if iszero(lt(c, 0x20)) {
                            if iszero(and(shl(c, 1), e)) {
                                // Not in `["\\"","\\\\"]`.
                                mstore8(result, c)
                                result := add(result, 1)
                                continue
                            }
                            mstore8(result, 0x5c) // "\\\\".
                            mstore8(add(result, 1), c)
                            result := add(result, 2)
                            continue
                        }
                        if iszero(and(shl(c, 1), 0x3700)) {
                            // Not in `["\\b","\\t","\
        ","\\f","\\d"]`.
                            mstore8(0x1d, mload(shr(4, c))) // Hex value.
                            mstore8(0x1e, mload(and(c, 15))) // Hex value.
                            mstore(result, mload(0x19)) // "\\\\u00XX".
                            result := add(result, 6)
                            continue
                        }
                        mstore8(result, 0x5c) // "\\\\".
                        mstore8(add(result, 1), mload(add(c, 8)))
                        result := add(result, 2)
                    }
                    if addDoubleQuotes {
                        mstore8(result, 34)
                        result := add(1, result)
                    }
                    let last := result
                    mstore(last, 0) // Zeroize the slot after the string.
                    result := mload(0x40)
                    mstore(result, sub(last, add(result, 0x20))) // Store the length.
                    mstore(0x40, add(last, 0x20)) // Allocate the memory.
                }
            }
            /// @dev Escapes the string to be used within double-quotes in a JSON.
            function escapeJSON(string memory s) internal pure returns (string memory result) {
                result = escapeJSON(s, false);
            }
            /// @dev Returns whether `a` equals `b`.
            function eq(string memory a, string memory b) internal pure returns (bool result) {
                /// @solidity memory-safe-assembly
                assembly {
                    result := eq(keccak256(add(a, 0x20), mload(a)), keccak256(add(b, 0x20), mload(b)))
                }
            }
            /// @dev Returns whether `a` equals `b`, where `b` is a null-terminated small string.
            function eqs(string memory a, bytes32 b) internal pure returns (bool result) {
                /// @solidity memory-safe-assembly
                assembly {
                    // These should be evaluated on compile time, as far as possible.
                    let m := not(shl(7, div(not(iszero(b)), 255))) // `0x7f7f ...`.
                    let x := not(or(m, or(b, add(m, and(b, m)))))
                    let r := shl(7, iszero(iszero(shr(128, x))))
                    r := or(r, shl(6, iszero(iszero(shr(64, shr(r, x))))))
                    r := or(r, shl(5, lt(0xffffffff, shr(r, x))))
                    r := or(r, shl(4, lt(0xffff, shr(r, x))))
                    r := or(r, shl(3, lt(0xff, shr(r, x))))
                    // forgefmt: disable-next-item
                    result := gt(eq(mload(a), add(iszero(x), xor(31, shr(3, r)))),
                        xor(shr(add(8, r), b), shr(add(8, r), mload(add(a, 0x20)))))
                }
            }
            /// @dev Packs a single string with its length into a single word.
            /// Returns `bytes32(0)` if the length is zero or greater than 31.
            function packOne(string memory a) internal pure returns (bytes32 result) {
                /// @solidity memory-safe-assembly
                assembly {
                    // We don't need to zero right pad the string,
                    // since this is our own custom non-standard packing scheme.
                    result :=
                        mul(
                            // Load the length and the bytes.
                            mload(add(a, 0x1f)),
                            // `length != 0 && length < 32`. Abuses underflow.
                            // Assumes that the length is valid and within the block gas limit.
                            lt(sub(mload(a), 1), 0x1f)
                        )
                }
            }
            /// @dev Unpacks a string packed using {packOne}.
            /// Returns the empty string if `packed` is `bytes32(0)`.
            /// If `packed` is not an output of {packOne}, the output behavior is undefined.
            function unpackOne(bytes32 packed) internal pure returns (string memory result) {
                /// @solidity memory-safe-assembly
                assembly {
                    // Grab the free memory pointer.
                    result := mload(0x40)
                    // Allocate 2 words (1 for the length, 1 for the bytes).
                    mstore(0x40, add(result, 0x40))
                    // Zeroize the length slot.
                    mstore(result, 0)
                    // Store the length and bytes.
                    mstore(add(result, 0x1f), packed)
                    // Right pad with zeroes.
                    mstore(add(add(result, 0x20), mload(result)), 0)
                }
            }
            /// @dev Packs two strings with their lengths into a single word.
            /// Returns `bytes32(0)` if combined length is zero or greater than 30.
            function packTwo(string memory a, string memory b) internal pure returns (bytes32 result) {
                /// @solidity memory-safe-assembly
                assembly {
                    let aLength := mload(a)
                    // We don't need to zero right pad the strings,
                    // since this is our own custom non-standard packing scheme.
                    result :=
                        mul(
                            // Load the length and the bytes of `a` and `b`.
                            or(
                                shl(shl(3, sub(0x1f, aLength)), mload(add(a, aLength))),
                                mload(sub(add(b, 0x1e), aLength))
                            ),
                            // `totalLength != 0 && totalLength < 31`. Abuses underflow.
                            // Assumes that the lengths are valid and within the block gas limit.
                            lt(sub(add(aLength, mload(b)), 1), 0x1e)
                        )
                }
            }
            /// @dev Unpacks strings packed using {packTwo}.
            /// Returns the empty strings if `packed` is `bytes32(0)`.
            /// If `packed` is not an output of {packTwo}, the output behavior is undefined.
            function unpackTwo(bytes32 packed)
                internal
                pure
                returns (string memory resultA, string memory resultB)
            {
                /// @solidity memory-safe-assembly
                assembly {
                    // Grab the free memory pointer.
                    resultA := mload(0x40)
                    resultB := add(resultA, 0x40)
                    // Allocate 2 words for each string (1 for the length, 1 for the byte). Total 4 words.
                    mstore(0x40, add(resultB, 0x40))
                    // Zeroize the length slots.
                    mstore(resultA, 0)
                    mstore(resultB, 0)
                    // Store the lengths and bytes.
                    mstore(add(resultA, 0x1f), packed)
                    mstore(add(resultB, 0x1f), mload(add(add(resultA, 0x20), mload(resultA))))
                    // Right pad with zeroes.
                    mstore(add(add(resultA, 0x20), mload(resultA)), 0)
                    mstore(add(add(resultB, 0x20), mload(resultB)), 0)
                }
            }
            /// @dev Directly returns `a` without copying.
            function directReturn(string memory a) internal pure {
                assembly {
                    // Assumes that the string does not start from the scratch space.
                    let retStart := sub(a, 0x20)
                    let retSize := add(mload(a), 0x40)
                    // Right pad with zeroes. Just in case the string is produced
                    // by a method that doesn't zero right pad.
                    mstore(add(retStart, retSize), 0)
                    // Store the return offset.
                    mstore(retStart, 0x20)
                    // End the transaction, returning the string.
                    return(retStart, retSize)
                }
            }
        }
        // SPDX-License-Identifier: MIT
        pragma solidity ^0.8.0;
        /// @title Types
        /// @notice Contains various types used throughout the Optimism contract system.
        library Types {
            /// @notice OutputProposal represents a commitment to the L2 state. The timestamp is the L1
            ///         timestamp that the output root is posted. This timestamp is used to verify that the
            ///         finalization period has passed since the output root was submitted.
            /// @custom:field outputRoot    Hash of the L2 output.
            /// @custom:field timestamp     Timestamp of the L1 block that the output root was submitted in.
            /// @custom:field l2BlockNumber L2 block number that the output corresponds to.
            struct OutputProposal {
                bytes32 outputRoot;
                uint128 timestamp;
                uint128 l2BlockNumber;
            }
            /// @notice Struct representing the elements that are hashed together to generate an output root
            ///         which itself represents a snapshot of the L2 state.
            /// @custom:field version                  Version of the output root.
            /// @custom:field stateRoot                Root of the state trie at the block of this output.
            /// @custom:field messagePasserStorageRoot Root of the message passer storage trie.
            /// @custom:field latestBlockhash          Hash of the block this output was generated from.
            struct OutputRootProof {
                bytes32 version;
                bytes32 stateRoot;
                bytes32 messagePasserStorageRoot;
                bytes32 latestBlockhash;
            }
            /// @notice Struct representing a deposit transaction (L1 => L2 transaction) created by an end
            ///         user (as opposed to a system deposit transaction generated by the system).
            /// @custom:field from        Address of the sender of the transaction.
            /// @custom:field to          Address of the recipient of the transaction.
            /// @custom:field isCreation  True if the transaction is a contract creation.
            /// @custom:field value       Value to send to the recipient.
            /// @custom:field mint        Amount of ETH to mint.
            /// @custom:field gasLimit    Gas limit of the transaction.
            /// @custom:field data        Data of the transaction.
            /// @custom:field l1BlockHash Hash of the block the transaction was submitted in.
            /// @custom:field logIndex    Index of the log in the block the transaction was submitted in.
            struct UserDepositTransaction {
                address from;
                address to;
                bool isCreation;
                uint256 value;
                uint256 mint;
                uint64 gasLimit;
                bytes data;
                bytes32 l1BlockHash;
                uint256 logIndex;
            }
            /// @notice Struct representing a withdrawal transaction.
            /// @custom:field nonce    Nonce of the withdrawal transaction
            /// @custom:field sender   Address of the sender of the transaction.
            /// @custom:field target   Address of the recipient of the transaction.
            /// @custom:field value    Value to send to the recipient.
            /// @custom:field gasLimit Gas limit of the transaction.
            /// @custom:field data     Data of the transaction.
            struct WithdrawalTransaction {
                uint256 nonce;
                address sender;
                address target;
                uint256 value;
                uint256 gasLimit;
                bytes data;
            }
            /// @notice Enum representing where the FeeVault withdraws funds to.
            /// @custom:value L1 FeeVault withdraws funds to L1.
            /// @custom:value L2 FeeVault withdraws funds to L2.
            enum WithdrawalNetwork {
                L1,
                L2
            }
        }
        // SPDX-License-Identifier: MIT
        pragma solidity ^0.8.0;
        import { IResourceMetering } from "src/L1/interfaces/IResourceMetering.sol";
        /// @notice This interface corresponds to the Custom Gas Token version of the SystemConfig contract.
        interface ISystemConfig {
            enum UpdateType {
                BATCHER,
                FEE_SCALARS,
                GAS_LIMIT,
                UNSAFE_BLOCK_SIGNER,
                EIP_1559_PARAMS
            }
            struct Addresses {
                address l1CrossDomainMessenger;
                address l1ERC721Bridge;
                address l1StandardBridge;
                address disputeGameFactory;
                address optimismPortal;
                address optimismMintableERC20Factory;
                address gasPayingToken;
            }
            event ConfigUpdate(uint256 indexed version, UpdateType indexed updateType, bytes data);
            event Initialized(uint8 version);
            event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
            function BATCH_INBOX_SLOT() external view returns (bytes32);
            function DISPUTE_GAME_FACTORY_SLOT() external view returns (bytes32);
            function L1_CROSS_DOMAIN_MESSENGER_SLOT() external view returns (bytes32);
            function L1_ERC_721_BRIDGE_SLOT() external view returns (bytes32);
            function L1_STANDARD_BRIDGE_SLOT() external view returns (bytes32);
            function OPTIMISM_MINTABLE_ERC20_FACTORY_SLOT() external view returns (bytes32);
            function OPTIMISM_PORTAL_SLOT() external view returns (bytes32);
            function START_BLOCK_SLOT() external view returns (bytes32);
            function UNSAFE_BLOCK_SIGNER_SLOT() external view returns (bytes32);
            function VERSION() external view returns (uint256);
            function basefeeScalar() external view returns (uint32);
            function batchInbox() external view returns (address addr_);
            function batcherHash() external view returns (bytes32);
            function blobbasefeeScalar() external view returns (uint32);
            function disputeGameFactory() external view returns (address addr_);
            function gasLimit() external view returns (uint64);
            function eip1559Denominator() external view returns (uint32);
            function eip1559Elasticity() external view returns (uint32);
            function gasPayingToken() external view returns (address addr_, uint8 decimals_);
            function gasPayingTokenName() external view returns (string memory name_);
            function gasPayingTokenSymbol() external view returns (string memory symbol_);
            function initialize(
                address _owner,
                uint32 _basefeeScalar,
                uint32 _blobbasefeeScalar,
                bytes32 _batcherHash,
                uint64 _gasLimit,
                address _unsafeBlockSigner,
                IResourceMetering.ResourceConfig memory _config,
                address _batchInbox,
                Addresses memory _addresses
            )
                external;
            function isCustomGasToken() external view returns (bool);
            function l1CrossDomainMessenger() external view returns (address addr_);
            function l1ERC721Bridge() external view returns (address addr_);
            function l1StandardBridge() external view returns (address addr_);
            function maximumGasLimit() external pure returns (uint64);
            function minimumGasLimit() external view returns (uint64);
            function optimismMintableERC20Factory() external view returns (address addr_);
            function optimismPortal() external view returns (address addr_);
            function overhead() external view returns (uint256);
            function owner() external view returns (address);
            function renounceOwnership() external;
            function resourceConfig() external view returns (IResourceMetering.ResourceConfig memory);
            function scalar() external view returns (uint256);
            function setBatcherHash(bytes32 _batcherHash) external;
            function setGasConfig(uint256 _overhead, uint256 _scalar) external;
            function setGasConfigEcotone(uint32 _basefeeScalar, uint32 _blobbasefeeScalar) external;
            function setGasLimit(uint64 _gasLimit) external;
            function setUnsafeBlockSigner(address _unsafeBlockSigner) external;
            function setEIP1559Params(uint32 _denominator, uint32 _elasticity) external;
            function startBlock() external view returns (uint256 startBlock_);
            function transferOwnership(address newOwner) external; // nosemgrep
            function unsafeBlockSigner() external view returns (address addr_);
            function version() external pure returns (string memory);
            function __constructor__() external;
        }
        // SPDX-License-Identifier: MIT
        pragma solidity ^0.8.0;
        interface ISuperchainConfig {
            enum UpdateType {
                GUARDIAN
            }
            event ConfigUpdate(UpdateType indexed updateType, bytes data);
            event Initialized(uint8 version);
            event Paused(string identifier);
            event Unpaused();
            function GUARDIAN_SLOT() external view returns (bytes32);
            function PAUSED_SLOT() external view returns (bytes32);
            function guardian() external view returns (address guardian_);
            function initialize(address _guardian, bool _paused) external;
            function pause(string memory _identifier) external;
            function paused() external view returns (bool paused_);
            function unpause() external;
            function version() external view returns (string memory);
            function __constructor__() external;
        }
        // SPDX-License-Identifier: MIT
        pragma solidity ^0.8.0;
        import { Types } from "src/libraries/Types.sol";
        interface IL2OutputOracle {
            event Initialized(uint8 version);
            event OutputProposed(
                bytes32 indexed outputRoot, uint256 indexed l2OutputIndex, uint256 indexed l2BlockNumber, uint256 l1Timestamp
            );
            event OutputsDeleted(uint256 indexed prevNextOutputIndex, uint256 indexed newNextOutputIndex);
            function CHALLENGER() external view returns (address);
            function FINALIZATION_PERIOD_SECONDS() external view returns (uint256);
            function L2_BLOCK_TIME() external view returns (uint256);
            function PROPOSER() external view returns (address);
            function SUBMISSION_INTERVAL() external view returns (uint256);
            function challenger() external view returns (address);
            function computeL2Timestamp(uint256 _l2BlockNumber) external view returns (uint256);
            function deleteL2Outputs(uint256 _l2OutputIndex) external;
            function finalizationPeriodSeconds() external view returns (uint256);
            function getL2Output(uint256 _l2OutputIndex) external view returns (Types.OutputProposal memory);
            function getL2OutputAfter(uint256 _l2BlockNumber) external view returns (Types.OutputProposal memory);
            function getL2OutputIndexAfter(uint256 _l2BlockNumber) external view returns (uint256);
            function initialize(
                uint256 _submissionInterval,
                uint256 _l2BlockTime,
                uint256 _startingBlockNumber,
                uint256 _startingTimestamp,
                address _proposer,
                address _challenger,
                uint256 _finalizationPeriodSeconds
            )
                external;
            function l2BlockTime() external view returns (uint256);
            function latestBlockNumber() external view returns (uint256);
            function latestOutputIndex() external view returns (uint256);
            function nextBlockNumber() external view returns (uint256);
            function nextOutputIndex() external view returns (uint256);
            function proposeL2Output(
                bytes32 _outputRoot,
                uint256 _l2BlockNumber,
                bytes32 _l1BlockHash,
                uint256 _l1BlockNumber
            )
                external
                payable;
            function proposer() external view returns (address);
            function startingBlockNumber() external view returns (uint256);
            function startingTimestamp() external view returns (uint256);
            function submissionInterval() external view returns (uint256);
            function version() external view returns (string memory);
            function __constructor__() external;
        }
        // SPDX-License-Identifier: MIT
        // OpenZeppelin Contracts (last updated v4.7.0) (utils/Address.sol)
        pragma solidity ^0.8.1;
        /**
         * @dev Collection of functions related to the address type
         */
        library AddressUpgradeable {
            /**
             * @dev Returns true if `account` is a contract.
             *
             * [IMPORTANT]
             * ====
             * It is unsafe to assume that an address for which this function returns
             * false is an externally-owned account (EOA) and not a contract.
             *
             * Among others, `isContract` will return false for the following
             * types of addresses:
             *
             *  - an externally-owned account
             *  - a contract in construction
             *  - an address where a contract will be created
             *  - an address where a contract lived, but was destroyed
             * ====
             *
             * [IMPORTANT]
             * ====
             * You shouldn't rely on `isContract` to protect against flash loan attacks!
             *
             * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
             * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
             * constructor.
             * ====
             */
            function isContract(address account) internal view returns (bool) {
                // This method relies on extcodesize/address.code.length, which returns 0
                // for contracts in construction, since the code is only stored at the end
                // of the constructor execution.
                return account.code.length > 0;
            }
            /**
             * @dev Replacement for Solidity's `transfer`: sends `amount` wei to
             * `recipient`, forwarding all available gas and reverting on errors.
             *
             * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
             * of certain opcodes, possibly making contracts go over the 2300 gas limit
             * imposed by `transfer`, making them unable to receive funds via
             * `transfer`. {sendValue} removes this limitation.
             *
             * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
             *
             * IMPORTANT: because control is transferred to `recipient`, care must be
             * taken to not create reentrancy vulnerabilities. Consider using
             * {ReentrancyGuard} or the
             * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
             */
            function sendValue(address payable recipient, uint256 amount) internal {
                require(address(this).balance >= amount, "Address: insufficient balance");
                (bool success, ) = recipient.call{value: amount}("");
                require(success, "Address: unable to send value, recipient may have reverted");
            }
            /**
             * @dev Performs a Solidity function call using a low level `call`. A
             * plain `call` is an unsafe replacement for a function call: use this
             * function instead.
             *
             * If `target` reverts with a revert reason, it is bubbled up by this
             * function (like regular Solidity function calls).
             *
             * Returns the raw returned data. To convert to the expected return value,
             * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
             *
             * Requirements:
             *
             * - `target` must be a contract.
             * - calling `target` with `data` must not revert.
             *
             * _Available since v3.1._
             */
            function functionCall(address target, bytes memory data) internal returns (bytes memory) {
                return functionCall(target, data, "Address: low-level call failed");
            }
            /**
             * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
             * `errorMessage` as a fallback revert reason when `target` reverts.
             *
             * _Available since v3.1._
             */
            function functionCall(
                address target,
                bytes memory data,
                string memory errorMessage
            ) internal returns (bytes memory) {
                return functionCallWithValue(target, data, 0, errorMessage);
            }
            /**
             * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
             * but also transferring `value` wei to `target`.
             *
             * Requirements:
             *
             * - the calling contract must have an ETH balance of at least `value`.
             * - the called Solidity function must be `payable`.
             *
             * _Available since v3.1._
             */
            function functionCallWithValue(
                address target,
                bytes memory data,
                uint256 value
            ) internal returns (bytes memory) {
                return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
            }
            /**
             * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
             * with `errorMessage` as a fallback revert reason when `target` reverts.
             *
             * _Available since v3.1._
             */
            function functionCallWithValue(
                address target,
                bytes memory data,
                uint256 value,
                string memory errorMessage
            ) internal returns (bytes memory) {
                require(address(this).balance >= value, "Address: insufficient balance for call");
                require(isContract(target), "Address: call to non-contract");
                (bool success, bytes memory returndata) = target.call{value: value}(data);
                return verifyCallResult(success, returndata, errorMessage);
            }
            /**
             * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
             * but performing a static call.
             *
             * _Available since v3.3._
             */
            function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
                return functionStaticCall(target, data, "Address: low-level static call failed");
            }
            /**
             * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
             * but performing a static call.
             *
             * _Available since v3.3._
             */
            function functionStaticCall(
                address target,
                bytes memory data,
                string memory errorMessage
            ) internal view returns (bytes memory) {
                require(isContract(target), "Address: static call to non-contract");
                (bool success, bytes memory returndata) = target.staticcall(data);
                return verifyCallResult(success, returndata, errorMessage);
            }
            /**
             * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the
             * revert reason using the provided one.
             *
             * _Available since v4.3._
             */
            function verifyCallResult(
                bool success,
                bytes memory returndata,
                string memory errorMessage
            ) internal pure returns (bytes memory) {
                if (success) {
                    return returndata;
                } else {
                    // Look for revert reason and bubble it up if present
                    if (returndata.length > 0) {
                        // The easiest way to bubble the revert reason is using memory via assembly
                        /// @solidity memory-safe-assembly
                        assembly {
                            let returndata_size := mload(returndata)
                            revert(add(32, returndata), returndata_size)
                        }
                    } else {
                        revert(errorMessage);
                    }
                }
            }
        }