- Initiate on Base: the withdrawal transaction is sent on Base. This records the withdrawal message in the
L2ToL1MessagePassercontract. - Prove on Ethereum: after the relevant Base state has been posted to Ethereum, anyone can submit a proof to the
OptimismPortalcontract showing that the withdrawal message exists on Base. - Finalize on Ethereum: after the finalization window has passed, anyone can finalize the withdrawal on Ethereum. Finalization releases the assets or relays the message to the target contract.
Canonical withdrawals to Ethereum can be finalized only after the dispute game for the output root they are proven against has passed its finalization window. Since the Beryl upgrade, that window is 5 days for a single-proof dispute game and 1 day on the dual-proof fast path, when both a TEE proof and a ZK proof back the same proposal. The window gives network participants time to dispute an invalid output root before withdrawals that depend on it can be finalized.Most of the total time from initiating a withdrawal on Base to receiving funds on Ethereum is the finalization window. Waiting for the relevant Base state to be proposed on Ethereum usually adds only about 20 to 60 minutes, plus the time to submit the prove and finalize transactions. See Transaction Finality for how withdrawal finality differs from ordinary Base transaction finality.
Overview
Withdrawals are cross domain transactions which are initiated on L2, and finalized by a transaction executed on L1. Notably, withdrawals may be used by an L2 account to call an L1 contract, or to transfer ETH from an L2 account to an L1 account. Vocabulary note: withdrawal can refer to the transaction at various stages of the process, but we introduce more specific terms to differentiate:- A withdrawal initiating transaction refers specifically to a transaction on L2 sent to the Withdrawals predeploy.
- A withdrawal proving transaction refers specifically to an L1 transaction which proves the withdrawal is correct (that it has been included in a merkle tree whose root is committed to by a dispute game on L1).
- A withdrawal finalizing transaction refers specifically to an L1 transaction which finalizes and relays the withdrawal.
OptimismPortal, which proves the inclusion of this withdrawal message.
Withdrawals are finalized on L1 via a call to the OptimismPortal contract,
which verifies that the proof maturity delay has passed since the withdrawal was proven and that the
dispute game it was proven against is now a valid claim.
In this way, withdrawals are different from deposits which make use of a special transaction type in the
execution engine client. Rather, withdrawals transaction must use smart contracts on L1 for
finalization.
Withdrawal Flow
We first describe the end to end flow of initiating and finalizing a withdrawal:On L2
An L2 account sends a withdrawal message (and possibly also ETH) to theL2ToL1MessagePasser predeploy contract.
This is a very simple contract that stores the hash of the withdrawal data.
On L1
- A relayer submits a withdrawal proving transaction with the required inputs
to the
OptimismPortalcontract. The relayer is not necessarily the same entity which initiated the withdrawal on L2. These inputs include the withdrawal transaction data, inclusion proofs, and the index of a dispute game in theDisputeGameFactory. The game’s root claim is an L2 output root that commits to the withdrawal as registered on L2. On Base, these games areAggregateVerifiergames. - The
OptimismPortalcontract looks up the game in theDisputeGameFactoryand checks through theAnchorStateRegistrythat the game is proper and of the respected game type, and that it has not resolved in favor of a challenger. It then verifies the output root proof against the game’s root claim and the withdrawal’s inclusion in theL2ToL1MessagePasserstorage root. - If proof verification fails, the call reverts. Otherwise the game and the proof timestamp are recorded for the proof submitter. A withdrawal can be re-proven, for example against a different game if the first one is invalidated; re-proving resets that submitter’s proof timestamp.
- The dispute game runs its finalization window: 5 days for a single-proof game, or 1 day when both TEE and ZK proofs back the proposal (see Beryl). During this window, a challenger can dispute an invalid root claim.
- Once the game’s claim is valid and the proof maturity delay has passed, a relayer submits a withdrawal
finalizing transaction to the
OptimismPortalcontract. The relayer doesn’t need to be the same entity that initiated the withdrawal on L2. - The
OptimismPortalcontract receives the withdrawal transaction data and verifies that the withdrawal has been proven, that at leastproofMaturityDelaySecondshave passed since it was proven, and thatAnchorStateRegistry.isGameClaimValid()returns true for the game it was proven against. - If the requirements are not met, the call reverts. Otherwise the call is forwarded, and the hash is recorded to prevent it from being replayed.
The L2ToL1MessagePasser Contract
A withdrawal is initiated by calling the L2ToL1MessagePasser contract’sinitiateWithdrawal function.
The L2ToL1MessagePasser is a simple predeploy contract at 0x4200000000000000000000000000000000000016
which stores messages to be withdrawn.
L2ToL1MessagePasser.sol
MessagePassed event includes all of the data that is hashed and
stored in the sentMessages mapping, as well as the hash itself.
Addresses Are Not Aliased on Withdrawals
When a contract makes a deposit, the sender’s address is aliased. The same is not true of withdrawals, which do not modify the sender’s address. The difference is that:- on L2, the deposit sender’s address is returned by the
CALLERopcode, meaning a contract cannot easily tell if the call originated on L1 or L2, whereas - on L1, the withdrawal sender’s address is accessed by calling the
l2Sender()function on theOptimismPortalcontract.
l2Sender() removes any ambiguity about which domain the call originated from. Still, developers will need to
recognize that having the same address does not imply that a contract on L2 will behave the same as a contract on L1.
The Optimism Portal Contract
The Optimism Portal serves as both the entry and exit point to the Base L2. It is a contract which inherits from the OptimismPortal contract, and in addition provides the following interface for withdrawals:OptimismPortal.sol
Withdrawal Verification and Finalization
The following inputs are required to prove and finalize a withdrawal:- Withdrawal transaction data:
nonce: Nonce for the provided message.sender: Message sender address on L2.target: Target address on L1.value: ETH to send to the target.data: Data to send to the target.gasLimit: Gas to be forwarded to the target.
- Proof and verification data:
disputeGameIndex: The index in theDisputeGameFactoryof the dispute game whose root claim is the applicable output root.outputRootProof: Fourbytes32values which are used to derive the output root.withdrawalProof: An inclusion proof for the given withdrawal in the L2ToL1MessagePasser contract.
- The game at
disputeGameIndexis proper and respected according to theAnchorStateRegistry, and has not resolved withCHALLENGER_WINS. - The keccak256 hash of the
outputRootProofvalues is equal to the game’s root claim. - The
withdrawalProofis a valid inclusion proof demonstrating that a hash of the Withdrawal transaction data is contained in the storage of the L2ToL1MessagePasser contract on L2.
- The withdrawal has been proven by the proof submitter and has not already been finalized.
- More than
proofMaturityDelaySecondshave passed since the withdrawal was proven. AnchorStateRegistry.isGameClaimValid()returns true for the game the withdrawal was proven against. This requires the game to have resolved withDEFENDER_WINSafter its finalization window.
Security Considerations
Key Properties of Withdrawal Verification
- It should not be possible to ‘double spend’ a withdrawal, ie. to relay a withdrawal on L1 which does not correspond to a message initiated on L2. For reference, see this writeup of a vulnerability of this type found on Polygon.
-
For each withdrawal initiated on L2 (i.e. with a unique
messageNonce()), the following properties must hold:- It should only be possible to prove the withdrawal once, unless the outputRoot for the withdrawal has changed.
- It should only be possible to finalize the withdrawal once.
- It should not be possible to relay the message with any of its fields modified, ie.
- Modifying the
senderfield would enable a ‘spoofing’ attack. - Modifying the
target,data, orvaluefields would enable an attacker to dangerously change the intended outcome of the withdrawal. - Modifying the
gasLimitcould make the cost of relaying too high, or allow the relayer to cause execution to fail (out of gas) in thetarget.
- Modifying the
Handling Successfully Verified Messages That Fail When Relayed
If the execution of the relayed call fails in thetarget contract, it is unfortunately not possible to determine
whether or not it was ‘supposed’ to fail, and whether or not it should be ‘replayable’. For this reason, and to
minimize complexity, we have not provided any replay functionality, this may be implemented in external utility
contracts if desired.
OptimismPortal Can Send Arbitrary Messages on L1
TheL2ToL1MessagePasser contract’s initiateWithdrawal function accepts a _target address and _data bytes,
which is passed to a CALL opcode on L1 when finalizeWithdrawalTransaction is called after the withdrawal
becomes finalizable. This means that, by design, the OptimismPortal contract can be used to send arbitrary transactions on
the L1, with the OptimismPortal as the msg.sender.
This means users of the OptimismPortal contract should be careful what permissions they grant to the portal.
For example, any ERC20 tokens mistakenly sent to the OptimismPortal contract are essentially lost, as they can
be claimed by anybody that pre-approves transfers of this token out of the portal, using the L2 to initiate the
approval and the L1 to prove and finalize the approval (after the finalization window).