fix: add Parent-QC consistency check to prevent malformed blocks #284
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Add validation that
Block.Parent() == Block.QuorumCert().BlockHash()inVoter.Verify()to prevent Byzantine leaders from creating malformed blocks.The Bug
The protocol was missing a fundamental check: Block.Parent must equal Block.QC.BlockHash.
Without this check, a Byzantine leader can create a malformed block where:
Block.Parentpoints to an early/fork blockBlock.QCpoints to the latest valid block (existing QC, no need to forge)Attack Scenario
Why Attack Works (Before Fix)
NewBlock(parent, qc, ...)allows any combinationBlockFromProtodeserializes independentlyqcBlock.View > bLock.View✓Voter.Verifyhad no Parent-QC checkImpact Without Fix
blockchain.Extends()returns incorrect results: It traverses Parent chainThe Fix
In
protocol/consensus/voter.go,Verify()now checks:Test
twins/parent_qc_mismatch_test.go- Creates a malformed block and verifiesVoter.Verify()correctly rejects it.Fixes #283