From 28ce9061c9eff83a4da43b4ef04f132500b818d4 Mon Sep 17 00:00:00 2001 From: Bui Quang Minh Date: Fri, 21 Jul 2023 13:52:35 +0700 Subject: [PATCH] consortium/v2: fix the finality vote fetch from pool The commit fix the bug when collects and aggregates signatures from vote pool. --- consensus/consortium/v2/consortium.go | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/consensus/consortium/v2/consortium.go b/consensus/consortium/v2/consortium.go index bfb34f37d2..e493dd855b 100644 --- a/consensus/consortium/v2/consortium.go +++ b/consensus/consortium/v2/consortium.go @@ -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 } @@ -1135,11 +1138,21 @@ 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 @@ -1147,13 +1160,11 @@ func (c *Consortium) assembleFinalityVote(header *types.Header, snap *Snapshot) } 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