Skip to content

Commit

Permalink
chore(types): detect quorum hash mismatch when verifying commit (#791)
Browse files Browse the repository at this point in the history
* chore(types): detect quorum hash mismatch when verifying commit

* test(types): wrong quorum hash when verifying commits
  • Loading branch information
lklimek authored May 20, 2024
1 parent e1239db commit 991f9bc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
10 changes: 10 additions & 0 deletions types/validation_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package types

import (
"bytes"
"context"
"testing"

Expand Down Expand Up @@ -101,6 +102,15 @@ func TestValidatorSet_VerifyCommit_All(t *testing.T) {
QuorumSigns: QuorumSigns{BlockSign: vote2.BlockSignature, VoteExtensionSignatures: vote2.VoteExtensions.GetSignatures()},
},
), true},
// quorum hash mismatch
{"wrong quorum hash", chainID, vote.BlockID, vote.Height,
NewCommit(vote.Height, vote.Round, vote.BlockID,
vote.VoteExtensions,
&CommitSigns{
QuorumHash: bytes.Repeat([]byte{0xaa}, crypto.QuorumHashSize),
QuorumSigns: QuorumSigns{BlockSign: vote2.BlockSignature, VoteExtensionSignatures: vote2.VoteExtensions.GetSignatures()},
},
), true},
}

for _, tc := range testCases {
Expand Down
9 changes: 7 additions & 2 deletions types/validator_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -914,6 +914,11 @@ func (vals *ValidatorSet) VerifyCommit(chainID string, blockID BlockID,
if err != nil {
return err
}
if !vals.QuorumHash.Equal(commit.QuorumHash) {
return fmt.Errorf("invalid commit -- wrong quorum hash: validator set uses %X, commit has %X",
vals.QuorumHash, commit.QuorumHash)

}
err = quorumSigns.Verify(vals.ThresholdPublicKey, NewQuorumSignsFromCommit(commit))
if err != nil {
return fmt.Errorf("invalid commit signatures for quorum(type=%v, hash=%X), thresholdPubKey=%X: %w",
Expand Down Expand Up @@ -991,7 +996,7 @@ func (vals *ValidatorSet) StringIndented(indent string) string {
return "nil-ValidatorSet"
}
var valStrings []string
vals.Iterate(func(index int, val *Validator) bool {
vals.Iterate(func(_index int, val *Validator) bool {
valStrings = append(valStrings, val.String())
return false
})
Expand Down Expand Up @@ -1021,7 +1026,7 @@ func (vals *ValidatorSet) StringIndentedBasic(indent string) string {
return "nil-ValidatorSet"
}
var valStrings []string
vals.Iterate(func(index int, val *Validator) bool {
vals.Iterate(func(_index int, val *Validator) bool {
valStrings = append(valStrings, val.ShortStringBasic())
return false
})
Expand Down

0 comments on commit 991f9bc

Please sign in to comment.