Skip to content

Commit eea6c25

Browse files
committed
Fix most lint issues share
1 parent 434c405 commit eea6c25

File tree

7 files changed

+136
-101
lines changed

7 files changed

+136
-101
lines changed

share/dkg/pedersen/dkg.go

+6-10
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,7 @@ func NewDistKeyHandler(c *Config) (*DistKeyGenerator, error) {
139139
return nil, errors.New("dkg: can't run with empty node list")
140140
}
141141

142-
var isResharing bool
143-
if c.Share != nil || c.PublicCoeffs != nil {
144-
isResharing = true
145-
}
142+
isResharing := c.Share != nil || c.PublicCoeffs != nil
146143
if isResharing {
147144
if len(c.OldNodes) == 0 {
148145
return nil, errors.New("dkg: resharing config needs old nodes list")
@@ -153,7 +150,7 @@ func NewDistKeyHandler(c *Config) (*DistKeyGenerator, error) {
153150
}
154151
// canReceive is true by default since in the default DKG mode everyone
155152
// participates
156-
var canReceive = true
153+
var canReceive, canIssue = true, false
157154
pub := c.Suite.Point().Mul(c.Longterm, nil)
158155
oidx, oldPresent := findPub(c.OldNodes, pub)
159156
nidx, newPresent := findPub(c.NewNodes, pub)
@@ -170,7 +167,6 @@ func NewDistKeyHandler(c *Config) (*DistKeyGenerator, error) {
170167

171168
var dealer *vss.Dealer
172169
var err error
173-
var canIssue bool
174170
if c.Share != nil {
175171
// resharing case
176172
secretCoeff := c.Share.Share.V
@@ -306,7 +302,7 @@ func (d *DistKeyGenerator) Deals() (map[int]*Deal, error) {
306302
d.processed = true
307303
if resp, err := d.ProcessDeal(distd); err != nil {
308304
panic("dkg: cannot process own deal: " + err.Error())
309-
} else if resp.Response.Status != vss.StatusApproval {
305+
} else if resp.Response.StatusApproved != vss.StatusApproval {
310306
panic("dkg: own deal gave a complaint")
311307
}
312308
continue
@@ -365,7 +361,7 @@ func (d *DistKeyGenerator) ProcessDeal(dd *Deal) (*Response, error) {
365361
// indicate to VSS that this dkg's new status is complaint for this
366362
// deal
367363
d.verifiers[uint32(dd.Index)].UnsafeSetResponseDKG(uint32(d.nidx), vss.StatusComplaint)
368-
resp.Status = vss.StatusComplaint
364+
resp.StatusApproved = vss.StatusComplaint
369365
s, err := schnorr.Sign(d.suite, d.long, resp.Hash(d.suite))
370366
if err != nil {
371367
return nil, err
@@ -463,7 +459,7 @@ func (d *DistKeyGenerator) processResharingResponse(resp *Response) (*Justificat
463459
return nil, err
464460
}
465461

466-
if resp.Response.Status == vss.StatusApproval {
462+
if resp.Response.StatusApproved == vss.StatusApproval {
467463
//nolint:nilnil // status approved, no justification needed
468464
return nil, nil
469465
}
@@ -575,7 +571,7 @@ func (d *DistKeyGenerator) QualifiedShares() []int {
575571
}
576572
for holderIndex := range d.c.NewNodes {
577573
resp, ok := responses[uint32(holderIndex)]
578-
if ok && resp.Status == vss.StatusComplaint {
574+
if ok && resp.StatusApproved == vss.StatusComplaint {
579575
// 1. rule
580576
invalidDeals[int(dealerIndex)] = true
581577
break

share/dkg/pedersen/dkg_test.go

+12-12
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ func TestDKGProcessDeal(t *testing.T) {
108108
// good deal
109109
resp, err = rec.ProcessDeal(deal)
110110
require.NotNil(t, resp)
111-
require.Equal(t, vss.StatusApproval, resp.Response.Status)
111+
require.Equal(t, vss.StatusApproval, resp.Response.StatusApproved)
112112
require.Nil(t, err)
113113
_, ok := rec.verifiers[deal.Index]
114114
require.True(t, ok)
@@ -158,7 +158,7 @@ func TestDKGProcessResponse(t *testing.T) {
158158
resp, err := rec.ProcessDeal(encD)
159159
require.Nil(t, err)
160160
require.NotNil(t, resp)
161-
require.Equal(t, vss.StatusComplaint, resp.Response.Status)
161+
require.Equal(t, vss.StatusComplaint, resp.Response.StatusApproved)
162162
deal.SecShare.V = goodSecret
163163

164164
// no verifier tied to Response
@@ -201,10 +201,10 @@ func TestDKGProcessResponse(t *testing.T) {
201201
resp12, err := rec.ProcessDeal(deals2[idxRec])
202202
require.NoError(t, err)
203203
require.NotNil(t, resp)
204-
require.Equal(t, vss.StatusComplaint, resp12.Response.Status)
204+
require.Equal(t, vss.StatusComplaint, resp12.Response.StatusApproved)
205205
require.Equal(t, deals2[idxRec].Index, uint32(dkg2.nidx))
206206
require.Equal(t, resp12.Index, uint32(dkg2.nidx))
207-
require.Equal(t, vss.StatusComplaint, rec.verifiers[uint32(dkg2.oidx)].Responses()[uint32(rec.nidx)].Status)
207+
require.Equal(t, vss.StatusComplaint, rec.verifiers[uint32(dkg2.oidx)].Responses()[uint32(rec.nidx)].StatusApproved)
208208

209209
deal21.SecShare.V = goodRnd21
210210
deals2, err = dkg2.Deals()
@@ -229,7 +229,7 @@ func TestDKGProcessResponse(t *testing.T) {
229229

230230
// hack because all is local, and resp has been modified locally by dkg2's
231231
// dealer, the status has became "justified"
232-
resp12.Response.Status = vss.StatusComplaint
232+
resp12.Response.StatusApproved = vss.StatusComplaint
233233
err = dkg.ProcessJustification(j)
234234
require.Nil(t, err)
235235

@@ -326,7 +326,7 @@ func TestDKGResharingThreshold(t *testing.T) {
326326
if dkg.newPresent && dkg.nidx == j {
327327
resp, err := dkg.ProcessDeal(d)
328328
require.Nil(t, err)
329-
require.Equal(t, vss.StatusApproval, resp.Response.Status)
329+
require.Equal(t, vss.StatusApproval, resp.Response.StatusApproved)
330330
resps[i] = append(resps[i], resp)
331331
}
332332
}
@@ -447,7 +447,7 @@ func TestDKGThreshold(t *testing.T) {
447447
}
448448
resp, err := recipient.ProcessDeal(d)
449449
require.Nil(t, err)
450-
require.Equal(t, vss.StatusApproval, resp.Response.Status)
450+
require.Equal(t, vss.StatusApproval, resp.Response.StatusApproved)
451451
resps = append(resps, resp)
452452
}
453453
}
@@ -478,7 +478,7 @@ func TestDKGThreshold(t *testing.T) {
478478
for i, v := range dkg.verifiers {
479479
var app int
480480
for _, r := range v.Responses() {
481-
if r.Status == vss.StatusApproval {
481+
if r.StatusApproved == vss.StatusApproval {
482482
app++
483483
}
484484
}
@@ -585,7 +585,7 @@ func fullExchange(t *testing.T, dkgs []*DistKeyGenerator, checkQUAL bool) {
585585
for i, d := range deals {
586586
resp, err := dkgs[i].ProcessDeal(d)
587587
require.Nil(t, err)
588-
require.Equal(t, vss.StatusApproval, resp.Response.Status)
588+
require.Equal(t, vss.StatusApproval, resp.Response.StatusApproved)
589589
resps = append(resps, resp)
590590
}
591591
}
@@ -824,7 +824,7 @@ func TestDKGResharingNewNodesThreshold(t *testing.T) {
824824
dkg := newDkgs[j]
825825
resp, err := dkg.ProcessDeal(d)
826826
require.Nil(t, err)
827-
require.Equal(t, vss.StatusApproval, resp.Response.Status)
827+
require.Equal(t, vss.StatusApproval, resp.Response.StatusApproved)
828828
resps[i] = append(resps[i], resp)
829829
}
830830
}
@@ -1030,7 +1030,7 @@ func TestDKGResharingNewNodes(t *testing.T) {
10301030
dkg := newDkgs[dest]
10311031
resp, err := dkg.ProcessDeal(d)
10321032
require.NoError(t, err)
1033-
require.Equal(t, vss.StatusApproval, resp.Response.Status)
1033+
require.Equal(t, vss.StatusApproval, resp.Response.StatusApproved)
10341034
resps[i] = append(resps[i], resp)
10351035
}
10361036
}
@@ -1217,7 +1217,7 @@ func TestDKGResharingPartialNewNodes(t *testing.T) {
12171217
dkg := newDkgs[j]
12181218
resp, err := dkg.ProcessDeal(d)
12191219
require.Nil(t, err)
1220-
require.Equal(t, vss.StatusApproval, resp.Response.Status)
1220+
require.Equal(t, vss.StatusApproval, resp.Response.StatusApproved)
12211221
resps[i] = append(resps[i], resp)
12221222
}
12231223
}

share/vss/pedersen/vss.go

+43-36
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ package vss
66

77
import (
88
"bytes"
9-
"crypto/cipher"
109
"encoding/binary"
1110
"errors"
1211
"fmt"
@@ -29,8 +28,7 @@ type Suite interface {
2928
// Dealer encapsulates for creating and distributing the shares and for
3029
// replying to any Responses.
3130
type Dealer struct {
32-
suite Suite
33-
reader cipher.Stream
31+
suite Suite
3432
// long is the longterm key of the Dealer
3533
long kyber.Scalar
3634
pub kyber.Point
@@ -83,7 +81,7 @@ type Response struct {
8381
// Index of the verifier issuing this Response from the new set of nodes
8482
Index uint32
8583
// false = NO APPROVAL == Complaint , true = APPROVAL
86-
Status bool
84+
StatusApproved bool
8785
// Signature over the whole packet
8886
Signature []byte
8987
}
@@ -115,7 +113,7 @@ type Justification struct {
115113
// does not have to be trusted by other Verifiers. The security parameter t is
116114
// the number of shares required to reconstruct the secret. MinimumT() provides
117115
// a middle ground between robustness and secrecy. Increasing t will increase
118-
// the secrecy at the cost of the decreased robustness and vice versa. It
116+
// the secrecy at the cost of the decreased robustness and vice versa. It
119117
// returns an error if the t is inferior or equal to 2.
120118
func NewDealer(suite Suite, longterm, secret kyber.Scalar, verifiers []kyber.Point, t int) (*Dealer, error) {
121119
d := &Dealer{
@@ -227,14 +225,15 @@ func (d *Dealer) EncryptedDeals() ([]*EncryptedDeal, error) {
227225
}
228226

229227
// ProcessResponse analyzes the given Response. If it's a valid complaint, then
230-
// it returns a Justification. This Justification must be broadcasted to every
231-
// participants. If it's an invalid complaint, it returns an error about the
228+
// it returns a Justification. This Justification must be broadcast to every
229+
// participant. If it's an invalid complaint, it returns an error about the
232230
// complaint. The verifiers will also ignore an invalid Complaint.
233231
func (d *Dealer) ProcessResponse(r *Response) (*Justification, error) {
234232
if err := d.verifyResponse(r); err != nil {
235233
return nil, err
236234
}
237-
if r.Status == StatusApproval {
235+
if r.StatusApproved {
236+
//nolint:nilnil // Expected behavior
238237
return nil, nil
239238
}
240239

@@ -370,12 +369,12 @@ func (v *Verifier) ProcessEncryptedDeal(e *EncryptedDeal) (*Response, error) {
370369
}
371370

372371
r := &Response{
373-
SessionID: sid,
374-
Index: uint32(v.index),
375-
Status: StatusApproval,
372+
SessionID: sid,
373+
Index: uint32(v.index),
374+
StatusApproved: StatusApproval,
376375
}
377376
if err = v.VerifyDeal(d, true); err != nil {
378-
r.Status = StatusComplaint
377+
r.StatusApproved = StatusComplaint
379378
}
380379

381380
if errors.Is(err, errDealAlreadyProcessed) {
@@ -503,11 +502,12 @@ func (v *Verifier) SetTimeout() {
503502
// that works on basis of approval only.
504503
func (v *Verifier) UnsafeSetResponseDKG(idx uint32, approval bool) {
505504
r := &Response{
506-
SessionID: v.Aggregator.sid,
507-
Index: uint32(idx),
508-
Status: approval,
505+
SessionID: v.Aggregator.sid,
506+
Index: uint32(idx),
507+
StatusApproved: approval,
509508
}
510509

510+
//nolint:errcheck // Unsafe function
511511
v.Aggregator.addResponse(r)
512512
}
513513

@@ -527,7 +527,14 @@ type Aggregator struct {
527527
timeout bool
528528
}
529529

530-
func newAggregator(suite Suite, dealer kyber.Point, verifiers, commitments []kyber.Point, t int, sid []byte) *Aggregator {
530+
func newAggregator(
531+
suite Suite,
532+
dealer kyber.Point,
533+
verifiers,
534+
commitments []kyber.Point,
535+
t int,
536+
sid []byte,
537+
) *Aggregator {
531538
agg := &Aggregator{
532539
suite: suite,
533540
dealer: dealer,
@@ -636,7 +643,7 @@ func (a *Aggregator) verifyJustification(j *Justification) error {
636643
if !ok {
637644
return errors.New("vss: no complaints received for this justification")
638645
}
639-
if r.Status != StatusComplaint {
646+
if r.StatusApproved {
640647
return errors.New("vss: justification received for an approval")
641648
}
642649

@@ -645,7 +652,7 @@ func (a *Aggregator) verifyJustification(j *Justification) error {
645652
a.badDealer = true
646653
return err
647654
}
648-
r.Status = StatusApproval
655+
r.StatusApproved = StatusApproval
649656
return nil
650657
}
651658

@@ -688,10 +695,10 @@ func (a *Aggregator) DealCertified() bool {
688695
for i := range a.verifiers {
689696
if r, ok := a.responses[uint32(i)]; !ok {
690697
absentVerifiers++
691-
} else if r.Status == StatusComplaint {
692-
isComplaint = true
693-
} else if r.Status == StatusApproval {
698+
} else if r.StatusApproved {
694699
approvals++
700+
} else {
701+
isComplaint = true
695702
}
696703
}
697704
enoughApprovals := approvals >= a.t
@@ -727,15 +734,6 @@ func validT(t int, verifiers []kyber.Point) bool {
727734
return t >= 2 && t <= len(verifiers) && int(uint32(t)) == t
728735
}
729736

730-
func deriveH(suite Suite, verifiers []kyber.Point) kyber.Point {
731-
var b bytes.Buffer
732-
for _, v := range verifiers {
733-
_, _ = v.MarshalTo(&b)
734-
}
735-
base := suite.Point().Pick(suite.XOF(b.Bytes()))
736-
return base
737-
}
738-
739737
func findPub(verifiers []kyber.Point, idx uint32) (kyber.Point, bool) {
740738
iidx := int(idx)
741739
if iidx >= len(verifiers) {
@@ -746,18 +744,27 @@ func findPub(verifiers []kyber.Point, idx uint32) (kyber.Point, bool) {
746744

747745
func sessionID(suite Suite, dealer kyber.Point, verifiers, commitments []kyber.Point, t int) ([]byte, error) {
748746
h := suite.Hash()
749-
_, _ = dealer.MarshalTo(h)
747+
_, err := dealer.MarshalTo(h)
748+
if err != nil {
749+
return nil, err
750+
}
750751

751752
for _, v := range verifiers {
752-
_, _ = v.MarshalTo(h)
753+
_, err = v.MarshalTo(h)
754+
if err != nil {
755+
return nil, err
756+
}
753757
}
754758

755759
for _, c := range commitments {
756-
_, _ = c.MarshalTo(h)
760+
_, err = c.MarshalTo(h)
761+
if err != nil {
762+
return nil, err
763+
}
757764
}
758-
_ = binary.Write(h, binary.LittleEndian, uint32(t))
759765

760-
return h.Sum(nil), nil
766+
err = binary.Write(h, binary.LittleEndian, uint32(t))
767+
return h.Sum(nil), err
761768
}
762769

763770
// Hash returns the Hash representation of the Response
@@ -766,7 +773,7 @@ func (r *Response) Hash(s Suite) []byte {
766773
_, _ = h.Write([]byte("response"))
767774
_, _ = h.Write(r.SessionID)
768775
_ = binary.Write(h, binary.LittleEndian, r.Index)
769-
_ = binary.Write(h, binary.LittleEndian, r.Status)
776+
_ = binary.Write(h, binary.LittleEndian, r.StatusApproved)
770777
return h.Sum(nil)
771778
}
772779

0 commit comments

Comments
 (0)