From 61d6547ccfdb7f800de2fad1e886be04d234ed49 Mon Sep 17 00:00:00 2001 From: laizy Date: Thu, 30 Dec 2021 15:55:34 +0800 Subject: [PATCH] check duplicated key in verify header (#1382) --- core/store/ledgerstore/ledger_store.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/core/store/ledgerstore/ledger_store.go b/core/store/ledgerstore/ledger_store.go index e55f5758a..c1e64cd17 100644 --- a/core/store/ledgerstore/ledger_store.go +++ b/core/store/ledgerstore/ledger_store.go @@ -491,15 +491,17 @@ func (this *LedgerStoreImp) verifyHeader(header *types.Header) error { if len(header.Bookkeepers) < m { return fmt.Errorf("header Bookkeepers %d more than 6/7 len vbftPeerInfo%d", len(header.Bookkeepers), len(vbftPeerInfo)) } + usedPubKey := make(map[string]bool) for _, bookkeeper := range header.Bookkeepers { pubkey := vconfig.PubkeyID(bookkeeper) _, present := vbftPeerInfo[pubkey] - if !present { + if !present || usedPubKey[pubkey] { 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 } hash := header.Hash() err = signature.VerifyMultiSignature(hash[:], header.Bookkeepers, m, header.SigData)