Skip to content

PoS seal activation gate - #2170

Open
nullPointerEnjoyer wants to merge 16 commits into
masterfrom
consensus/pos-seal-activation-gate
Open

nullPointerEnjoyer wants to merge 16 commits into
masterfrom
consensus/pos-seal-activation-gate

Conversation

@nullPointerEnjoyer

Copy link
Copy Markdown
Collaborator

Summary

Adds an optional chainstate setting, pos_seal_activation_gate, and enables it by default on the testnet.

The gate. When enabled, a node refuses to activate a chain whose newly activated segment consists entirely of blocks whose PoS consensus proofs are duplicates of proofs already seen on other known blocks (the seal duplication tracking index). A single fresh proof in the segment is enough to activate as usual, so honest reorgs are unaffected. The initial block download and the reorgs of the user-initiated block invalidation path are always exempt.

Motivation. The VRF transcript binds the pool, the epoch randomness and the timestamp — but not the parent or the block content, so a block whose consensus data reuses another block's VRF proof can extend the chain with strictly higher trust while carrying no fresh entropy. The gate denies exactly that construction. Indexing (tracking) ships default-on; this PR adds the refusal classification.

Defaults. Option<bool> following the enable_heavy_checks pattern: an explicit config value always wins; unset means the chain-type default — enabled on testnet only, disabled on mainnet/signet/regtest. The testnet (Babbage, #2169) therefore runs the gate from launch with no operator action, while mainnet operators opt in explicitly.

Config validation. Enabling the gate while pos_seal_duplication_tracking is disabled is now rejected at chainstate initialization (SealActivationGateWithoutTracking) instead of being silently ignored — the gate has no effect without its index.

Testing. Unit resolver tests pin all four chain types and both override directions; an adversarial chainstate suite drives the gate end to end (twin blocks, grafted reused proofs, refusal and recovery, bypass matrix); the rejection path is pinned by a should_panic test through the real construction path; and the whole chainstate test-suite (465 tests) now runs gate-ON on its testnet-type chains.

Notes for reviewers

  • With the gate default-on for testnet-type chains, the unit-test builder chains flip to gate-ON; the one affected control leg (activation_gate_refuses_reused_proof_extension gate-off leg) now sets the gate off explicitly.
  • Refusal-rate telemetry and the mainnet default-on question remain open by decision record; live Babbage operation is the data source.

Add a disabled-by-default chainstate config setting that refuses to
activate a chain whose newly activated segment consists entirely of
blocks whose PoS consensus proofs are duplicates of proofs already seen
on other known blocks.

The classification reads the per-seal index maintained by the seal
duplication tracking and runs at activation time, so it never stores new
state and re-evaluates on every attempt: a refused branch becomes
activatable again as soon as its segment contains a block with a fresh
proof, which then proceeds under the ordinary trust comparison.

The gate never fires on the initial block download or on the reorgs of
the user-initiated block invalidation path, and it is fail-open: blocks
that do not yield a well-formed seal are never classified as duplicates.
Refused branches stay stored, valid and relayable.
Extract the duplicate-proof segment classification into a testable
function with unit tests pinning the refusal semantics (empty segment,
fresh proof, unindexed proof, missing seal, at-cap index entry), refuse
only non-empty segments explicitly, document the dependency of the gate
on the seal duplication tracking with a startup warning when the gate is
enabled without its index, and drop an unused parameter from the test
mining helper.
Differentiate the classification test's twin block by parent instead of
relying on the randomization of the VRF proof bytes, drop an unused test
import, and refine the empty-segment comment wording.
Cover the seal activation gate and the equivocation-containment
properties at the chainstate level: tip-equivocation races converge via
fresh proofs, a withheld variant released late never displaces the
incumbent chain, partition halves keep their own valid chains without
content-based canonicalization, honest resealing at the same height with
different timestamps is never flagged, variant flooding stops at the
index cap while every variant stays stored and fully valid, and
same-pool chains keep progressing with decayed trust.
Re-add the honest-reseal test (silently lost in the partition rewrite)
with the negative evidence assertions, pin the variant-cap boundedness
(index arrival order, ninth variant stored but unindexed, evidence
capped), pin the seal-index arrival order in the partition halves, use a
90-second reseal margin inside the future-timestamp limit, assert the
twin VRF-proof inequality, and document the parent PoS-ness heuristic.
Tighten the honest-reseal and variant-cap assertions (exact evidence
count, storage of every variant, index arrival order), rename the
reseal test to consecutive heights, apply neutral wording, add
parent-aware target derivation for side-branch mining, and document why
the refusal short-circuit is unreachable through normal block
processing (fresh sightings pass the gate, twin chains tie on trust,
duplicate rebuilds carry identical trust) with the invalidation-recovery
state covered by the bypass test.
A block whose consensus data reuses the VRF data of an already-sighted
block (the seal binds the pool, the epoch randomness and the timestamp,
not the parent or the block content) extends the incumbent chain with
strictly higher trust while carrying a duplicate proof. With the gate
enabled, its activation is refused: the tip stays on the incumbent, the
block stays stored, and the reused proof carries its evidence record.
With the gate disabled, the same block activates and becomes the tip.

Also fix the section header divider, reword the same-pool trust comment
(the asymptote weights timestamp gaps, not pool identity), and derive
the twins-helper target from the parent chain like the fresh helper.
@github-actions

github-actions Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

🔍 OpenCodeReview found 1 issue(s) in this PR.

  • ✅ Successfully posted inline: 0 comment(s)
  • 📋 Routed to summary by policy: 1 comment(s)

maintainability · low

📄 chainstate/src/detail/chainstateref/mod.rs (L1516-L1519)

⚠️ GitHub could not post this as an inline comment: Routed to summary (severity low · category maintainability)

A gate refusal is a consensus-liveness/security event (the node is deliberately declining the heaviest known chain). info makes it easy to miss during operator triage on testnet, where the gate is on by default. Consider log::warn! (or adding a metric/counter) so an ongoing duplicate-seal attack is visibly surfaced.

💡 Suggested Change

Before:

            log::info!(
                "Not activating a chain whose new segment consists only of blocks reusing \
                 already-known PoS consensus proofs"
            );

After:

            log::warn!(
                "Not activating a chain whose new segment consists only of blocks reusing \
                 already-known PoS consensus proofs"
            );

Comment on lines +1732 to +1735
let duplicated = match db_tx.get_seal_index_entry(&seal).map_err(BlockError::from)? {
Some(entry) => entry.blocks().len() > 1,
None => false,
};

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

bug · medium
The duplication classification relies solely on the raw size of the seal index entry, but the index is never pruned when a block is invalidated: index_block_seal adds block ids permanently, and the block invalidation path (which bypasses the gate via ChainActivationContext::InvalidationRecovery) does not remove seal index entries. Consequently, after a user invalidates one of the twin blocks carrying a reused seal, a segment block whose only duplicate partner is that invalidated block is still classified as fully duplicated and its chain activation is refused indefinitely (until a fresh-seal extension exists). Since invalidated blocks are by definition not part of any acceptable chain, this makes the gate fire on what is effectively a unique seal. Consider skipping invalid-pruned/invalidated block ids when counting partner blocks (e.g. checking db_tx.get_block_index(id) status), or documenting why a permanently refused activation is acceptable for invalidated twins.

Suggestion:

Suggested change
let duplicated = match db_tx.get_seal_index_entry(&seal).map_err(BlockError::from)? {
Some(entry) => entry.blocks().len() > 1,
None => false,
};
let duplicated = match db_tx.get_seal_index_entry(&seal).map_err(BlockError::from)? {
Some(entry) => {
// Only count partners that are still known-valid; entries are
// not pruned when a block is invalidated, so an invalidated
// twin must not make a seal look reused.
entry.blocks().iter().any(|(partner_id, _)| {
partner_id != &(*block_index.block_id())
&& db_tx
.get_block_index(partner_id)
.map_err(BlockError::from)?
.map(|idx| idx.status().is_ok())
.unwrap_or(false)
})
}
None => false,
};

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Investigated — the facts are correct (the classification uses the raw entry size and invalidation does not prune the seal index), but the suggested fix is rejected as a security regression, and the behavior is intended and now pinned.

Why counting only valid partners is a laundering vector: a reused seal becomes "unique" again as soon as one of its twins is invalidated (operator action, or the implicit stale-block invalidation path). That would re-enable exactly the trust-inflation activation the gate exists to refuse — an attacker profits from having one of its own twins invalidated.

Why no honest chain can be affected: honestly-mined VRF proofs are unique, and the reference miner's timestamp search starts at prev_block_timestamp + 1, so an honest segment always carries at least one fresh seal and activates normally. A segment that is entirely reused-proof blocks is adversarial by construction. Sightings are historical facts; the index is deliberately append-only (fail-closed direction: invalidation can only grow the duplicated set, never shrink it).

Recovery: a refused chain activates as soon as it gains a single fresh-seal block, so nothing is stranded permanently.

Pinned end to end in invalidated_partner_does_not_launder_a_reused_seal (invalidated twin → second reused-proof sibling still refused → fresh-seal child activates), with the rationale documented on segment_seals_all_duplicated.

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.

1 participant