Skip to content

protocol/node: bao verified-range streaming on cdn/client/v1 (verified resume + parallel multi-source fetch) #915

Closed

Description

@alpergundogdu

Problem

Integrity verification on cdn/client/v1 uses a flat, sequential blake3::Hasher over the assembled stream:

  • Buffered: whole-blob re-hash after StreamEnd — crates/node/src/client_requester.rs:509
  • Progressive: incremental flat hasher fed chunk-by-chunk, finalized in finish() — crates/node/src/client_requester.rs:756, :819

A flat hash is inherently sequential — you cannot verify byte N without bytes 0..N. Consequences:

  1. Resume fetches (byte_offset > 0) skip whole-blob verification (client_requester.rs:495). A node can serve a corrupt tail on a resumed range and the receiver has no way to reject it on its own.
  2. No parallel multi-source fetch. Disjoint ranges from different peers can't be independently verified against the content address, so we can't safely stitch a blob from multiple sources.

Insight

BLAKE3 is a Merkle tree, not a flat hash. The content hash we already store/advertise is the bao root. Given the bao outboard (the interior tree nodes), any range verifies independently against the root with an O(log n) proof — no earlier bytes needed. This closes the resume gap and unlocks parallel fetch with one mechanism.

The outboard is already materialized for free: every node imports blobs through FsStore::add_stream / add_bytes (crates/cache/src/engine.rs:1960, :2051), and iroh-blobs (0.100, bao-tree transitive) builds + persists the outboard as a byproduct. Nothing new to compute on the hot path; nothing to transmit as "trusted" (content-derived, self-validating). The publisher CLI stays flat-blake3 / iroh-blobs-free (#578) — the flat root is the bao root, so the first importing node derives a matching tree.

Approach: option 2 — bao interleaved encoding as payload

Carry bao's native interleaved verified-stream encoding (proof nodes inline, immediately before the data they authenticate) instead of bolting a separate boundary proof onto the StreamResponse header.

Rationale over the header-proof variant:

  • Reuses the codec. bao-tree's decoder only consumes proof+data interleaved in tree order. A separate-header layout forces us to re-interleave or hand-roll the verifier — i.e. own the cryptographically-exact path while the tested dep sits unused.
  • No two-chunk-size reconciliation. Our wire ChunkData frame size != bao's 16 KiB group size. Interleaved encoding makes the bao codec the source of truth; wire framing stays irrelevant to verification (partial last group, right-edge spine handled by the codec).
  • Composes into parallel fetch for free. Each source hands an independently-decodable interleaved range; bao-tree verifies each against the same root and we concatenate.

Scope / plan

cdn/client/v1 is not finalised (pre-testnet), so we change the format in place — no version bump, no backwards-compat shim.

  1. Wire (crates/protocol) — change the delivery payload to a bao-encoded byte stream (still framed into ChunkData-sized pieces so payment vouchers stay interleaved as today). Keep the StreamResponse / voucher / StreamEnd envelope.
  2. Serve side (crates/cache + crates/node/src/handlers/client.rs) — export verified ranges from the store (iroh-blobs range export over ChunkRanges) instead of get_bytes + raw write. Outboard already on disk; read it, don't recompute.
  3. Receive side (crates/node/src/client_requester.rs) — replace the flat blake3::Hasher with a bao-tree verifying decoder fed the reassembled stream, validating each group as it lands (early rejection) and on finish(). Removes the byte_offset > 0 verification gap.
  4. Tests — corrupt-tail-on-resume now rejected; verified range from offset > 0; (later) multi-range stitch verifies against root.

Conditional / non-goals

  • Offset-0, single-source, contiguous fetch is untouched and pays zero proof overhead — the existing flat-hasher path already fully verifies that case; a proof there is redundant. Verified-range encoding applies only to resume / non-zero / multi-source.
  • Origin-cold path (first pull straight from origin, outboard still being built) can't ship proofs for not-yet-imported bytes; it stays sequential single-source. Verified-range serving kicks in on every subsequent serve from a node holding the full blob.
  • Parallel multi-source scheduler (which peer gets which range, stitching, re-dispatch on failure) is a separate, larger effort — out of scope here. This issue is the verification prerequisite that makes it safe. Likely warrants its own ADR.

Open decision

Payment metering. With interleaved encoding, paid bytes = data + proof (~0.4% overhead rides on the paid channel). The header-proof variant would have metered pure content with the proof free. Deliberate call needed — probably "yes, charge for it, it's bandwidth," but record the choice.

Suggested follow-up

Consider an ADR (next number 038) for the verified-range protocol change, and a second ADR for the multi-source fetch scheduler it unlocks.

Refs: crates/protocol/src/client.rs, crates/node/src/client_requester.rs, crates/node/src/handlers/client.rs, crates/cache/src/engine.rs. iroh-blobs 0.100 / bao-tree.

Activity

  1. added
    kind:feature
    prio:medium
    rust
    on Jun 15, 2026
  2. added
    design:adr
    design:missing-decision
    kind:security
    on Jun 15, 2026
  3. github-actions commented on Jun 15, 2026

    @github-actions

    🎯 Triage report

    This issue identifies a concrete integrity gap in cdn/client/v1: resumed fetches (byte_offset > 0) currently bypass whole-blob BLAKE3 verification, allowing a malicious upstream to serve a corrupt tail undetected. The fix is a protocol-layer switch to bao interleaved encoding, leveraging the outboard already materialized by iroh-blobs — no new cryptographic computation on the hot path. The proposal is well-scoped, references specific file/line locations, and correctly identifies a breaking wire-protocol version bump as the one unavoidable consequence.

    📊 Assessment

    Dimension Value Reasoning
    Type Feature New capability (verified-range streaming); the security gap it closes exists today but requires a malicious peer to exploit
    Labels security, ADR, missing-decision added Security: resume verification gap is exploitable by a malicious upstream node. ADR: explicitly requests ADR 038 for the wire change. Missing-decision: payment metering for proof bytes is flagged as an open call
    Coding agent Needs more info Steps 1–4 are well-specified, but the open payment metering decision and ADR 038 must be settled first; the wire version bump is a coordination point touching both node and cli

    🔗 Similar issues

    💡 Notes and suggestions

    Pre-requisites before implementation starts

    1. Write ADR 038 (wire format change + bao interleaved encoding rationale). The issue explicitly says "next number 038" — verify by listing adr/ first. The ADR should record the payment metering decision (issue's open question: "charge for proof bytes or not?"). The suggested answer ("yes, charge for it, it's bandwidth") is reasonable and worth locking down to avoid a second round-trip.
    2. Resolve payment metering in the ADR. Proof overhead is ~0.4% (bao-tree interleaved proofs for 16 KiB groups). Recommended: charge for it — it simplifies the metering model and is negligible economically.

    Implementation notes

    • The byte_offset > 0 skip at client_requester.rs:495 is the immediate security gap. A targeted fix limited to that path (reject or down-grade unverifiable resumes until bao shipping) could be shipped as a short-term hardening before the full bao implementation lands.
    • For step 2 (serve side), iroh-blobs' ExportRanges / get_verified APIs expose the outboard-backed range export — no need to re-read the outboard manually.
    • For step 3 (receive side), bao_tree::io::DecodeResponseIter / AsyncSliceDecoder consume the interleaved stream and surface per-group errors, enabling early rejection well before StreamEnd.
    • Wire framing: ChunkData-sized pieces can still wrap the interleaved bao output; the bao codec doesn't care about transport framing, so voucher interleaving is unaffected.
    • Non-goal clarity: the issue is explicit that the parallel multi-source scheduler is out of scope; this is just the cryptographic prerequisite. Don't let scope creep pull the parallel scheduler into this PR.

    Suggested sub-tasks

    • Write ADR 038 (bao verified-range streaming + payment metering decision)
    • Short-term: reject/error on byte_offset > 0 resumes until bao path is implemented (client_requester.rs:495)
    • Protocol: version bump cdn/client/v1, document bao interleaved payload format
    • Serve side: switch handlers/client.rs to export via ChunkRanges range export, read outboard from iroh-blobs store
    • Receive side: replace blake3::Hasher flat path with bao_tree verifying decoder in client_requester.rs
    • Tests: corrupt-tail-on-resume rejected; verified range from offset > 0 accepted; mismatched root rejected

    Generated by Agentic Triage for issue #915 · ◷

    Add this agentic workflows to your repo

    To install this agentic workflow, run

    gh aw add githubnext/agentics/workflows/issue-triage.md@94ec5db57374c5b04a4b8eef8b4413f9af44d63f
    
  4. self-assigned this
    on Jun 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

design:adrdesign:missing-decisionkind:featurekind:securityprio:mediumrust

Fields

Priority

None yet

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions