Skip to content

Commit

Permalink
Revive Test_MakeKOSKSignature and Test_AggregatedSign
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan-Ethernal committed Oct 18, 2023
1 parent 265b353 commit 52365b9
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 0 deletions.
37 changes: 37 additions & 0 deletions bls/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,40 @@ func Test_SingleSign(t *testing.T) {
isOk = signature.Verify(blsKey.PublicKey(), invalidTestMsg, unexpectedDomain)
assert.False(t, isOk)
}

func Test_AggregatedSign(t *testing.T) {
t.Parallel()

validTestMsg, invalidTestMsg := testGenRandomBytes(t, messageSize), testGenRandomBytes(t, messageSize)

keys, err := CreateRandomBlsKeys(participantsNumber) // create keys for validators
require.NoError(t, err)

pubKeys := make([]*PublicKey, len(keys))

for i, key := range keys {
pubKeys[i] = key.PublicKey()
}

signatures := Signatures{}

// test all signatures at once
for i := 0; i < len(keys); i++ {
sign, err := keys[i].Sign(validTestMsg, expectedDomain)
require.NoError(t, err)

signatures = append(signatures, sign)

// verify correctness of AggregateSignature
aggSig := signatures.Aggregate()

isOk := aggSig.VerifyAggregated(pubKeys[:i+1], validTestMsg, expectedDomain)
assert.True(t, isOk)

isOk = aggSig.VerifyAggregated(pubKeys[:i+1], invalidTestMsg, expectedDomain)
assert.False(t, isOk)

isOk = aggSig.VerifyAggregated(pubKeys[:i+1], validTestMsg, unexpectedDomain)
assert.False(t, isOk)
}
}
40 changes: 40 additions & 0 deletions consensus/polybft/signer/utils_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package signer

import (
"encoding/hex"
"testing"

"github.com/0xPolygon/polygon-edge/bls"
"github.com/0xPolygon/polygon-edge/types"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func Test_MakeKOSKSignature(t *testing.T) {
t.Parallel()

expected := "03441ebc4bbca37664455b293cfc371ccf9a4f21e40c19a3a25beee77bf6e97d16cdd264c188a01d415ee99865f52567a402044a1c13aa6915a1237a41d35e9e"
bytes, _ := hex.DecodeString("3139343634393730313533353434353137333331343333303931343932303731313035313730303336303738373134363131303435323837383335373237343933383834303135343336383231")

pk, err := bls.UnmarshalPrivateKey(bytes)
require.NoError(t, err)

supernetManagerAddr := types.StringToAddress("0x1010101")
address := types.BytesToAddress((pk.PublicKey().Marshal())[:types.AddressLength])

signature, err := MakeKOSKSignature(pk, address, 10, DomainValidatorSet, supernetManagerAddr)
require.NoError(t, err)

signatureBytes, err := signature.Marshal()
require.NoError(t, err)

assert.Equal(t, expected, hex.EncodeToString(signatureBytes))

signature, err = MakeKOSKSignature(pk, address, 100, DomainValidatorSet, supernetManagerAddr)
require.NoError(t, err)

signatureBytes, err = signature.Marshal()
require.NoError(t, err)

assert.NotEqual(t, expected, hex.EncodeToString(signatureBytes))
}

0 comments on commit 52365b9

Please sign in to comment.