Skip to content

Commit

Permalink
consortium/v2: fix the finality vote fetch from pool
Browse files Browse the repository at this point in the history
The commit fix the bug when collects and aggregates signatures from vote pool.
  • Loading branch information
minh-bq committed Jul 21, 2023
1 parent 2f9ecd9 commit 28ce906
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions consensus/consortium/v2/consortium.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,10 @@ func (c *Consortium) VerifyVote(chain consensus.ChainHeaderReader, vote *types.V
return err
}

publicKey, _ := blst.PublicKeyFromBytes(vote.PublicKey[:])
publicKey, err := blst.PublicKeyFromBytes(vote.PublicKey[:])
if err != nil {
return err
}
if !snap.inBlsPublicKeySet(publicKey) {
return finality.ErrUnauthorizedFinalityVoter
}
Expand Down Expand Up @@ -1135,25 +1138,33 @@ func (c *Consortium) assembleFinalityVote(header *types.Header, snap *Snapshot)
if c.votePool != nil {
votes := c.votePool.FetchVoteByBlockHash(header.ParentHash)
if len(votes) > finalityThreshold {
for votePosition, vote := range votes {
for _, vote := range votes {
publicKey, err := blst.PublicKeyFromBytes(vote.PublicKey[:])
if err != nil {
log.Warn("Malformed public key from vote pool", "err", err)
continue
}
authorized := false
publicKey, _ := blst.PublicKeyFromBytes(vote.PublicKey[:])
for valPosition, validator := range snap.ValidatorsWithBlsPub {
if publicKey.Equals(validator.BlsPublicKey) {
signature, err := blst.SignatureFromBytes(vote.Signature[:])
if err != nil {
log.Warn("Malformed signature from vote pool", "err", err)
break
}
signatures = append(signatures, signature)
finalityVotedValidators.SetBit(valPosition)
authorized = true
break
}
}
if !authorized {
log.Warn("Unauthorized voter's signature from vote pool", "publicKey", hex.EncodeToString(publicKey.Marshal()))
// remove the signature of the invalid public key
signatures = append(signatures[:votePosition], signatures[votePosition+1:]...)
}
}

bitSetCount := len(finalityVotedValidators.Indices())
if bitSetCount > finalityThreshold && bitSetCount == len(signatures) {
if bitSetCount > finalityThreshold {
extraData, err := finality.DecodeExtra(header.Extra, true)
if err != nil {
// This should not happen
Expand Down

0 comments on commit 28ce906

Please sign in to comment.