No length check in AggregatePublicKeys (#9105)

* check of len and nil

* minor edit

* minor edit

Co-authored-by: terence tsao <terence@prysmaticlabs.com>
This commit is contained in:
ahadda5 2021-06-27 20:13:55 +04:00 committed by GitHub
parent a860648960
commit 349f832bd3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 0 deletions

View File

@ -57,6 +57,9 @@ func AggregatePublicKeys(pubs [][]byte) (common.PublicKey, error) {
if featureconfig.Get().SkipBLSVerify {
return &PublicKey{}, nil
}
if pubs == nil || len(pubs) == 0 {
return nil, errors.New("nil or empty public keys")
}
agg := new(blstAggregatePublicKey)
mulP1 := make([]*blstPublicKey, 0, len(pubs))
for _, pubkey := range pubs {

View File

@ -76,3 +76,9 @@ func TestPublicKey_Copy(t *testing.T) {
require.DeepEqual(t, pubkeyA.Marshal(), pubkeyBytes, "Pubkey was mutated after copy")
}
func TestPublicKeysEmpty(t *testing.T) {
pubs := [][]byte{}
_, err := blst.AggregatePublicKeys(pubs)
require.ErrorContains(t, "nil or empty public keys", err)
}