Skip to main content

run_subtree_audit

Function run_subtree_audit 

Source
pub async fn run_subtree_audit(
    p2p_node: &Arc<P2PNode>,
    config: &ReplicationConfig,
    challenged_peer: &PeerId,
    expected_commitment_hash: [u8; 32],
    key_count: u32,
    credit: Option<&AuditCredit<'_>>,
) -> AuditTickResult
Expand description

Run one gossip-triggered subtree audit against challenged_peer, pinned to the commitment hash the peer just gossiped (expected_commitment_hash).

ADR-0002 two-round audit. The auditor sends a fresh random nonce and runs:

  1. Structure (round 1) — the returned subtree rebuilds to the pinned root, within a size-scaled deadline.
  2. Verified slice (round 2) — for a 3..=5 FRESHLY-RANDOM sample of the proven leaves (chosen after the proof arrives, not nonce-derived — see random_spotcheck_leaves), the auditor opens one random 1 KiB block per leaf (plus its final block) and verifies a Bao slice against the chunk address and a nonced-tree opening against the round-1 nonced_root, over the bytes the responder serves. The auditor holds none of the peer’s chunks, and possession is the round-1 commitment, not a full-chunk transfer.
  3. Timing — a response deadline still bounds liveness, but (unlike the old full-byte round 2) it is no longer the possession proof; that is the round-1 nonced_root commitment.

A timeout (either round) is reported as AuditFailureReason::Timeout (the caller applies the strike/grace policy). Any structural failure, served content that fails a hash, an explicit Absent for a committed sampled key, or a rejection of a recently gossiped commitment, is a confirmed failure acted on immediately. On a full pass, records the peer as a proven holder.