Skip to content

ContentBlacklist: enumerable hash view to replace cold-start log replay #1493

Closed

Description

@alpergundogdu

Found by the genesis-replay audit spun off from #1491. Same shape as the OriginAssignment namespace replay: a cold node discovers a set by scanning event logs from the deploy block because the backing contract exposes no enumerable view. This issue proposes replacing that cold-start replay with an enumerable point read, the same way #1491 does for the origin directory.

The replay

crates/node/src/blacklist_watcher.rs (spawn, ColdStart::FromBlock, .with_from_block(from_block)): a cold node replays the entire blacklist history from the ContentBlacklist deploy block to reconstruct the current blacklisted (region, hash) set. The first eth_getLogs window is the historical replay; later ticks are the live tail. The watcher's own module doc states it plainly: "ContentBlacklist exposes no enumeration view, so events are the only way."

Backing state — contracts/src/ContentBlacklist.sol:

mapping(bytes32 region => mapping(bytes32 hash => HashEntry)) internal _hashEntries;

Nested mapping, no enumerable index. Every existing read (isHashBlacklisted, getHashEntry, …) is a point-read keyed by a hash you already know — there is no way to ask "give me the current set."

Core change

Add an enumerable per-region hash index to ContentBlacklist and switch the node's cold-start from log replay to a paginated point read.

Contract surface (ContentBlacklist.sol)

  • mapping(bytes32 region => EnumerableSet.Bytes32Set) _regionHashes, maintained on the add/remove paths (addHashRegional / removeHashRegional / global add/remove) on the 0↔1 liveness transitions.
  • Paginated views: blacklistedHashCount(bytes32 region) + blacklistedHashAt(bytes32 region, uint256 i) (offset/limit page form to match deferredSettlements(offset, limit)). A region enumerator to pair with them if the node needs to discover regions too — otherwise the node enumerates only the regions it's scoped to.
  • SSTOREs on the add/remove paths are accepted (per the audit constraint) — do not weigh index-maintenance gas against this.

Rust (crates/node/src/blacklist_watcher.rs)

  • Cold start: replace the ColdStart::FromBlock full replay with blacklistedHashCount → blacklistedHashAt(i) → getHashEntry for the node's scoped region(s). Authoritative current set, no deploy-block scan.
  • Live watcher (liveness only) stays: keep following the blacklist mutation events as the signal to re-read; drop only the historical-discovery role of the first window. The runtime still gates ALPN listeners on the initial-sync InitialSyncResult, so cold start must still complete before serving — an authoritative enumerated read satisfies that better than replaying removed-then-re-added history.

Priority / caveats — [your call]

Weaker candidate than #1491, for two reasons:

  1. Already locally persisted. The watcher persists entries durably (CheckpointKey::Blacklist + durable projection), so warm restarts don't replay — only a first/cold boot (fresh disk, new node) does. OriginAssignment: vetted-publisher instant origins (collapse assignment into publisher vetting) #1491's origin directory persists only a cursor and leans on the live tail to re-surface older namespaces, so it replays more often.
  2. Bigger enumerable surface. The nested region => hash scoping means the index is per-region (and possibly a region enumerator too), vs. origin's single flat UintSet of namespaces.

Net: real replay-elimination and an authoritative-read upgrade for cold/new nodes, but lower payoff than the origin directory. Reasonable to land after #1491 or defer.

Do we need the whole set at all? (reconsidered — likely NOT)

The serve hot path checks self.cache.is_denied(hash) (crates/node/src/handlers/client/dispatch.rs:201) — a synchronous local lookup, so today the node mirrors the whole region blacklist locally. But a node can only ever be asked to serve a hash it has cached; it never needs verdicts for the rest of the global blacklist. The whole-set mirror materializes far more than this node can be asked about.

Alternative that removes the replay AND the enumerable view AND any contract change:

  • Check isHashBlacklisted(hash) at cache admission (first pull/cache of a blob) instead of mirroring the global set. The local deny-set then scopes to cached content only.
  • Keep the live event tail to revoke already-cached content that gets blacklisted later.

This is a bigger shift than swapping a getter — it moves enforcement off the synchronous hot path and re-frames the InitialSyncResult listener gate — so it isn't free. But it's the honest answer to "do we need the whole index": for blacklist, likely no.

So the enumerable-view proposal above is the right fix ONLY IF we deliberately keep mirroring the entire region blacklist locally (synchronous, fail-closed hot-path check). If we're open to scope-to-cached admission-time checks, prefer that — it needs no contract change. [your call] on which model to commit to; that decision should precede any contract work here.

Activity

  1. added
    rust
    area:contracts
    on Jul 28, 2026
  2. thiras commented on Jul 29, 2026

    @thiras
    Contributor

    Audited against main (14abf22c): the contract and Rust work this issue proposes has already shipped in #1504, under different names. Closing via #1510, which carries no code change for this issue beyond a stale doc fix.

    Contract — contracts/src/ContentBlacklist.sol:

    • :221 — mapping(bytes32 region => EnumerableSet.Bytes32Set) internal _regionHashes, maintained in the two choke points _addHash / _removeHashRegional. Exactly the storage proposed here.
    • :593 blacklistedHashCount(bytes32 region), :614 blacklistedHashes(bytes32 region, uint256 offset, uint256 limit).
    • Bonus beyond this issue: :231 EnumerableSet.AddressSet _blacklistedAddrs (origin ∪ operator) with blacklistedAddressCount / blacklistedAddresses.

    Note the shape difference: the shipped view is the paginated page form blacklistedHashes(offset, limit), matching deferredSettlements(offset, limit) — not the per-index blacklistedHashAt(i) this issue proposed. blacklistedHashAt should not be added; the page form supersedes it.

    Rust — crates/node/src/blacklist_watcher.rs:

    • :1161 — cold start is bootstrap_snapshot, which pins a block via get_block_number then pages blacklistedAddresses / blacklistedHashes, with a count-vs-seen ensure! abort on a partial read (:461). Fail-closed, no log replay.
    • The live tail is seeded at the snapshot block (CursorStart::Seeded, no persist), plus a periodic re-enumeration backstop (:724).
    • ColdStart::FromBlock no longer exists — chain_events/resumable_watcher.rs:64 now has the single variant Head, and FromBlock returns nothing workspace-wide.

    On the "do we need the whole set at all?" alternative — not taken, deliberately. The node still mirrors the entire in-scope region blacklist locally. handlers/client/dispatch.rs:201 consults cache.is_denied / cache.is_chain_denied synchronously on the serve hot path, and the two-set/one-wire-code design exists to satisfy the ADR 011 §StreamRequest indistinguishability requirement. Moving enforcement to an admission-time isHashBlacklisted check would re-frame that gate and the InitialSyncResult listener gate, so it is a separate decision — not something to fold into a getter swap.

    Only stale prose remained: crates/node/src/content_deny.rs still said the watcher "fills that in once it has replayed". Fixed in #1510 along with the same class of drift in chain_origin_directory.rs and chain_events/backfill.rs.

  3. self-assigned this
    on Jul 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area:contractsprio:mediumrust

Type

Fields

Priority

None yet

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions