Optimism is an Optimistic Rollup solution that processes transactions at a lower cost than Ethereum Mainnet (Layer 1/L1) while maintaining security by writing all data to L1. To use L1 assets on Optimism (or any L2), assets must be bridged. This involves locking assets on L1 and receiving equivalent assets on L2, which can later be bridged back.
How the Optimism Standard Bridge Works
The Optimism standard bridge facilitates two main flows:
- Deposit Flow (L1 โ L2)
- Withdrawal Flow (L2 โ L1)
Deposit Flow
Layer 1 Process
- For ERC-20 deposits, the depositor grants the bridge an allowance
- The depositor calls the L1 bridge (
depositERC20,depositERC20To,depositETH, ordepositETHTo) The L1 bridge takes possession of the assets:
- ETH: Transferred as part of the call
- ERC-20: Transferred via the allowance
- The L1 bridge uses cross-domain messaging to call
finalizeDepositon the L2 bridge
Layer 2 Process
- The L2 bridge verifies the call's legitimacy
Checks if the L2 ERC-20 contract is correct:
- Matches the L1 counterpart
- Supports the correct interface via ERC-165
- If valid, mints tokens to the specified address; otherwise initiates a withdrawal process
Withdrawal Flow
Layer 2 Process
- The withdrawer calls the L2 bridge (
withdraworwithdrawTo) - The L2 bridge burns the tokens
- Uses cross-domain messaging to call
finalizeETHWithdrawalorfinalizeERC20Withdrawalon L1
Layer 1 Process
- The L1 bridge verifies the call's legitimacy
- Transfers the asset (ETH or ERC-20) to the specified address
Layer 1 Contract Implementation
Key Components
- IL1ERC20Bridge Interface: Handles ERC-20 token bridging
- IL1StandardBridge Interface: Extends IL1ERC20Bridge for ETH handling
- CrossDomainEnabled: Facilitates cross-layer messaging
The L1 bridge contract:
- Initializes deposits from L1 to L2
- Finalizes withdrawals from L2 to L1
- Uses OpenZeppelin's SafeERC20 for secure token transfers
- Implements security checks to prevent unauthorized access
Layer 2 Contract Implementation
Key Components
- IL2StandardERC20 Interface: Standard interface for L2 ERC-20 tokens
L2StandardERC20 Contract: Implementation that:
- Only allows the L2 bridge to mint/burn tokens
- Tracks the corresponding L1 token address
- Implements ERC-165 for interface support verification
The L2 bridge contract:
- Initiates withdrawals from L2 to L1
- Finalizes deposits from L1 to L2
- Includes sanity checks to ensure token compatibility
FAQ
What is the difference between deposits and withdrawals in Optimism's bridge?
- Deposits move assets from L1 to L2
- Withdrawals move assets from L2 to L1
How long do withdrawals take?
Withdrawals require a challenge period (typically 7 days) before they can be finalized on L1.
Can any ERC-20 token be bridged?
Yes, but the L2 token must implement the IL2StandardERC20 interface and properly track its L1 counterpart.
Is ETH handled differently from ERC-20 tokens?
On L1, yes - ETH uses separate functions. On L2, ETH is handled as an ERC-20 token with a special address.
What security measures are in place?
The bridge implements multiple security checks:
- Cross-domain message verification
- Interface support verification (ERC-165)
- Mint/burn permissions restricted to the bridge
- Sanity checks for token address matching
๐ Learn more about Optimism bridging
Conclusion
The Optimism standard bridge provides a secure, flexible mechanism for moving assets between L1 and L2. While it offers maximum flexibility, users often prefer third-party bridges for faster withdrawals. Understanding the bridge's implementation helps developers create secure cross-chain applications and contributes to Optimism's growing ecosystem.