Repository navigation
feat(bao-range): verify and encode a blob size proof - #2882
Closed
alpergundogdu wants to merge 3 commits into
Closed
alpergundogdu wants to merge 3 commits into
alpergundogdu wants to merge 3 commits into
Conversation
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]>
Code coverage overviewLanguages: Rust Rust / code-coverage/cargo-llvm-cov
View coverage of the 4 most impacted files.
ℹ️ Calculations represent line coverage. Results may change as calculations are updated. Updated |
…codec # Conflicts: # CLAUDE.md
…codec # Conflicts: # CLAUDE.md
Contributor
Author
|
Superseded by #2885, which is built on this codec branch. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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: whetherproofproves that the blob with BLAKE3 hashrootissizebytes long. It runs the stockbao-treedecoder over the last chunk at block size 0 into a target that discards the bytes, so it allocates nothing that grows withsize. A proof that is too long, that has bytes past its last chunk, or that does not verify givesfalse.encode_size_proof(root, size, outboard, tail) -> Result<Bytes, SizeProofError>: builds the proof from what an origin holds, the group-level{hex}.obao4outboard 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 withblake3::hazmat. It verifies the proof againstrootbefore 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:bao-treeencoder gives from a chunk-level outboard of the whole blob.u64::MAXincluded.Checks
cargo fmt -- --check: cleancargo clippy -p decdn-bao-range --all-targets --all-features -- -D warnings: cleancargo nextest run -p decdn-bao-range: 28 passCARGO_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;blake3comes through thebao-treere-export.Not in this PR
StreamResponseandProbeResponse, and the ADR text for them (docs(adr)!: a node proves the blob size #2880).decdn origin import, storing it in the node's cache, and verifying it in the client.Refs #2879
🤖 Generated with Claude Code