Role in Clementine
The Bridge Circuit enables trust-minimized asset transfers between Bitcoin and Citrea L2 by acting as an automated verifier that enforces protocol rules. Unlike traditional bridges that rely on trusted intermediaries, Clementine uses zero-knowledge proofs to cryptographically verify all bridge operations.Covenant Emulation
The bridge circuit works in conjunction with pre-signed transactions to emulate Bitcoin covenants:- Pre-Signed Transaction Set: During peg-in, a committee of n signers pre-signs transactions that govern future peg-outs
- Deterministic Game Tree: Creates a predictable and unalterable execution path for BitVM2 challenge-response
- Automated Enforcement: The circuit receives correct inputs guaranteed by the pre-signed transaction structure
How Pre-Signed Transactions Connect to the Circuit
How Pre-Signed Transactions Connect to the Circuit
KickOff Transaction
- Operator initiates peg-out and activates pre-signed connector outputs
- Commits payout block hash data on-chain via Winternitz One-Time Signature (WOTS)
- Each connector can only be spent by specific pre-signed transactions
- Watchtower spends personal funds to submit challenge transaction with Work Only Proof
- Operator must acknowledge via pre-signed OperatorChallengeACK transaction
- If Operator fails to acknowledge, Challenger uses pre-signed OperatorChallengeNACK to slash them
- Ensures
watchtower_sent_challengeboolean array input to Bridge Circuit is accurate
- Operator posts Assert transactions with off-chain Bridge Circuit execution results
- Challengers use pre-signed Disprove transaction to verify on-chain if errors exist
- Disprove logic includes Groth16 proof verification encoded in pre-signed outputs
BitVM2 Integration
The Bridge Circuit integrates with BitVM2 to verify computations that exceed Bitcoin Script size limits:Off-Chain Execution
Operator executes the payout transaction and generates a Bridge Circuit proof off-chain
On-Chain Commitment
Operator commits the payout block hash in the KickOff transaction witness via WOTS
Challenge Initiation
Any Challenger who suspects malicious behavior can spend the Challenge connector
Disprove Scripts
Two types of scripts handle on-chain verification: BridgeDisproveScript- Verifies the main Bridge Circuit computation
- Uses Groth16 proof to validate circuit execution
- Checks Header Chain Proof, Watchtower challenges, SPV, and storage proofs
- Ensures inputs to Bridge Circuit match on-chain state
- Verifies Watchtower challenges weren’t censored
- Confirms block hash commitments via WOTS are used correctly
Verification Logic
The Bridge Circuit performs comprehensive verification across multiple domains:1. Header Chain Proof Verification
- Validates the Operator’s Header Chain Proof (HCP) method ID matches expected value
- Cryptographically verifies the HCP using RISC Zero’s
verify()function - Ensures the Operator is following a valid Bitcoin chain
2. Watchtower Challenge Processing
The circuit processes challenges from watchtowers who monitor operator behavior:Signature Verification
For each watchtower challenge transaction, verify the Schnorr signature for spending the KickOff connector output (src/bridge_circuit/mod.rs:309-484)
Challenge Flag Setting
If signature is valid, set corresponding bit in
challenge_sending_watchtowers bitmap (20 bytes, 160 watchtowers max)Groth16 Verification
Verify Groth16 proofs sequentially until first valid proof is found, yielding
max_total_work (mod.rs:590-600)Technical: Watchtower Challenge Transaction Formats
Technical: Watchtower Challenge Transaction Formats
Watchtower challenge transactions have two valid output formats:Single Output Format
- One OP_RETURN output containing 144 bytes
- 128 bytes: Compressed Groth16 proof
- 16 bytes: Total work value
- Output 1: P2TR containing first 32 bytes of Groth16 proof
- Output 2: P2TR containing next 32 bytes of Groth16 proof
- Output 3: OP_RETURN containing remaining 64 bytes of proof + 16 bytes total work
3. Simple Payment Verification (SPV)
- Verifies inclusion of payout transaction in the claimed Bitcoin block
- Uses Merkle tree proof based on transaction IDs
- Confirms block header is in the Merkle Mountain Range (MMR) of the canonical chain
4. Light Client Proof Verification
- Verifies the Light Client Proof from Citrea’s recursive circuit
- Ensures L1 block hash from LCP matches the payout transaction’s block hash
- Validates the L2 state root for storage proof verification
5. EVM Storage Proof Verification
- Verifies storage proof for deposit UTXO using state root from LCP
- Verifies storage proof for withdrawal data from bridge contract
- Confirms payout transaction data matches contract state
6. Output Generation
The circuit generates a final output hash committed to the zkVM journal:Technical: Deposit Constant Calculation
Technical: Deposit Constant Calculation
The
deposit_constant is a SHA-256 hash of:- Operator’s X-only public key (32 bytes)
- Watchtower challenge connector start index (4 bytes)
- SHA-256 hash of all tweaked watchtower public keys
- Move transaction ID (32 bytes)
- Round transaction ID (32 bytes)
- KickOff round vout (4 bytes)
- Genesis state hash (32 bytes)
Groth16 Proof System
The Bridge Circuit uses Groth16 proofs for efficient verification of Work Only Circuit outputs:Proof Structure
Groth16 proofs are compressed to 128 bytes containing:- Elliptic curve points proving witness computation
- Pairing check elements
- Constraint satisfaction evidence
Verification Process
- Reconstructs the Work Only Circuit output from
total_workandgenesis_state_hash - Creates output digest using SHA-256
- Generates claim digest for the proof
- Verifies against prepared verification key using BN254 curve pairing
Key Implementation Files
RISC Zero Guest
risc0-circuits/bridge-circuit/guest/src/main.rs
- Entry point for RISC Zero zkVM execution
- Dynamically resolves Work Only circuit method ID based on network
- Initializes guest environment and invokes bridge circuit logic
Core Circuit Logic
circuits-lib/src/bridge_circuit/mod.rs
The main verification function at mod.rs:137-245 orchestrates:
- Input reading from host
- HCP verification (line 146)
- Watchtower challenge processing (line 148-149)
- Work comparison (line 156-160)
- SPV verification (line 164-169)
- Light client verification (line 172)
- Block hash consistency check (line 178-180)
- Storage proof verification (line 183-184)
- Output generation and commitment (line 237-244)
Build Configuration
risc0-circuits/bridge-circuit/build.rs
The build script:
- Compiles
bridge-circuit-guestinto RISC Zero ELF binary - Computes unique method ID for the compiled program
- Handles
BITCOIN_NETWORKenvironment variable for network-specific builds - Optionally uses Docker for reproducible guest builds
- Copies generated ELF to
elfsfolder withtest-prefix ifuse-test-vkfeature enabled
Next Steps
Header Chain Circuit
Learn how Bitcoin header chains are verified
Work Only Circuit
Understand proof-of-work extraction for watchtower challenges