Skip to content

Commit

Permalink
make keygen output deterministic for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aayush-rockx committed Oct 3, 2022
1 parent e9a5b8c commit 732d4d4
Showing 1 changed file with 29 additions and 4 deletions.
33 changes: 29 additions & 4 deletions dkg/frost/frost_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package frost

import (
crand "crypto/rand"
"encoding/hex"
"encoding/json"
"math/big"
mrand "math/rand"
Expand All @@ -23,7 +24,31 @@ func resetRandSeed() {
}

func TestFrostDKG(t *testing.T) {

resetRandSeed()

type ExpectedKGOutput struct {
Share map[uint32]string
ValidatorPK string
OperatorPubKeys map[uint32]string
}

expected := ExpectedKGOutput{
Share: map[uint32]string{
1: "285a26f43b026b246ca0c33b34aaf90890c016d943a75456efbe00d4d0bdee01",
2: "1d3701ab6e7b902bd482ac899ec7bab1852376ae234474bae1a3f83bb41dc48f",
3: "42afa077e46dd25be4d7bb5be8734e77df5f074e0933f6ef6af8bdbe3e205cd0",
4: "67c262ae06e14097b7b3e5a1a36526d6640ac899407bf61fd38c3490e43afed4",
},
ValidatorPK: "84d633334d8d615d6739d1f011f2c9b194601e38213937999868ed9b016cab8500e16319a2866ed853411ce1628e84b3",
OperatorPubKeys: map[uint32]string{
1: "960498d1f66481d570b80c2cb6fbafa40a250f46510412eb51abaf1b62aa17e747c8c40f69d01606cd29dd0466f4a9a2",
2: "a73f10841b40509f3a727a3311c77ee46ce0ae43ffdbd44aca87f837e392772834f51d1b38eacbe91d21057c0717a51b",
3: "8982bd51c3a08d8eb0d470eeb57fe3a8a8db4f426026019bf27a5faa745fc13bc75e3e2bea2435f47fa9148313959000",
4: "af4ce0c5ec16cc0d52acb5419d8b51051bcb271275680ab17c3a445d4de3c661971f19786667ab60216955bf20a13ea7",
},
}

requestID := getRandRequestID()

operators := []types.OperatorID{
Expand Down Expand Up @@ -89,11 +114,11 @@ func TestFrostDKG(t *testing.T) {

for _, operatorID := range operators {
output := outputs[uint32(operatorID)]
t.Logf("printing generated keys for id %d\n", operatorID)
t.Logf("sk %x", output.Share.Serialize())
t.Logf("vk %x", output.ValidatorPK)

require.Equal(t, expected.ValidatorPK, hex.EncodeToString(output.ValidatorPK))
require.Equal(t, expected.Share[uint32(operatorID)], output.Share.SerializeToHexStr())
for opID, publicKey := range output.OperatorPubKeys {
t.Logf("id %d pk %x", opID, publicKey.Serialize())
require.Equal(t, expected.OperatorPubKeys[uint32(opID)], publicKey.SerializeToHexStr())
}
}
}
Expand Down

0 comments on commit 732d4d4

Please sign in to comment.