-
Notifications
You must be signed in to change notification settings - Fork 83
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: revert changes to TSS struct #149
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,13 +38,31 @@ type PubShare struct { | |
// TSS (threshold signing scheme) wraps PubKey (PublicKey), Verifiers (the public shares corresponding to each secret share) | ||
// and threshold (number of shares). | ||
type TSS struct { | ||
Verifier *share.FeldmanVerifier | ||
NumShares int | ||
verifier *share.FeldmanVerifier | ||
numShares int | ||
|
||
// PublicKey and Threshold are inferred from verifier commitments in NewTSS. | ||
// publicKey inferred from verifier commitments in NewTSS. | ||
publicKey *bls_sig.PublicKey | ||
} | ||
|
||
// Verifier returns the feldman verifier containing the public shares of the threshold signature scheme. | ||
func (t TSS) Verifier() *share.FeldmanVerifier { | ||
return t.verifier | ||
} | ||
|
||
// NumShares returns the number of shares in the threshold signature scheme. | ||
func (t TSS) NumShares() int { | ||
return t.numShares | ||
} | ||
|
||
// PublicKey returns the threshold signature scheme's root public key. | ||
func (t TSS) PublicKey() *bls_sig.PublicKey { | ||
return t.publicKey | ||
} | ||
|
||
PublicKey *bls_sig.PublicKey | ||
Threshold int | ||
// Threshold returns the minimum number of partial signatures required to aggregate the threshold signature. | ||
func (t TSS) Threshold() int { | ||
return len(t.verifier.Commitments) | ||
} | ||
|
||
func NewTSS(verifier *share.FeldmanVerifier, numShares int) (TSS, error) { | ||
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. I think it is good to still calculate the public key on construction:
|
||
|
@@ -55,10 +73,9 @@ func NewTSS(verifier *share.FeldmanVerifier, numShares int) (TSS, error) { | |
} | ||
|
||
return TSS{ | ||
Verifier: verifier, | ||
PublicKey: pk, | ||
NumShares: numShares, | ||
Threshold: len(verifier.Commitments), | ||
verifier: verifier, | ||
publicKey: pk, | ||
numShares: numShares, | ||
}, nil | ||
} | ||
|
||
|
@@ -88,7 +105,7 @@ func GenerateTSS(t, n int, reader io.Reader) (TSS, []*bls_sig.SecretKeyShare, er | |
// AggregateSignatures aggregates partial signatures over the given message. | ||
// Returns aggregated signatures and slice of signers identifiers that had valid partial signatures. | ||
func AggregateSignatures(tss TSS, partialSigs []*bls_sig.PartialSignature, msg []byte) (*bls_sig.Signature, []byte, error) { | ||
if len(partialSigs) < tss.Threshold { | ||
if len(partialSigs) < tss.Threshold() { | ||
return nil, nil, errors.New("insufficient signatures") | ||
} | ||
|
||
|
@@ -99,7 +116,7 @@ func AggregateSignatures(tss TSS, partialSigs []*bls_sig.PartialSignature, msg [ | |
|
||
for _, psig := range partialSigs { | ||
// TODO(dhruv): add break condition if valid shares >= threshold | ||
pubShare, err := getPubShare(uint32(psig.Identifier), tss.Verifier) | ||
pubShare, err := getPubShare(uint32(psig.Identifier), tss.Verifier()) | ||
if err != nil { | ||
return nil, nil, errors.Wrap(err, "get Public Share") | ||
} | ||
|
@@ -113,7 +130,7 @@ func AggregateSignatures(tss TSS, partialSigs []*bls_sig.PartialSignature, msg [ | |
signers = append(signers, psig.Identifier) | ||
} | ||
|
||
if len(validShares) < tss.Threshold { | ||
if len(validShares) < tss.Threshold() { | ||
return nil, nil, errors.New("insufficient valid signatures") | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
refactoring to private fields, with getter methods. To make it explicit that you should use
NewTSS
for constructing.