Skip to content

fix(consensus): validate every component of a BlockID before it is trusted - #1435

Closed
lklimek wants to merge 4 commits into
v1.8-devfrom
fix/validate-proposal-block-id
Closed

lklimek wants to merge 4 commits into
v1.8-devfrom
fix/validate-proposal-block-id

Conversation

@lklimek

@lklimek lklimek commented Sep 7, 2026

Copy link
Copy Markdown
Collaborator

What this fixes

A BlockID has three independent components — Hash, PartSetHeader and StateID — and consensus verifies at most two of them anywhere it matters. The part set header is validated implicitly by assembling the block; the hash is compared in some places; StateID is never compared against the block it claims to describe.

That gap is reachable by two independent routes, and closing only one leaves the vulnerability open.

Route 1 — proposal to prevote

RoundState.BlockID() returns rs.Proposal.BlockID verbatim, and that value feeds the prevote signature. A proposer can therefore sign a BlockID whose Hash/StateID do not describe the block its own part set assembles, and honest nodes lock and precommit it.

Route 2 — commit to apply, no proposal involved

The commit-readiness and apply gates compare Hash and PartSetHeader only, and the signature check runs against the commit's own BlockID, which is tautological. A node holding the honest block accepts a forged-StateID commit with no proposal in the picture at all.

Why it is permanent

Finalization derives the real BlockID from the block itself, so state.LastBlockID records the true StateID while the stored commit carries the forged one. At the next height, LastCommit can never match, and both sides of that comparison are already persisted. Every future proposer, every future round, and it survives a restart.

What changed

  • Proposal admission — at block completion, the assembled block is compared against the BlockID the proposal claims. Each field is checked separately so an operator is told which one disagreed rather than being handed a single opaque mismatch.
  • RoundState.BlockID() — derives from the block and its part set whenever the block is held, falling back to the proposal only when it is not. This narrows an existing trusting path: the accessor already derived whenever no proposal was held.
  • Commit verification — the three field comparisons are extracted into one function and the StateID comparison is added alongside the two that already existed. The extraction is deliberate and not required by the fix: reaching those checks previously needed a live ABCI client, and separating them lets each rejection be tested with a nil executor, so a test that ever stops rejecting panics instead of passing quietly.

For an honest proposer the signed BlockID is the derivable value by construction — makeProposal builds it as block.BlockID(blockParts) — so this is an exact equality with no tolerance, and a mismatch is never an honest disagreement.

Verification

The guard was measured before it was written. An instrumented comparison ran at every block completion across the consensus and replay suites without acting on its result:

agreements disagreements
unmodified 767 0
positive control (one forged StateID byte) 0 778

Every completion that previously agreed disagrees under the control, in the attack shape, which establishes the instrument could have reported a mismatch had one existed. No honest flow fails the new check.

Tests are RED-first and mutation-verified against the whole package, and include non-vacuity guards — an honest proposal still prevotes its BlockID, and a node holding no block still falls back to the proposal — so the change is not satisfiable by refusing everything.

go build ./... clean; go test -p 1 ./internal/consensus/... ./types/... exit 0; -race exit 0 with zero races; golangci-lint at the version CI installs reports 0 issues against the base.

Notes

This does not repair a chain already halted; nothing at this layer can, since the halting values are persisted. It prevents the forged commit from being produced or accepted in the first place.

Misbehaviour is logged with the proposer's ProTxHash rather than evicting the peer: eviction acts on the node that relayed the message, an honest relayer cannot detect the mismatch before the block is assembled, and the evidence arrives after the signature. Proposer accountability belongs with evidence and slashing, not the p2p layer.

🤖 Generated with Claude Code

https://claude.ai/code/session_019gAC8rAzQagn5sgDxUJNjj

lklimek and others added 2 commits September 7, 2026 07:19
A Proposal carries a BlockID and a proposer signature over it. The BlockID
has three fields, and until the block arrives none of them can be checked
against anything: PartSetHeader is validated implicitly, because the parts
have to assemble under it, but Hash and StateID are taken on the proposer's
word. RoundState.BlockID() then hands that BlockID, unexamined, to the
prevote signer.

So a proposer can gossip a genuine block and sign a BlockID that does not
describe it. Every node that receives the block assembles it, finds nothing
that disagrees, and signs a prevote for the proposer's value. A commit forms
over a BlockID no node ever verified.

The height that commit seals is fine: finalization derives the BlockID from
the block itself, so the committed state records the real one. The next
height is not. Its LastCommit carries the BlockID the votes actually signed,
and validation compares that against the previous height's recorded value.
They differ, and neither can be revised -- one is persisted state, the other
is sealed by a threshold signature over a finalized height. Every proposer
at every subsequent round fails the same comparison. The chain does not
recover, and restarting does not help.

An honest proposer derives its BlockID from the block and the parts it is
gossiped in, so once the block is assembled the claim is exactly checkable.
Two changes, at the two points that matter:

- When the part set completes, compare the Proposal's BlockID against the
  one derived from the block just assembled. On disagreement the block is
  kept -- it is the bytes, and they are what they are -- and the Proposal is
  dropped with its receive time, which leaves the proposal incomplete so the
  round prevotes nil and moves on. A round is a cheap price; the alternative
  is signing the value that ends the chain.
- RoundState.BlockID() returns the BlockID derived from the block and parts
  whenever it holds them, and falls back to the Proposal's only when there
  is no block to derive from. The check above is what reports the lie; this
  is what keeps an unexamined claim from reaching a signature by some other
  route.

Honest operation is unaffected, and that is measured rather than argued. An
instrumented build that compared the two values at every block completion,
without acting on the result, recorded 767 agreements and no disagreement
across the consensus suite, replay included. Forging one StateID byte in the
derived value turned all 778 of them into disagreements, so the comparison
was in a position to report one.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_019gAC8rAzQagn5sgDxUJNjj
A commit names a block by hash, part set header and state ID. Before
applying one, a node checks that the block it holds matches the first two
and never looks at the third. A commit that agrees on hash and part set
header while naming a different state ID is therefore applied against this
block, and then recorded carrying its own BlockID.

That record is what the next height is validated against. Its LastCommit
holds the BlockID the votes signed; the previous height's committed state
holds the one derived from the block. They disagree, and neither side can be
revised: one is sealed by a threshold signature over a finalized height, the
other is persisted state. Every proposer at every subsequent round fails the
same comparison, and restarting changes nothing.

Ask the third field. It is asked separately from the other two, rather than
as one comparison over the whole BlockID, so an operator is told which field
disagreed instead of only that something did.

The three checks move into verifyCommitBlock. That is an extraction made for
testability and worth naming as such: reaching them previously required an
ABCI client, because the surrounding function hands the block to the
application immediately afterwards. Separated, each field's rejection is
tested directly, with a nil executor so that a test which stops rejecting
panics rather than passing quietly.

Making the new comparison tautological fails exactly one subtest across the
package, and nothing else notices.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_019gAC8rAzQagn5sgDxUJNjj
@coderabbitai

coderabbitai Bot commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: 5b507492-63b1-4e05-9db8-3e671175cb99

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@thepastaclaw

thepastaclaw commented Sep 7, 2026 •

Copy link
Copy Markdown

🕓 Queued for automated review — 13th in line, estimated start in ~2.4 h (commit 604f5c6)
Estimated review time once started: ~20 min (two-phase automated review; median of recent runs).

  • Request priority review — tick this box and the review moves to the front of the queue.

@thepastaclaw thepastaclaw 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.

Final validation — Phase 2 only (queue backlog)

At head 665ff68, the new commit BlockID validation is bypassed by commit-first/block-second delivery, leaving the PR's stated no-proposal protection incomplete. Independent source tracing and a focused controller-level reproduction confirmed that an authentic threshold-signed commit with an incorrect StateID is persisted inconsistently with the applied state. The reproduction passed using compatible local BLS artifacts and the existing test-only overlay; no tracked files were changed.

Source: reviewer 1: gpt-6-astra (agent: phase2-reviewer, role: general); reviewer 2: gpt-6-astra (agent: phase2-reviewer, role: tenderdash-consensus-security); final verifier: gpt-6-astra (agent: astra-verifier, role: final-verifier)

Review provenance

  • Triage: critical by gpt-6-astra (effort low) — This change alters consensus-critical proposal admission, prevote BlockID selection, and commit validation, where incorrect checks or side effects could cause divergent votes, acceptance of invalid commits, or a persistent chain halt.
  • Phase 1 reviewers: not run (skipped for throughput: 46 PRs queued, above the 10 limit)
  • Fresh verifier: gpt-6-astra — final-verifier; agent astra-verifier
  • Phase 2 reviewers: gpt-6-astra — general (completed, effort xhigh); agent phase2-reviewer, gpt-6-astra — tenderdash-consensus-security (completed, effort xhigh); agent phase2-reviewer

🔴 1 blocking

🤖 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 `internal/consensus/state_try_add_commit.go`:
- [BLOCKING] internal/consensus/state_try_add_commit.go:189-191: Validate buffered commits before applying or persisting them
  The new comparison is bypassed when the commit arrives before the proposal. With Proposal == nil, StateData.verifyCommit verifies the threshold signature against the commit's own BlockID, assigns s.Commit, and returns (false, nil) (state_data.go:453-480), so this wrapper returns before reaching verifyCommitBlock. When the block finishes assembling, state_add_prop_block.go:211-222 dispatches AddCommitEvent directly. Neither AddCommitAction nor ApplyCommitAction compares the commit's StateID with the block before SaveBlock; finalization then derives state.LastBlockID from the block instead. I independently reran the controller-level reproduction: both the honest and incorrect-StateID cases advance from height 1 to 2, but the latter stores a commit whose BlockID differs from state.LastBlockID. This requires an authentic threshold-signed certificate, not an undetected modification of a signed commit; such a certificate is precisely what the proposal attack on unpatched quorum members can produce. The resulting persisted mismatch leaves the PR's Route 2 and next-height LastCommit rejection open. Enforce all three BlockID comparisons at a shared pre-application/pre-persistence gate covering deferred commits, and add a regression test that dispatches the commit followed by block parts rather than testing only the helper.
Out-of-scope follow-up suggestions (1)

These are valid observations, but they are outside this PR's scope and should be handled in separate issues or author/maintainer-requested PRs rather than blocking this review.

  • Proposal StateID is not authenticated by the proposal signature — Proposal signing uses CanonicalizeProposal, which calls BlockID.ToCanonicalBlockID; that conversion includes Hash and PartSetHeader but omits StateID. A relay can therefore mutate Proposal.BlockID.StateID without changing the proposal signing bytes. This pre-existing behavior means the new mismatch log cannot establish proposer misconduct, even though the block-derived voting value protects the direct signing path. The issue warrants separate tracking because attributing an unsigned-field mutation to the proposer would be unsafe.
    • Follow-up: Track proposal StateID authentication and accountability separately. Any sign-byte change needs an explicit compatibility plan, and evidence or slashing must not treat this mismatch alone as proof of proposer misconduct.

Comment on lines +189 to +191
if verified, err := cs.verifyCommitBlock(ctx, stateData, commit); !verified || err != nil {
return verified, err
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔴 Blocking: Validate buffered commits before applying or persisting them

The new comparison is bypassed when the commit arrives before the proposal. With Proposal == nil, StateData.verifyCommit verifies the threshold signature against the commit's own BlockID, assigns s.Commit, and returns (false, nil) (state_data.go:453-480), so this wrapper returns before reaching verifyCommitBlock. When the block finishes assembling, state_add_prop_block.go:211-222 dispatches AddCommitEvent directly. Neither AddCommitAction nor ApplyCommitAction compares the commit's StateID with the block before SaveBlock; finalization then derives state.LastBlockID from the block instead. I independently reran the controller-level reproduction: both the honest and incorrect-StateID cases advance from height 1 to 2, but the latter stores a commit whose BlockID differs from state.LastBlockID. This requires an authentic threshold-signed certificate, not an undetected modification of a signed commit; such a certificate is precisely what the proposal attack on unpatched quorum members can produce. The resulting persisted mismatch leaves the PR's Route 2 and next-height LastCommit rejection open. Enforce all three BlockID comparisons at a shared pre-application/pre-persistence gate covering deferred commits, and add a regression test that dispatches the commit followed by block parts rather than testing only the helper.

source: ['claude']

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Resolved (re-reviewed at ad6ac25b): The buffered-commit path no longer reaches application or block-store persistence unchecked: ApplyCommit invokes verifyCommitBlock for non-nil commits before mustEnsureProcess, mustValidate, SaveBlock, and EndHeight handling. This covers commits dispatched directly after their block parts complete as well as locally finalized commits.

Keep the newer base implementations and regression tests: this proposal
validation change was already integrated and refined through #1442.
The resulting tree is identical to v1.8-dev at 3b30d21.

<sub>🤖 Co-authored by [Claudius the Magnificent](https://github.com/lklimek/claudius) AI Agent</sub>

@thepastaclaw thepastaclaw 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.

Final validation — Phase 2 only (queue backlog)

The reviewed head correctly closes both consensus paths for forged BlockID components. Proposal completion validates the assembled block against the proposed BlockID, and commit application validates the hash, part-set header, and StateID before persistence or state finalization, including buffered commits. No new in-scope issues remain.

Source: reviewer 1: gpt-6-astra (agent: phase2-reviewer, role: general); reviewer 2: gpt-6-astra (agent: phase2-reviewer, role: tenderdash-consensus-security); final verifier: gpt-6-astra (agent: astra-verifier, role: final-verifier)

Review provenance

  • Triage: critical by gpt-6-astra (effort low) — This is a security-sensitive consensus change that alters proposal admission, BlockID derivation, commit verification, and persistent chain-validity behavior, where an implementation bug could enable forged commits or halt future consensus.
  • Phase 1 reviewers: not run (skipped for throughput: 15 PRs queued, above the 10 limit)
  • Fresh verifier: gpt-6-astra — final-verifier; agent astra-verifier
  • Phase 2 reviewers: gpt-6-astra — general (completed, effort xhigh); agent phase2-reviewer, gpt-6-astra — tenderdash-consensus-security (completed, effort xhigh); agent phase2-reviewer

@lklimek

lklimek commented Sep 10, 2026

Copy link
Copy Markdown
Collaborator Author

already fixed in v1.8-dev

@lklimek lklimek closed this Sep 10, 2026
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.

2 participants