Purpose
The circuit serves a specialized role in Clementine’s challenge mechanism:- Proof-of-Work Extraction: Isolates the
total_workvalue from full header chain proofs - Work Compression: Converts 256-bit work values to efficient 128-bit representations
- Watchtower Challenges: Enables watchtowers to submit compact work proofs when challenging operators
- Groth16 Proof Generation: Produces small proofs suitable for Bitcoin Script verification
Core Logic
The circuit performs a focused verification and extraction process:1. Method ID Validation
- Ensures the input proof comes from a compatible Header Chain Circuit
- Prevents verification of proofs from wrong network types (mainnet vs testnet)
- Compile-time constant matching the expected network configuration
2. Proof Verification
- Cryptographically verifies the entire Header Chain Circuit output using RISC Zero’s
env::verify() - This is a zero-knowledge check proving the integrity of the header chain proof
- Ensures the proof was generated by a valid Header Chain Circuit execution
3. Work Extraction and Conversion
- Extracts the 256-bit
total_workfrom the verified chain state - Converts to 128-bit representation by truncating upper 128 bits
- Returns as big-endian byte array for efficient serialization
Why 128-bit Work is Sufficient
Why 128-bit Work is Sufficient
Bitcoin’s current total accumulated work is far below 2^128. The 128-bit representation provides:
- Adequate Precision: Sufficient for comparing chain work for centuries at current hash rates
- Storage Efficiency: Reduces proof size by 50% (16 bytes vs 32 bytes)
- Script Compatibility: Easier to manipulate in Bitcoin Script constraints
4. Output Commitment
work_u128: 128-bit accumulated proof-of-work (16 bytes)genesis_state_hash: Original genesis state hash from header chain proof (32 bytes)
Watchtower Challenge Flow
The Work Only Circuit enables watchtowers to participate in the challenge mechanism:Header Chain Proof Generation
Watchtower generates a Header Chain Proof tracking their view of the canonical Bitcoin chain
Work Only Proof Creation
Watchtower executes this circuit with their Header Chain Proof as input, producing a compact Work Only Proof (WOP)
Challenge Transaction
Watchtower submits challenge transaction containing the Groth16 proof and work value in OP_RETURN outputs
Bridge Circuit Verification
Bridge Circuit verifies all watchtower Groth16 proofs and identifies the maximum valid work submitted
Groth16 Proof Format
Watchtowers submit their Work Only Proofs as Groth16 proofs in Bitcoin transactions:Transaction Output Formats
Watchtower challenge transactions use two valid output structures (as verified in Bridge Circuit): Single OP_RETURN OutputTechnical: Groth16 Verification in Bridge Circuit
Technical: Groth16 Verification in Bridge Circuit
The Bridge Circuit verifies Work Only Groth16 proofs using:The verifier reconstructs the Work Only Circuit output from
total_work and genesis_state_hash, then verifies the Groth16 proof against the prepared verification key.Circuit Input/Output
Input Structure
Output Structure
Key Implementation Files
RISC Zero Guest
risc0-circuits/work-only/guest/src/main.rs
Core Circuit Logic
circuits-lib/src/work_only/mod.rs
The main circuit function at mod.rs:71-91:
- Reads
WorkOnlyCircuitInputfrom host (line 72) - Validates method ID matches expected header chain circuit (lines 73-77)
- Verifies the header chain proof cryptographically (lines 78-82)
- Extracts and converts work value (lines 83-85)
- Commits compact output (lines 87-90)
work_conversion helper function at mod.rs:111-114 handles the 256-bit to 128-bit conversion.
Build Configuration
risc0-circuits/work-only/build.rs
The build script:
- Compiles
work-only-guestinto RISC Zero ELF binary - Computes unique method ID for the compiled program
- Handles
BITCOIN_NETWORKandREPR_GUEST_BUILDenvironment variables - Optionally uses Docker for reproducible guest builds
- Copies generated ELF to
elfsfolder
Network-Specific Method IDs
The circuit uses compile-time constants to ensure network compatibility:circuits-lib/src/common/constants.rs and must match between:
- Header Chain Circuit (producer of proofs)
- Work Only Circuit (consumer/verifier of header chain proofs)
- Bridge Circuit (verifier of work only proofs)
Usage in Bridge Circuit
The Bridge Circuit uses Work Only Proofs to verify watchtower challenges:WORK_ONLY_IMAGE_ID is passed to the Bridge Circuit for verifying watchtower Groth16 proofs. This ensures:
- Only Work Only Proofs from the correct network are accepted
- Watchtowers cannot submit proofs from different circuit versions
- Network-specific consensus rules are enforced throughout the verification chain
Security Considerations
Genesis State Hash: The genesis state hash is preserved to ensure all work proofs can be traced back to a specific chain starting point. This prevents mixing proofs from different chain histories.
Next Steps
Header Chain Circuit
Understand how header chain proofs are generated
Bridge Circuit
See how work proofs are verified in the bridge