diff --git a/dkg/pedersen/dkg.go b/dkg/pedersen/dkg.go index fb18c68fc..e088ed325 100644 --- a/dkg/pedersen/dkg.go +++ b/dkg/pedersen/dkg.go @@ -106,7 +106,12 @@ func (s *instance) getState() *state { } // handleMessage implements dkgInstance. It handles the DKG messages. -func (s *instance) handleMessage(ctx context.Context, msg serde.Message, from mino.Address, out mino.Sender) error { +func (s *instance) handleMessage( + ctx context.Context, + msg serde.Message, + from mino.Address, + out mino.Sender, +) error { // We expect a Start message or a decrypt request at first, but we might // receive other messages in the meantime, like a Deal. switch msg := msg.(type) { @@ -194,8 +199,10 @@ func (s *instance) handleMessage(ctx context.Context, msg serde.Message, from mi // start is called when the node has received its start message. Note that we // might have already received some deals from other nodes in the meantime. The // function handles the DKG creation protocol. -func (s *instance) start(ctx context.Context, start types.Start, deals channel.Timed[types.Deal], - resps channel.Timed[types.Response], from mino.Address, out mino.Sender) error { +func (s *instance) start( + ctx context.Context, start types.Start, deals channel.Timed[types.Deal], + resps channel.Timed[types.Response], from mino.Address, out mino.Sender, +) error { err := s.startRes.switchState(sharing) if err != nil { @@ -227,8 +234,10 @@ func (s *instance) start(ctx context.Context, start types.Start, deals channel.T } // doDKG calls the subsequent DKG steps -func (s *instance) doDKG(ctx context.Context, deals channel.Timed[types.Deal], - resps channel.Timed[types.Response], out mino.Sender, from mino.Address) error { +func (s *instance) doDKG( + ctx context.Context, deals channel.Timed[types.Deal], + resps channel.Timed[types.Response], out mino.Sender, from mino.Address, +) error { defer func() { s.Lock() @@ -315,7 +324,11 @@ func (s *instance) deal(ctx context.Context, out mino.Sender) error { return nil } -func (s *instance) respond(ctx context.Context, deals channel.Timed[types.Deal], out mino.Sender) error { +func (s *instance) respond( + ctx context.Context, + deals channel.Timed[types.Deal], + out mino.Sender, +) error { numReceivedDeals := 0 participants := s.startRes.getParticipants() @@ -346,7 +359,11 @@ func (s *instance) respond(ctx context.Context, deals channel.Timed[types.Deal], // - Resharing with leaving or joining node: (n_common + (n_new - 1)) * n_old, // nodes that are doing a resharing will broadcast their own deals // - Resharing with staying node: (n_common + n_new) * n_old -func (s *instance) certify(ctx context.Context, resps channel.Timed[types.Response], expected int) error { +func (s *instance) certify( + ctx context.Context, + resps channel.Timed[types.Response], + expected int, +) error { responsesReceived := 0 @@ -414,8 +431,10 @@ func (s *instance) finalize(ctx context.Context, from mino.Address, out mino.Sen } // handleDeal process the Deal and send the responses to the other nodes. -func (s *instance) handleDeal(ctx context.Context, msg types.Deal, - out mino.Sender, to []mino.Address) error { +func (s *instance) handleDeal( + ctx context.Context, msg types.Deal, + out mino.Sender, to []mino.Address, +) error { deal := &pedersen.Deal{ Index: msg.GetIndex(), @@ -466,7 +485,12 @@ func (s *instance) handleDeal(ctx context.Context, msg types.Deal, return nil } -func (s *instance) finalizeReshare(ctx context.Context, nt nodeType, out mino.Sender, from mino.Address) error { +func (s *instance) finalizeReshare( + ctx context.Context, + nt nodeType, + out mino.Sender, + from mino.Address, +) error { // Send back the public DKG key publicKey := s.startRes.getDistKey() @@ -508,8 +532,14 @@ func (s *instance) finalizeReshare(ctx context.Context, nt nodeType, out mino.Se // reshare handles the resharing request. Acts differently for the new // and old and common nodes -func (s *instance) reshare(ctx context.Context, out mino.Sender, - from mino.Address, msg types.StartResharing, reshares channel.Timed[types.Reshare], resps channel.Timed[types.Response]) error { +func (s *instance) reshare( + ctx context.Context, + out mino.Sender, + from mino.Address, + msg types.StartResharing, + reshares channel.Timed[types.Reshare], + resps channel.Timed[types.Response], +) error { err := s.startRes.switchState(resharing) if err != nil { @@ -534,8 +564,14 @@ func (s *instance) reshare(ctx context.Context, out mino.Sender, // doReshare is called when the node has received its reshare message. Note that // we might have already received some deals from other nodes in the meantime. // The function handles the DKG resharing protocol. -func (s *instance) doReshare(ctx context.Context, start types.StartResharing, - from mino.Address, out mino.Sender, reshares channel.Timed[types.Reshare], resps channel.Timed[types.Response]) error { +func (s *instance) doReshare( + ctx context.Context, + start types.StartResharing, + from mino.Address, + out mino.Sender, + reshares channel.Timed[types.Reshare], + resps channel.Timed[types.Response], +) error { s.log.Info().Msgf("resharing with %v", start.GetAddrsNew()) @@ -668,8 +704,10 @@ func (s *instance) doReshare(ctx context.Context, start types.StartResharing, // sendDealsResharing is similar to sendDeals except that it creates // dealResharing which has more data than Deal. Only the old nodes call this // function. -func (s *instance) sendDealsResharing(ctx context.Context, out mino.Sender, - participants []mino.Address, publicCoeff []kyber.Point) error { +func (s *instance) sendDealsResharing( + ctx context.Context, out mino.Sender, + participants []mino.Address, publicCoeff []kyber.Point, +) error { s.log.Trace().Msgf("%v is generating its deals", s.me) @@ -692,7 +730,7 @@ func (s *instance) sendDealsResharing(ctx context.Context, out mino.Sender, ), ) - //dealResharing contains the public coefficients as well + // dealResharing contains the public coefficients as well dealResharingMsg := types.NewReshare(dealMsg, publicCoeff) s.log.Trace().Msgf("%s sent dealResharing %d", s.me, i) @@ -714,8 +752,10 @@ func (s *instance) sendDealsResharing(ctx context.Context, out mino.Sender, // receiveDealsResharing is similar to receiveDeals except that it receives the // dealResharing. Only the new or common nodes call this function -func (s *instance) receiveDealsResharing(ctx context.Context, nt nodeType, - resharingRequest types.StartResharing, out mino.Sender, reshares channel.Timed[types.Reshare]) error { +func (s *instance) receiveDealsResharing( + ctx context.Context, nt nodeType, + resharingRequest types.StartResharing, out mino.Sender, reshares channel.Timed[types.Reshare], +) error { s.log.Trace().Msgf("%v is handling deals from other nodes", s.me) @@ -780,11 +820,13 @@ func (s *instance) receiveDealsResharing(ctx context.Context, nt nodeType, return nil } -func (s *instance) handleDecrypt(out mino.Sender, msg types.DecryptRequest, - from mino.Address) error { +func (s *instance) handleDecrypt( + out mino.Sender, msg types.DecryptRequest, + from mino.Address, +) error { if !s.startRes.Done() { - return xerrors.Errorf("you must first initialize DKG. Did you call setup() first?") + return xerrors.Errorf(initDkgFirst + "1") } S := suite.Point().Mul(s.privShare.V, msg.K) @@ -801,11 +843,13 @@ func (s *instance) handleDecrypt(out mino.Sender, msg types.DecryptRequest, return nil } -func (s *instance) handleReencryptRequest(out mino.Sender, msg types.ReencryptRequest, - from mino.Address) error { +func (s *instance) handleReencryptRequest( + out mino.Sender, msg types.ReencryptRequest, + from mino.Address, +) error { if !s.startRes.Done() { - return xerrors.Errorf("you must first initialize DKG. Did you call setup() first?") + return xerrors.Errorf(initDkgFirst + "2") } ui := s.getUI(msg.K, msg.PubK) @@ -841,8 +885,10 @@ func (s *instance) getUI(K, pubk kyber.Point) *share.PubShare { } } -func (s *instance) handleVerifiableDecrypt(out mino.Sender, - msg types.VerifiableDecryptRequest, from mino.Address) error { +func (s *instance) handleVerifiableDecrypt( + out mino.Sender, + msg types.VerifiableDecryptRequest, from mino.Address, +) error { type job struct { index int // index where to put the response diff --git a/dkg/pedersen/pedersen.go b/dkg/pedersen/pedersen.go index 6b6e2a087..96ba2e03a 100644 --- a/dkg/pedersen/pedersen.go +++ b/dkg/pedersen/pedersen.go @@ -25,7 +25,7 @@ import ( ) // initDkgFirst message helping the developer to verify whether setup did occur -const initDkgFirst = "you must first initialize DKG. Did you call setup() first?" +const initDkgFirst = "you must first initialize the DKG. Did you call setup() first? #" // failedStreamCreation message indicating a stream creation failure const failedStreamCreation = "failed to create stream: %v" @@ -47,7 +47,7 @@ var ( // associated with the `dkg-decrypt` protocol. protocolNameDecrypt = "dkg-decrypt" // protocolNameReencrypt denotes the value of the protocol span tag - //// associated with the `dkg-reencrypt` protocol. + // // associated with the `dkg-reencrypt` protocol. protocolNameReencrypt = "dkg-reencrypt" // ProtocolNameResharing denotes the value of the protocol span tag // associated with the `dkg-resharing` protocol. @@ -214,7 +214,7 @@ func (a *Actor) GetPublicKey() (kyber.Point, error) { func (a *Actor) Encrypt(msg []byte) (kyber.Point, []kyber.Point, error) { if !a.startRes.Done() { - return nil, nil, xerrors.Errorf(initDkgFirst) + return nil, nil, xerrors.Errorf(initDkgFirst + "3") } pubK, err := a.GetPublicKey() @@ -258,7 +258,7 @@ func (a *Actor) Encrypt(msg []byte) (kyber.Point, []kyber.Point, error) { func (a *Actor) Decrypt(K kyber.Point, Cs []kyber.Point) ([]byte, error) { if !a.startRes.Done() { - return nil, xerrors.Errorf(initDkgFirst) + return nil, xerrors.Errorf(initDkgFirst + "4") } ctx, cancel := context.WithTimeout(context.Background(), decryptTimeout) @@ -332,12 +332,13 @@ func (a *Actor) Decrypt(K kyber.Point, Cs []kyber.Point) ([]byte, error) { // this person. // // See https://arxiv.org/pdf/2205.08529.pdf / section 5.4 Protocol / step 1 -func (a *Actor) VerifiableEncrypt(message []byte, GBar kyber.Point) (types.Ciphertext, - []byte, error) { +func (a *Actor) VerifiableEncrypt(message []byte, GBar kyber.Point) ( + types.Ciphertext, + []byte, error, +) { if !a.startRes.Done() { - return types.Ciphertext{}, nil, xerrors.Errorf("you must first initialize " + - "DKG. Did you call setup() first?") + return types.Ciphertext{}, nil, xerrors.Errorf(initDkgFirst + "5") } // Embed the message (or as much of it as will fit) into a curve point. @@ -391,7 +392,7 @@ func (a *Actor) VerifiableEncrypt(message []byte, GBar kyber.Point) (types.Ciphe func (a *Actor) VerifiableDecrypt(ciphertexts []types.Ciphertext) ([][]byte, error) { if !a.startRes.Done() { - return nil, xerrors.Errorf(initDkgFirst) + return nil, xerrors.Errorf(initDkgFirst + "6") } players := mino.NewAddresses(a.startRes.getParticipants()...) @@ -480,8 +481,10 @@ func (a *Actor) VerifiableDecrypt(ciphertexts []types.Ciphertext) ([][]byte, err return decryptedMessage, nil } -func newWorker(numParticipants int, decryptedMessage [][]byte, - responses []types.VerifiableDecryptReply, ciphertexts []types.Ciphertext) worker { +func newWorker( + numParticipants int, decryptedMessage [][]byte, + responses []types.VerifiableDecryptReply, ciphertexts []types.Ciphertext, +) worker { return worker{ numParticipants: numParticipants, @@ -535,7 +538,7 @@ func (w worker) work(jobIndex int) error { // participants. func (a *Actor) Reshare(coAuth crypto.CollectiveAuthority, thresholdNew int) error { if !a.startRes.Done() { - return xerrors.Errorf(initDkgFirst) + return xerrors.Errorf(initDkgFirst + "7") } addrsNew := make([]mino.Address, 0, coAuth.Len()) diff --git a/dkg/pedersen/reencrypt.go b/dkg/pedersen/reencrypt.go index 9a1a31db5..84a746d0f 100644 --- a/dkg/pedersen/reencrypt.go +++ b/dkg/pedersen/reencrypt.go @@ -27,7 +27,7 @@ type reencryptStatus struct { // Reencrypt implements dkg.Actor. func (a *Actor) Reencrypt(K kyber.Point, pubk kyber.Point) (XhatEnc kyber.Point, err error) { if !a.startRes.Done() { - return nil, xerrors.Errorf(initDkgFirst) + return nil, xerrors.Errorf(initDkgFirst + "8") } ctx, cancel := context.WithTimeout(context.Background(), decryptTimeout) @@ -79,7 +79,8 @@ func (a *Actor) Reencrypt(K kyber.Point, pubk kyber.Point) (XhatEnc kyber.Point, if err == nil { dela.Logger.Debug().Msgf("Reencryption Uis: %v", status.Uis) - XhatEnc, err := share.RecoverCommit(suites.MustFind("Ed25519"), status.Uis, status.threshold, status.nbnodes) + XhatEnc, err := share.RecoverCommit(suites.MustFind("Ed25519"), status.Uis, + status.threshold, status.nbnodes) if err != nil { return nil, xerrors.Errorf("Reencryption failed: %v", err) }