circuits_lib::bridge_circuit

Function bridge_circuit

Source
pub fn bridge_circuit(guest: &impl ZkvmGuest, work_only_image_id: [u8; 32])
Expand description

Executes the bridge circuit in a zkVM environment, verifying multiple cryptographic proofs related to watchtower work, SPV, and storage proofs.

§Parameters

  • guest: A reference to a zkVM guest implementing ZkvmGuest.
  • work_only_image_id: A 32-byte array representing the work-only image ID used in verification.

§Functionality

  1. Reads the BridgeCircuitInput from the host.
  2. Ensures the method ID in hcp (header chain proof) matches HEADER_CHAIN_METHOD_ID.
  3. Verifies the header chain proof (hcp).
  4. Computes total work and watchtower challenge flags using total_work_and_watchtower_flags.
  5. Validates that the computed total_work does not exceed the total work in hcp.chain_state.
  6. Fetches the MMR (Merkle Mountain Range) for block hashes from hcp.chain_state.
  7. Verifies the SPV proof (payout_spv) using the fetched MMR.
  8. Verifies the light client proof using lc_proof_verifier.
  9. Checks storage proofs for deposit and withdrawal transaction indices using verify_storage_proofs.
  10. Converts the verified withdrawal outpoint into a Bitcoin transaction ID.
  11. Ensures the withdrawal transaction ID matches the input reference in payout_spv.transaction.
  12. Computes the deposit_constant using the last output of the payout transaction.
  13. Extracts and truncates the latest block hash and the payout transaction’s block hash.
  14. Computes a Blake3 hash over concatenated block hash and watchtower flags.
  15. Generates a final journal hash using Blake3 over concatenated data and commits it.

§Panics

  • If the method ID in hcp does not match HEADER_CHAIN_METHOD_ID.
  • If max_total_work given by watchtowers is greater than hcp.chain_state.total_work.
  • If the SPV proof is invalid.
  • If the storage proof verification fails.
  • If the withdrawal transaction ID does not match the referenced input in payout_spv.