// SPDX-License-Identifier: MIT pragma solidity 0.8.15; // Contracts import { ProxyAdminOwnedBase } from "src/universal/ProxyAdminOwnedBase.sol"; import { Initializable } from "@openzeppelin/contracts/proxy/utils/Initializable.sol"; import { ResourceMetering } from "src/L1/ResourceMetering.sol"; import { ReinitializableBase } from "src/universal/ReinitializableBase.sol"; // Libraries import { EOA } from "src/libraries/EOA.sol"; import { SafeCall } from "src/libraries/SafeCall.sol"; import { Constants } from "src/libraries/Constants.sol"; import { Predeploys } from "src/libraries/Predeploys.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 { Claim, GameStatus, GameType, GameTypes } from "src/dispute/lib/Types.sol"; import { Features } from "src/libraries/Features.sol"; import { BridgeHookTypes } from "src/libraries/BridgeHookTypes.sol"; import { BridgeHookHashing } from "src/libraries/BridgeHookHashing.sol"; import { BridgeHookDecoder } from "src/libraries/BridgeHookDecoder.sol"; // Interfaces import { ISemver } from "interfaces/universal/ISemver.sol"; import { ISystemConfig } from "interfaces/L1/ISystemConfig.sol"; import { IResourceMetering } from "interfaces/L1/IResourceMetering.sol"; import { IDisputeGameFactory } from "interfaces/dispute/IDisputeGameFactory.sol"; import { IDisputeGame } from "interfaces/dispute/IDisputeGame.sol"; import { IAnchorStateRegistry } from "interfaces/dispute/IAnchorStateRegistry.sol"; import { IETHLockbox } from "interfaces/L1/IETHLockbox.sol"; import { IOptimismPortal2 } from "interfaces/L1/IOptimismPortal2.sol"; import { ISuperchainConfig } from "interfaces/L1/ISuperchainConfig.sol"; import { IBridgeHook } from "interfaces/L1/IBridgeHook.sol"; import { IL1StandardBridge } from "interfaces/L1/IL1StandardBridge.sol"; /// @custom:proxied true /// @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, ReinitializableBase, ProxyAdminOwnedBase, ISemver { /// @notice Represents a proven withdrawal. /// @custom:field disputeGameProxy Game that the withdrawal was proven against. /// @custom:field timestamp Timestamp at which the withdrawal was proven. struct ProvenWithdrawal { IDisputeGame disputeGameProxy; uint64 timestamp; } /// @notice The lowest value in seconds that `proofMaturityDelaySeconds` may be set to. uint256 internal immutable MIN_PROOF_MATURITY_DELAY_SECONDS; /// @notice The highest value in seconds that `proofMaturityDelaySeconds` may be set to. uint256 internal immutable MAX_PROOF_MATURITY_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 value 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; /// @custom:legacy /// @custom:spacer superchainConfig /// @notice Spacer for backwards compatibility. address private spacer_53_1_20; /// @custom:legacy /// @custom:spacer l2Oracle /// @notice Spacer taking up the legacy `l2Oracle` address slot. address private spacer_54_0_20; /// @notice Address of the SystemConfig contract. /// @custom:network-specific ISystemConfig public systemConfig; /// @custom:network-specific /// @custom:legacy /// @custom:spacer disputeGameFactory /// @notice Spacer taking up the legacy `disputeGameFactory` address slot. address private spacer_56_0_20; /// @notice A mapping of withdrawal hashes to proof submitters to ProvenWithdrawal data. mapping(bytes32 => mapping(address => ProvenWithdrawal)) public provenWithdrawals; /// @custom:legacy /// @custom:spacer disputeGameBlacklist bytes32 private spacer_58_0_32; /// @custom:legacy /// @custom:spacer respectedGameType GameType private spacer_59_0_4; /// @custom:legacy /// @custom:spacer respectedGameTypeUpdatedAt uint64 private spacer_59_4_8; /// @notice Mapping of withdrawal hashes to addresses that have submitted a proof for the /// withdrawal. Original OptimismPortal contract only allowed one proof to be submitted /// for any given withdrawal hash. Fault Proofs version of this contract must allow /// multiple proofs for the same withdrawal hash to prevent a malicious user from /// blocking other withdrawals by proving them against invalid proposals. Submitters /// are tracked in an array to simplify the off-chain process of determining which /// proof submission should be used when finalizing a withdrawal. mapping(bytes32 => address[]) public proofSubmitters; /// @custom:legacy /// @custom:spacer _balance uint256 private spacer_61_0_32; /// @notice Address of the AnchorStateRegistry contract. IAnchorStateRegistry public anchorStateRegistry; /// @notice Address of the ETHLockbox contract. Set by `initialize` when given a nonzero /// lockbox and by `migrateToSharedDisputeGame`. Must be nonzero while the ETH_LOCKBOX /// feature is enabled. IETHLockbox public ethLockbox; /// @custom:legacy /// @custom:spacer superRootsActive bool private spacer_63_20_1; /// @notice The delay between when a withdrawal is proven and when it may be finalized. /// Bounded by `MIN_PROOF_MATURITY_DELAY_SECONDS` and `MAX_PROOF_MATURITY_DELAY_SECONDS`. /// @custom:network-specific uint256 public proofMaturityDelaySeconds; /// @notice Bridge hook that screens deposits and withdrawals, or the zero address if unset. /// @custom:network-specific IBridgeHook public bridgeHook; /// @notice Deposits the hook is holding, keyed by item ID. mapping(bytes32 => bool) public heldDeposits; /// @notice Withdrawals the hook is holding, keyed by item ID. mapping(bytes32 => bool) public heldWithdrawals; /// @notice Nonce of the next screened deposit. uint256 internal depositNonce; /// @notice Emitted when the Portal is migrated. /// @param oldLockbox The lockbox before the migration /// @param newLockbox The shared lockbox /// @param oldAnchorStateRegistry The anchorStateRegistry used before the migration /// @param newAnchorStateRegistry The anchorStateRegistry used after the migration event PortalMigrated( IETHLockbox oldLockbox, IETHLockbox newLockbox, IAnchorStateRegistry oldAnchorStateRegistry, IAnchorStateRegistry newAnchorStateRegistry ); /// @notice Migrates the total ETH balance to the ETHLockbox. event ETHMigrated(address indexed lockbox, uint256 balance); /// @notice Emitted when the bridge hook is set. /// @param bridgeHook The new bridge hook. event BridgeHookSet(IBridgeHook indexed bridgeHook); /// @notice Emitted when the bridge hook is removed. /// @param bridgeHook The removed bridge hook. event BridgeHookRemoved(IBridgeHook indexed bridgeHook); /// @notice Emitted when the bridge hook holds a deposit. /// @param id Identifier of the held deposit. event DepositHeld(bytes32 indexed id); /// @notice Emitted when the bridge hook holds a withdrawal. /// @param id Identifier of the held withdrawal. /// @param withdrawalHash Hash of the withdrawal transaction. event WithdrawalHeld(bytes32 indexed id, bytes32 indexed withdrawalHash); /// @notice Emitted when the proof maturity delay is set. /// @param proofMaturityDelaySeconds The new proof maturity delay in seconds. event ProofMaturityDelaySecondsSet(uint256 proofMaturityDelaySeconds); /// @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 proven. Exists as a separate event to /// allow for backwards compatibility for tooling that observes the WithdrawalProven /// and WithdrawalProvenExtension1 events. /// @param withdrawalHash Hash of the withdrawal transaction. /// @param proofSubmitter Address of the proof submitter. /// @param disputeGameProxy Dispute game the withdrawal was proven against. event WithdrawalProvenExtension2( bytes32 indexed withdrawalHash, address indexed proofSubmitter, IDisputeGame indexed disputeGameProxy ); /// @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 proof for a withdrawal transaction is deleted. /// @param withdrawalHash Hash of the withdrawal transaction. /// @param proofSubmitter Address of the proof submitter. event WithdrawalProofDeleted(bytes32 indexed withdrawalHash, address indexed proofSubmitter); /// @notice Thrown when a withdrawal has already been finalized. error OptimismPortal_AlreadyFinalized(); /// @notice Thrown when the target of a withdrawal is unsafe. error OptimismPortal_BadTarget(); /// @notice Thrown when the calldata for a deposit is too large. error OptimismPortal_CalldataTooLarge(); /// @notice Thrown when the portal is paused. error OptimismPortal_CallPaused(); /// @notice Thrown when a CGT withdrawal is not allowed. error OptimismPortal_NotAllowedOnCGTMode(); /// @notice Thrown when a gas estimation transaction is being executed. error OptimismPortal_GasEstimation(); /// @notice Thrown when the gas limit for a deposit is too low. error OptimismPortal_GasLimitTooLow(); /// @notice Thrown when the target of a withdrawal is not a proper dispute game. error OptimismPortal_ImproperDisputeGame(); /// @notice Thrown when a withdrawal has not been proven against a valid dispute game. error OptimismPortal_InvalidDisputeGame(); /// @notice Thrown when Interop is set without the lockbox feature flag error OptimismPortal_InvalidInteropState(); /// @notice Thrown when a withdrawal has not been proven against a valid merkle proof. error OptimismPortal_InvalidMerkleProof(); /// @notice Thrown when a withdrawal has not been proven against a valid output root proof. error OptimismPortal_InvalidOutputRootProof(); /// @notice Thrown when a withdrawal's timestamp is not greater than the dispute game's creation timestamp. error OptimismPortal_InvalidProofTimestamp(); /// @notice Thrown when the root claim of a dispute game is invalid. error OptimismPortal_InvalidRootClaim(); /// @notice Thrown when a withdrawal from the L2CrossDomainMessenger fails in the /// L1CrossDomainMessenger. error OptimismPortal_L1CDMCallFailed(); /// @notice Thrown when migrating to the registry that was previously /// set on the OptimismPortal prior to the migration error OptimismPortal_MigratingToSameRegistry(); /// @notice Thrown when a withdrawal is being finalized by a reentrant call. error OptimismPortal_NoReentrancy(); /// @notice Thrown when calling a function that is only available when INTEROP /// is enabled error OptimismPortal_NotUsingInterop(); /// @notice Thrown when calling a function that requires an active ETHLockbox. error OptimismPortal_NotUsingLockbox(); /// @notice Thrown when a withdrawal has not been proven for long enough. error OptimismPortal_ProofNotOldEnough(); /// @notice Thrown when a withdrawal has not been proven. error OptimismPortal_Unproven(); /// @notice Thrown when removing a bridge hook that is not set. error OptimismPortal_InvalidBridgeHookState(); /// @notice Thrown when the caller is not the bridge hook. error OptimismPortal_NotBridgeHook(); /// @notice Thrown when completing an item that is not held. error OptimismPortal_NotHeld(); /// @notice Thrown when the ETH sent with a completion does not match the held item. error OptimismPortal_ValueMismatch(); /// @notice Thrown when the call of a completed withdrawal fails. error OptimismPortal_TargetCallFailed(); /// @notice Thrown when ETHLockbox is set/unset incorrectly depending on the feature flag. error OptimismPortal_InvalidLockboxState(); /// @notice Thrown when migrateToSharedDisputeGame is called with a zero address. error OptimismPortal_ZeroAddress(); /// @notice Thrown when the new lockbox has not authorized this portal. error OptimismPortal_LockboxNotAuthorizedForPortal(); /// @notice Thrown when a dispute game has not been permanently invalidated. error OptimismPortal_DisputeGameNotInvalidated(); /// @notice Thrown when the proof maturity delay bounds are zero or inverted. error OptimismPortal_InvalidProofMaturityDelayBounds(); /// @notice Thrown when a proof maturity delay is outside the configured bounds. error OptimismPortal_InvalidProofMaturityDelay(); /// @notice Semantic version. /// @custom:semver 7.9.1 function version() public pure virtual returns (string memory) { return "7.9.1"; } /// @param _minProofMaturityDelaySeconds The lowest proof maturity delay a chain may use. /// @param _maxProofMaturityDelaySeconds The highest proof maturity delay a chain may use. constructor(uint256 _minProofMaturityDelaySeconds, uint256 _maxProofMaturityDelaySeconds) ReinitializableBase(4) { if (_minProofMaturityDelaySeconds == 0 || _minProofMaturityDelaySeconds > _maxProofMaturityDelaySeconds) { revert OptimismPortal_InvalidProofMaturityDelayBounds(); } MIN_PROOF_MATURITY_DELAY_SECONDS = _minProofMaturityDelaySeconds; MAX_PROOF_MATURITY_DELAY_SECONDS = _maxProofMaturityDelaySeconds; _disableInitializers(); } /// @notice Initializer. If `_bridgeHook` is nonzero, sets it as the current hook and emits /// BridgeHookSet. Upgrades pass the zero address to keep the current hook. /// WARNING: Do not set a bridge hook on a chain that carries migrated pre-Bedrock /// withdrawals, such as OP Mainnet. Already-relayed legacy (version 0) withdrawals can /// still be proven, and the hold path unlocks their ETH from the lockbox before the /// L1CrossDomainMessenger's already-relayed check runs, so the ETH ends up held and /// can never complete. See https://github.com/ethereum-optimism/optimism/issues/24397 /// /// @param _systemConfig Address of the SystemConfig. /// @param _anchorStateRegistry Address of the AnchorStateRegistry. /// @param _ethLockbox Address of the ETHLockbox. /// @param _proofMaturityDelaySeconds The proof maturity delay in seconds. /// @param _bridgeHook Bridge hook to set, or the zero address to keep the current one. function initialize( ISystemConfig _systemConfig, IAnchorStateRegistry _anchorStateRegistry, IETHLockbox _ethLockbox, uint256 _proofMaturityDelaySeconds, IBridgeHook _bridgeHook ) external reinitializer(initVersion()) { // Initialization transactions must come from the ProxyAdmin or its owner. _assertOnlyProxyAdminOrProxyAdminOwner(); // Now perform initialization logic. systemConfig = _systemConfig; anchorStateRegistry = _anchorStateRegistry; if (address(_ethLockbox) != address(0)) { ethLockbox = _ethLockbox; } if (address(_bridgeHook) != address(0)) { // The previous hook retains held value. The Portal retains the held item commitments, // which the new hook can complete by supplying the required value. bridgeHook = _bridgeHook; emit BridgeHookSet(_bridgeHook); _countAlreadyPublished(); } _assertValidInteropState(); // Assert that the lockbox state is valid. _assertValidLockboxState(); // Set the proof maturity delay and check it against the configured bounds. _setProofMaturityDelaySeconds(_proofMaturityDelaySeconds); // 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; } // Initialize the ResourceMetering contract. __ResourceMetering_init(); } /// @notice Allows the ProxyAdmin owner to set the proof maturity delay. The new value applies /// to every proven withdrawal, including withdrawals proven before the change. /// @param _proofMaturityDelaySeconds The new proof maturity delay in seconds. function setProofMaturityDelaySeconds(uint256 _proofMaturityDelaySeconds) external { // Only the ProxyAdmin owner can change the proof maturity delay. _assertOnlyProxyAdminOwner(); _setProofMaturityDelaySeconds(_proofMaturityDelaySeconds); } /// @notice Getter for the current paused status. function paused() public view returns (bool) { return ethLockbox.paused(); } /// @notice Getter for the lowest value that the proof maturity delay may be set to. function minProofMaturityDelaySeconds() public view returns (uint256) { return MIN_PROOF_MATURITY_DELAY_SECONDS; } /// @notice Getter for the highest value that the proof maturity delay may be set to. function maxProofMaturityDelaySeconds() public view returns (uint256) { return MAX_PROOF_MATURITY_DELAY_SECONDS; } /// @notice Getter for the address of the DisputeGameFactory contract. function disputeGameFactory() public view returns (IDisputeGameFactory) { return anchorStateRegistry.disputeGameFactory(); } /// @notice Returns the SuperchainConfig contract. /// @return ISuperchainConfig The SuperchainConfig contract. function superchainConfig() external view returns (ISuperchainConfig) { return ethLockbox.superchainConfig(); } /// @custom:legacy /// @notice Getter function for the address of the guardian. function guardian() external view returns (address) { return ethLockbox.guardian(); } /// @custom:legacy /// @notice Getter for the dispute game finality delay. function disputeGameFinalityDelaySeconds() external view returns (uint256) { return anchorStateRegistry.disputeGameFinalityDelaySeconds(); } /// @custom:legacy /// @notice Getter for the respected game type. function respectedGameType() external view returns (GameType) { return anchorStateRegistry.respectedGameType(); } /// @custom:legacy /// @notice Getter for the retirement timestamp. Note that this value NO LONGER reflects the /// timestamp at which the respected game type was updated. Game retirement and /// respected game type value have been decoupled, this function now only returns the /// retirement timestamp. function respectedGameTypeUpdatedAt() external view returns (uint64) { return anchorStateRegistry.retirementTimestamp(); } /// @custom:legacy /// @notice Getter for the dispute game blacklist. /// @param _disputeGame The dispute game to check. /// @return Whether the dispute game is blacklisted. function disputeGameBlacklist(IDisputeGame _disputeGame) public view returns (bool) { return anchorStateRegistry.disputeGameBlacklist(_disputeGame); } /// @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 * 40 + 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. function donateETH() external payable { // Intentionally empty. } /// @notice Proves a withdrawal transaction using an Output Root proof. /// @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 storage root. /// @param _withdrawalProof Inclusion proof of the withdrawal within the L2ToL1MessagePasser. function proveWithdrawalTransaction( Types.WithdrawalTransaction memory _tx, uint256 _disputeGameIndex, Types.OutputRootProof calldata _outputRootProof, bytes[] calldata _withdrawalProof ) external { // Cannot prove withdrawal transactions while the system is paused. _assertNotPaused(); // Make sure that the target address is safe. if (_isUnsafeTarget(_tx.target)) { revert OptimismPortal_BadTarget(); } // Cannot prove withdrawal with value when custom gas token mode is enabled. if (_isUsingCustomGasToken()) { if (_tx.value > 0) revert OptimismPortal_NotAllowedOnCGTMode(); } // Fetch the dispute game proxy from the `DisputeGameFactory` contract. (,, IDisputeGame disputeGameProxy) = disputeGameFactory().gameAtIndex(_disputeGameIndex); // Game must be a Proper Game. if (!anchorStateRegistry.isGameProper(disputeGameProxy)) { revert OptimismPortal_ImproperDisputeGame(); } // Game must have been respected game type when created. if (!anchorStateRegistry.isGameRespected(disputeGameProxy)) { revert OptimismPortal_InvalidDisputeGame(); } // Game must not have resolved in favor of the Challenger (invalid root claim). if (_gameStatus(disputeGameProxy) == GameStatus.CHALLENGER_WINS) { revert OptimismPortal_InvalidDisputeGame(); } // As a sanity check, we make sure that the current timestamp is not less than or equal to // the dispute game's creation timestamp. Not strictly necessary but extra layer of // safety against weird bugs. Note that this blocks withdrawals from being proven in the // same block that a dispute game is created. if (block.timestamp <= _gameCreatedAt(disputeGameProxy)) { revert OptimismPortal_InvalidProofTimestamp(); } // Extract the output root claim. Super game types use rootClaimByChainId to extract // the per-chain output root from the super root. Legacy game types use rootClaim directly. // TODO(#19816): Post interop clean up the legacy rootClaim() usage in OptimismPortal2. Claim outputRootClaim; if (GameTypes.isSuperGame(disputeGameProxy.gameType())) { outputRootClaim = disputeGameProxy.rootClaimByChainId(systemConfig.l2ChainId()); } else { outputRootClaim = disputeGameProxy.rootClaim(); } // Verify that the output root can be generated with the elements in the proof. if (outputRootClaim.raw() != Hashing.hashOutputRootProof(_outputRootProof)) { revert OptimismPortal_InvalidOutputRootProof(); } // Load the ProvenWithdrawal into memory, using the withdrawal hash as a unique identifier. bytes32 withdrawalHash = Hashing.hashWithdrawal(_tx); // 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. if ( SecureMerkleTrie.verifyInclusionProof({ _key: abi.encode(storageKey), _value: hex"01", _proof: _withdrawalProof, _root: _outputRootProof.messagePasserStorageRoot }) == false ) { revert OptimismPortal_InvalidMerkleProof(); } // Designate the withdrawalHash as proven by storing the disputeGameProxy and timestamp in // the provenWithdrawals mapping. A given user may re-prove a withdrawalHash multiple // times, but each proof will reset the proof timer. provenWithdrawals[withdrawalHash][msg.sender] = ProvenWithdrawal({ disputeGameProxy: disputeGameProxy, timestamp: uint64(block.timestamp) }); // Add the proof submitter to the list of proof submitters for this withdrawal hash. proofSubmitters[withdrawalHash].push(msg.sender); // Emit a WithdrawalProven events. emit WithdrawalProven(withdrawalHash, _tx.sender, _tx.target); emit WithdrawalProvenExtension1(withdrawalHash, msg.sender); emit WithdrawalProvenExtension2(withdrawalHash, msg.sender, disputeGameProxy); } /// @notice Finalizes a withdrawal transaction. If a bridge hook is set, the hook can hold the /// withdrawal. A held withdrawal does not call its target or emit WithdrawalFinalized /// until the hook completes it. /// @param _tx Withdrawal transaction to finalize. function finalizeWithdrawalTransaction(Types.WithdrawalTransaction memory _tx) external { finalizeWithdrawalTransactionExternalProof(_tx, msg.sender); } /// @notice Migrates the total ETH balance of this contract to the ETHLockbox. Custom gas /// token chains keep custody in the portal and cannot migrate ETH. function migrateLiquidity() public { if (!_isUsingLockbox()) revert OptimismPortal_NotUsingLockbox(); // Liquidity migration can only be triggered by the ProxyAdmin owner. _assertOnlyProxyAdminOwner(); if (_isUsingCustomGasToken()) revert OptimismPortal_NotAllowedOnCGTMode(); // Migrate the liquidity. uint256 ethBalance = address(this).balance; _lockETH(ethBalance); emit ETHMigrated(address(ethLockbox), ethBalance); } /// @notice Allows the owner of the ProxyAdmin to migrate the OptimismPortal to use a new /// lockbox, point at a new AnchorStateRegistry, and start to use the Super Roots proof /// method. Primarily used for OptimismPortal instances to join the interop set, but /// can also be used to swap the proof method from Output Roots to Super Roots if the /// provided lockbox is the same as the current one. /// @dev It is possible to change lockboxes without migrating liquidity. This can cause one /// of the OptimismPortal instances connected to the new lockbox to not be able to /// unlock sufficient ETH to finalize withdrawals which would trigger reverts. To avoid /// this issue, guarantee that this function is called atomically alongside the /// ETHLockbox.migrateLiquidity() function within the same transaction. /// @param _newLockbox The address of the new ETHLockbox contract. /// @param _newAnchorStateRegistry The address of the new AnchorStateRegistry contract. function migrateToSharedDisputeGame( IETHLockbox _newLockbox, IAnchorStateRegistry _newAnchorStateRegistry ) external { if (!_isUsingInterop()) revert OptimismPortal_NotUsingInterop(); // Migration can only be triggered when the system is not paused because the migration can // potentially unpause the system as a result of the modified ETHLockbox address. _assertNotPaused(); // Migration can only be triggered by the ProxyAdmin owner. _assertOnlyProxyAdminOwner(); // Chains can use this method to swap the proof method from Output Roots to Super Roots // without joining the interop set. In this case, the old and new lockboxes will be the // same. However, whether or not a chain is joining the interop set, all chains will need a // new AnchorStateRegistry when migrating to Super Roots. We therefore check that the new // AnchorStateRegistry is different than the old one to prevent this function from being // accidentally misused. if (anchorStateRegistry == _newAnchorStateRegistry) { revert OptimismPortal_MigratingToSameRegistry(); } // Defense-in-depth: reject obvious operator footguns. The ProxyAdmin owner is fully // trusted (can upgrade the portal), but these checks make it harder to brick the portal by // installing zero / non-contract / unauthorized / mis-wired addresses. if (address(_newLockbox) == address(0) || address(_newAnchorStateRegistry) == address(0)) { revert OptimismPortal_ZeroAddress(); } if (!_newLockbox.authorizedPortals(IOptimismPortal2(payable(address(this))))) { revert OptimismPortal_LockboxNotAuthorizedForPortal(); } // Update the ETHLockbox. IETHLockbox oldLockbox = ethLockbox; ethLockbox = _newLockbox; // Update the AnchorStateRegistry. IAnchorStateRegistry oldAnchorStateRegistry = anchorStateRegistry; anchorStateRegistry = _newAnchorStateRegistry; // Emit a PortalMigrated event. emit PortalMigrated(oldLockbox, _newLockbox, oldAnchorStateRegistry, _newAnchorStateRegistry); } /// @notice Finalizes a withdrawal transaction, using an external proof submitter. If a bridge /// hook is set, the hook can hold the withdrawal. A held withdrawal does not call its /// target or emit WithdrawalFinalized until the hook completes it. /// @param _tx Withdrawal transaction to finalize. /// @param _proofSubmitter Address of the proof submitter. function finalizeWithdrawalTransactionExternalProof( Types.WithdrawalTransaction memory _tx, address _proofSubmitter ) public { // Cannot finalize withdrawal transactions while the system is paused. _assertNotPaused(); // Cannot finalize withdrawal with value when custom gas token mode is enabled. if (_isUsingCustomGasToken()) { if (_tx.value > 0) revert OptimismPortal_NotAllowedOnCGTMode(); } // Block reentrancy from a withdrawal's target. l2Sender holds the withdrawal's sender while the // target executes. A nested finalization would change l2Sender before the outer call ends. if (l2Sender != Constants.DEFAULT_L2_SENDER) { revert OptimismPortal_NoReentrancy(); } // Make sure that the target address is safe. if (_isUnsafeTarget(_tx.target)) { revert OptimismPortal_BadTarget(); } // Grab the withdrawal. 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; // If using ETHLockbox, unlock the ETH from the ETHLockbox. if (_isUsingLockbox()) { if (_tx.value > 0) _unlockETH(_tx.value); } // NOTE: ETH is unlocked before screening; legacy already-relayed messages are not // rejected here (see https://github.com/ethereum-optimism/optimism/issues/24397). if (_isUsingBridgeHook()) { ProvenWithdrawal memory proven = provenWithdrawals[withdrawalHash][_proofSubmitter]; uint256 maturedAt = proven.timestamp + proofMaturityDelaySeconds; uint256 settledAt = proven.disputeGameProxy.resolvedAt().raw() + anchorStateRegistry.disputeGameFinalityDelaySeconds(); // The withdrawal waits for both its proof delay and its game delay. It can first finalize // one second after the later of their end times. uint256 finalizableAt = (maturedAt > settledAt ? maturedAt : settledAt) + 1; BridgeHookTypes.Item memory item = BridgeHookTypes.Item({ direction: BridgeHookTypes.Direction.Withdrawal, asset: BridgeHookTypes.Asset.ETH, from: _tx.sender, aliased: false, to: _tx.target, ethAmount: _tx.value, l2Value: 0, gasLimit: _tx.gasLimit, isCreation: false, data: _tx.data, nonce: _tx.nonce }); // Sets the item's asset to ERC20 if the item is a token transfer. bytes memory message = _recognize(item); if (!bridgeHook.screenWithdrawal(item, finalizableAt)) { bytes32 id = _commitHold(item, message, heldWithdrawals); emit WithdrawalHeld(id, withdrawalHash); bridgeHook.holdWithdrawal{ value: _tx.value }(item); return; } } // 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; // 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 OptimismPortal_GasEstimation(); } // A failed call means the L1CrossDomainMessenger reverted without recording the message, // e.g. because it ran out of gas. Revert so the withdrawal stays unfinalized and can be // finalized again with more gas, instead of being finalized with no way to replay it. // // Not every messenger failure is a gas problem. The messenger reverts whatever the gas // when the message targets an unsafe address (the L1CrossDomainMessenger or this // contract) or is a legacy message that was already relayed. Such withdrawals can be // proven but never finalized, where before they were finalized as failed. Their funds // stay locked in the same place either way. // // Checking the sender is enough because the L2CrossDomainMessenger only initiates // withdrawals to `otherMessenger`, and blocks `L2ToL1MessagePasser` as a relay target. if (!success && _tx.sender == Predeploys.L2_CROSS_DOMAIN_MESSENGER) { revert OptimismPortal_L1CDMCallFailed(); } // All other withdrawals are immediately finalized. Replayability can // be achieved through contracts built on top of this contract emit WithdrawalFinalized(withdrawalHash, success); // If using ETHLockbox, send ETH back to the Lockbox in the case of a failed transaction or // it'll get stuck here and would need to be moved back via admin action. if (_isUsingLockbox()) { if (!success && _tx.value > 0) { _lockETH(_tx.value); } } } /// @notice Checks that a withdrawal has been proven and is ready to be finalized. /// @param _withdrawalHash Hash of the withdrawal. /// @param _proofSubmitter Address of the proof submitter. function checkWithdrawal(bytes32 _withdrawalHash, address _proofSubmitter) public view { // Grab the withdrawal and dispute game proxy. ProvenWithdrawal memory provenWithdrawal = provenWithdrawals[_withdrawalHash][_proofSubmitter]; IDisputeGame disputeGameProxy = provenWithdrawal.disputeGameProxy; // Check that this withdrawal has not already been finalized, this is replay protection. if (finalizedWithdrawals[_withdrawalHash]) { revert OptimismPortal_AlreadyFinalized(); } // 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. if (provenWithdrawal.timestamp == 0) { revert OptimismPortal_Unproven(); } // 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. Note that this blocks withdrawals that // are proven in the same block that a dispute game is created. if (provenWithdrawal.timestamp <= _gameCreatedAt(disputeGameProxy)) { revert OptimismPortal_InvalidProofTimestamp(); } // A proven withdrawal must wait at least `proofMaturityDelaySeconds` before finalizing. // A zero delay means the proxy was upgraded without calling `initialize`, so fail closed // rather than finalize withdrawals with no review period. if (proofMaturityDelaySeconds == 0 || block.timestamp - provenWithdrawal.timestamp <= proofMaturityDelaySeconds) { revert OptimismPortal_ProofNotOldEnough(); } // Check that the root claim is valid. if (!anchorStateRegistry.isGameClaimValid(disputeGameProxy)) { revert OptimismPortal_InvalidRootClaim(); } } /// @notice Deletes a withdrawal proof whose dispute game can never lead to finalization. /// Permissionless because both conditions checked here are permanent. /// @param _withdrawalHash Hash of the withdrawal. /// @param _proofSubmitter Address of the proof submitter. function deleteProvenWithdrawal(bytes32 _withdrawalHash, address _proofSubmitter) external { ProvenWithdrawal memory provenWithdrawal = provenWithdrawals[_withdrawalHash][_proofSubmitter]; if (provenWithdrawal.timestamp == 0) { revert OptimismPortal_Unproven(); } IDisputeGame disputeGameProxy = provenWithdrawal.disputeGameProxy; if ( _gameStatus(disputeGameProxy) != GameStatus.CHALLENGER_WINS && !anchorStateRegistry.isGameBlacklisted(disputeGameProxy) ) { revert OptimismPortal_DisputeGameNotInvalidated(); } delete provenWithdrawals[_withdrawalHash][_proofSubmitter]; emit WithdrawalProofDeleted(_withdrawalHash, _proofSubmitter); } /// @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. /// If a bridge hook is set, the hook can hold the deposit, unless the sender is the /// ProxyAdmin owner. A held deposit does not emit TransactionDeposited until the hook /// completes it. /// @dev The `msg.value` is locked on the ETHLockbox and minted as ETH when the deposit /// arrives on L2, while `_value` specifies how much ETH to send to the target. /// @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) { if (_isUsingCustomGasToken()) { if (msg.value > 0) revert OptimismPortal_NotAllowedOnCGTMode(); } // Just to be safe, make sure that people specify address(0) as the target when doing // contract creations. if (_isCreation && _to != address(0)) { revert OptimismPortal_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 OptimismPortal_GasLimitTooLow(); } // 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 OptimismPortal_CalldataTooLarge(); } // Transform the from-address to its alias if the caller is a contract. address from = msg.sender; if (!EOA.isSenderEOA()) { from = AddressAliasHelper.applyL1ToL2Alias(msg.sender); } // The L1PAO skips the hook so that governance can always reach L2. if (_isUsingBridgeHook() && msg.sender != proxyAdminOwner()) { BridgeHookTypes.Item memory item = BridgeHookTypes.Item({ direction: BridgeHookTypes.Direction.Deposit, asset: BridgeHookTypes.Asset.ETH, from: from, aliased: from != msg.sender, to: _to, ethAmount: msg.value, l2Value: _value, gasLimit: _gasLimit, isCreation: _isCreation, data: _data, nonce: depositNonce++ }); // Sets the item's asset to ERC20 if the item is a token transfer. bytes memory message = _recognize(item); if (!bridgeHook.screenDeposit(item)) { bytes32 id = _commitHold(item, message, heldDeposits); emit DepositHeld(id); bridgeHook.holdDeposit{ value: msg.value }(item); return; } } _lockEthAndEmitDeposit(from, _to, _value, _gasLimit, _isCreation, _data); } /// @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; } /// @notice Removes the bridge hook. Only callable by the ProxyAdmin owner. The removed hook /// keeps the value it holds and stops being an unsafe target. Only initialize can set /// a hook again. function removeHook() external { _assertOnlyProxyAdminOwner(); if (address(bridgeHook) == address(0)) revert OptimismPortal_InvalidBridgeHookState(); IBridgeHook hook = bridgeHook; bridgeHook = IBridgeHook(address(0)); emit BridgeHookRemoved(hook); } /// @notice Sends a held deposit to L2 on its original terms. Only callable by the bridge hook, /// which can also complete deposits held under an earlier hook. The hook must attach /// the item's ETH and approve the bridge to reclaim escrowed tokens. /// @param _item Held deposit. function completeDepositTransaction(BridgeHookTypes.Item memory _item) external payable { _releaseHeld(_item, heldDeposits); _lockEthAndEmitDeposit( _item.from, _item.to, _item.l2Value, uint64(_item.gasLimit), _item.isCreation, _item.data ); } /// @notice Executes a held withdrawal on its original terms. Only callable by the bridge hook, /// which can also complete withdrawals held under an earlier hook. The hook must /// attach the item's ETH and approve the bridge to reclaim escrowed tokens. Reverts /// if the call fails, so the withdrawal stays held. /// @param _item Held withdrawal. function completeWithdrawalTransaction(BridgeHookTypes.Item memory _item) external payable { _assertNotPaused(); if (l2Sender != Constants.DEFAULT_L2_SENDER) revert OptimismPortal_NoReentrancy(); if (_isUnsafeTarget(_item.to)) revert OptimismPortal_BadTarget(); _releaseHeld(_item, heldWithdrawals); l2Sender = _item.from; bool success = SafeCall.callWithMinGas(_item.to, _item.gasLimit, _item.ethAmount, _item.data); l2Sender = Constants.DEFAULT_L2_SENDER; if (!success) revert OptimismPortal_TargetCallFailed(); emit WithdrawalFinalized( Hashing.hashWithdrawal( Types.WithdrawalTransaction({ nonce: _item.nonce, sender: _item.from, target: _item.to, value: _item.ethAmount, gasLimit: _item.gasLimit, data: _item.data }) ), true ); } /// @notice Locks ETH in the ETHLockbox. /// @param _amount Amount of ETH to lock. function _lockETH(uint256 _amount) internal { ethLockbox.lockETH{ value: _amount }(); } /// @notice Unlocks ETH from the ETHLockbox. /// @param _amount Amount of ETH to unlock. function _unlockETH(uint256 _amount) internal { ethLockbox.unlockETH(_amount); } /// @notice Returns the L1StandardBridge. /// @return The L1StandardBridge. function _l1StandardBridge() internal view returns (IL1StandardBridge) { return IL1StandardBridge(payable(systemConfig.l1StandardBridge())); } /// @notice Checks if a SystemConfig feature is enabled. /// @param _feature Feature to check. /// @return bool True if the feature is enabled. function _isFeatureEnabled(bytes32 _feature) internal view returns (bool) { return systemConfig.isFeatureEnabled(_feature); } /// @notice Returns a dispute game's status. /// @param _game Dispute game. /// @return The game's status. function _gameStatus(IDisputeGame _game) internal view returns (GameStatus) { return _game.status(); } /// @notice Returns when a dispute game was created. /// @param _game Dispute game. /// @return The game's creation timestamp. function _gameCreatedAt(IDisputeGame _game) internal view returns (uint64) { return _game.createdAt().raw(); } /// @notice Sets the item's asset to ERC20 if the item is a token transfer. /// @param _item Item to recognize. /// @return message_ The bridge's call, or empty if not a token transfer. function _recognize(BridgeHookTypes.Item memory _item) internal view returns (bytes memory message_) { bool isTokenTransfer; (isTokenTransfer, message_) = BridgeHookDecoder.recognizeTokenTransfer( _item, systemConfig.l1CrossDomainMessenger(), address(_l1StandardBridge()) ); if (isTokenTransfer) _item.asset = BridgeHookTypes.Asset.ERC20; } /// @notice Commits a held item and moves its escrowed tokens to the hook. /// @param _item Held item. /// @param _message The bridge's call, for a token transfer. /// @param _held Held items of the item's direction. /// @return id_ Identifier of the held item. function _commitHold( BridgeHookTypes.Item memory _item, bytes memory _message, mapping(bytes32 => bool) storage _held ) internal returns (bytes32 id_) { id_ = BridgeHookHashing.hashItem(_item); _held[id_] = true; if (_item.asset == BridgeHookTypes.Asset.ERC20) { _l1StandardBridge().holdERC20(id_, _item.direction, _message); } } /// @notice Deletes a held item's commitment and returns its escrowed tokens to the bridge. /// Reverts unless the caller is the hook and sends the item's ETH. /// @param _item Held item. /// @param _held Held items of the direction that the caller completes. function _releaseHeld(BridgeHookTypes.Item memory _item, mapping(bytes32 => bool) storage _held) internal { if (msg.sender != address(bridgeHook)) revert OptimismPortal_NotBridgeHook(); bytes32 id = BridgeHookHashing.hashItem(_item); if (!_held[id]) revert OptimismPortal_NotHeld(); delete _held[id]; if (msg.value != _item.ethAmount) revert OptimismPortal_ValueMismatch(); if (_item.asset == BridgeHookTypes.Asset.ERC20) { (, bytes memory message) = BridgeHookDecoder.extractTokenMessage(_item); _l1StandardBridge().restoreERC20(id, _item.direction, message); } } /// @notice Locks the deposit's ETH and emits its TransactionDeposited event. /// @param _from Sender on L2, aliased if a contract. /// @param _to Target address on L2. /// @param _value ETH value to send to the recipient. /// @param _gasLimit Amount of L2 gas to purchase. /// @param _isCreation Whether or not the transaction is a contract creation. /// @param _data Data to trigger the recipient with. function _lockEthAndEmitDeposit( address _from, address _to, uint256 _value, uint64 _gasLimit, bool _isCreation, bytes memory _data ) internal { if (_isUsingBridgeHook() || _publishedParams.prevBlockNum == block.number) _countPublished(_gasLimit); // TODO(#23835): Remove this check once every chain uses the ETHLockbox. if (_isUsingLockbox()) { if (msg.value > 0) _lockETH(msg.value); } // 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 Checks if a bridge hook is set. /// @return bool True if a bridge hook is set. function _isUsingBridgeHook() internal view returns (bool) { return address(bridgeHook) != address(0); } /// @notice Checks if the ETHLockbox feature is enabled. /// @return bool True if the ETHLockbox feature is enabled. function _isUsingLockbox() internal view returns (bool) { return _isFeatureEnabled(Features.ETH_LOCKBOX) && address(ethLockbox) != address(0); } /// @notice Checks if the Interop feature is enabled. /// @return bool True if the Interop feature is enabled. function _isUsingInterop() internal view returns (bool) { return _isFeatureEnabled(Features.INTEROP) && _isFeatureEnabled(Features.ETH_LOCKBOX); } /// @notice Checks if the Custom Gas Token feature is enabled. /// @return bool True if the Custom Gas Token feature is enabled. function _isUsingCustomGasToken() internal view returns (bool) { // NOTE: Chains are not supposed to enable Custom Gas Token (CGT) mode after initial deployment. // Enabling CGT post-deployment is strongly discouraged and may lead to unexpected behavior. return _isFeatureEnabled(Features.CUSTOM_GAS_TOKEN); } /// @notice Asserts that the contract is not paused. function _assertNotPaused() internal view { if (paused()) { revert OptimismPortal_CallPaused(); } } /// @notice Asserts the ETHLockbox feature flag must be set if INTEROP is set function _assertValidInteropState() internal view { if (_isFeatureEnabled(Features.INTEROP) && !_isFeatureEnabled(Features.ETH_LOCKBOX)) { revert OptimismPortal_InvalidInteropState(); } } /// @notice Asserts that the ETHLockbox is configured. function _assertValidLockboxState() internal view { if (!_isFeatureEnabled(Features.ETH_LOCKBOX) || address(ethLockbox) == address(0)) { revert OptimismPortal_InvalidLockboxState(); } } /// @notice Sets the proof maturity delay after checking it against the configured bounds. /// @param _proofMaturityDelaySeconds The new proof maturity delay in seconds. function _setProofMaturityDelaySeconds(uint256 _proofMaturityDelaySeconds) internal { if ( _proofMaturityDelaySeconds < MIN_PROOF_MATURITY_DELAY_SECONDS || _proofMaturityDelaySeconds > MAX_PROOF_MATURITY_DELAY_SECONDS ) { revert OptimismPortal_InvalidProofMaturityDelay(); } proofMaturityDelaySeconds = _proofMaturityDelaySeconds; emit ProofMaturityDelaySecondsSet(_proofMaturityDelaySeconds); } /// @notice Checks if a target address is unsafe. The L1StandardBridge and the bridge hook are /// unsafe only while a hook is set. function _isUnsafeTarget(address _target) internal view virtual returns (bool) { // Prevent users from targeting an unsafe target address on a withdrawal transaction. if (_target == address(this) || _target == address(ethLockbox)) return true; if (!_isUsingBridgeHook()) return false; return _target == address(_l1StandardBridge()) || _target == address(bridgeHook); } /// @notice Getter for the resource config. Used internally by the ResourceMetering contract. /// The SystemConfig is the source of truth for the resource config. /// @return config_ ResourceMetering ResourceConfig function _resourceConfig() internal view override returns (ResourceMetering.ResourceConfig memory config_) { IResourceMetering.ResourceConfig memory config = systemConfig.resourceConfig(); assembly ("memory-safe") { config_ := config } } }