circuits_lib::bridge_circuit

Function total_work_and_watchtower_flags

Source
pub fn total_work_and_watchtower_flags(
    circuit_input: &BridgeCircuitInput,
    work_only_image_id: &[u8; 32],
) -> (TotalWork, ChallengeSendingWatchtowers)
Expand description

Computes the maximum verified total work and watchtower challenge flags from challenge transactions.

§Parameters

  • kickoff_txid: The transaction ID of the kickoff transaction.
  • circuit_input: The BridgeCircuitInput containing all watchtower inputs and related data.
  • work_only_image_id: A 32-byte identifier used for Groth16 verification against the work-only circuit.

§Returns

A tuple containing:

  • [u8; 16]: The total work from the highest valid watchtower challenge (after successful Groth16 verification).
  • [u8; 20]: Bitflags representing which watchtowers sent valid challenges (1 bit per watchtower).

§Notes

  • The function robustly skips over any challenges that are malformed, have invalid signatures, or do not adhere to the expected transaction output structure.
  • Each watchtower challenge transaction is expected to contain one of two distinct output structures:
    • Single Output Format: A single OP_RETURN script containing a total of 144 bytes. This includes the entire 128-byte compressed Groth16 proof followed by the 16-byte total_work value.
    • Three Output Format:
      • The first two outputs must be P2TR (Pay-to-Taproot) outputs. These two outputs collectively contain the first 64 bytes of the compressed Groth16 proof parts (32 bytes from each P2TR output).
      • The third output must be an OP_RETURN script, containing the remaining 64 bytes of the compressed Groth16 proof and the 16-byte total_work value.
  • Valid commitments are sorted in descending order by their total_work value. The Groth16 verifier is then applied sequentially to these sorted commitments, and the first successfully verified total_work is selected as the maximum verified work.