Skip to content

feat(bao-range): verify and encode a blob size proof - #2882

Closed
alpergundogdu wants to merge 3 commits into
mainfrom
claude/size-proof-codec
Closed

alpergundogdu wants to merge 3 commits into
mainfrom
claude/size-proof-codec

Conversation

@alpergundogdu

Copy link
Copy Markdown
Contributor

The codec for #2879: verify and build a blob size proof in decdn-bao-range. Nothing calls it yet. It is a draft until the wire fields and the callers land with it.

What it adds

crates/bao-range/src/size_proof.rs:

  • verify_size_proof(root, size, proof) -> bool: whether proof proves that the blob with BLAKE3 hash root is size bytes long. It runs the stock bao-tree decoder over the last chunk at block size 0 into a target that discards the bytes, so it allocates nothing that grows with size. A proof that is too long, that has bytes past its last chunk, or that does not verify gives false.
  • encode_size_proof(root, size, outboard, tail) -> Result<Bytes, SizeProofError>: builds the proof from what an origin holds, the group-level {hex}.obao4 outboard and the bytes of the last chunk group. It walks the right edge of the tree: a pair above the chunk group is read from the outboard, and a pair inside the last group is hashed from the tail with blake3::hazmat. It verifies the proof against root before it returns it, so neither input is trusted.
  • size_proof_tail_start(size): the offset an origin reads from to get the tail.
  • MAX_SIZE_PROOF_BYTES: the bound the verifier enforces, 1 KiB plus 64 bytes for each of 54 levels.

A proof is the last chunk (at most 1 KiB) plus 64 bytes for each level on its path to the root. A 1 MiB blob gives 1,664 bytes, and a 37 MiB blob with a 5-byte last chunk gives 389.

Tests

crates/bao-range/src/size_proof/tests.rs, over 24 sizes from 0 bytes to 37 MiB that sit on every boundary the encoder branches on:

  • The encoder's output equals, byte for byte, what the stock bao-tree encoder gives from a chunk-level outboard of the whole blob.
  • A proof verifies under the true size and under none of about 19 wrong sizes for each blob, u64::MAX included.
  • A proof does not verify under another blob's root. The empty proof verifies only for the empty blob's hash.
  • A single flipped bit anywhere in a proof, one byte more, or one byte less fails.
  • A proof stays under the stated bound.
  • The encoder gives a typed error for an outboard or tail of the wrong length, and for a tail, outboard or root that does not belong to the blob.

Checks

  • cargo fmt -- --check: clean
  • cargo clippy -p decdn-bao-range --all-targets --all-features -- -D warnings: clean
  • cargo nextest run -p decdn-bao-range: 28 pass
  • CARGO_BUILD_WARNINGS=deny cargo doc -p decdn-bao-range --no-deps --document-private-items: clean
  • .github/scripts/check_crate_edges.py: clean. The crate gains no dependency; blake3 comes through the bao-tree re-export.

Not in this PR

  • The wire fields on StreamResponse and ProbeResponse, and the ADR text for them (docs(adr)!: a node proves the blob size #2880).
  • Writing the proof at decdn origin import, storing it in the node's cache, and verifying it in the client.

Refs #2879

🤖 Generated with Claude Code

A size proof is the bao encoding of a blob's final BLAKE3 chunk at chunk
granularity: one pair of parent hashes for each level on the path from
the root, then the chunk. Only the true size verifies a final chunk
under the root.

verify_size_proof takes the root, a claimed size and a proof and answers
yes or no. It is the stock bao-tree decoder over the last chunk, and it
allocates nothing that grows with the size.

encode_size_proof builds the proof from the group-level .obao4 outboard
and the bytes of the last chunk group. The outboard stores no hash below
a chunk group, so the encoder hashes the pairs inside the last group
from its bytes. It verifies the proof against the root before it
returns it.

Refs #2879

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@github-code-quality

github-code-quality Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

Code coverage overview

Languages: Rust

Rust / code-coverage/cargo-llvm-cov

main 7e5ec60 claude/size-proof-co... 7bda23a +/-
77% 77% 0%
View coverage of the 4 most impacted files.
File main 7e5ec60 claude/size-proof-co... 7bda23a +/-
crates/protocol/src/framing.rs 93% 92% -1%
crates/cache/src/engine.rs 91% 91% 0%
crates/node/src...s/client/mod.rs 95% 95% 0%
crates/bao-rang...c/size_proof.rs 0% 97% +97%

ℹ️ Calculations represent line coverage. Results may change as calculations are updated.


Updated November 12, 2026 01:45 UTC

@alpergundogdu

Copy link
Copy Markdown
Contributor Author

Superseded by #2885, which is built on this codec branch.

@alpergundogdu
alpergundogdu deleted the claude/size-proof-codec branch November 18, 2026 11:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant