Skip to content

cache: corrupt-at-rest blobs keep earning paid serves — no post-admission integrity audit #1984

Closed

Description

@thiras

Severity: medium-high — attack-surface review of the paid delivery path. Sibling finding: the inflated-total_bytes billing gap (filed separately); both trace to the same root — bytes are proven once, at an edge, always after money moves.

The gap

BLAKE3 verification is exclusively receiver-side and admission-time-only:

  • Pull-through and peer-fill admissions verify before commit (encode_verified_range, admit_bao_stream) — correct, and the last time the node hashes anything it holds.
  • Every serve leg reads store bytes plus the stored outboard verbatim: export_bao_range_stream (crates/cache/src/engine.rs:4096) re-emits what is on disk, and outboard_pairs (engine.rs:4197) exports proof nodes with "NO re-hashing".
  • There is no scrub / bitrot / integrity pass anywhere in the cache engine. rescan_origins probes origin existence and size only.
  • serve_audit (engine.rs:2087) answers presence + size + gates; it does not touch hashes.
  • has_blob means "root-verified at admission" (ADR 022), so discovery keeps routing buyers to a node whose stored bytes diverged after the fact.

Nothing distinguishes a malicious operator tampering with its own store from honest disk rot. In both cases the blob stays fully serveable and metered until manual eviction/GC.

Attack (deliberate case)

An operator legitimately pulls and admits blob H (passes verification, earns honest paid serves). It then corrupts the stored bytes at rest and keeps serving:

  1. Serve legs emit the corrupted bytes with internally-consistent-looking bao framing drawn from the stale outboard — BLAKE3 preimage resistance guarantees every receiver ends at typed HashMismatch (crates/client-pull/src/lib.rs:2116, sink.rs:154), so content poisoning is impossible. What remains is billing.
  2. Vouchers/reveals are released per delivered chunk as bytes arrive (receive_and_pay, client-pull/src/lib.rs:2352) — payment precedes verification by construction. Revealed amounts are irreversible; the 48–72 h dispute window (PaymentPool.sol:69) adjudicates watermarks and rate evidence, not content quality.
  3. Reputation is local-only EWMA (ADR 008): each new victim independently rediscovers the bad node and pays for the discovery again. A fetch gives the offender at most MAX_PROVIDER_ATTEMPTS = 3 (crates/node/src/selection.rs:18) fully-billed corrupt attempts.

This is a pure pay-for-garbage vector: identical settlement dynamics to the sibling billing finding, minus the inflation lever. Bytes billed per victim equal the genuine blob size (wire ≈ content × 1.002).

Impact

Lever Value
Persistence Until eviction/GC — no detection mechanism exists in-node
Per-victim cost Full blob-size bill at the quoted rate, repeated across all comers
Attacker revenue Honest-rate payment for undelivered service — profit = zero-quality-service revenue, not free money

Not a duplicate

#853 / #837 / #835 cover wrong-hash admissions at the pull-through edge and their eviction side effects. This finding covers at-rest divergence after a correct admission, where none of today's machinery looks again.

Refs: #853, ADR 038 §Payment metering, ADR 008.

Activity

  1. added
    kind:bug
    kind:security
    rust
    on Sep 10, 2026
  2. thiras commented on Sep 10, 2026

    @thiras
    ContributorAuthor

    Recommendation

    Keep the primary defense where it is — receiver-side verification + local scoring (typed HashMismatch → Corruption, wired through is_bao_corruption) — and add only what the trustless axiom permits:

    1. Sampled re-hash in rescan_origins. Re-verify K random held blobs per pass; evict on mismatch. This is hygiene, not the attack fix: an attacker patches it out. It earns its place because honest bitrot today presents identically to the attack, and both deserve eviction.
    2. [your call] Persistent mark-and-avoid. Extend the reputation Corruption label with offending operator id + last-seen so it survives restarts. NodeIds are handshake-bound and staked, so rotation isn't free — but adopt only if measurement shows the EWMA recovery horizon lets a corrupted node re-win candidates too cheaply.
    3. Considered and deferred: on-chain "false delivery" slashing. It alone among heavier options survives the trustless axiom (the evidence — the node-signed StreamResponse{ok:true} plus one delivered chunk group with its bao sibling path, checked against H by a small on-chain evaluator — binds the benefit-taker). Contract surface for new machinery; build only if the tests below show material loss.

    Tests to write

    1. Corrupt-at-rest e2e: tamper the FsStore behind a live daemon → serve → buyer gets typed HashMismatch, provider scores Corruption, ≤ MAX_PROVIDER_ATTEMPTS payments reach the offender per fetch.
    2. Voucher ledger invariant: total committed == f(wire bytes received) across the corrupt stream — pins "billed bytes stop at detection".
    3. Sampling scrub unit test: rot injected into N of M held blobs is caught within ⌈N/K⌉ rescan passes.

    Shared-root note with the sibling finding: neither issue introduces a new untrusted input; both shrink to noise once the distance between "money moved" and "byte proven" collapses to one chunk group everywhere.

  3. yigitdot commented on Sep 11, 2026

    @yigitdot
    Contributor

    Verification against main (8b437de5)

    Partially valid — the headline is overstated.

    Holds:

    • No scrub / bitrot / re-hash pass exists in crates/cache. rescan_origins probes origin existence + size only; serve_audit checks presence + size + gates; has_blob means root-verified at admission (ADR 022).
    • A rotten blob is never auto-evicted and stays advertised until an operator evicts it (ADR 040 names CacheEngine::evict as the corruption-recovery path).

    Does not hold — serve legs do not emit unverified bytes:

    • export_bao_range_stream / outboard_pairs do no hashing at the decdn layer, but the iroh-blobs call beneath them does. iroh-blobs 0.103.0 export_bao_impl (src/store/fs.rs:1213) runs bao-tree traverse_ranges_validated, which re-derives every parent CV from the outboard against the root and re-hashes every leaf (LeafHashMismatch / ParentHashMismatch) before emitting the item. A mismatch surfaces as a mid-stream Err (engine.rs:4171-4176) and the node aborts without StreamEnd (delivery.rs:129-141).
    • The progressive serve-miss leg uses encode_ranges_validated (serve_encoder.rs:339), same guarantee.
    • The only unvalidated reader is engine.get / export_range (iroh export_ranges), whose callers are admin/metrics, not the paid serve.

    So a corrupt-at-rest group aborts the serve at that group; the client pays only for the valid prefix it received. "Pay-for-garbage until eviction" does not happen. The real cost is a failed delivery (wasted buyer bandwidth + a local Corruption reputation hit), not honest-rate payment for garbage.

    Suggested rescope: retitle to "cache: no post-admission scrub; rotten blobs stay advertised until a serve trips" and downgrade to low/medium. Item 1 of the recommendation (sampled re-hash in rescan_origins, evict on mismatch) is still the right hygiene fix; items 2–3 lose their motivation.

    Docs bugs surfaced by this check (worth a separate PR):

  4. self-assigned this
    on Sep 14, 2026
  5. moved this from Backlog to In progress in deCDNon Sep 14, 2026
  6. moved this from In progress to Done in deCDNon Sep 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind:bugkind:securityrust

Type

No type

Fields

Priority

None yet

Projects

  • Status
    Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions