Skip to content

Commit

Permalink
fix check pubkey in verify header (#1383)
Browse files Browse the repository at this point in the history
* fix check pubkey in verify header

* remove block height check

* update code
  • Loading branch information
xiemylogos authored and laizy committed Jan 27, 2022
1 parent 55a382e commit 94c3bcd
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion core/store/ledgerstore/ledger_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,21 @@ func (this *LedgerStoreImp) verifyHeader(header *types.Header) error {
} else {
chainConfigHeight = blkInfo.LastConfigBlockNum
}
chainConfigHeader, err := this.GetHeaderByHeight(chainConfigHeight)
if err != nil && err != scom.ErrNotFound {
return fmt.Errorf("get chain config header error %s,height:%d", err, chainConfigHeight)
}
if chainConfigHeader == nil {
return fmt.Errorf("cannot find chain config header by height:%d", chainConfigHeight)
}
chanConfigBlkInfo, err := vconfig.VbftBlock(chainConfigHeader)
if err != nil {
return err
}
if chanConfigBlkInfo.NewChainConfig == nil {
return fmt.Errorf("cannot find newchainconfig header by height:%d", chainConfigHeight)
}
c := chanConfigBlkInfo.NewChainConfig.C
this.lock.RLock()
vbftPeerInfo, ok := this.vbftPeerInfoMap[chainConfigHeight]
if !ok {
Expand All @@ -487,14 +502,19 @@ func (this *LedgerStoreImp) verifyHeader(header *types.Header) error {
for _, bookkeeper := range header.Bookkeepers {
pubkey := vconfig.PubkeyID(bookkeeper)
_, present := vbftPeerInfo[pubkey]
if !present || usedPubKey[pubkey] {
if !present {
val, _ := json.Marshal(vbftPeerInfo)
log.Errorf("verify header error: invalid pubkey :%v, height:%d, current vbftPeerInfo :%s",
pubkey, header.Height, string(val))
return fmt.Errorf("verify header error: invalid pubkey : %v", pubkey)
}
usedPubKey[pubkey] = true
}
if uint32(len(usedPubKey)) < c+1 {
log.Errorf("verify header error: height:%d,pubkey len:%d,c:%d",
header.Height, len(usedPubKey), c)
return fmt.Errorf("verify header error height:%d", header.Height)
}
hash := header.Hash()
err = signature.VerifyMultiSignature(hash[:], header.Bookkeepers, m, header.SigData)
if err != nil {
Expand Down

0 comments on commit 94c3bcd

Please sign in to comment.