Repository navigation
fix(consensus): prevent vote-extension count mismatch from halting consensus (SEC-001) - #1362
Conversation
… (SEC-001) A single Byzantine validator could broadcast a precommit for the about-to-commit block carrying a mismatched (e.g. zero) vote-extension count. Its own signatures are valid, so it passed every admission check and entered votesByBlock. Once the quorum threshold was crossed, types.SignsRecoverer either returned a length-mismatch error or - if the bad vote was in the minimal quorum-crossing set - left too few consistent extension shares to recover, and addVerifiedVote panicked, halting every node (a network-wide liveness DoS). PR #1342 relocated rather than removed this panic; v1.5.x silently skipped zero-extension precommits and so was not affected. Fix (both parts are needed): - signs_recoverer.go: restore the v1.5.x behaviour - a precommit with no vote extensions contributes only its block signature and is skipped for vote-extension recovery instead of producing an error. Dropping the share is safe: every vote's own extension signatures are verified against its validator key before admission (Vote.Verify -> QuorumSignData.Verify), so a Byzantine validator can influence only the count of extensions it offers, never their content. A genuine non-zero count mismatch is still reported (it has no safe canonical interpretation). - vote_set.go: addVerifiedVote no longer commits maj23 and crashes at the exact crossing vote. Because the BLS recovery threshold equals the consensus quorum threshold, the minimal crossing set may not yet hold enough consistent extension shares. It now tentatively sets maj23 (so the recoverer sees the correct quorum-reached state), attempts recovery, and on failure rolls maj23 back and retries as more honest votes arrive; maj23 is finalized only once recovery actually succeeds. A hard fail is retained solely for the genuinely-unattributable case where every validator has already voted for the block and recovery still fails. Adds TestVoteSet_AddVote_MismatchedVoteExtensionCountDoesNotHalt, which drives the real AddVote -> addVerifiedVote -> recovery path with the Byzantine vote added first and asserts no panic, quorum still reached, and a commit that verifies against the threshold public key. Updates two TestSignsRecovererErrors cases that asserted the removed #1342 behaviour. Co-Authored-By: Claude Opus 4.8 <[email protected]>
…y (SEC-001) Follow-up to 69ef559. That commit fixed the ZERO-extension trigger but a NON-ZERO count mismatch still halted: a Byzantine validator that precommits the winning block with, say, 1 extension while honest validators produce 2 would, once all validators had voted, hit the retained hard-fail panic ("received vote extensions with different length") - an ATTRIBUTABLE Byzantine input, contradicting the comment that the panic only covers unattributable errors. Root cause: addVoteExtensionSigs seeded the canonical extension count from the first vote and errored on any mismatch, so recovery could never fall back to the consistent honest majority. Fix: recover from the count-consistent majority, not the first vote. - vote_set.go: new canonicalVoteExtensionCount groups a block's votes by extension count and sums each group's voting power; the canonical count is the one backed by >= the threshold-signature recovery power. The bar is the FIXED, LLMQ-type-derived recovery threshold (QuorumTypeThresholdVotingPower), NOT the configurable commit gate (QuorumVotingThresholdPower). This matters: the VotingPowerThreshold override (GO-003) can set the commit gate below 1/2 of the power, under which two count-groups could both clear it and the smallest-count tie-break could wrongly pick a Byzantine count - starving recovery and halting the chain. The recovery threshold is always >= ~2/3 (> 1/2) of the quorum power, so at most one group can ever reach it: the selection is deterministic across nodes (no fork), the tie-break is unreachable, and the canonical count is always the honest one under < 1/3 Byzantine power. recoverThresholdSigns passes it to the recoverer and returns an error when no count reaches the threshold (handled by the existing retry/backstop). - validator_set.go: add QuorumTypeThresholdVotingPower (the type-derived recovery threshold, ignoring the override) and route QuorumVotingThresholdPower's fallback through it (no behaviour change); document that QuorumVotingThresholdPower honors the override. - signs_recoverer.go: WithCanonicalVoteExtensionCount makes addVoteExtensionSigs contribute extension shares only from votes carrying the canonical count - excluding a differing-count minority (zero OR non-zero) - while every vote still contributes its block signature. No count mismatch is treated as an error on this path. Excluding a vote is safe: each vote's own extension signatures are verified at admission, so a Byzantine validator can influence only the count it offers, never the content. The retained panic now fires only when every validator has voted yet no count is backed by the recovery threshold power (> 1/3 Byzantine, a BFT-safety violation) or the BLS layer is broken - genuinely unattributable, as the comment states. Also folds in two low-severity review items: - Document IsQuorumReached as lock-free, internal-use-only (called under voteSet.mtx) and non-monotonic during recovery (nil -> tentative -> nil), steering external callers to the locked accessors. No behaviour change. - Make the regression test name/coverage honest. Tests (types/vote_set_test.go): - TestVoteSet_AddVote_InconsistentVoteExtensionCountDoesNotHalt: table-driven over zero-count (all voted), non-zero mismatch (all voted), non-zero mismatch (not all voted); each asserts no panic + valSet.VerifyCommit. - TestVoteSet_AddVote_SubThirdCommitGateUsesRecoveryThreshold: with a sub-1/3 VotingPowerThreshold override, a Byzantine count must NOT be selected; asserts the honest count is canonical and the commit verifies. Fails (halts) on revert. - TestVoteSet_AddVote_NoRecoverableExtensionCountPanics: a > 1/3 split where no count reaches the recovery threshold must fire the backstop hard-fail. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
✅ Review complete (commit a7958ac) |
There was a problem hiding this comment.
Pull request overview
This PR hardens Tenderdash precommit threshold-signature recovery against vote-extension count mismatches (SEC-001) that could previously panic and halt consensus, by retrying recovery as more votes arrive and by filtering vote-extension recovery to a canonical (threshold-backed) extension count.
Changes:
- Update
VoteSet.addVerifiedVoteto tentatively setmaj23, attempt threshold-signature recovery, and rollmaj23back on recover/verify failure (panic only when all votes for that block are present and recovery still fails). - Introduce canonical vote-extension count selection keyed off the fixed quorum-type recovery threshold, and plumb it into
SignsRecoverervia a new option. - Add targeted regression tests covering inconsistent extension counts, sub-⅓ commit-gate behavior, and the retained hard-fail backstop.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
types/vote_set.go |
Implements retry/rollback of maj23 on recovery failure and adds canonical vote-extension count selection for recovery. |
types/vote_set_test.go |
Adds SEC-001 regression tests to ensure mismatched vote-extension counts don’t halt consensus and recovery still verifies. |
types/validator_set.go |
Extracts fixed quorum-type recovery threshold voting power into QuorumTypeThresholdVotingPower. |
types/signs_recoverer.go |
Adds canonical-count filtering so mismatched-count votes don’t break vote-extension recovery while still contributing block signatures. |
types/signs_recoverer_test.go |
Updates error-behavior expectations to reflect “skip zero-ext precommits” behavior introduced by SEC-001 fix. |
|
@thepastaclaw please review this SEC-001 vote-extension fix when you get a chance — CI is fully green (17/17). 🤖 Co-authored by Claudius the Magnificent AI Agent |
…ability The three inline comments in vote_set.go and validator_set.go incorrectly asserted that the LLMQ recovery threshold is always >= ~2/3 (> 1/2) of quorum power. In practice some devnet/test types (LLMQType_DEVNET, TEST_DIP0024, DEVNET_DIP0024) have exactly 50% thresholds, while all production Platform types are >= 60%. The uniqueness argument (at most one extension-count group can reach the threshold) does not require > 1/2: under the standard < 1/3 Byzantine assumption the Byzantine group holds < 1/3 < 50% <= threshold for all supported types and therefore cannot form a qualifying group on its own. For > 1/2 threshold types the stronger pigeonhole guarantee additionally applies. The tiebreak is exercisable only under BFT-violating Byzantine stake. No logic changes; comments only. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
thepastaclaw
left a comment
There was a problem hiding this comment.
Code Review
The SEC-001 retry+canonical-count approach is sound for the default configuration, but verification is built from the triggering vote rather than the canonical group. When VotingPowerThreshold is configured above QuorumTypeThresholdVotingPower (validateThreshold permits this), a Byzantine minority that delays voting can leave every post-gate triggering vote with a non-canonical extension count, causing quorumDataSigns.Verify to fail on length mismatch and eventually triggering the all-voted backstop panic despite an honest count-consistent group existing. One blocking gap, one performance suggestion on the new retry loop.
🔴 1 blocking | 🟡 1 suggestion(s)
1 additional finding(s) omitted (not in diff).
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review. Verify each finding against the current code and only fix it if needed.
In `types/vote_set.go`:
- [BLOCKING] types/vote_set.go:398-400: Verify uses triggering-vote sign items, not the canonical-count shape recovery produced
`quorumDataSigns` is constructed in `AddVote` from the currently-added vote (`MakeQuorumSignsWithVoteSet(voteSet, vote.ToProto())` at line 241) and threaded into `recoverThresholdSignsAndVerify`. After `recoverThresholdSigns` selects the canonical-count group and `signsRecoverer.GetVoteExtensions` populates `voteSet.thresholdVoteExtSigs` with `canonicalCount` signatures, `makeQuorumSigns()` returns a `QuorumSigns` whose `VoteExtensionSignatures` length equals the canonical count. `quorumDataSigns.VerifyVoteExtensions` then fails with `count of vote extension signatures (X) doesn't match recoverable vote extensions (Y)` whenever the triggering vote's extension count differs from the canonical count, even though recovery itself succeeded.
This breaks the PR's stated invariant ("Once the honest count-consistent group reaches the threshold, recovery succeeds") under any configuration where the commit gate sits above the BLS recovery threshold. `ValidatorSet.validateThreshold` only rejects `threshold > totalPower`, so a `VotingPowerThreshold` between the type-derived recovery threshold and `TotalVotingPower` is accepted. Concrete failure (10 validators @ 100 power, recovery=700, commit gate=800, 3 Byzantine with ext=1 voting last):
- 7 honest (ext=2) → sum=700, below gate, no trigger.
- Vote 8 Byzantine (ext=1) → sum=800, triggers. canonical=2, recovery produces 2 sigs; `quorumDataSigns` built from the Byzantine vote has 1 sign item → Verify length mismatch → maj23 rollback.
- Votes 9 and 10 Byzantine → same mismatch → all voted → backstop `panic(...failed recovering or verifying threshold signature with all votes present...)`.
Byzantine ordering (vote-last) is attacker-controlled, so this is a deterministic liveness DoS under a supported configuration. Fix: build the verification `QuorumSignData` from the canonical extension shape (e.g. from any one contributing canonical-count vote in `blockVotes` or from the recovered `voteSet.thresholdVoteExtSigs` set), not from the just-added vote. Equivalently, key the verification's expected `VoteExtensionSignItems` off the same canonical selection `recoverThresholdSigns` already performs.
- [SUGGESTION] types/vote_set.go:331-372: Threshold recovery re-runs on every vote after the gate is crossed
Once `votesByBlock.sum >= quorum` and `maj23` is still nil, every subsequent `addVerifiedVote` rebuilds a fresh `SignsRecoverer`, recomputes `canonicalVoteExtensionCount` (O(N)) and re-runs full BLS threshold recovery for both block and vote-extension shares. With a large quorum (e.g. LLMQ_400_60: ~268 shares per recovery attempt, ~132 votes between threshold crossing and full set) and an adversarial vote ordering, cumulative work is O(N·threshold) BLS interpolations even though only one of those attempts can newly succeed. Not a correctness issue, but a cheap mitigation is to cache per-(count) running power totals and only re-attempt full recovery when a new vote contributes to a count-group that newly crosses `QuorumTypeThresholdVotingPower`.
…t triggering vote (SEC-001) quorumDataSigns was constructed from the just-added triggering vote (MakeQuorumSignsWithVoteSet at line 241) and passed into recoverThresholdSignsAndVerify. After recoverThresholdSigns selected the canonical-count group (votes backed by >= QuorumTypeThreshold power) and populated thresholdVoteExtSigs with canonicalCount signatures, makeQuorumSigns() returned a QuorumSigns with VoteExtensionSignatures of length == canonicalCount. But quorumDataSigns.VerifyVoteExtensions checked against the *triggering* vote's extension count via len(q.VoteExtensionSignItems) — causing a spurious length-mismatch error whenever the triggering vote carried a Byzantine-crafted count different from the canonical one. Attack scenario (gate > recovery threshold, supported by validateThreshold when VotingPowerThreshold is set): 10 validators @ 100 power, recovery=700, commit gate=800, 3 Byzantine with ext=1 voting last. 7 honest votes (ext=2) reach 700 (below gate); Byzantine vote 8 triggers (sum=800), recovery succeeds with canonical count 2 but verify fails (1 vs 2 sign items) → maj23 rollback. Same for votes 9 and 10 → all-voted backstop panic. Deterministic liveness DoS under an operator-configurable and validated configuration. Fix: after recoverThresholdSigns returns, find any vote in blockVotes whose total extension count matches len(thresholdVoteExtSigs) (the canonical count) and build the verification QuorumSignData from it. This guarantees sign-item count == recovered-signature count regardless of what the triggering vote carries. Also removes the now-dead quorumDataSigns parameter from recoverThresholdSignsAndVerify and addVerifiedVote, and the MakeQuorumSignsWithVoteSet call that only existed to supply it. Adds a deterministic regression test (gate=800 > recovery=700, Byzantine votes last) that panics pre-fix and passes with the fix. Adds a TODO for the perf suggestion (🟡 thepastaclaw): skip BLS recovery re-attempts when no count-group's power changed since last attempt (deferred; correctness before optimization). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
@thepastaclaw please re-review — the blocking finding is addressed in 53364ee (verification now built from the canonical-count group; regression test added; independently verified). The perf suggestion is deferred with a TODO. 🤖 Co-authored by Claudius the Magnificent AI Agent |
thepastaclaw
left a comment
There was a problem hiding this comment.
Code Review
The PR correctly fixes SEC-001 by selecting the canonical vote-extension count from the recovery-threshold-backed voting power group, skipping non-canonical votes from extension recovery while still using their block signatures, tentatively setting maj23 with rollback on recovery failure, and building verification sign data from a vote whose extension count matches the canonical count rather than the triggering vote. The previously identified BLOCKING regression (verification sign data from triggering vote's QuorumSignData) is resolved, and the new ByzantineLastWithGateAboveRecovery test directly exercises the gate>recovery Byzantine-last scenario. All agent findings are either out-of-scope, pre-existing, or stylistic nits below the threshold for actionable review feedback.
…igs on rollback, clarify vote-copy Follow-up to the SEC-001 vote-extension fix in addVerifiedVote. Three self-review items on the recovery/rollback path: 1. Observability (:342): the error from recoverThresholdSignsAndVerify was surfaced only on the all-votes-present panic path; on the soft-retry path it was silently discarded. Thread a log.Logger into types.VoteSet (no-op default via functional option, so existing NewVoteSet callers compile unchanged) and propagate the real logger from consensus State through HeightVoteSet. Log the failure at Debug - it is an expected, benign retry that fires on every post-gate vote while maj23 is unset, so Warn/Error would be noise. The error is NOT propagated to AddVote (callers treat that as a rejected/punishable vote). 2. Stale-state rollback (:361): recoverThresholdSigns may set thresholdBlockSig/thresholdVoteExtSigs before the later verification fails. The rollback previously reset only maj23, leaving stale, unverified signatures behind. Reset both signature fields alongside maj23 so they are recomputed on the next successful recovery. 3. Clarity (:365): document why the error path intentionally skips copying votes into voteSet.votes - the vote already lives in the persistent votesByBlock bucket that the next recovery attempt reads, and voteSet.votes is the finalization "publish" step, which must not run while maj23 is rolled back. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
@thepastaclaw please re-review — addressed the self-review items in
gofmt/vet/build clean; 🤖 Co-authored by Claudius the Magnificent AI Agent |
…edge (#1365) * fix(consensus): resend catch-up block parts until the peer applies them TestReactorValidatorSetChanges intermittently hung for 120s (e.g. PR #1362 CI: a node stuck at height 17 during a validator-set change). The root cause is a consensus catch-up gossip wedge, not test timing. When a node falls behind, peers catch it up via GossipBlockPartsForCatchup. If the lagging node is still at RoundStepNewHeight/Propose with a nil ProposalBlockParts, it drops the incoming block part ("received a block part when we are not expecting any", state_add_prop_block.go). The sender, however, had already optimistically recorded the part as delivered (updatePeerProposalBlockPart), so prs.ProposalBlockParts.Not().PickRandom() reports nothing missing and the part is never resent. The catch-up commit then arrives, the node stores it and builds an empty part set from the commit header ("Commit came in before proposal", state_data.go), and waits forever for a part that is never resent -> permanent wedge. In production this recovers via propose/round timeouts (which reset peer round state and re-trigger gossip) and via blocksync. The test disables both (onlyOnce mock ticker, consensus-only reactor), turning the latent fragility into a hang. Fix: catch-up block-part gossip no longer optimistically marks the part as delivered; it keeps resending the missing part each gossip tick until the peer applies the block and advances its height. This mirrors the "resend until acked" behavior already used for catch-up commits and removes catch-up's dependency on timeouts to recover a dropped part. Regular same-height block-part gossip is unchanged. Adds TestGossipBlockPartsForCatchupResends as a regression guard. Before: wedge reproduces under high-contention parallel -race stress (captured at heights 17 and 19). After: 0 wedges across ~600 -race runs; the gossiper unit suite and single-instance -race runs pass. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> * fix(consensus): correct catch-up gossip comment and add multi-part resend test Fix 1 (gossiper.go ~line 207): remove the false claim that catch-up block-part gossip "mirrors the 'resend until acked' behavior used for catch-up commits." GossipCommit is single-shot: updatePeerCommit calls SetHasCommit on first send and GossipCommit early-returns on HasCommit, so commits are never resent. Keeping a false invariant in a comment near consensus-critical gossip logic is a maintenance hazard; the sentence is replaced with a clean full-stop that preserves the correct WHY. Fix 2 (gossiper_test.go): add TestGossipBlockPartsForCatchupResendsMultiPart. The existing single-part test cannot distinguish "iterates all missing indices" from "always re-picks the only index." The new test builds a 3-part block, leaves all parts missing on the lagging peer, runs 90 gossip ticks (coupon-collector ≈5.5 ticks; P(miss any index) <10^-16), and asserts every part index was sent at least once AND the peer's ProposalBlockParts bit-array was never optimistically marked. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> * style(consensus): fix US-locale misspelling flagged by misspell linter 'serialises' → 'serializes' in TestGossipBlockPartsForCatchupResendsMultiPart comment (gossiper_test.go:462), fixing the misspell linter finding that was blocking PR #1365 CI. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> --------- Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
…havior) Two comment-only changes in height_vote_set.go and vote_set.go; swept all PR-changed Go files — no further British spellings found. Co-authored-by: Claudius the Magnificent <[email protected]>
thepastaclaw
left a comment
There was a problem hiding this comment.
Code Review
SEC-001 fix is correctly implemented at HEAD 8e2a9f0: count-mismatch can no longer halt consensus, the canonical-count selection key is the LLMQ recovery threshold (not the configurable commit gate so a sub-threshold override can't be exploited), verification is rebuilt from a canonical-count vote rather than the triggering vote, and maj23 rollback now clears stale threshold signatures. Test coverage spans zero/non-zero count mismatch and the gate>recovery configuration. No in-scope defect found; only a minor style nit on a newly-introduced TODO.
💬 1 nitpick(s)
STYLE_GUIDE.md forbids TODO in source; single token change on vote_set.go:346. Co-authored-by: Claudius the Magnificent <[email protected]>
thepastaclaw
left a comment
There was a problem hiding this comment.
Code Review
The SEC-001 fix is correct and well-scoped: canonical-count selection is gated on the fixed BLS recovery threshold (not the configurable commit gate), verification sign data is rebuilt from a canonical-count vote rather than the triggering vote, and recovery failure rolls back both tentative maj23 and stale threshold sigs. Tests cover the gate-above-recovery Byzantine-last case, sub-1/3 commit gate, count-mismatch tolerance, and the retained backstop panic. One docstring overstates the security claim of the fix; everything else is out of scope or already acknowledged in code (NOTE(perf)).
💬 1 nitpick(s)
| // the excluded set can never be the honest majority. Excluding a vote's | ||
| // extension share is safe because every vote's own extension signatures are | ||
| // verified against its validator's key before admission (Vote.Verify -> | ||
| // QuorumSignData.Verify), so a Byzantine validator can only influence the | ||
| // *count* of extensions it offers, never their content. |
There was a problem hiding this comment.
💬 Nitpick: Docstring overstates the bound this PR establishes
The comment ends with "a Byzantine validator can only influence the count of extensions it offers, never their content." That is stronger than what the fix actually delivers. A Byzantine validator can sign a same-count vote with different-but-valid extension content using its own BLS share; Vote.Verify only checks that share against the validator's own sign bytes, so the vote is admitted, its share is mixed into Lagrange recovery, and the recovered threshold signature will not verify under the canonical sign item bytes — landing on the soft-retry path and (if everyone else has voted) the retained backstop panic. That content-mismatch attack is pre-existing and out of scope for this PR; what this PR genuinely establishes is that a Byzantine count can no longer halt liveness. Reword so the comment doesn't claim more than the patch provides.
source: ['claude']
Summary
A vote-extension count mismatch at the quorum-crossing instant could panic and halt consensus. This fix tentatively sets `maj23`, attempts threshold-signature recovery, and rolls `maj23` back on failure so consensus retries instead of crashing.
Recovery contributes vote-extension shares only from votes whose extension count matches the canonical count (the count backed by ≥ the fixed `QuorumTypeThresholdVotingPower`, which config cannot lower), while every vote still contributes its block signature. The hard-fail panic is retained only when no extension count reaches the recovery threshold.
Additional fix (thepastaclaw BLOCKING finding — commit 53364ee)
The threshold-signature verification was incorrectly built from the triggering vote's sign data (`quorumDataSigns`). When `VotingPowerThreshold` (the commit gate) is configured above `QuorumTypeThresholdVotingPower` (the BLS recovery threshold) — a supported configuration — a Byzantine attacker can place its votes last so that every post-gate triggering vote carries a non-canonical extension count. The resulting length mismatch in `VerifyVoteExtensions` (triggering-vote ext count ≠ canonical count) rolled back `maj23` on every subsequent vote, eventually hitting the backstop panic — a deterministic liveness DoS.
Fix: after `recoverThresholdSigns` returns, find any vote in `blockVotes` whose total extension count matches `len(thresholdVoteExtSigs)` (the canonical count) and build the verification `QuorumSignData` from it. This guarantees sign-item count == recovered-signature count regardless of what the triggering vote carries.
The now-dead `quorumDataSigns` parameter has been removed from `recoverThresholdSignsAndVerify` and `addVerifiedVote`, along with the `MakeQuorumSignsWithVoteSet` call that only existed to supply it.
Tests
Safety
Adversarially verified — no fork risk; safety rests on the BLS DKG threshold which configuration cannot weaken.
🤖 Generated with Claude Code