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 implementingZkvmGuest
.work_only_image_id
: A 32-byte array representing the work-only image ID used in verification.
§Functionality
- Reads the
BridgeCircuitInput
from the host. - Ensures the method ID in
hcp
(header chain proof) matchesHEADER_CHAIN_METHOD_ID
. - Verifies the header chain proof (
hcp
). - Computes total work and watchtower challenge flags using
total_work_and_watchtower_flags
. - Validates that the computed
total_work
does not exceed the total work inhcp.chain_state
. - Fetches the MMR (Merkle Mountain Range) for block hashes from
hcp.chain_state
. - Verifies the SPV proof (
payout_spv
) using the fetched MMR. - Verifies the light client proof using
lc_proof_verifier
. - Checks storage proofs for deposit and withdrawal transaction indices using
verify_storage_proofs
. - Converts the verified withdrawal outpoint into a Bitcoin transaction ID.
- Ensures the withdrawal transaction ID matches the input reference in
payout_spv.transaction
. - Computes the
deposit_constant
using the last output of the payout transaction. - Extracts and truncates the latest block hash and the payout transaction’s block hash.
- Computes a Blake3 hash over concatenated block hash and watchtower flags.
- Generates a final journal hash using Blake3 over concatenated data and commits it.
§Panics
- If the method ID in
hcp
does not matchHEADER_CHAIN_METHOD_ID
. - If
max_total_work
given by watchtowers is greater thanhcp.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
.