Skip to content
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

refactor: Improve codebase #490

Merged
merged 1 commit into from
Aug 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion share/dkg/pedersen/dkg.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,10 @@ func (d *DistKeyGenerator) ProcessDeal(dd *Deal) (*Response, error) {
return nil, err
}

ver, _ := d.verifiers[dd.Index]
ver, ok := d.verifiers[dd.Index]
if !ok {
return nil, fmt.Errorf("missing verifiers")
}

resp, err := ver.ProcessEncryptedDeal(dd.Deal)
if err != nil {
Expand Down
11 changes: 4 additions & 7 deletions share/dkg/pedersen/dkg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ func TestDKGProcessResponse(t *testing.T) {
require.Nil(t, err)

resp12, err := rec.ProcessDeal(deals2[idxRec])
require.NoError(t, err)
require.NotNil(t, resp)
require.Equal(t, vss.StatusComplaint, resp12.Response.Status)
require.Equal(t, deals2[idxRec].Index, uint32(dkg2.nidx))
Expand Down Expand Up @@ -797,7 +798,7 @@ func TestDKGResharingNewNodesThreshold(t *testing.T) {
require.Equal(t, newDkgs[i].nidx, i)
}

//alive := oldT - 1
// alive := oldT - 1
alive := oldT
oldSelected := make([]*DistKeyGenerator, 0, alive)
selected := make(map[string]bool)
Expand Down Expand Up @@ -1130,12 +1131,8 @@ func TestDKGResharingPartialNewNodes(t *testing.T) {

newPrivs := make([]kyber.Scalar, 0, newN)
newPubs := make([]kyber.Point, 0, newN)
for _, priv := range oldPrivs[1:] {
newPrivs = append(newPrivs, priv)
}
for _, pub := range oldPubs[1:] {
newPubs = append(newPubs, pub)
}
newPrivs = append(newPrivs, oldPrivs[1:]...)
newPubs = append(newPubs, oldPubs[1:]...)
// add two new nodes
priv1, pub1 := genPair()
priv2, pub2 := genPair()
Expand Down
2 changes: 1 addition & 1 deletion share/dkg/rabin/dkg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@ func genPair() (kyber.Scalar, kyber.Point) {

func randomBytes(n int) []byte {
var buff = make([]byte, n)
_, _ = rand.Read(buff[:])
_, _ = rand.Read(buff)
return buff
}
func checkDks(dks1, dks2 *DistKeyShare) bool {
Expand Down
2 changes: 1 addition & 1 deletion share/vss/pedersen/vss.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ func (v *Verifier) ProcessEncryptedDeal(e *EncryptedDeal) (*Response, error) {
r.Status = StatusComplaint
}

if err == errDealAlreadyProcessed {
if errors.Is(err, errDealAlreadyProcessed) {
return nil, err
}

Expand Down
1 change: 1 addition & 0 deletions share/vss/pedersen/vss_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,7 @@ func TestVSSAggregatorVerifyResponse(t *testing.T) {
// wrong index
resp.Index = uint32(len(verifiersPub))
sig, err := schnorr.Sign(suite, v.longterm, resp.Hash(suite))
assert.NoError(t, err)
resp.Signature = sig
assert.Error(t, aggr.verifyResponse(resp))
resp.Index = 0
Expand Down
36 changes: 19 additions & 17 deletions share/vss/rabin/vss.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,26 @@
// verifier can check the validity of the received share. The protocol has the
// following steps:
//
// 1) The dealer send a Deal to every verifiers using `Deals()`. Each deal must
// be sent securely to one verifier whose public key is at the same index than
// the index of the Deal.
// 1. The dealer send a Deal to every verifiers using `Deals()`. Each deal must
// be sent securely to one verifier whose public key is at the same index than
// the index of the Deal.
//
// 2) Each verifier processes the Deal with `ProcessDeal`.
// This function returns a Response which can be twofold:
// - an approval, to confirm a correct deal
// - a complaint to announce an incorrect deal notifying others that the
// 2. Each verifier processes the Deal with `ProcessDeal`.
// This function returns a Response which can be twofold:
// - an approval, to confirm a correct deal
// - a complaint to announce an incorrect deal notifying others that the
// dealer might be malicious.
// All Responses must be broadcasted to every verifiers and the dealer.
// 3) The dealer can respond to each complaint by a justification revealing the
// share he originally sent out to the accusing verifier. This is done by
// calling `ProcessResponse` on the `Dealer`.
// 4) The verifiers refuse the shared secret and abort the protocol if there
// are at least t complaints OR if a Justification is wrong. The verifiers
// accept the shared secret if there are at least t approvals at which point
// any t out of n verifiers can reveal their shares to reconstruct the shared
// secret.
// All Responses must be broadcasted to every verifiers and the dealer.
//
// 3. The dealer can respond to each complaint by a justification revealing the
// share he originally sent out to the accusing verifier. This is done by
// calling `ProcessResponse` on the `Dealer`.
//
// 4. The verifiers refuse the shared secret and abort the protocol if there
// are at least t complaints OR if a Justification is wrong. The verifiers
// accept the shared secret if there are at least t approvals at which point
// any t out of n verifiers can reveal their shares to reconstruct the shared
// secret.
package vss

import (
Expand Down Expand Up @@ -400,7 +402,7 @@ func (v *Verifier) ProcessEncryptedDeal(e *EncryptedDeal) (*Response, error) {
r.Approved = false
}

if err == errDealAlreadyProcessed {
if errors.Is(err, errDealAlreadyProcessed) {
return nil, err
}

Expand Down
2 changes: 2 additions & 0 deletions share/vss/rabin/vss_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ func TestVSSAggregatorVerifyJustification(t *testing.T) {
d.SecShare.V = goodV

j, err := dealer.ProcessResponse(resp)
assert.NoError(t, err)

// invalid deal justified
goodV = j.Deal.SecShare.V
Expand Down Expand Up @@ -388,6 +389,7 @@ func TestVSSAggregatorVerifyResponse(t *testing.T) {
// wrong index
resp.Index = uint32(len(verifiersPub))
sig, err := schnorr.Sign(suite, v.longterm, resp.Hash(suite))
assert.NoError(t, err)
resp.Signature = sig
assert.Error(t, aggr.verifyResponse(resp))
resp.Index = 0
Expand Down