Skip to content

docs(adr): harden cdn/dht/v1 — per-publisher quota, DHT rate limit, lookup invariants, jitter, negative probe cache - #628

Merged
alpergundogdu merged 2 commits into
mainfrom
harden-dht-permissionless-surface
May 21, 2026
Merged

alpergundogdu merged 2 commits into
mainfrom
harden-dht-permissionless-surface

Conversation

@alpergundogdu

Copy link
Copy Markdown
Contributor

Summary

Six related canonical-design additions to ADR 022 and ADR 001 that close DoS and lookup-manipulation vectors on the cdn/dht/v1 permissionless surface. All six are presented as canonical design decisions rather than retrofits.

  • ADR 022 § Content Records and TTL — Max records per publisher (200) plus per-publisher LRU eviction policy. Closes single-publisher exhaustion of the 100k global cap.
  • ADR 022 § STORE Flow — publish to K+3 closest receivers; re-publish jittered uniformly in [T+30 min, T+50 min] per record. Closes deterministic re-publish suppression.
  • ADR 022 new § DHT Rate Limiting — three-layer token bucket (global / per-IP / per-peer), symmetric to ADR 005's probe rate limiter; applies uniformly to FindValue, FindNode, and Store before routing-table lookup or response serialization. Highest-leverage change in the set.
  • ADR 022 § FIND_VALUE Flow — Provider ordering paragraph replaced with Lookup integrity: three requester-side invariants (XOR distance check on closer_nodes, active-staker filter on providers, negative probe cache consultation) plus MUST randomization of the surviving set on the requester side.
  • ADR 001 § Probe cache — adds the symmetric negative probe cache (NodeId, hash) → has_blob: false, TTL 5 min, max 1024 entries. Bounds the cost of false-STORE publishers at K-closest receivers to one failed probe per requester per cache window.
  • ADR 022 acceptance criteria — criterion 3 updated to K+3 (=23); six new criteria (10–15) covering quota+eviction isolation, rate limiting, XOR invariant, requester-side randomization, negative cache consultation, and jitter + overflow.

Closes #625.

Why this shape

Three of the six changes (per-publisher quota, DHT rate limit, negative probe cache) compound against multiple attack classes — see the analysis on #625. The DHT rate limit in particular caps the rate at which most other DHT attacks can be mounted, so it appears as a top-level section under ### cdn/dht/v1 Protocol alongside the message-types and routing-table sections rather than buried in a threat-model appendix.

The negative probe cache mechanics live in ADR 001 (symmetric to the existing positive probe cache); ADR 022's FIND_VALUE Flow consults it via cross-reference. This matches the existing pattern where probe machinery lives in ADR 001 and DHT machinery lives in ADR 022.

Test plan

  • make check-refs — ADR reference hygiene (bare refs, missing anchors, numeric § refs)
  • markdownlint via pre-commit
  • Manual review of cross-references between ADR 001 § Probe cache and ADR 022 § FIND_VALUE Flow / § Content Records and TTL
  • Manual review that no PoC/Production-scale framing leaked into new text (verified locally: all such references are pre-existing)

…ookup invariants, re-publish jitter, negative probe cache

Six related changes to ADR 022 and ADR 001 that close DoS and lookup-manipulation
vectors on the cdn/dht/v1 permissionless surface.

ADR 022 § Content Records and TTL — adds Max records per publisher (200) and a
per-publisher LRU eviction policy. Without per-publisher isolation, the 100k
global cap admits a single-publisher exhaustion path that evicts legitimate
records.

ADR 022 § STORE Flow — publishes to K+3 closest receivers (not K) and jitters
re-publish uniformly in [T+30, T+50] minutes per record. Closes deterministic
re-publish suppression by spreading the targeted-DoS receiver set and the
suppression window.

ADR 022 new § DHT Rate Limiting — three-layer token bucket (global, per-IP,
per-peer) mirroring ADR 005's probe rate limiter. Applies to FindValue,
FindNode, and Store uniformly, before any routing-table lookup, quota check,
or response serialization. This is the highest-leverage change: it caps the
rate at which most other DHT attacks can be mounted.

ADR 022 § FIND_VALUE Flow — Provider ordering paragraph replaced with three
requester-side lookup-integrity invariants (XOR-distance check on
closer_nodes, active-staker filter on providers, negative probe cache
consultation), followed by a MUST on requester-side randomization of the
surviving provider set. Responder-side ordering is no longer the load-bearing
defense against ordering manipulation.

ADR 001 § Probe cache — adds the symmetric negative probe cache referenced
from ADR 022 (NodeId, hash) → has_blob:false, TTL 5 min, max 1024 entries.
Bounds the cost of false-STORE publishers at K-closest receivers to one
failed probe per requester per cache window.

ADR 022 acceptance criteria — criterion 3 updated to K+3=23; six new criteria
(10–15) cover quota+eviction isolation, DHT rate limiting, XOR invariant,
requester-side randomization, negative cache consultation, and re-publish
jitter + K+overflow.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request introduces several security and robustness enhancements to the DHT and probing mechanisms, including a negative probe cache to suppress redundant probes, per-publisher record quotas with LRU eviction, and a three-layered rate-limiting system. It also strengthens lookup integrity through XOR distance checks and staker filters. Feedback highlights a potential slot-exhaustion vulnerability in the eviction policy that could block new publishers and suggests extending the active-staker filter to 'closer_nodes' to further improve DHT response validation.

Comment thread adr/022-content-discovery.md Outdated
| Max records per publisher (per receiver) | 200 | Bounds a single publisher's storage footprint at any receiver; sized so the per-node cap admits ≥500 distinct active publishers concurrently |

A node **stops re-publishing** when it evicts the blob. Stale records self-expire within TTL — no explicit retraction messages needed. **TTL is anchored on the receiver's wall-clock at acceptance time:** the receiver computes `expiry_us = receive_us + record_ttl_us`, where `receive_us` is the receiver's wall-clock microsecond timestamp at acceptance and `record_ttl_us` is the Record TTL parameter above in microseconds (1 hour = 3,600,000,000 μs). `StoreRequest` carries no sender-asserted timestamp, so record lifetime is independent of any clock the holder controls. A re-publish at 45 min refreshes the receiver's record by replacing stored `expiry_us` with one derived from the new `receive_us`, extending effective lifetime ahead of the previous expiry while the holder still has the blob. Rationale matches the receiver-anchored TTL pattern in [Appendix: Peer Table Eviction](appendix-peer-table-eviction.md#appendix-peer-table-eviction-policy).
**Per-publisher quota and eviction.** When a receiver's per-publisher quota for some publisher P is full, the receiver MUST reject new `StoreRequest`s from P with `StoreAck { accepted: false }`. Eviction is **per-publisher LRU on receive time**, never across publishers: P flooding records can only evict P's own oldest entries. A global LRU policy is not used because it admits an exhaustion path where a single publisher fills all 100,000 slots and forces eviction of legitimate records from other publishers. The per-publisher cap also bounds the surface area of a false-STORE publisher (a node advertising hashes it does not hold) at any one receiver, so the requester's negative probe cache ([ADR 001 § Probe cache](001-network.md#probe-cache)) sees a bounded set of `(NodeId, hash)` pairs to absorb.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The policy stating that eviction is "never across publishers" combined with the global limit of 100,000 records creates a potential slot-exhaustion vector for new publishers. If 500 staked publishers each fill their 200-record quota, the node reaches its global capacity. At this point, a 501st publisher would be unable to store any records because they have no existing entries of their own to evict, and the policy forbids evicting records from other publishers.

Since the per-publisher quota (200) already prevents the specific exhaustion path mentioned in the rationale (a single publisher filling all 100,000 slots), a global LRU policy—where the oldest record in the node is evicted to make room for a new one—would be safe to implement. This would ensure that new staked publishers can always participate without being blocked by a "first-come-first-served" exhaustion of the global pool.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Adopted in 78baf0b. The slot-exhaustion path is real — replaced the per-publisher LRU policy with a two-tier scheme: per-publisher cap (200) is still the hard limit and rejects with StoreAck { accepted: false }, but when the global cap (100k) is hit and the inserting publisher is below their per-publisher cap, the receiver MUST evict the globally-oldest record to make room. The per-publisher cap still prevents the original single-publisher exhaustion attack, and the global-LRU below-quota path closes the 501st-publisher lockout.

Comment thread adr/022-content-discovery.md Outdated
**Lookup integrity.** Three requester-side invariants govern lookup result acceptance, applied in order to each `FindValueResponse`:

1. **XOR distance check on `closer_nodes`.** The requester MUST drop any `closer_nodes` entry whose XOR distance to the target hash is not strictly less than the responder's own. A responder that returns "closer" nodes that are not in fact closer is attempting to redirect the lookup; honest Kademlia responders never produce such entries. Offending entries are dropped without affecting honest entries from the same response.
2. **Active-staker filter on `providers`.** The requester MUST filter `providers` against its cached active-staker set ([ADR 019](019-node-onboarding.md#adr-019-node-onboarding-and-bootstrapping-flow) registry cache) before probing. Non-staked NodeIds are silently dropped — they cannot legitimately hold DHT records, since STORE receivers reject non-staked publishers at admission ([§ STORE Flow (Cache Event → DHT Publish)](#store-flow-cache-event--dht-publish)), so their appearance in a response is either responder misbehavior or stale state on the responder's side.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The active-staker filter is currently specified only for providers. However, applying this filter to closer_nodes as well would improve lookup integrity and efficiency. Since the DHT is restricted to staked nodes, any non-staked NodeId appearing in closer_nodes is indicative of responder misbehavior or stale state. Filtering them out at the requester side prevents wasting resources on connection attempts to nodes that cannot legitimately participate in the protocol.

Suggested change
2. **Active-staker filter on `providers`.** The requester MUST filter `providers` against its cached active-staker set ([ADR 019](019-node-onboarding.md#adr-019-node-onboarding-and-bootstrapping-flow) registry cache) before probing. Non-staked NodeIds are silently dropped — they cannot legitimately hold DHT records, since STORE receivers reject non-staked publishers at admission ([§ STORE Flow (Cache Event → DHT Publish)](#store-flow-cache-event--dht-publish)), so their appearance in a response is either responder misbehavior or stale state on the responder's side.
2. **Active-staker filter on `closer_nodes` and `providers`.** The requester MUST filter both `closer_nodes` and `providers` against its cached active-staker set ([ADR 019](019-node-onboarding.md#adr-019-node-onboarding-and-bootstrapping-flow) registry cache). Non-staked NodeIds are silently dropped — they cannot legitimately participate in the DHT or hold records, so their appearance in a response is either responder misbehavior or stale state on the responder's side. This filter ensures the requester only routes through or probes nodes that are currently registered and staked.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Adopted in 78baf0b. Extended the filter to both closer_nodes and providers with the routing-pool-restricted rationale you suggested. Avoided the inline suggestion's exact phrasing only because the integrity subsection already breaks lookup-checking into three named invariants and I wanted to keep that structure — the merged item now reads "Active-staker filter on closer_nodes and providers" with both fields explicitly named throughout.

Two refinements to the cdn/dht/v1 hardening introduced in the previous
commit, addressing structural feedback from automated code review.

§ Content Records and TTL — replace per-publisher LRU with a two-tier
policy: per-publisher cap (200) is the hard limit (reject with
StoreAck{accepted:false}); global cap (100,000) uses global LRU when
the inserting publisher is below their per-publisher cap. The per-publisher
cap still prevents the single-publisher exhaustion attack, and global LRU
for below-quota inserts closes the slot-exhaustion lockout where 500
publishers at 200 records each would block all newly-active staked
publishers from participating in the DHT.

§ FIND_VALUE Flow — extend the active-staker filter to closer_nodes,
not just providers. The DHT routing pool is restricted to staked nodes,
so non-staked entries in either field are misbehavior or stale state
regardless of which list carries them. Filtering closer_nodes at the
requester avoids wasted iteration through nodes that cannot legitimately
participate.

Acceptance criterion 10 updated to match the two-tier policy.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@alpergundogdu
alpergundogdu merged commit 40c120e into main May 21, 2026
11 checks passed
@alpergundogdu
alpergundogdu deleted the harden-dht-permissionless-surface branch May 21, 2026 12:28
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.

cdn/dht/v1 DoS hardening — per-publisher quota, DHT rate limit, lookup invariants

1 participant