Repository navigation
Description
Summary
Make total_bytes a verified fact. A node that states a blob size on cdn/client/v1 or cdn/probe/v1 attaches a size proof that the receiver checks against the content hash before it uses the size.
Today every size is a claim. The signed StreamResponse.total_bytes, the probe's total_bytes and an origin's HEAD size are all unverified until a leg happens to reach the true end of the blob. Everything that plans from a size has to defend against a lie.
Why
An unverified size has cost us repeatedly:
- A client that guesses a size can overpay or plan work past the end of the blob.
- A node cannot size a coverage bitmap, a buffer or an outboard from a claim without a clamp (client: with max_blob_bytes = 0 the planner sizes its work from an unsigned peer size claim #2843, cache: the untrusted .obao4 outboard read is capped by the origin's own size claim #2842).
- A relay cannot compare a blob with its
max_blob_sizebefore it pulls, because a holder that inflates the claim could make every relay refuse the blob. - Multi-source planning and segment splitting work on a bound that moves as legs verify.
- The gateway pays for a separate pull of the last chunk group before it can send a
Content-Length.
#2874 answers this by never trusting a size: the plan starts from one 64 MiB seed and grows from verified bytes, and one lane fetches the tail to prove the claim. That works, and it is about 2,000 lines of planner logic whose only job is to live without a fact that is cheap to prove.
The fact is cheap to prove because BLAKE3 binds the length into the tree. Only the true size verifies a final chunk under the root.
The proposal
- A size proof travels with the size.
StreamResponsecarries it, and so does aProbeResponsethat states a size. A node states no size that it cannot prove. - The receiver verifies it against the content hash, before it plans, allocates, splits, or pays against the size.
- A proof depends on the hash alone. It names no node and carries no signature, so any party that holds one can pass it on.
- The origin makes it.
decdn origin importalready computes the outboard, so it can write the proof beside it. A node that pulls a blob keeps the proof it verified from its upstream and can serve the proof before it holds the tail of the blob.
What we gain
- A client plans the whole blob at first contact: exact ranges, exact splits across sources, no growing bound.
- A client pays the last partial chunk exactly. This matters more under proposal: payer-fronted credit, so a node never delivers ahead of payment #2876, where the client pays ahead.
- A node sizes its bitmaps, buffers and outboards from a verified number, bounded by its own cap.
- A relay refuses a blob over its
max_blob_sizebefore it pulls a byte. decdn quote,decdn get --dry-runanddecdn probecan show a size and an estimate for a raw blob.- The gateway answers
Content-Lengthfrom the proof and no longer pays for a size pull. - The grow-from-verified planner in refactor(client,node)!: a size claim only picks the verification shape #2874 is not needed.
What it costs
- A proof reveals the end of the blob, unpaid. The receiver needs the bytes of the final BLAKE3 chunk to check the length, so a proof carries up to 1 KiB of content. For a blob of 1 KiB or less the proof is the whole blob. The value is about one thousandth of a chunk price for each blob.
- A wire change to
StreamResponseandProbeResponse, and a new stored artifact at the origin and in the node's cache. - A node that holds a blob without its tail needs the proof from somewhere. A partial holder gets it from the upstream it pulled from. An origin-backed node reads the last chunk group from its origin once and keeps the result.
- Probe responses grow by the size of the proof.
Open decisions
- Encoding. Two candidates. The first is the existing bao verified-range response for the last chunk group (ADR 038): no new format, up to 16 KiB plus the path. The second descends below the chunk group to the final 1 KiB BLAKE3 chunk: smaller, and it needs the chaining values inside the last group, which the group-level outboard does not store.
- Probe or stream only. A proof on the probe lets a client plan before it opens a stream. It also makes every probe answer larger.
- Whether a node may serve without a proof while it fetches one, or must refuse.
- What happens to refactor(client,node)!: a size claim only picks the verification shape #2874. Several of its fixes do not depend on this and are still needed:
num_blockssaturation, the pull-leg plan clamp to the request end andmax_blob_size, theWanttail fix (client: cap-0 explicit ranges longer than the 1 TiB sizing ceiling truncate or overfetch #2865), and the cache path where an origin-backed node verifies the last chunk group, which is the generator this proposal needs.
Relation to other work
- proposal: payer-fronted credit, so a node never delivers ahead of payment #2876 (payer-fronted credit) needs a verified size to make the final prepayment exact. This proposal does not depend on it and can land first.
- refactor(client,node)!: a size claim only picks the verification shape #2874 is on hold as a draft until this is decided.
Metadata
Metadata
Assignees
Labels
Type
Fields
Priority
Projects
- StatusShow more project fieldsDone
Activity
docs(adr): move the size proof out to its own change
alpergundogdu commentedon Nov 11, 2026
Draft ADR change: #2880. #2874 is converted to draft and on hold until this is decided.
alpergundogdu commentedon Nov 11, 2026
Encoding decided: the final 1 KiB BLAKE3 chunk, not the 16 KiB chunk group.
A throwaway test built the proof with stock
bao-treecalls at block size 0 (encode_ranges_validatedover the last chunk) and checked it with the stock decoder (decode_ranges). Over 14 sizes from 1 byte to 37 MiB, each proof verified under the true size and under none of about 19 wrong sizes. Measured proofs were 1 byte to 1.7 KiB: the last chunk plus 64 bytes for each level on its path to the root. A 100 GiB blob comes to under 3 KiB.So the verifier is one small function in
decdn-bao-rangethat takes the root, the claimed size and the proof, and answers yes or no. The generator needs the hashes inside the last chunk group, which the group-level.obao4outboard does not store, so it computes them from the last group's bytes.alpergundogdu commentedon Nov 11, 2026
Codec: #2882 adds
verify_size_proofandencode_size_prooftodecdn-bao-range. It is a draft with no caller yet. The encoder's output matches the stockbao-treeencoder byte for byte over 24 sizes, and it builds the proof from the group-level.obao4outboard plus the last chunk group, so an origin needs to read at most 16 KiB of the blob.feat!: the size proof is the only statement of a blob size (#2879) (#…
yigitdot commentedon Nov 13, 2026
Implemented by #2885 (merged as a6405f5): every blob size a node states now travels with a size proof that is verified before anything plans, allocates, compares with a cap or pays from it. Closing as completed — the PR's "Implements" reference did not auto-close this.
Merge remote-tracking branch 'origin/main' into claude/payer-fronted-…
docs(adr)!: the payer fronts credit (#2877)