Skip to content

Commit

Permalink
validate results to support various thresholds
Browse files Browse the repository at this point in the history
  • Loading branch information
alonmuroch committed Apr 16, 2024
1 parent 0fab098 commit 26903da
Show file tree
Hide file tree
Showing 7 changed files with 234 additions and 100 deletions.
15 changes: 1 addition & 14 deletions initiator.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ func RunDKG(init *Init) ([]*Result, error) {
init.Owner,
init.Nonce,
id,
len(init.Operators),
results)
return results, err
}
Expand All @@ -49,7 +48,6 @@ func RunReshare(
signedReshare.Reshare.Owner,
signedReshare.Reshare.Nonce,
id,
len(signedReshare.Reshare.NewOperators),
results)
return results, err
}
Expand All @@ -64,32 +62,21 @@ func RunResign(
) ([]*Result, error) {
operators := maps.Keys(proofs)

t, err := ThresholdForCluster(operators)
if err != nil {
return nil, err
}

id := NewID()

var results []*Result
/*
DKG ceremony ...
*/

expectedResultsCount := int(t)
if len(results) > expectedResultsCount {
expectedResultsCount = len(results)
}

_, _, _, err = ValidateResults(
_, _, _, err := ValidateResults(
operators,
withdrawalCredentials,
validatorPK,
fork,
signedResign.Resign.Owner,
signedResign.Resign.Nonce,
id,
expectedResultsCount, // resign only requires a threshold of signers
results)
return results, err
}
Expand Down
7 changes: 5 additions & 2 deletions result.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,13 @@ func ValidateResults(
ownerAddress [20]byte,
nonce uint64,
requestID [24]byte,
t int, // threshold for minimum results needed
results []*Result,
) (*bls.PublicKey, *phase0.DepositData, *bls.Sign, error) {
if len(results) != len(operators) {
t, err := ThresholdForCluster(operators)
if err != nil {
return nil, nil, nil, err
}
if len(results) < int(t) || len(results) > len(operators) {
return nil, nil, nil, fmt.Errorf("mistmatch results count")
}

Expand Down
33 changes: 27 additions & 6 deletions testing/fixtures/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,34 @@ import (
"github.com/stretchr/testify/require"
)

func TestSSS(t *testing.T) {
func TestSSS(tt *testing.T) {
t := 9
n := 13

// master key Polynomial
msk := make([]bls.SecretKey, 10)
msk := make([]bls.SecretKey, t)

sk := &bls.SecretKey{}
err := sk.SetHexString(TestValidator10Operators)
require.NoError(t, err)
require.NoError(tt, err)

msk[0] = *sk

// construct poly
for i := uint64(1); i < 7; i++ {
for i := uint64(1); i < uint64(t); i++ {
sk := bls.SecretKey{}
sk.SetByCSPRNG()
msk[i] = sk
}

ids := []uint64{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
ids := []uint64{}
for i := 1; i <= n; i++ {
ids = append(ids, uint64(i))
}

// evaluate shares - starting from 1 because 0 is master key
shares := make(map[uint64]*bls.SecretKey)
for i := uint64(0); i < 10; i++ {
for i := uint64(0); i < uint64(n); i++ {
id := ids[i]
blsID := bls.ID{}
err := blsID.SetDecString(fmt.Sprintf("%d", id))
Expand All @@ -59,6 +65,21 @@ func TestSSS(t *testing.T) {

fmt.Printf("validator sk: %s\n", sk.GetHexString())

////////

ids = make([]uint64, t)
pks := make([]*bls.PublicKey, t)

for i := uint64(1); i <= uint64(t); i++ {
pk := shares[i].GetPublicKey()
pks[i-1] = pk
ids[i-1] = i
}

reconstructed, err := crypto.RecoverValidatorPublicKey(ids, pks)
require.NoError(tt, err)

require.EqualValues(tt, sk.GetPublicKey().Serialize(), reconstructed.Serialize())
}

func TestSignNonce(t *testing.T) {
Expand Down
54 changes: 27 additions & 27 deletions testing/fixtures/keys.go

Large diffs are not rendered by default.

26 changes: 13 additions & 13 deletions testing/fixtures/proofs.go

Large diffs are not rendered by default.

52 changes: 26 additions & 26 deletions testing/fixtures/signatures.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,31 +55,31 @@ var (
)

var (
TestOperator1DepositSignature13Operators = "9405b225c424fea4eaa58679378d51fe77856e28a28ed1dc4e1bdeb813d7e5e87521ccaf918e0a297c8e8cdd0244f39101ccbe932f517838804e3fb2df0ed5e17721fea2fbd7e85041e0121fe96400e5a222ae3bd4914941fa54f43e0dd9b132"
TestOperator2DepositSignature13Operators = "b85da6db81c5e160320acffd004e7daaadf720a30efb3b46a1d444c8705d296f2758d7078fd5897ba2311dee6e2da030172b195878243c6dd2c9cc4f6b07fe64eff9dc1dc240a9da5606279475a9cd7f1a461f79ca3f22f54cfff8bdf5d74eee"
TestOperator3DepositSignature13Operators = "b8d3499d4662adc311c2fd695214051d0738b9db6e1a94cde22fb36dd777e93f01226f3fdbb44c983e1fd44416bc2f5d16c989d7d9aab5a5b42f7d8e437ca5938e328585603c77e1894773941c691f096ec6bf328ea3b58ccebc1bf4fa906677"
TestOperator4DepositSignature13Operators = "b5281a1361e9450fdd49a4189d1affe910fbdf594f32e923d7f4476c88531de11d1b9c7a3a5d738367fe78006b4b316a0a73b32f383e250c191cd7d71ef2f24de5764ffa2130a9c0e15bebe63eb6ae205ad9628c6bdfc7c0bcec6620accb3c97"
TestOperator5DepositSignature13Operators = "a5e0b31332d359f5b06c3b132ffe0868ddf1661954c83ac5af08d3cb826d72207adb726351fa2175ef401d361a4a2bdb104500e707bae00f378f02e5a1cf4a55bcb2a995ce99796299f36462fa996338520d71e8727a05cdc00017387d4721db"
TestOperator6DepositSignature13Operators = "a377db4e5a6245c78990ea874900029c5f34d060a95b57e82fdc0378407adabd7b4eb7970de289e58aa30d22d03bf397131e2b8623a63679c3607343555ab33828b24e68397b65a000628f3fbaa2f05e4815812d784729c75101c8736f876037"
TestOperator7DepositSignature13Operators = "b1f6bee35d39b0ee8c217716164f9b68e21a0deb35f3e82dd6c5a8ba9b16f49c7472911a12b89de6d3234e5c72c1dcf812727c71419ba930ab8bea033e1abfce7c12a5db05f685b8f05ba2d358b1d4dd217d9eaa8f90fb6fd5c0e303f4e4b64f"
TestOperator8DepositSignature13Operators = "9037863eab0d2cb845bd9117803d37948488078eeec9319b2f515664a9699959aa88764f93d35f36464070ca118cb64a12940ff8c7856b2ab6e3e802ab4d97df2ea6d0c6ee84bda271a08e18ad885bc4d5f39089a15b72e7409e36500387f331"
TestOperator9DepositSignature13Operators = "891973e20f634ad183bad3a9221ef066318e701c370350d5e2b30d5e6003c31840e6d3a8c6e67d267ba085783d49f5b204a657d82ac7a44d2ee4914f837624ea9616bac2273095e5c1cc8b8fa351a8c5a58861eca5f160e905881136e284e9e4"
TestOperator10DepositSignature13Operators = "b7e8aab51bf21aa845fc84141a07c3d580449bfa1cea10dd740436f9a21061bb434e5a511c0005ca6e4162ad8ffaa3520fb88dcaf1def87fda452a3252c93af02eb8719b636b7ff44d4923b0ff86fca355022370544f5090e797c3310293c105"
TestOperator11DepositSignature13Operators = "8c847ef5da2e8192d93a219cc8c4b68e1863c675ce1fc757b0bb7a0b9dd0b607cec511852cbb3cfcf7769b612bc1c15e141229794a38c265bb5b01311c540b1f24cf81abca1234fce43ec76429d3c2c4cbbd31dad0a2b3df420434dc9190876b"
TestOperator12DepositSignature13Operators = "aa993018ef01387af96284ddcf382059bae0ed9deb4b75af989882125a9702fac93748c83c97d925729548ea8a9e4bdd18ec769c18c59ce9148f957b0973e83e7ef6b7e359a5b890eca4a4e221eed59caeecaeeb579b3a38b89260490aa57ea7"
TestOperator13DepositSignature13Operators = "8ceebe524ad811036ede70d1f2f8e702eebd2b388ed602e64fd8103970c824653c2eaca50532afffeb4fc82fe0765c2f101aa93015db6118a06e5c78f9cc97cf658f016dc2f4ace2c466d5c179c3e133c50ddd78d942036e3711bcefb87ca37a"
TestOperator1DepositSignature13Operators = "93008a42657570c6df799938302cd04ff184d65d8e685b7d024b7e385094fc2e5ad235751423ba33933b3be61294b5cf080ed6e92bbf497e8c8783166093c134925a4b4384112c0bdbc39ba1f62a69e907aed3214766a4936ce559b68b2bbc54"
TestOperator2DepositSignature13Operators = "83c0732c5601848560394bfb55665a16eda01a0fb85b96b214e9b072db6072994453233e73ddc2ab9443eb1ad322fc170c89b22fb46ecd8872c44f791801bda112b1e15051ff3a1bfb0add7ab10a9bba49070cc2f688a93d8507352a410193da"
TestOperator3DepositSignature13Operators = "a4acfc798958d82a2cd3a0d9bc3c14b5b3b5bb67acaf090c6865e505b6be597b8a61553c1dd05d5747e77bd7382029d200d82c913167b58afd1ade238301ce773320800278e32e4b98845147d4dbc5cc8ef07d45880df30430eafb95c9a2ed62"
TestOperator4DepositSignature13Operators = "b56c4ad53d1934c11fb5e7a2b830f682a2b8ad4842bff79f7e86cb2dd28a0c88618d036d05ae5a83183b0e03632fdb210cddef7d9613a1c962b08e69ddb29d12eb2554a52d92557d82427ffd85b59b8d4ca3b4e662bfd555a30fab09da3bee1d"
TestOperator5DepositSignature13Operators = "b46fbe279129716f4036262da9e70d295d72f72f0140e9bb0e144d3e1e481233f5599660655f1ad8cfcacea768e2797818e14f949f963e5714b1c404de4f57fbd2fd47efdc0888ea8627c9b720079905fe01b7ed2214291344479c80664bb589"
TestOperator6DepositSignature13Operators = "b48cd8295db839c02b710b2eba7f4a00a8404eeb90cac5c2c434575c37dbd936545dab8e4e65391e77464c6636bbefdc062731348d50852a3fd4a93930d9668a4f6e6e0b564c5a168a3789594dbe43c7c4fca7225388d8a43abf27a8c0dc1d51"
TestOperator7DepositSignature13Operators = "a55f1003714349e4b57289c7f5393d9e93397402256147eb11eeb671f99c5ec86dd1b169b09f0fec0c0b140a272c09c4197cad67bc8d9939278741223749c3c2f71a9e74149e75fc790855a017c4d249fac63e397ffa3dfbfe0b3be56badeb81"
TestOperator8DepositSignature13Operators = "987db1a4d9bbd18b106937c993b225d78efbbef661deac2866b2e8336d441c9def1740bbf42966835b1f5063b8bac044182b4ed325d8ee9fb4748969eaef5cd35bd30ba52fa865dd1587096ad725aa3c60bca4e5e039e5185b965161e867a79d"
TestOperator9DepositSignature13Operators = "b9d125d3c1e0cfd1df7afa601a4b85f61e4533e5719c2384714a86825d56ba965ffdbe7b6ec39432823359e5b28b7ff50e8802c9d48204c548c9934f17144a5f352d6e32dbd25ed15dcb786d674ae87a7083705a856bf56e5f732537eac93c75"
TestOperator10DepositSignature13Operators = "a5a921ceca8f3914bfee04ac4c76997b4b1a9c74907d8ad0e12227493e1cb7e75b51a9ef899b08d1be3f70cee01260fa026bac9f7f933344d9081445d04f9137d34e051d3146c8756cad8e02e83a4966d17c5521d09b8c0c8fa8870b44b8bc9f"
TestOperator11DepositSignature13Operators = "b29ca4a765cbc85b3b5598169f9ddd376300691513c9ed66d763761807784d445bb7753d180c33e2d9c9122769831fff0a02e98bef677466d6dc916a7cdf38c1a1d29689784dce9013f8b8f31ac2968a3d24590bfeaf8ba50a85b7d7b5dbd508"
TestOperator12DepositSignature13Operators = "a59f2df2fe0b1978318ca50c58bb2f9da79989959ce95d6291232fb24d5c450f56d731cfe26e6bf022dfe7525d2e644811e204a609f9635432b0652afd68edad934308011a00071200967e75eb2bf7aa07235362593811c3a2d38dfb76df52f6"
TestOperator13DepositSignature13Operators = "ad6a77d0ec16af6a7032387e01556026ba30019de3f09e046e0ea248612c09f26b0a477116230b0acc84412369a684a6166acabcd36fb0917e4474439e368a6d36d39e30175806c27be275a544000e10f29f82f0e8f09bc6465c37ee78ae1457"

TestOperator1NonceSignature13Operators = "aa48c674fb0f121b677e390d80b36428080bb1e0c183fb61682a2571b17365773e7f9b4d48c598c8eda57e7f6690c8a5199b49190d04f2191c0cdc5ad3f581cacbb130ed6efeb0e997d9dca3b8317a0beca2925d06fde7c2ef1d00ea12f84427"
TestOperator2NonceSignature13Operators = "b1d293f24303fb9c1b57c9c6d82ecb4790d64205c0b000c3b6ecaa624b98f4e4b80a5d8d7560e40e44e060b4ee4a81b70e7fab9413311fe5c58d360d6ce7a3d7fc0c974e5691bb619f02c4b6743f75140b6af2200a42816c222c8d1c43db0dea"
TestOperator3NonceSignature13Operators = "80ca642509e1801ff410927d2df6d7363bfc9b4e9334afa379d4e9d6a3586825ae430da008c8013460ab4c1f2efea39d02d95206451bd556c53f5631748fb142e9fcc41ee9a6e7412d0ef3425f5a136f1b4f4606207f5119da22697365862c48"
TestOperator4NonceSignature13Operators = "8455e0c746bbdebef217ea17e0f7bb29ce1be138299809af856399dc51edcd52cb34cf2cdad5220a9b9c97dcd44878a01610ce1792e186503c759bf4d5ea0a495a3def3bd2cb40184c8cb13bf4f635522fe68758abe62c638eed53ba996ec9a7"
TestOperator5NonceSignature13Operators = "87a6c22b7c14c6a4189a3b42ce13efeddee6da3d67e3f5e0bf6521e22732d2302b39dbe1034770526649e9835137389402d2c6e98fd9de4cea28da53acef310a03e30392a652c2ef99089dcc8a4a1939c89770cf05ef90ca6c85a42ff796d574"
TestOperator6NonceSignature13Operators = "a14ee009b225020af32088482a46933fb0fe8584035ea8b4aea0e6444c80baf6464d0eee706a7df7ac77fe633af565610d160583adf365a3737ad3db7c6a29c89ae36492a2c5eadc7c6e0b341aef3d47f6126e9c79fdd940233dd9965e709a64"
TestOperator7NonceSignature13Operators = "a138967371c9dac845fcc76bae47029a68cd2b95f01aba6a5d5c2ab0c9258e90308b664242fb926e788f73415dd8b6a40173d039accc5c0a3380dfb246db19fb129575dcfb2e1044c7563fb52d793d6ed443dbb879ad277b56f9eab9a8fafa85"
TestOperator8NonceSignature13Operators = "8ccc0e6be899ca12af4f232d5e3f9734e5fb2a40711cb6d6829940f7a93b83055a36008aa492a37bef5a2ad379df00c60c42cce58b4933beba9e955c26b3bbc69960f1e4b1d3eee3eff872515ed942ca104ca9c31d4fea8e4545edc56e807c3b"
TestOperator9NonceSignature13Operators = "ada4fa4b904f30a6026b1072b2baf52f77a83a172e6ae11f52e3bc3fea850eccda48378a90c952258db4dd2b06a1e81109f2b9b1db0aa7551b6c2e415dc6792d58c77d94d3ae8d643bf74555259fc70de65721b2a32333d3dd1a84c2c783f0d7"
TestOperator10NonceSignature13Operators = "ab5ae505bdb740205feadbc0eb43ca69d0df7a33ffbbde4d0452d130a55d3a2860175350539ae685f731e7e00fd5adf60039da9856b6c874e492dceb4fa1d218780f5eb2ee1009d7011358b11de0982bc151f09a6ad39310eb36751250f493e2"
TestOperator11NonceSignature13Operators = "91c324d1572d5a8b053a52715ba15687975d75290d08da4d654bd828b6be41366654f4e16e1950c33bcc0dc32f2b80c4105b9be14d676229aee134739cc15fde45d2678e9678deffcdb832d723dade57fc33668cce6c5dfdda5a744c7057cd8d"
TestOperator12NonceSignature13Operators = "afb51afa0673a5d513b5e29a99a91d5fa91fc6368975c79f5625c842a38f5838936a948283e2985d6e88c03ed47557890f9e7d622eb5bef57280a685823996dc4432cc36c9dcb8455627b048cc3530cf61e73f150ae3ad47116a4a3ca37c95d9"
TestOperator13NonceSignature13Operators = "97e8ca9ac34b3841878df6774cb700ac2218fe8733409809909d2b022fb790ac89ee1a7faf235b93e69b06c93a97a83d09db2ee44b43048cabe5d37c4dbd90e602544e1620672eaf625623f0ff7c00cca324d6f086ec0cb66b301f8145bb02b1"
TestOperator1NonceSignature13Operators = "a1915dd571f836318d2c443d33cbde0d3ae355b877d5f6724fe0737f8d7224e8b210863bbfa758f01f8031d882d2d13e16cb1635900575b93132224c37b8f60db77ebd0166e3a3d798814ed6943877a8d66eba34696744be419b6a771076e77d"
TestOperator2NonceSignature13Operators = "a9af7a1ec523681da03a7bd6e6b66affb0931a873fa8d795da749e74e9365f0d276bb0369218aff7d2e56e3879a285b300b81bfc7583e773d160cf710f1a59b89d4ad213ab043aea8bab4e81f866c35958445bba4bc715a6ac3976cf4c9fe236"
TestOperator3NonceSignature13Operators = "840a5c722ff6b59d624b28aba6969f4556250422b81e97b1362273488e5a33964a4b39670fd0e1723fbd89f4cbea2cac0799e0e4331fbaf3f8d56a5c06cd8f3883e75910dd1e6a69980d75481bbe049fd4435d19c0f67491026f561ca3cbc713"
TestOperator4NonceSignature13Operators = "a4786f3d27aac24e9513a2daf95055164e0671c97bd97fd7b10f89a9af8cb3437634c6437e68745a55220fcf03695a2c0bdb648503b8561d3d2357a27cd1af5f058e427a433de25c54740b55c76f30bf7e61f4cd2d65eaeebb4221ee87b6ffb3"
TestOperator5NonceSignature13Operators = "99acaf28e6bdb23075c8e6a25f6d7b60e4f2ea88621af3e1f492c94ae1e06c429b6c61044465c99a37879238ebb6b55a06bfd2555a0320ad597c5877c15ff6e8312da474749b2bc9ec4ac22420b491876b2142247892d7aa8eba5ad795c5b4b0"
TestOperator6NonceSignature13Operators = "aaf445010a16e245e0d1476d9dee209c63e796eb0285e2952b17b528a1f1b730aa1c8894ac3314d19de4464df0152e1f07e76333564df543f015f193be4a382542f58c37d15bfb01dfbced22eac7529abe6a943a02785412d0b6bf7265ea1f13"
TestOperator7NonceSignature13Operators = "8cc508f3f10b54a1d68e16b42925bf285dd7713dac67475dccfd881058cadf305026997a405c7f0a1bd8af41fc4280281447f3d653571d2230dae73fd14d9d31282f0fe3fc249bd31a4118db0802c0e09f38a8b4fb4b142abe6fca5bc4cc02b4"
TestOperator8NonceSignature13Operators = "92e6210d1e16af4459b73863d793ec358e89a06ebf4e2cd767d29eb1f02b7ce1e16df8b968884d2c111e2a8efaae6fcc0b0f79d220a7acaf7f11ac3183135e71f0d3186d5275f2d2172223617353c9f15e5f625d129e0080776431e630ee2274"
TestOperator9NonceSignature13Operators = "b63640e861d17e9333f4ddd2b86dfb05db560694a7dd4daa8b908430d4c3ff66696d4b1438eede7983e2e563aeb287d9122ce09e6c79c7b27d26b73992d7d49a8c019977b399fcf0c3a3e164f092de5872d6a6dc536009cbea6916107ae8d247"
TestOperator10NonceSignature13Operators = "a5e65b63d605c4e837a8a916b581712347dc547384b8cb6f57917b66b3cc5daf1b0cb10b67d34a292e839a8e109c880c1349e9920c7cf65e594135422d8223583f0d24f379d0bb8e0fc14ba05ea1d2dc108e3226d35dd91f620fb61fca893cc5"
TestOperator11NonceSignature13Operators = "b89db7e2ab93e7793e462d511620c578e9c98bed8ff77a0c845e63c78d9807967b3adc1091f9784092580d66aa69123c161c0893e53f2566b61997c2f9d9cc1e3a20f95aebf6a1244584a38ce52508bc465c0d3157d2e07330fadded18faeca2"
TestOperator12NonceSignature13Operators = "ace0f712eab924c33c93def4c778b4ec6d43c724954336dda41395d0775b797d05f51414d876b63c6f8a72ae4ea401af12da3803158dc62f0140f919ef7ae505dc5268dd92ff7c49326d72277930014ae9ad41351eaf07244ec877d7d9cf6f62"
TestOperator13NonceSignature13Operators = "862822ad3c7bb4c46de20d8130aa3d5d6b88d74c1128c7965e7dfbe87742d8a67242afeaceb3357131c435b9174f88b513d65076425bc20f5ba1e152c02b996b7824ddb1190b648707adb2a1088a9de366e018484c642dc03486af9fda5c682b"
)
Loading

0 comments on commit 26903da

Please sign in to comment.