Skip to content

feat!: the size proof is the only statement of a blob size (#2879) - #2885

Merged
alpergundogdu merged 22 commits into
mainfrom
claude/size-proof-wiring
Nov 13, 2026
Merged

alpergundogdu merged 22 commits into
mainfrom
claude/size-proof-wiring

Conversation

@alpergundogdu

@alpergundogdu alpergundogdu commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Implements #2879: every blob size a node states arrives with a size proof, and nothing plans, allocates, compares with a cap or pays from a size before its proof verifies. Built on the size-proof codec (#2882) and the ADR text of #2880, retargeted to main.

Wire-breaking (!), and the EIP-712 StreamResponse type changes. No compatibility shim.

The size proof is the size

  • SizeProof carries the size beside the proof. It is the only place any message states a blob size: total_bytes is gone from StreamResponseBody (and from the signed EIP-712 StreamResponse, SlashJudge.STREAM_RESPONSE_TYPEHASH), from ProbeResponseExt, and from DHT OriginAttestations.
  • StreamResponseExt.outcome is Served(SizeProof) or Refused(StreamError), and validate ties it to the signed ok: a served response without a proof cannot be built or accepted. The node signs through sign_served (needs the proof) or sign_refusal.
  • {H}.sizeproof holds the size (8 LE bytes) then the proof; decdn origin import writes it so. An origin object is served, and advertised in the DHT, only under a size its {H}.sizeproof proves; an object with no size or no proof is never served from the origin. (fix(cache): a present but unsized origin object is no longer memoised as an absence #2867 is closed: the unsized tri-state has no use.)
  • Receipts drop the signed size and the EntrySize fault. Frame sizes: full probe answer 4,807 B; origin attestation 86 B; full BatchStore 61,475 B; full FindValue 16,675 B.
  • SlashJudge: type string and StreamMsg drop totalBytes; Foundry suite 815 passed, gas snapshot regenerated.

What changed

decdn-protocol

  • SizeProof (opaque bytes, bounded at MAX_SIZE_PROOF_BYTES = 4,480 at decode, with a visitor that refuses a huge declared length before it allocates) and SizeProofTooLong.
  • StreamResponseExt.size_proof and ProbeResponseExt.size_proof.
  • Probe ceilings split: MAX_PROBE_REQUEST_FRAME = 1 KiB (what the node reads), MAX_PROBE_FRAME = 8 KiB (the response the requester reads; a full answer is 4,808 B). MAX_STREAM_RESPONSE_FRAME = 8 KiB for the response the payer reads; MAX_CLIENT_CONTROL_FRAME stays 4 KiB for what the node reads, so the node's reader-buffer bound (ADR 013) does not grow.
  • num_blocks saturates at u32::MAX.

decdn-bao-range

  • SIZE_PROOF_SUFFIX = ".sizeproof"; encode_outboard yields the size proof in the same pass.
  • size_proof_from_tail_wire builds a proof from a verified export of the last chunk group, and refuses a wire with unused pairs.

decdn-cli origin import

  • Writes {hex}.obao4 and {hex}.sizeproof before the data object, so a --move cut short keeps its source and the next import finishes it.

decdn-cache

  • CacheEngine::size_proof(hash, size): memo → stored tag → last chunk group in the local store → the origin's {H}.sizeproof. Every proof verifies before it is kept or returned; a wrong size gets None and quarantines nothing.
  • {H}.sizeproof is mandatory for an origin object: the outboard-build fallback is gone. Origin lookups are single-flight per hash, with a 5 s negative memo (4,096 entries).
  • Persistence: a proof is a named tag decdn-sizeproof-{hex}/{size}/{proof} whose value is the empty blob, so a tag never keeps content alive. Tags are written only while the store tracks the blob; a proof for an unheld blob stays in memory. Eviction, release and quarantine delete them; an orphan sweep runs at open and on every origin rescan.
  • In-memory memo of 16,384 entries (about 70 MiB at the 4,480-byte maximum).

decdn-node

  • sign_response attaches the proof on every ok = true response and refuses to sign a size it cannot prove.
  • Probe states total_bytes (and coverage) only with a proof and only for a hash it does not refuse; a chain-stale or refused hash costs no proof work.
  • Own-origin serve checks the proof first; with none, the request is not served from the origin spine or the local populate.
  • Window pull-through: keeps the upstream proof, refuses a missing proof as CacheMiss (releasing its reservation), and refuses an offset at or past the proven size with RangeNotSatisfiable before signing. Direct serve with no proof answers InternalError.
  • planned_len: the pull leg and the coverage gate plan no further than the request end or max_blob_size + one chunk group.

decdn-client

  • ProvenSize: check_size_proof returns one, and it is the only way to make one outside tests (ProvenSize::assume_for_tests, test-util). AcquireTarget, DownloadTarget, FirstClaim, Streamer::open/open_range, IngestStore::prove_size, Probed, the quote census and the CLI's known sizes take or hold it, so a raw u64 from a node cannot reach planning, a cap or payment.
  • check_size_proof + typed UnprovenSize (a source fault). verify_response checks every ok = true response; classify_probe and the node's probe consumer drop an answer whose size has no valid proof.
  • Claim growth deleted. The acquire loop records the first size as proven (store.prove_size(c0)) before any leg opens; claim_reach, known_end and the growth paths are gone. A resumed record with a different recorded size takes the fresh proven size. A proven size past the cap ends the item before any leg opens.
  • The planner walks only the blocks a gap touches (touched_blocks), so its work follows the gap, not the blob size.
  • Want tail fix (client: cap-0 explicit ranges longer than the 1 TiB sizing ceiling truncate or overfetch #2865): only a zero-length range is a tail; ranges past the size are clipped.
  • Bundles: an entry always takes a proven size (probe answer, else a whole-blob open). The manifest's declared size sizes nothing; its dedup ranges apply only when it equals the proven size (ranges_at_proven_size), otherwise the entry fetches whole. A pinned node is always probed for an entry.

decdn-cli

  • decdn probe fails on an answer with an unproven size (check_stated_size).
  • decdn get: the host's known sizes hold proven sizes only; a declared size_cap only caps.
  • Gateway: the paid size pull is gone. learn_size runs a size_only fetch whose fallback open is the blob's first byte (one chunk group at most). A raw blob whose proven size passes --max-blob-mb answers 413 before any pull.

ADRs and CLAUDE.md

  • ADR 005 (proof rules, mandatory {H}.sizeproof, empty-blob tags, negative memo), 013 (ceilings), 022, 037, 038 (§ Size proof, origin-cold cost incl. {H}.sizeproof), 039 (size rule; claim growth replaced), appendix-gateway, appendix-bundles; CLAUDE.md crate notes.

Decisions taken

  1. A probe always carries the proof when it states a size (answer up to 4.8 KiB).
  2. Proofs persist as empty-blob named tags while the store holds the blob; proofs for unheld blobs (including origin-only reads) stay in the 16,384-entry memo.
  3. {H}.sizeproof is mandatory; an origin object without it is advertised with no size and no coverage. decdn origin import writes it.
  4. Separate 8 KiB response ceilings; node-read ceilings stay small.
  5. Gateway size lookups go through the same per-bucket admission queue as pulls; no extra lookup rate limit.
  6. Pinned bundle entries are probed (one probe per entry) instead of trusting the manifest size.

SDK contract

The TypeScript and Python contract suites against the real binary do not observe this change (the suites use a 1 GiB allowance and assert Content-Length only on bundle entries), so neither SDK pin moves. Only the SDK fakes model the removed 16 KiB size-pull charge (fake-gateway.ts prove(), fake_gateway.py _prove); cleaning those is a follow-up in the SDK repos.

Tests

New or rewritten: proof decode bound; ceilings; tail-wire padding refusal; cache memo/tag semantics (restart, unheld blob, eviction leaves no tag, wrong size with no quarantine for full and partial holders, origin without .sizeproof + negative memo); dedup ranges at the proven size; first-byte size-lookup leg; gateway 413; decdn probe unproven size; origin import --move order and resume; probe of a denied held blob and of an origin object without .sizeproof; resumed records and cap tests under proven sizes. Node test origins now carry .sizeproof like a real import.

Results (local, on the merged tree unless noted):

  • cargo fmt -- --check, cargo clippy --workspace --all-targets --all-features -- -D warnings, CARGO_BUILD_WARNINGS=deny cargo doc --workspace --no-deps --document-private-items: clean. cargo clippy -p decdn-cache --no-default-features --all-targets: clean.
  • cargo nextest run: decdn-client + decdn-cli + decdn-cache 3,050/3,050; decdn-node 1,944/1,944 (1 flaky retry); decdn-protocol + decdn-bao-range pass.
  • Anvil e2e (--features anvil-e2e): 136/141 before the merge; the 4 real failures were e2e origins without .sizeproof (fixture fixed) and one read a file mid-merge. All 7 affected tests pass after the fix and merge.
  • Public API snapshots: protocol +MAX_PROBE_REQUEST_FRAME; client +UnprovenSize, +check_size_proof, -Streamer::prove_size.
  • Crate edges OK; client/CLI/sponsord closures stay free of iroh-blobs / aws-sdk-s3.

Not covered by a dedicated test

  • Window pull-through RangeNotSatisfiable at offset == size and for the empty blob, and the wire result of the "no proof" refusals on the window and direct-serve paths (the code paths are covered by the existing gates, not by new loopback tests).
  • Concurrent probes sharing one origin .sizeproof read (single-flight); the negative memo has a cache-level test.

🤖 Generated with Claude Code

alpergundogdu and others added 11 commits November 11, 2026 22:02
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]>
A StreamResponse, and a ProbeResponse that states total_bytes, carries a
size proof: the final BLAKE3 chunk and its path to the root. The
receiver verifies the proof against the content hash before it uses the
size. A proof depends on the hash alone, so the origin makes it at
import and any node passes it on.

Refs #2879

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Add SizeProof, bounded at MAX_SIZE_PROOF_BYTES at decode, as an
extension field of StreamResponseExt and ProbeResponseExt. Raise the
probe and client control frame ceilings to 8 KiB to fit a full proof.
num_blocks saturates at u32::MAX. encode_outboard builds the size
proof in the same pass, and SIZE_PROOF_SUFFIX names its origin object.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A node attaches a size proof to every StreamResponse with ok = true and
to every probe answer that states total_bytes. Nothing plans,
allocates, compares with a cap or pays against a size before its proof
verifies.

- cache: Origin::fetch_size_proof (fs, S3, HTTP); CacheEngine keeps one
  verified proof per blob, builds it from the local store or the origin,
  and drops it on eviction.
- origin import writes {hex}.sizeproof beside {hex}.obao4.
- node: signs no size it cannot prove; keeps the upstream's verified
  proof; probes state a size only with its proof; window pull-through
  refuses an offset past the proven size; pull plan is cut to the
  request end and max_blob_size (planned_len).
- client: check_size_proof / UnprovenSize (a source fault) on every
  open and probe answer; the first paid leg's proof sets the store's
  size; Want tail fix (#2865); range clipping past the bound.
- protocol: MAX_STREAM_RESPONSE_FRAME for the response the payer reads.
- cli/gateway: decdn probe shows only a verified size; the gateway's
  paid size pull is replaced by a free size lookup.

Refs #2879

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Finish the size-proof ADR text: the max_blob_size paragraphs and probe
field in ADR 005, the frame and field tables in ADR 013, the proof
format in ADR 038, the size rule in ADR 039, ADR 022 and 037
(criterion 13), and the gateway and bundles appendices. CLAUDE.md names
the new crate parts.

Refs #2879

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A kept proof lives under a named tag on the blob it proves
(decdn-sizeproof-{hex}/{size}/{proof}), with the in-memory memo as a
cache in front. Evicting the blob drops the tag with the blob's other
tags, and the engine deletes the tags of blobs it does not hold at open.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…aude/size-proof-wiring-bc490c

# Conflicts:
#	CLAUDE.md
@alpergundogdu
alpergundogdu changed the base branch from claude/size-proof-codec to main November 12, 2026 01:24
alpergundogdu and others added 2 commits November 12, 2026 02:34
….sizeproof

- Delete the client's claim growth: acquire records the first size as
  proven before any leg opens; bundle entries always take a proven size
  and keep dedup ranges only when the manifest size matches it.
- Known sizes on a host are proven only; a declared size only caps.
- Gateway size lookups open the blob's first byte (one chunk group at
  most); a proven size past --max-blob-mb answers 413 before any pull.
- Cache: {H}.sizeproof is mandatory (no outboard-build fallback), origin
  reads are single-flight with a negative memo; proof tags point at the
  empty blob and exist only while the store tracks the blob.
- Probe: no size, proof or coverage for refused or unprovable hashes;
  split request/response frame ceilings.
- origin import writes both siblings before the data object.
- decdn probe fails on an unproven size; tests, ADRs and docs updated.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Resolve the Streamer store refactor (#2887) against the proven-size
acquire: the stream store opens at the proven size with no cap clamp, and
the streamer tests keep the caller-supplied store test. Seed e2e origins
with their .sizeproof sibling.

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

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

Copy link
Copy Markdown

Code coverage overview

Languages: Rust, Solidity

Rust / code-coverage/cargo-llvm-cov

main eb7e2d7 claude/size-proof-wi... bba1a00 +/-
77% 77% 0%
View coverage of the 10 most impacted files.
File main eb7e2d7 claude/size-proof-wi... bba1a00 +/-
crates/cache/src/origin/s3.rs 86% 80% -6%
crates/node/src...lient/window.rs 74% 72% -2%
crates/node/src...ent/dispatch.rs 88% 87% -1%
crates/client/src/scheduler.rs 94% 94% 0%
crates/cli/src/...mmands/fetch.rs 46% 47% +1%
crates/client/s...undle/engine.rs 65% 66% +1%
crates/client/src/lib.rs 89% 90% +1%
crates/protocol...c/size_proof.rs 0% 89% +89%
crates/bao-rang...c/size_proof.rs 0% 96% +96%
crates/cache/sr.../size_proofs.rs 0% 98% +98%

Solidity / code-coverage/forge

main eb7e2d7 claude/size-proof-wi... bba1a00 +/-
92% 92% 0%

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


Updated November 13, 2026 18:26 UTC

@alpergundogdu
alpergundogdu marked this pull request as ready for review November 12, 2026 03:27
Copilot AI balanced review requested due to automatic review settings November 12, 2026 03:27

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note

Copilot was unable to complete this review at the selected tier due to model policy or plan restrictions.

🟡 Changes recommended

Approval is blocked because the review evidence identifies multiple lingering documentation/comment inaccuracies about size-proof fallback behavior, which now misdescribe how CacheEngine::size_proof handles missing {H}.sizeproof.

3 open issues
What changed in this PR

Wire-breaking update that makes blob sizes provable end-to-end: whenever a node states a size it includes a bounded size proof, and node/client/cache/CLI verify the proof before using sizes for planning, allocation, caps, or signing.

Changes:

  • Add SizeProof to the protocol, extend probe/stream response extensions with size_proof, and adjust framing ceilings.
  • Generate, fetch, cache, and persist .sizeproof siblings across bao-range, origins, cache, and node handlers.
  • Update client fetch/planning/bundles and CLI/gateway behavior to operate only on proven sizes; refresh tests, fixtures, and ADRs accordingly.
File Description
crates/​protocol/​tests/​snapshots/​public_api__public_api.snap Updates protocol public API snapshot for the new size-proof types/fields and framing ceiling constants.
crates/​protocol/​src/​size_proof/​tests.rs Adds tests covering size-proof encoding/decoding limits and defensive length handling.
crates/​protocol/​src/​size_proof.rs Introduces the SizeProof type with bounded decoding and maximum proof-size enforcement.
crates/​protocol/​src/​message/​tests.rs Updates message-level tests for probe extensions, wire format, and revised frame ceilings including size proofs.
crates/​protocol/​src/​message.rs Extends probe messaging with size_proof and splits probe frame ceilings into request vs response bounds.
crates/​protocol/​src/​lib.rs Re-exports size-proof APIs and updates crate-level constants/docs for new framing ceilings.
crates/​protocol/​src/​framing/​tests.rs Adjusts framing roundtrip tests to include size proofs in probe/response flows.
crates/​protocol/​src/​coverage/​tests.rs Adds tests validating saturation behavior for coverage num_blocks calculations.
crates/​protocol/​src/​coverage.rs Changes num_blocks computation to saturate at u32::MAX to avoid overflow/truncation issues.
crates/​protocol/​src/​client/​tests.rs Updates client protocol tests and fixtures for stream responses carrying size proofs and updated ceilings.
crates/​protocol/​src/​client.rs Adds StreamResponseExt.size_proof plus stream response frame ceiling constants and related docs.
crates/​node/​tests/​support/​mod.rs Updates node test support to seed/register .sizeproof siblings and work with new response ceilings.
crates/​node/​tests/​probe_loopback.rs Updates probe loopback tests to ensure sizes are only stated when accompanied by a valid proof.
crates/​node/​tests/​partial_serve.rs Adjusts partial-serve tests and fixtures to include .sizeproof origin siblings and proven-size expectations.
crates/​node/​tests/​origin_range_pull.rs Updates origin range pull tests to serve/require .sizeproof alongside origin data and outboards.
crates/​node/​tests/​node_to_node_pull_through.rs Updates pull-through tests so upstream responses propagate proven sizes via size proofs.
crates/​node/​src/​selection.rs Updates selection logic/docs to treat size hints as proof-backed rather than trusted declarations.
crates/​node/​src/​node_origin/​tests.rs Adds/updates node-origin tests asserting probe-stated sizes are accepted only with valid proofs.
crates/​node/​src/​node_origin/​ranged_pull/​tests.rs Adds tests for bounded planning behavior (planned_len) under proven-size and cap constraints.
crates/​node/​src/​node_origin/​ranged_pull.rs Introduces planned_len and related logic to bound ranged pulls to proven size/cap reach.
crates/​node/​src/​node_origin/​mod.rs Updates node-origin behavior to drop or ignore unproven size claims before they influence planning/serve.
crates/​node/​src/​node_origin/​backend_source.rs Updates backend source integration to align headers/behavior with the size-proof requirement model.
crates/​node/​src/​metrics.rs Updates metric definitions/documentation to use proven-size terminology and semantics.
crates/​node/​src/​handlers/​probe.rs Updates probe handler to include size proofs whenever stating sizes and to respect new request ceilings.
crates/​node/​src/​handlers/​client/​wire.rs Updates response signing to attach size proofs on successful responses and refuse signing unprovable sizes.
crates/​node/​src/​handlers/​client/​tests.rs Updates/extends handler tests to validate proof attachment and refusal behavior when proofs are unavailable.
crates/​node/​src/​handlers/​client/​mod.rs Adjusts client handler docs/flow to reflect proven-size gating and new refusal behavior.
crates/​node/​src/​handlers/​client/​fill.rs Tightens fill/serve logic so direct/fast paths require an available verified size proof.
crates/​node/​src/​handlers/​client/​dispatch.rs Updates dispatch to gate origin/local serving and range validation on proven size before signing/serving.
crates/​node/​src/​dht/​probe_cache.rs Updates probe-cache handling/documentation to store only proof-backed size information.
crates/​e2e/​tests/​pool_floor_ceiling_aggregate.rs Updates E2E tests to use the new stream-response frame ceiling constant.
crates/​e2e/​tests/​gateway_public.rs Updates gateway E2E coverage for proof-based size learning and revised sizing/accounting behavior.
crates/​e2e/​src/​node.rs Updates E2E node fixture setup to write .sizeproof siblings for origin content.
crates/​e2e/​src/​client.rs Updates E2E client harness to use revised frame ceilings and proven-size behavior.
crates/​client/​tests/​snapshots/​public_api__public_api.snap Updates client public API snapshot for new size-proof APIs and removal of claim-growth-related interfaces.
crates/​client/​src/​tests.rs Adds/updates client tests enforcing proof verification before size usage and bound parity with protocol limits.
crates/​client/​src/​targets/​tests.rs Updates target-selection tests to ensure probe-derived sizes are retained only when proven by a valid proof.
crates/​client/​src/​streamer.rs Removes claim-growth logic and rewires streaming to record and rely on proven sizes only.
crates/​client/​src/​source.rs Adds size-proof verification/plumbing in source handling, including recording proven sizes into storage.
crates/​client/​src/​source_set.rs Updates source-set behavior and docs so past-end and bounds decisions use proven size.
crates/​client/​src/​segment/​tests.rs Updates segment tests for new range canonicalization/clipping behavior under proven-size bounds.
crates/​client/​src/​segment.rs Adjusts segment/range canonicalization to clip to proven bounds and treat tails consistently.
crates/​client/​src/​ranged_store/​tests.rs Updates ranged-store tests to cover proven-size recording, replacement, and rejection of unproven sizing.
crates/​client/​src/​ranged_store.rs Adds/updates store APIs to record proven sizes and enforce clamping/behavior based on those bounds.
crates/​client/​src/​quote.rs Updates quoting/census logic and documentation to treat sizes as proof-backed facts.
crates/​client/​src/​probe.rs Clarifies probe verification responsibilities and ensures size proof validation occurs before size use.
crates/​client/​src/​lane_sources/​tests.rs Adds/updates tests for first-open/priming flows that learn sizes via proof-backed mechanisms.
crates/​client/​src/​lane_sources.rs Reworks lane source logic to operate on the first proven size (not claim growth) and updates docs.
crates/​client/​src/​first_open.rs Updates first-open logic/docs to learn and store proven size before planning further work.
crates/​client/​src/​driver/​tests.rs Updates driver tests to validate propagation and storage of proven sizes from proof-carrying responses.
crates/​client/​src/​driver.rs Updates the driver to record proven size early and prevent planning/allocations based on unproven sizes.
crates/​client/​src/​downloader/​tests.rs Updates downloader tests for resume and tail semantics under the proven-size model.
crates/​client/​src/​downloader.rs Updates downloader behavior to use proven-size bounds, including tail range handling and end-clamping.
crates/​client/​src/​discovery.rs Updates discovery logic/docs to store and act on sizes only after proof verification.
crates/​client/​src/​coverage_plan/​tests.rs Adds tests ensuring planner work scales with the touched gap blocks rather than total blob size.
crates/​client/​src/​coverage_plan.rs Introduces touched_blocks planning optimization and adjusts coverage planning to use proven size bounds.
crates/​client/​src/​bundle/​engine/​tests.rs Adds tests enforcing that dedup ranges apply only when manifest declared size matches the proven size.
crates/​client/​src/​bundle.rs Updates bundle semantics so manifest sizes are declared-only and proven size governs fetch/dedup decisions.
crates/​client/​examples/​common/​mod.rs Updates example client code to drop or ignore stated sizes that lack a valid size proof.
crates/​cli/​tests/​origin_import.rs Updates origin import tests to ensure .sizeproof is written and verified before data is considered complete.
crates/​cli/​src/​commands/​probe/​tests.rs Adds tests ensuring decdn probe rejects responses that state sizes without valid proofs.
crates/​cli/​src/​commands/​probe.rs Updates decdn probe to require proven stated sizes via explicit size-proof checks.
crates/​cli/​src/​commands/​origin/​tests.rs Updates origin command tests for .sizeproof sibling creation and --move ordering/resume behavior.
crates/​cli/​src/​commands/​gateway/​worker/​tests.rs Updates gateway worker tests for the new size-learning flow and renamed/requested behavior.
crates/​cli/​src/​commands/​gateway/​worker.rs Updates gateway worker logic/docs to learn sizes via proof-backed operations rather than a paid size pull.
crates/​cli/​src/​commands/​fetch/​tests.rs Updates fetch command tests to reflect that known sizes are proven sizes and caps only constrain.
crates/​cache/​src/​size_proofs/​tests.rs Adds tests for the in-memory and persisted size-proof memo/tag semantics and lifecycle.
crates/​cache/​src/​size_proofs.rs Implements bounded size-proof memoization and persistence semantics for verified proofs.
crates/​cache/​src/​ranged_store.rs Updates ranged store behavior/comments to match proven-size end clamping and related semantics.
crates/​cache/​src/​origin/​s3.rs Updates S3 origin support to fetch .sizeproof siblings and handle size-proof-related error classification.
crates/​cache/​src/​origin/​mod.rs Extends the origin abstraction with fetch_size_proof and documents the required .sizeproof behavior.
crates/​cache/​src/​origin/​http.rs Updates HTTP origin support to fetch .sizeproof siblings alongside content/outboards as needed.
crates/​cache/​src/​origin/​fs.rs Updates filesystem origin support to read .sizeproof siblings and enforce size-proof constraints.
crates/​cache/​src/​lib.rs Wires the new size-proof subsystem into the cache crate and exports the necessary integration points.
crates/​cache/​src/​fill_session.rs Updates fill-session behavior/comments to align with proven-size clamping and no-unproven-size usage.
crates/​bao-range/​src/​origin_seed/​tests.rs Adds tests validating .sizeproof generation and that proofs verify true size and reject mismatches.
crates/​bao-range/​src/​origin_seed.rs Updates origin seeding to emit .sizeproof in the same pass as outboard encoding and standardizes naming.
crates/​bao-range/​src/​lib.rs Re-exports size-proof helpers/constants and updates docs to match new proven-size behavior.
CLAUDE.md Updates repository guidance/notes to reflect the proven-size invariant and related crate responsibilities.
adr/​appendix-gateway.md Updates the gateway appendix ADR to describe proof-based size learning and the removal of paid size pulls.
adr/​appendix-bundles.md Updates the bundles appendix ADR to clarify declared vs proven sizes and dedup applicability rules.
adr/​039-multi-source-parallel-fetch.md Updates ADR 039 to replace claim-growth sizing with proven-size-first rules and related planning behavior.
adr/​038-bao-verified-range-streaming.md Updates ADR 038 with size-proof format/requirements and cost model notes for origin-cold reads.
adr/​037-regional-proxy-warming.md Updates ADR 037 to require/propagate size proofs in proxy warming and pull-through flows.
adr/​022-content-discovery.md Updates ADR 022 to treat discovered sizes as proof-backed facts and adjust related rules/wording.
adr/​013-schema-evolution.md Updates ADR 013 to document the wire/schema changes, including new ceilings and size-proof fields.

Review effort: Balanced

Comment thread crates/cache/src/origin/http.rs Resolved
Comment thread crates/cache/src/origin/mod.rs Resolved
Comment thread crates/cache/src/origin/s3.rs Resolved
alpergundogdu and others added 2 commits November 13, 2026 10:19
The probe's size and the header's size are both proven against the hash,
so they are equal: the first-leg size check and the past-end whole-blob
fallback cannot fire for an honest node. A wrong past-end refusal is now
the handshake's own fault.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Keep the flag-taking public gateway helper with main's new worker-count
argument.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@yigitdot yigitdot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review: size proof wiring (head 161f4f8c)

Five read-only review passes (code, silent failures, tests, comments/ADRs, type design). Items marked ✔ were re-checked by hand against the source.

Critical

  1. ✔ Evicting or quarantining Hash::EMPTY deletes every size-proof tag. drop_named_tags_for (crates/cache/src/engine.rs:2946) deletes every tag with info.hash == hash, and every proof tag points at Hash::EMPTY (:4164). The memo still says stored = true, so nothing rewrites the tags; all proofs are lost at the next restart. Fix: skip names with the size-proof tag prefix in that loop.
  2. ✔ A pulled partial proof never reaches the store. admit_bao_stream calls protect_partial (engine.rs:4626) before record_access (:4634), so tracks() (:4143) is false for a new hash and store_size_proof_if_held writes nothing; partial_protected then short-circuits later admits. A restart before any lookup loses the proof. a_kept_proof_survives_a_restart admits before it keeps the proof (the reverse of production order), so it passes. Fix: record_access before protect_partial.
  3. Forged size can exhaust client memory (not hand-verified). A proof binds a size to a hash, not to real content: anyone who builds their own hash can prove ~2^60. With claim_reach deleted, a small --range window passes the early BlobTooLarge check (client/src/scheduler.rs:3535), and lanes without a probed bitmap (proxy lanes, lane_sources.rs:987; pinned nodes) build Coverage::full(u32::MAX) (~512 MiB, ~4.3 G iterations) at scheduler.rs:989/1141/3055. Fix: size coverage and work by request reach, keep the proven size for clipping.

Important

  1. ✔ Gateway 413 refuses Range requests on large blobs. gateway.rs:2120 runs over_blob_cap before the range parse; curl -r 0-1023 on a 10 GiB blob with a 100 MiB cap now gets 413. Conflicts with ADR 005:429 and the gateway module doc. Fix: compare the requested span (or whole blob without Range) with the cap.
  2. Orphan sweep can delete every proof. If iter_hashes fails, seed_access_times_from_store warns and leaves access_times empty; the sweep then finds nothing tracked. tracks() also maps a status() error to not-held (engine.rs:1651, 4142-4150, 4202-4218). Skip the sweep after a failed seed; keep the tag on a status error.
  3. Origin outages are cached as no-proof for 5 s, logged at debug (engine.rs:4262-4274). A .sizeproof that fails to verify is skipped with no log. Cache the miss only when every origin answered cleanly; warn on a verify failure.
  4. An origin blob with no .sizeproof goes dark silently (dispatch.rs:1166-1170, probe.rs:264-270): no warn, no metric, fault_seen unset; the node pays peers for content its own origin holds. Add a rate-limited warn naming decdn origin import, plus a metric.
  5. ✔ delete_prefix(..)? runs before partial_protected.remove (engine.rs:2920-2933), which breaks the comment right below it ("a delete failure mid-loop still leaves the memo clear"). Move it after the memo clear.
  6. Window pull-through no-proof refusals (window.rs:329-347, 365-370) use respond_error(CacheMiss): they skip the respond_miss log line and ignore fault_seen. The verified-but-not-kept branch deserves an error!/debug_assert!.
  7. Stale docs that contradict the new behaviour:
    • node_origin/pull_leg.rs:908-912 describes the deleted whole-blob retry and size-mismatch drop.
    • handlers/probe.rs:228-230 says None means unknown but fetchable; the probe now advertises no coverage and has_blob = false.
    • ADR 037 :81, :84, :183 and ADR 038 :45, :85, :105: the origin fallback now needs {H}.sizeproof, otherwise the blob is not served from the origin.
    • streamer.rs:598-603 (removed clamp), :643-644 (resumed bound no longer wins), the Streamer::open doc (says the first leg sets the size; acquire proves it at once), and the "claim that may be inflated" comment in acquire.
  8. ✔ over_blob_cap sits between the doc comment of too_large and the fn (gateway.rs:1297-1307), so too_large lost its doc.

Test gaps

  • Window pull-through ok with no proof: CacheMiss plus reservation released (the scripted upstream in node_origin_pull.rs only omits the proof on error answers).
  • Offset at or past the proven size: RangeNotSatisfiable before signing, including the empty blob.
  • Negative memo expiry after 5 s, with an origin read counter (the current test passes with or without the memo).
  • Positive orphan-sweep test (both current assertions expect 0) and the sweep in tidy_store.
  • origin import --move write order: make the sibling write fail and assert the source survives.
  • Bundle engine path where the manifest size differs from the proven size.
  • a_blob_past_the_cap_ends_the_item lacks the opened_bytes == 0 assertion its sibling uses; decode_refuses_a_huge_declared_length fails in postcard with or without the custom visitor.

Suggestions

  • A ProvenSize(u64) newtype returned by check_size_proof and taken by AcquireTarget, IngestStore::prove_size and UpstreamPullHeader, so a raw u64 cannot reach cap/plan logic. Today DownloadTarget.total_bytes and Streamer::open hints flow into prove_size unchecked.
  • StreamResponseExt::validate: (ok = true, size_proof: None) is an error. Merge the probe total_bytes/size_proof pair into Option<StatedSize>.
  • CacheEngine::size_proof could return SizeProof, removing the SizeProof::new(..).ok() rewrap in the node.
  • Origin proof lookup is not fully single-flight (engine.rs:4253-4275): the memo insert happens after the per-hash lock is released.
  • The gateway learn_size fallback can pay one chunk group but charges nothing to the allowance.
  • Unproven probe sizes from peers count as ProbeDrop::Inconsistent at debug with no peer or hash (node_origin/mod.rs:1708-1710).
  • ADR wording: 005:174 "one hash at a time" reads node-wide (it is one read per hash); 022:276 and 037:64 drop the extra chunk group of planned_len; 005:166 "carries" should be "carry"; about 30 code comments cite "ADR 005 § A node proves the blob size", which is a bold paragraph, not a heading.
  • Leftover claim/unsigned wording: streamer.rs:81, client/src/lib.rs:2841, driver.rs:847, pull_leg/prime_tests.rs:41, and a few test docs.

Strengths

Every constant matches its comments and ADRs (4,480-byte bound, frame ceilings, 4,808-byte probe answer, memo sizes). The SizeProof bound holds on every constructor. Forged and wrong-size proofs are rejected and tested at the client, probe readers and CLI, and the node never signs an unproven size. Lint, test-placement and present-tense rules are followed, with no compatibility shims.

🤖 Generated with Claude Code

- Evicting the empty blob no longer deletes every size proof tag; the
  proof delete runs after the partial-protection memo clear.
- A kept upstream proof reaches the store on the first admit (after
  recency is recorded), not only on a later lookup.
- The orphan sweep deletes a tag only for a blob known gone, and skips
  entirely after a failed recency seed.
- Origin outages are not remembered as proof misses; a non-verifying
  proof warns; a missing {H}.sizeproof warns and counts
  decdn_cache_size_proof_origin_missing_total. The origin proof enters
  the memo under its per-hash lock.
- Lanes without a probed bitmap cover only up to the requested reach,
  so a small window of a huge proven size sizes no huge bitmap.
- The gateway's 413 compares the pulled span, so a Range of a large
  blob is served.
- Window no-proof refusals go through respond_miss (unproven_size).
- Stale docs and ADR wording fixed; tests for each fix.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@alpergundogdu

Copy link
Copy Markdown
Contributor Author

Thanks for the review. Addressed in 280a343:

  • 1 Evicting the empty blob skips size-proof tags; the prefix delete runs after the partial-protection memo clear (8). Test: evicting_the_empty_blob_keeps_other_proofs.
  • 2 A kept proof is stored on the first admit, after recency is recorded (both admit paths). The restart test now keeps the proof before the admit, as production does.
  • 3 Lanes without a probed bitmap cover only up to the requested reach (Work::whole_coverage). Test: whole_blob_coverage_stops_at_the_requested_reach.
  • 4/11 The 413 compares the pulled span (whole blob or the Range's chunk-group span); a Range of a large blob is served. too_large has its doc back.
  • 5 The sweep deletes a tag only for a blob known gone (a store status error keeps it) and skips after a failed recency seed.
  • 6 An origin outage is not memoized as a miss; a non-verifying proof warns; the proof enters the memo under the per-hash lock.
  • 7 Missing {H}.sizeproof warns (once per blob per miss window) and counts decdn_cache_size_proof_origin_missing_total.
  • 9 Window no-proof refusals go through respond_miss (path unproven_size, honors fault_seen); the verified-but-not-kept branch logs error! with a debug_assert!.
  • 10 and the ADR/wording suggestions: fixed, and the ~30 citations now point at ADR 005 § Bounded byte ranges.
  • Tests added: miss memo expiry with a read counter, outage not memoized, positive and seed-skipped sweep, --move with a failing sibling write, window RangeNotSatisfiable at offset == size, opened == 0 on the cap test, and the decode tests now pin the error each path gives.

Not done here: the ProvenSize / StatedSize type changes, StreamResponseExt::validate for ok without a proof, size_proof returning SizeProof, learn_size charging its chunk group to the allowance, and the peer-probe drop logging. Also not covered by a new test: the window ok-without-proof branch (the client open rejects such a header before the window code sees it) and the bundle engine path with a differing manifest size (covered at the ranges_at_proven_size level).

🤖 Addressed by Claude Code

…ans from

check_size_proof returns a ProvenSize, the only way to make one outside
tests. AcquireTarget, DownloadTarget, FirstClaim, Streamer::open and
open_range, IngestStore::prove_size, Probed and the quote census take or
hold it, so a raw u64 from a node cannot reach planning, a cap or
payment. Tests build sizes with ProvenSize::assume_for_tests (test-util).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
alpergundogdu and others added 3 commits November 13, 2026 15:46
- SizeProof carries its size; StreamResponseBody, ProbeResponseExt and
  OriginAttestation drop total_bytes. A StreamResponse's outcome is
  Served(SizeProof) or Refused(StreamError), and validate ties it to the
  signed ok, so a served response without a proof cannot exist.
- The EIP-712 StreamResponse type drops totalBytes (SlashJudge, the
  incentive signer and binding, tests, gas snapshot). Receipts drop the
  signed size and the EntrySize fault.
- {H}.sizeproof objects hold the size (8 LE bytes) then the proof; origin
  import writes them so.
- A node serves an origin object only under a size its {H}.sizeproof
  proves, and advertises in the DHT only coverage it can prove.
- ADRs 005, 013, 014, 022, 037, 038 and frame byte counts updated.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Take main's removal of floor debt (#2873), including its floor-debt
tests; keep this branch's proven-size Declined row and imports.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@alpergundogdu alpergundogdu changed the title feat!: prove every blob size a node states (#2879) feat!: the size proof is the only statement of a blob size (#2879) Nov 13, 2026
@github-actions

Copy link
Copy Markdown

Gas snapshot

No gas changes vs base.

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.

3 participants