Compliance Module

Table of Contents

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

Overview

An OP Stack chain must be able to condition every deposit and withdrawal that crosses its canonical bridge. The OptimismPortal stores one optional hook address. While that address is address(0), the chain behaves exactly as any default OP Stack chain. When it is set, the Portal offers every item (see Item) to the hook before any value reaches its recipient.

For each item, the hook can answer in one of three ways:

  • Proceed. The item executes as it would on any default OP Stack chain.
  • Hold. The item is deferred. The protocol takes custody of its value and commits to running it later, unchanged.
  • Reject. The call reverts and the item is refused while nothing is consumed.

See Screening Outcome for the mechanics of each answer.

The hook is an interface, so any contract can implement it. These pages specify the interface, one reference implementation called the ComplianceModule, and the interface between that module and the policy owned by the chain, which decides what is acceptable. What a policy decides is outside this specification.

The feature is specified across four further pages:

  • OptimismPortal. The hook address, the IBridgeHook interface, how the Portal names an item, commits to its terms, and runs a held item later.
  • L1StandardBridge. How the escrow of a held token transfer moves to the hook and back.
  • Policy. The IPolicy interface, and what a hook requires of any policy behind it.
  • ComplianceModule. The reference hook implementation, which owns the verdict registry, custody of held value, and completion.

Problem Statement

Some chains must condition value crossing their canonical bridge, and must enforce that condition where it cannot be bypassed.

Screening at the sequencer only covers transactions submitted to it. It does not cover deposits submitted to L1, which carry forced inclusion, so the sequencer has no say in whether they are included. Withdrawals finalize on L1, outside the sequencer's reach. Since both deposits and withdrawals cross the OptimismPortal, that is where the chain can enforce a screening condition that cannot be bypassed.

Since the condition and the rules under which an item can pass through L1 and L2 boundaries belong to the chain, the protocol only supplies: a way to defer an item, take custody of its value, and resume it later on the terms it was deferred with.

Goals

  • Every deposit and withdrawal that crosses the canonical bridge is screened through the hook, whatever it carries, except deposits sent by the ProxyAdmin owner. A zero-value deposit still executes an arbitrary L2 call chosen by an L1 sender, such as a transfer between L2 accounts.
  • An item the hook defers has its value taken into the hook's custody, out of the protocol contracts, before any of it reaches the recipient.
  • An item can be deferred and resumed later on identical terms, with no user action in between.
  • An item is identified unambiguously.
  • The condition can be switched off for new items without releasing items already held.
  • No policy may redirect value or alter an item's terms.

Non-goals

  • Support for the L1ERC721Bridge or third-party bridge contracts.
  • Transactions users submit to the sequencer.
  • The type of policy applied by the chain governor, and the offchain service behind it.

Architecture

The OptimismPortal is the screening boundary. It is the only contract that asks the hook, and it asks once per item. A deposit is screened when it is submitted while a withdrawal is screened when it is finalized.

A deposit that already emitted TransactionDeposited is on its way to L2. A withdrawal whose call the Portal forwarded has already run. Neither can be recalled.

graph LR
    U[User]
    OP[OptimismPortal]
    SB[L1StandardBridge]
    CM["ComplianceModule (the hook, holds value)"]
    POL["Policy (chain-specific)"]

    subgraph onchain [On chain]
        OP
        SB
        CM
        POL
    end

    U -->|deposit / finalize| OP
    U -->|token deposit| SB
    SB <-->|"messages, through the messenger"| OP
    OP -->|"hold / restore escrow"| SB
    OP <-->|"screen / hold / complete"| CM
    CM <-->|"screenDeposit / screenWithdrawal / screenRelease"| POL
    POL -->|recordVerdict| CM
  • The OptimismPortal stores the hook address and calls the hook from depositTransaction and finalizeWithdrawalTransaction when one is set. It recognizes the messages the two canonical bridges exchange, and it commits the terms of every item it defers.
  • The L1StandardBridge gains two entry points, callable only by the Portal, that move the escrow of a token transfer to the hook and back. It keeps its own accounting and reads its own messages.
  • The ComplianceModule implements the hook. It owns the verdict registry, custody of any held value, and completion. It also decodes canonical messages to name the real parties for the policy. It is the only new contract that holds value.
  • The policy decides what items go through based on its own set of rules.

The Portal gains the ability to defer an item and resume it later, which a rate limiter, a per-token pause or a circuit breaker would use the same way.

Each contract moves only the value it holds. A hold is the Portal's own record, and the bridge only notes whether it escrowed the token. The Portal recognizes the messenger envelope and hands the bridge the message inside it. The bridge decodes that inner call itself, moves the escrow it names, and updates its own accounting.

The Portal builds every item and records its terms, and the hook only picks which item moves. No policy, however it is written, can redirect value or change what an item does. It can delay an item or refuse it, and nothing else.

Letting the L1StandardBridge screen its own token transfers looks simpler, because the parties arrive there as typed arguments. It does not work for withdrawals. A token withdrawal reaches the bridge inside the messenger's relay, after the Portal has already consumed the withdrawal. A revert there becomes a failed message rather than a rejection, so the bridge could hold an item but never refuse one.

Definitions

Item

An Item is one deposit or one withdrawal, as the OptimismPortal sees it. It can carry ETH, tokens, or no value at all. The Portal builds an item from the sender, target, value and call it sees. Each item is unique in its direction.

Identifier

An Identifier is an item's name, a hash of all of the item's fields. The OptimismPortal and the hook compute it the same way, so both agree on which item a Verdict names, and the verdict covers every term.

The identifier is built the same way for both directions: the Portal fills the same Item fields and hashes them. The direction field keeps a deposit and a withdrawal apart, and the nonce field holds the withdrawal's nonce or, for a deposit, the Deposit Counter.

Take two deposits from the same address for the same amount, to the same L2 address in the same L1 block. Every field except nonce is identical, so without the Deposit Counter both would share one identifier, and a clearance for one would release the other.

Screening

Screening is offering an item to the hook, which answers with a Screening Outcome. A deposit is screened when it is submitted. A withdrawal is screened when it is finalized.

Screening Outcome

A Screening Outcome is the hook's answer for one item. There are three possible outcomes:

  • Proceed. The item takes the normal path, unchanged.
  • Hold. The item is deferred. The Portal commits its terms and its value moves to the hook.
  • Reject. The call reverts and nothing is consumed. A rejected deposit never happens, and a rejected withdrawal remains finalizable and can be attempted again.

A hook need not use all three. An asynchronous policy proceeds or holds and never rejects. A synchronous policy proceeds or rejects and never holds. See Item Lifecycle for how an item moves between them.

Hook

The Hook is the contract at the OptimismPortal's hook address. The Portal asks it about every item and the hook takes custody of held value. Any contract that implements IBridgeHook can be a hook.

Terms Commitment

A Terms Commitment is the OptimismPortal's record of a held item. It is keyed by the item's Identifier in both directions, so it binds every term. Only an item that matches a commitment can complete, and only once.

Verdict

A Verdict is a decision about one item, recorded through the Policy against the item's Identifier. A verdict can be recorded before the item exists. It carries an expiry set by the Verdict Writer when it is written, and the policy can revoke it earlier.

A clear verdict is what lets value move. With one, a withdrawal pays out at finalization and a held item can complete, as long as the policy still allows it when the value moves. An item without one is uncleared.

Completion

Completion is moving a held item to its original destination, on the committed terms. Anyone can start it at the hook once the item has been cleared. A held item cannot be partially completed, and it is never returned to its sender.

Policy

A Policy is a contract the chain owns that decides the Screening Outcome for an item. The hook asks it when an item is screened and when value moves, and takes verdicts only from it.

Parties

The Parties of an item are the addresses the policy screens for it. For a message sent through the messengers, the hook decodes the real sender and recipient from the envelope. Where it stops decoding, it uses the sender and target of the last layer it read.

Token Bridge Message

A Token Bridge Message is a token transfer between the L1StandardBridge and the L2StandardBridge, sent through the messengers. The OptimismPortal recognizes it in two steps. The item's outer sender and target must be the messengers, and the envelope must decode to a finalizeBridgeERC20 call from the standard bridge. Since nobody can choose those fields, a message that matches came from the bridge. The item must also carry no ETH. The Portal marks such an item as a token transfer, and moves escrow only for it.

Finalizable Time

The Finalizable Time of a withdrawal is one second after the later of proofMaturityDelaySeconds after its proof was submitted and disputeGameFinalityDelaySeconds after that proof's dispute game resolved. The OptimismPortal requires both delays to have passed before it finalizes, so neither alone decides when a withdrawal can move. The game must also be proper, respected and resolved in the defender's favour, but those conditions carry no time and so are not part of this value.

A withdrawal can be proven more than once, by different submitters and against different games, and whoever finalizes names which proof to use. The Finalizable Time belongs to that proof, not to the withdrawal.

The Portal passes it to the hook at screening, so a policy can decide how long to wait before it holds an uncleared withdrawal.

Item Lifecycle

graph LR
    E["item enters the Portal"]
    S{"hook is asked"}
    P["proceeds, as on a default chain"]
    R["reverted, nothing happened"]
    H["held: terms committed, custody with the hook"]
    V["verdict recorded"]
    C["completed on the original terms"]

    E --> S
    S -->|proceed| P
    S -->|reject| R
    S -->|hold| H
    H -.-> V
    V --> C

An item is offered to the hook once when it enters. If it is held, it is checked again when its value moves, so the policy is consulted twice on a held item.

A verdict lives against an Identifier, not against the item itself. The identifier must name exactly one item, otherwise one clearance could release another.

Custody Model

The contract holding the value is the one that hands it to the hook. The OptimismPortal decides when.

ETH moves through the Portal. Every ETH route, through the bridge or through the messenger, ends at the Portal. On a hold, the Portal sends the ETH to the hook. On completion it comes back as the value of the completion call, and the Portal checks it against the committed terms.

Tokens move through the bridge. The L1StandardBridge escrows them, and it is the only contract that moves them to the hook and back. Tokens native to L2 are burned and minted rather than escrowed, so only their message is held, and the value behind such an item stays in the L2StandardBridge's escrow until it completes.

For a Token Bridge Message, the Portal hands the bridge the inner message and asks it to move escrow. The bridge decodes that inner call itself, runs its own checks, and records the balance change in its own accounting. Beyond whether it escrowed the token, it records nothing about the hold:

  • Hold. The Portal calls the bridge with the inner finalizeBridgeERC20 message it is holding. The bridge checks the selector, reads the tokens and the amount from it, and debits its escrow for that token pair, which reverts if the escrow is short. It then sends the tokens to the hook.
  • Completion. The hook approves the bridge for the item's amount and calls the Portal, which asks the bridge to take the tokens back and credit its escrow. The normal path then runs, so a deposit is emitted to L2 and a withdrawal is relayed.

The bridge does not depend on the hook, because only the Portal can send its escrow to the hook or take it back.

Trust Assumptions

A chain that sets a hook address accepts the following, on top of the trust model of a default OP Stack chain.

The chain is not a Stage 1 Rollup. A hook that holds indefinitely is a permanent Withdrawal Liveness failure caused by an actor that is neither the Security Council nor the Proxy Admin Owner. Users have to trust the chain operator not to censor them.

Whoever can upgrade the hook is the custodian of all deferred value. That authority is not constrained to be the chain's ProxyAdmin owner. What an upgraded hook does with value already in its custody is outside the protocol's guarantees. The exposure is not limited to what is held at any one moment. A hostile hook holds every new deposit and withdrawal as it arrives, so its custody grows with the chain's bridge flow for as long as it stays set. It still cannot redirect value or alter an item's terms. See iCM-003.

Removing the hook strands held items. The chain's ProxyAdmin owner can remove the hook at any time. New items stop being screened, but every item already held stays held. Its commitment stays in the Portal and its value stays with the removed hook.

The policy decides who can clear an item. A compromised policy can complete held items early, and so can any role it trusts. The value still only reaches the item's original destination. A compromised policy can also hold or refuse any new item.

A failing policy can halt bridging. The ComplianceModule's disable switch exists so that a problem in the policy, or a long outage of the Verdict Writer, cannot block new deposits and withdrawals indefinitely. It is not a release. While it is on, every deposit proceeds without the policy being asked, and so does every withdrawal initiated at or after the cutoff. Items already held, and withdrawals initiated before the cutoff, are still screened. A problem in the hook itself is fixed by upgrading it.

Backward Compatibility

The change is limited to L1 contracts, with no multi-client or consensus impact. A held deposit emits no TransactionDeposited event, so the derivation pipeline sees nothing until the deposit completes, and then sees an ordinary deposit.

For a chain that does not set a hook, behavior does not change, but two things change either way:

  • The L1StandardBridge gains two entry points that only the OptimismPortal can call.
  • The OptimismPortal gains completion functions, while existing user entry points are unchanged.

For a chain that enables it, these assumptions break:

  • A successful depositTransaction no longer implies that the deposit reaches L2.
  • A successful ERC-20 deposit, and the ERC20DepositInitiated and SentMessage events it emits, no longer imply that the deposit reaches L2.
  • finalizeWithdrawalTransaction can revert for a withdrawal that is not cleared, and once the hook holds it, it can succeed without paying the recipient.
  • A withdrawal that calls the L1StandardBridge directly can no longer be finalized, because the bridge is an Unsafe Target while a hook is set.
  • Held deposits complete out of submission order, because a verdict for a later item can land first.

A RelayedMessage event still implies the recipient was paid, because a withdrawal is held before the messenger relays it.

Impact on Developer Experience

No hook is set by default, so developers on chains that do not enable it see no difference.

For a chain that enables it:

  • A deposit may be held. The bridge call succeeds, no TransactionDeposited event is emitted, and the value sits with the hook. The item completes later with no further action from the user. SDKs and bridge interfaces should watch the hook's events and show a pending state rather than success.
  • A withdrawal that is not cleared cannot be finalized until it is, and the revert lets a bridge interface show it as pending. Once the policy stops waiting, finalizing it holds it, so the recipient is not paid until completion.

Integrators that bridge programmatically, including contracts that call depositTransaction directly, have to handle the held case rather than assuming the deposit succeeds atomically. Bridges and escrows outside the core contracts should treat a deposit as pending until it completes.

Tooling is able to find the hook through the OptimismPortal's hook address.