Skip to content

Commit

Permalink
Fix Test_verifyBLSCommittedSealsImpl
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan-Ethernal committed Oct 15, 2023
1 parent c917925 commit 9156c95
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
13 changes: 12 additions & 1 deletion bls/public.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,14 @@ import (
"github.com/0xPolygon/polygon-edge/helper/common"
)

var errInfinityPoint = errors.New("infinity point")
const (
PublicKeySize = 128
)

var (
errInfinityPoint = errors.New("infinity point")
ErrInvalidPublicKeySize = fmt.Errorf("public key must be %d bytes long", PublicKeySize)
)

// PublicKey represents bls public key
type PublicKey struct {
Expand Down Expand Up @@ -61,6 +68,10 @@ func (p *PublicKey) ToBigInt() [4]*big.Int {

// UnmarshalPublicKey unmarshals bytes to public key
func UnmarshalPublicKey(data []byte) (*PublicKey, error) {
if len(data) < PublicKeySize {
return nil, ErrInvalidPublicKeySize
}

g2 := new(bn256.G2)

if _, err := g2.Unmarshal(data); err != nil {
Expand Down
7 changes: 3 additions & 4 deletions consensus/ibft/signer/bls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -869,7 +869,6 @@ func Test_createAggregatedBLSPubKeys(t *testing.T) {
}

func Test_verifyBLSCommittedSealsImpl(t *testing.T) {
t.Skip("FIXME")
t.Parallel()

validatorKeyManager1, _, _ := newTestBLSKeyManager(t)
Expand Down Expand Up @@ -944,7 +943,7 @@ func Test_verifyBLSCommittedSealsImpl(t *testing.T) {
},
),
expectedRes: 0,
expectedErr: errors.New("failed to aggregate BLS Public Keys: public key must be 48 bytes"),
expectedErr: errors.New("failed to aggregate BLS Public Keys: public key must be 128 bytes long"),
},
{
name: "should return error if failed to unmarshal aggregated signature",
Expand All @@ -957,7 +956,7 @@ func Test_verifyBLSCommittedSealsImpl(t *testing.T) {
testBLSKeyManagerToBLSValidator(t, validatorKeyManager2),
),
expectedRes: 0,
expectedErr: errors.New("multi signature must be 96 bytes"),
expectedErr: errors.New("signature must be 64 bytes long"),
},
{
name: "should return error if message is nil",
Expand All @@ -971,7 +970,7 @@ func Test_verifyBLSCommittedSealsImpl(t *testing.T) {
),
msg: nil,
expectedRes: 0,
expectedErr: errors.New("signature and message and public key cannot be nil or zero"),
expectedErr: ErrInvalidSignature,
},
{
name: "should return ErrInvalidSignature if verification failed (different message)",
Expand Down

0 comments on commit 9156c95

Please sign in to comment.