-
Notifications
You must be signed in to change notification settings - Fork 90
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
tbls: replace verifier with pubshares #604
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,20 +31,12 @@ | |
}, | ||
"distributed_validators": [ | ||
{ | ||
"distributed_public_key": "0x7b182e046410f44bc4b0f3f03a0d06820a30f257", | ||
"threshold_verifiers": [ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. shouldn't |
||
"NCyLgFXEZtiGRB0lmQbWms2JS5aK6fDrnZZc5qRpPE4=", | ||
"vogVAbfZhGtm6wK1flzae2y6aJHWFr1obDe4NGE6yLo=" | ||
] | ||
"distributed_public_key": "0x7b182e046410f44bc4b0f3f03a0d06820a30f257" | ||
}, | ||
{ | ||
"distributed_public_key": "0xa22c008ffe688352734ae4e3f1217acd5f832708", | ||
"threshold_verifiers": [ | ||
"eVeydxnOPzGI3+V97r9vgllaEPe7ViygTVw9J5QpWMY=", | ||
"2zJiZwZJ87yX2aIxZzXt5oKl3+bxoBH7yYrQ++eQADw=" | ||
] | ||
"distributed_public_key": "0x342c8b8055c466d886441d259906d69acd894b96" | ||
} | ||
], | ||
"signature_aggregate": "bbXBREw6NNMqXEp/++jRgfftO4z+kE+T+PBtKbzZ7YQ=", | ||
"lock_hash": "wcS2qPDhSo0jvYr6tM+7pk4H+nsglA/cf8+baqBnuK0=" | ||
"lock_hash": "c1GjLXPvkrYyXHyyATXvQ64yEjCcc/YmXl4PrK5MeDQ=" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -219,7 +219,7 @@ func makeShares( | |
targetID uint32, | ||
) ([]share, error) { | ||
// Get set of public shares for each validator. | ||
pubShares := make(map[uint32]map[uint32]*bls_sig.PublicKey) // map[ValIdx]map[SourceID]*bls_sig.PublicKey | ||
pubShares := make(map[uint32]map[int]*bls_sig.PublicKey) // map[ValIdx]map[SourceID]*bls_sig.PublicKey | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: why There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. while going through the code i didn't found any specific reason to use uint32 for dkg, that's why i went with fundamental types such as int can change if there was any specific reason behind the usage of uint32 for dkg purposes |
||
for key, result := range r2Result { | ||
if key.TargetID != targetID { | ||
// Not for us. | ||
|
@@ -232,10 +232,10 @@ func makeShares( | |
|
||
m, ok := pubShares[key.ValIdx] | ||
if !ok { | ||
m = make(map[uint32]*bls_sig.PublicKey) | ||
m = make(map[int]*bls_sig.PublicKey) | ||
pubShares[key.ValIdx] = m | ||
} | ||
m[key.SourceID] = pubShare | ||
m[int(key.SourceID)] = pubShare | ||
} | ||
|
||
// Sort shares by vIdx | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,8 +21,6 @@ import ( | |
"io" | ||
"sort" | ||
|
||
"github.com/coinbase/kryptology/pkg/core/curves" | ||
"github.com/coinbase/kryptology/pkg/sharing" | ||
"github.com/coinbase/kryptology/pkg/signatures/bls/bls_sig" | ||
|
||
"github.com/obolnetwork/charon/app/errors" | ||
|
@@ -46,16 +44,13 @@ type share struct { | |
PubKey *bls_sig.PublicKey | ||
SecretShare *bls_sig.SecretKeyShare | ||
|
||
// One of the two below will be populated, | ||
Verifier *sharing.FeldmanVerifier | ||
PublicShares map[uint32]*bls_sig.PublicKey // map[shareIdx]*bls_sig.PublicKey | ||
PublicShares map[int]*bls_sig.PublicKey // map[shareIdx]*bls_sig.PublicKey | ||
} | ||
|
||
// shareMsg is the share message wire format sent by the dealer. | ||
type shareMsg struct { | ||
PubKey []byte | ||
PubShares [][]byte | ||
Verifiers [][]byte | ||
SecretShare []byte | ||
} | ||
|
||
|
@@ -169,12 +164,7 @@ func leadKeyCast(ctx context.Context, tp kcTransport, def cluster.Definition, ra | |
func createShares(numValidators, numNodes, threshold int, random io.Reader) ([][]share, error) { | ||
resp := make([][]share, numNodes) | ||
for i := 0; i < numValidators; i++ { | ||
pubkey, secret, err := tbls.Keygen() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
shares, verifier, err := tbls.SplitSecret(secret, threshold, numNodes, random) | ||
tss, shares, err := tbls.GenerateTSS(threshold, numNodes, random) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
@@ -185,9 +175,9 @@ func createShares(numValidators, numNodes, threshold int, random io.Reader) ([][ | |
|
||
for ni := 0; ni < numNodes; ni++ { | ||
resp[ni] = append(resp[ni], share{ | ||
PubKey: pubkey, | ||
Verifier: verifier, | ||
SecretShare: shares[ni], | ||
PubKey: tss.PublicKey(), | ||
PublicShares: tss.PublicShares(), | ||
SecretShare: shares[ni], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: can we rename the loop variable |
||
}) | ||
} | ||
} | ||
|
@@ -202,13 +192,6 @@ func msgFromShare(s share) (shareMsg, error) { | |
return shareMsg{}, errors.Wrap(err, "marshal pubkey") | ||
} | ||
|
||
var verifiers [][]byte | ||
if s.Verifier != nil { | ||
for _, commitment := range s.Verifier.Commitments { | ||
verifiers = append(verifiers, commitment.ToAffineCompressed()) | ||
} | ||
} | ||
|
||
// Sort pub shares by id/index. | ||
var pubSharesIDs []int | ||
for id := range s.PublicShares { | ||
|
@@ -218,7 +201,7 @@ func msgFromShare(s share) (shareMsg, error) { | |
|
||
var pubShares [][]byte | ||
for _, id := range pubSharesIDs { | ||
b, err := s.PublicShares[uint32(id)].MarshalBinary() | ||
b, err := s.PublicShares[id].MarshalBinary() | ||
if err != nil { | ||
return shareMsg{}, errors.Wrap(err, "marshal public share") | ||
} | ||
|
@@ -232,7 +215,6 @@ func msgFromShare(s share) (shareMsg, error) { | |
|
||
return shareMsg{ | ||
PubKey: pubkey, | ||
Verifiers: verifiers, | ||
SecretShare: secretShare, | ||
PubShares: pubShares, | ||
}, nil | ||
|
@@ -245,24 +227,14 @@ func shareFromMsg(msg shareMsg) (share, error) { | |
return share{}, errors.Wrap(err, "unmarshal pubkey") | ||
} | ||
|
||
var commitments []curves.Point | ||
for _, v := range msg.Verifiers { | ||
c, err := curves.BLS12381G1().Point.FromAffineCompressed(v) | ||
if err != nil { | ||
return share{}, errors.Wrap(err, "verifier hex") | ||
} | ||
|
||
commitments = append(commitments, c) | ||
} | ||
|
||
pubShares := make(map[uint32]*bls_sig.PublicKey) | ||
pubShares := make(map[int]*bls_sig.PublicKey) | ||
for id, bytes := range msg.PubShares { | ||
pubShare := new(bls_sig.PublicKey) | ||
if err := pubShare.UnmarshalBinary(bytes); err != nil { | ||
return share{}, errors.Wrap(err, "unmarshal public share") | ||
} | ||
|
||
pubShares[uint32(id+1)] = pubShare // Public shares IDs are 1-indexed. | ||
pubShares[id+1] = pubShare // Public shares IDs are 1-indexed. | ||
} | ||
|
||
secretShare := new(bls_sig.SecretKeyShare) | ||
|
@@ -272,7 +244,6 @@ func shareFromMsg(msg shareMsg) (share, error) { | |
|
||
return share{ | ||
PubKey: pubKey, | ||
Verifier: &sharing.FeldmanVerifier{Commitments: commitments}, | ||
SecretShare: secretShare, | ||
PublicShares: pubShares, | ||
}, nil | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: can remove this comment