L1StandardBridge

Table of Contents

Note: This document is not finalized and should be considered experimental.

Overview

This page specifies the L1StandardBridge changes to support a chain that enables a bridge hook. The model those changes serve, and the vocabulary they use, are in the Compliance Module overview. The bridge's behavior on a default OP Stack chain is specified in its contract specification.

The bridge gains two entry points, callable only by the OptimismPortal, that move the escrow of a held token transfer to the hook and back. It does not store the hook address and it never calls the hook directly. The only record it keeps of a held item is how that item's L1 token is classified, see Escrowed and Minted Tokens.

A hold is the Portal's record. The bridge is handed a message to decode and asked to move escrow for it. See Terms Commitment.

What the Bridge Receives From the Portal

The bridge only receives the inner finalizeBridgeERC20 encoded call carried in a message between the L1 and L2 bridges, which it decodes on its own: it checks the selector, then reads the token pair and the amount from the call's arguments.

The order of the token pair inside the message depends on the item's direction. A standard bridge encodes its message for the chain that will execute it, so the token local to the destination comes first. In a deposit's message the L1 token is therefore the second token argument, and in a withdrawal's message it is the first. The bridge is told the direction because it cannot tell the two apart from the message alone.

Whether the item is a Token Bridge Message at all is the Portal's judgement, not the bridge's. The bridge trusts the Portal on the message envelope: who sent the message, through which messenger, and to which bridge. See Routing and Recognition.

Escrowed and Minted Tokens

Only Native L1 Tokens are escrowed by the bridge, and only those have a deposits balance. An OptimismMintableERC20 is burned on deposit and minted on withdrawal, so there is no escrow to move for it.

A held item carrying an OptimismMintableERC20 therefore moves no tokens at the bridge. Only its message is held, and the value behind it stays in the L2StandardBridge's escrow on L2 until the item completes.

The bridge records how it handled each held transfer:

enum TokenKind { None, Escrowed, Mintable } // None means no hold is recorded

mapping(bytes32 => TokenKind) public heldTokenKinds; // keyed by the item's identifier

Assumptions

aCM-001: The OptimismPortal is trusted

The OptimismPortal only asks for an escrow move for a message it has recognized as a token transfer between the two canonical bridges, and only for an item whose terms it has committed to.

Mitigations

  • Both new entry points are restricted to the OptimismPortal, which the bridge reads from its SystemConfig. See Resolving the Portal.
  • Both new entry points read the Portal's bridgeHook() and revert while it is address(0), so a Portal on a chain that has configured no hook cannot move escrow at all.
  • The bridge decodes the inner call itself rather than trusting the Portal's reading of the token pair and amount.
  • The bridge's own escrow checks still apply, so a move that would overdraw the escrow reverts.
  • A faulty Portal can already drain the escrow through the L1CrossDomainMessenger, so these entry points add no additional capabilities to the Portal. See The Portal Could Already Reach the Escrow.

Function Specification

holdERC20

Moves the escrow of a held token transfer out of the bridge and to the hook.

Parameters:

  • _id: the Identifier of the held item.
  • _direction: whether the held item is a deposit or a withdrawal.
  • _message: the inner finalizeBridgeERC20 call the Portal is holding.

Behavior:

  • MUST revert if the caller is not the OptimismPortal.
  • MUST revert if the Portal's bridgeHook() is address(0).
  • MUST revert if the selector of _message is not finalizeBridgeERC20.
  • MUST read the token pair and the amount from _message, using _direction to tell which of the two token arguments is the L1 token.
  • MUST record whether the L1 token is a Native L1 Token, keyed by _id.
  • MUST transfer that amount of the L1 token to the bridge hook, if the L1 token is a Native L1 Token.
  • MUST decrease the deposits mapping for that token pair by that amount, if the L1 token is a Native L1 Token.
  • MUST revert if the deposits balance for that token pair is below the amount.
  • MUST emit an ERC20Held event with _id, the token pair and the amount, if the L1 token is a Native L1 Token.
  • MUST NOT move any tokens if the L1 token is an OptimismMintableERC20.

restoreERC20

Takes the escrow of a held token transfer back into the bridge, so the normal path can run.

Parameters:

  • _id: the same identifier that was passed to holdERC20.
  • _direction: the same direction that was passed to holdERC20.
  • _message: the same inner finalizeBridgeERC20 call that was passed to holdERC20.

Behavior:

  • MUST revert if the caller is not the OptimismPortal.
  • MUST revert if the Portal's bridgeHook() is address(0).
  • MUST revert if the selector of _message is not finalizeBridgeERC20.
  • MUST revert if the recorded classification for _id is None.
  • MUST read the token pair and the amount from _message, using _direction to tell which of the two token arguments is the L1 token.
  • MUST pull that amount of the L1 token from the bridge hook, using the allowance the hook granted, if the recorded classification is a Native L1 Token.
  • MUST increase the deposits mapping for that token pair by that amount, if the recorded classification is a Native L1 Token.
  • MUST emit an ERC20Restored event with _id, the token pair and the amount, if the recorded classification is a Native L1 Token.
  • MUST NOT move any tokens if the recorded classification is an OptimismMintableERC20.
  • MUST clear the recorded classification.
  • MUST NOT pay the recipient. The normal path runs after the escrow is back, so a deposit is emitted to L2 and a withdrawal is relayed, and it is the relay that pays the recipient from escrow.

Invariants

iCM-006: Bridge escrow moves only when requested by the Portal

Tokens leave the bridge's escrow for the hook, and return to it, only when the OptimismPortal calls. The hook never calls the bridge, and nobody else is authorized on either entry point.

Impact

Severity: Critical

If violated, any caller could drain the bridge's escrow to any address, taking the tokens of users whether or not they ever interacted with the hook.

iCM-007: The deposits balance always matches what the bridge still holds

Every escrow move updates the deposits mapping for the token pair it moves, in both directions. The value of a held item is accounted for at the hook, never at the bridge.

Impact

Severity: Critical

If violated, the bridge's accounting moves away from its real balance. Too low, and later legitimate withdrawals revert for users unrelated to the hold. Too high, and the bridge releases tokens it no longer has, which is a loss paid for by other users of the same token.

iCM-008: The bridge moves exactly the amount the message names

Both holdERC20 and restoreERC20 take their amount from the inner finalizeBridgeERC20 call they decode. A hold and the restore that reverses it therefore move the same amount, so an item's round trip through the hook leaves the escrow where it started.

Whether the L1 token is a Native L1 Token is recorded at hold and reused on restore, rather than derived again, so a token whose answer changes cannot break the round trip.

Impact

Severity: Critical

If violated, a restore could credit more escrow than the matching hold removed, creating a balance the bridge never received. Other users of that token pair pay for it, because their withdrawals draw on the same escrow.

iCM-009: Escrow leaves the bridge only to the hook or to the recipient

The new entry points add no way to pay an arbitrary address. holdERC20 sends escrow to the bridge hook and nowhere else, and restoreERC20 only pulls it back from there. The recipient named in the message is paid by the relay on the normal path, once the escrow has returned.

This is the bridge-side counterpart to iCM-003.

Impact

Severity: Critical

If violated, a hold could pay an address the item never named, which turns a mechanism for deferring value into one for redirecting it.

Security Considerations

A Refused Escrow Move Refuses the Hold

The bridge's own checks still apply when the Portal asks it to move escrow. If an inner check refuses the move, the whole hold reverts, and so does the finalization that triggered it. The withdrawal stays finalizable and can be attempted again.

This is the correct outcome for safety, but it is a liveness risk worth monitoring. A token whose escrow move the bridge always refuses is a token whose withdrawals can never be held, so flagged value for that token stays in the bridge's escrow indefinitely.

A cleared withdrawal never needs the move, because it pays through the normal path which should remain unchanged.

The Portal Could Already Reach the Escrow

These entry points do not widen what a faulty OptimismPortal can do to the bridge. finalizeBridgeERC20 releases escrow to any recipient the message names, as long as the messenger reports the L2StandardBridge as the cross-domain sender. The messenger takes that name from a parameter of relayMessage. And only the Portal may call relayMessage, with an l2Sender it sets itself. A compromised portal can already drain escrow through that path on a default OP Stack chain.

The existing path needs a well-formed relay through the messenger, and it leaves a RelayedMessage event and a successfulMessages entry behind. An escrow move through holdERC20 is a single call, reachable from depositTransaction, which never touched the bridge before, and it leaves no messenger record. Monitoring built on messenger events does not see it.

Resolving the Portal

The bridge reads the Portal from systemConfig.optimismPortal() and the hook from the Portal's bridgeHook() on every call, and stores neither.

Tokens Native to L2 Cannot Be Recovered From a Held Item

A held item carrying an OptimismMintableERC20 holds only the message. The tokens were burned on deposit, or were never minted on withdrawal, so there is nothing in the bridge for the hook to take custody of.

The consequence is that such an item can only ever complete to its original recipient or stay held. Nothing, including upgrading the hook, can redirect the value, because the value is not in the hook's custody. On L2 it remains in the L2StandardBridge's escrow.