fix: add Parent-QC consistency check to prevent malformed blocks#284
Open
SherlockShemol wants to merge 1 commit intorelab:mainfrom
Open
fix: add Parent-QC consistency check to prevent malformed blocks#284SherlockShemol wants to merge 1 commit intorelab:mainfrom
SherlockShemol wants to merge 1 commit intorelab:mainfrom
Conversation
5af44d7 to
b7f6f1a
Compare
Add validation in Voter.Verify to ensure Block.Parent == Block.QC.BlockHash. Without this check, a Byzantine leader could create malformed blocks where: - Block.Parent points to an early block (e.g., Genesis) - Block.QC points to a recent block (e.g., View 5) This causes blockchain data structure inconsistency and incorrect Extends() results, potentially leading to liveness failures. Fixes relab#283
b7f6f1a to
d7616f8
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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