mirror of
https://github.com/luxfi/threshold.git
synced 2026-10-30 15:15:53 +00:00
round.Helper was the canonical anti-pattern: a bare-noun
qualifier-name that told you nothing about what the type does. The
type is the embeddable Session implementation that protocol round
structs anchor on — its VALUE is "the base every round builds on".
Rename it to that.
type Helper struct { ... } → type Base struct { ... }
func (h *Helper) ... → func (h *Base) ...
func NewSession(...) (*Helper, error) → (*Base, error)
Output { *Helper } → Output { *Base }
Abort { *Helper } → Abort { *Base }
round.Helper → round.Base (18 files)
Helper: helper → Base: helper (struct literal init)
r.Helper.X / r.Helper → r.Base.X / r.Base (field access)
internal/round/helper.go → base.go
internal/round/helper_test.go → base_test.go
Forward-only — no type alias, no deprecation. The Go FAQ pointer-
receiver consistency landed in the prior commit (f7b1365) so the
method set is already aligned; this commit only renames the type.
Build + vet clean; round / CMP keygen smoke / FROST keygen all
PASS unchanged.
90 lines
2.7 KiB
Go
90 lines
2.7 KiB
Go
package keygen
|
|
|
|
import (
|
|
"crypto/rand"
|
|
|
|
"github.com/luxfi/threshold/internal/ot"
|
|
"github.com/luxfi/threshold/internal/params"
|
|
"github.com/luxfi/threshold/internal/round"
|
|
"github.com/luxfi/threshold/pkg/hash"
|
|
"github.com/luxfi/threshold/pkg/math/curve"
|
|
"github.com/luxfi/threshold/pkg/math/sample"
|
|
zksch "github.com/luxfi/threshold/pkg/zk/sch"
|
|
)
|
|
|
|
// message1R is the message we send in this round.
|
|
type message1R struct {
|
|
// Commit is the commitment to our public point.
|
|
Commit hash.Commitment
|
|
// ChainKeyCommit is the commitment to our ChainKey randomness
|
|
ChainKeyCommit hash.Commitment
|
|
// RefreshCommit is the commitment to our refresh scalar.
|
|
RefreshCommit hash.Commitment
|
|
// OtMsg is the underlying OT setup message.
|
|
OtMsg *ot.CorreOTSetupReceiveRound1Message
|
|
}
|
|
|
|
func (message1R) RoundNumber() round.Number { return 1 }
|
|
|
|
// round1R corresponds to the first round from the Receiver's perspective.
|
|
type round1R struct {
|
|
*round.Base
|
|
// refresh indicates whether or not we should refresh
|
|
refresh bool
|
|
// public is an existing public key, if we're refresing
|
|
public curve.Point
|
|
// Our generated secret share
|
|
secretShare curve.Scalar
|
|
// Our secret share * G
|
|
publicShare curve.Point
|
|
receiver *ot.CorreOTSetupReceiver
|
|
}
|
|
|
|
// VerifyMessage implements round.Round.
|
|
//
|
|
// Since this is the start of the protocol, we aren't expecting to have received
|
|
// any messages yet, so we do nothing.
|
|
func (r *round1R) VerifyMessage(round.Message) error { return nil }
|
|
|
|
// StoreMessage implements round.Round.
|
|
func (r *round1R) StoreMessage(round.Message) error { return nil }
|
|
|
|
func (r *round1R) Finalize(out chan<- *round.Message) (round.Session, error) {
|
|
proof := zksch.NewProof(r.Hash(), r.publicShare, r.secretShare, nil)
|
|
commit, decommit, err := r.Hash().Commit(r.publicShare)
|
|
if err != nil {
|
|
return r, err
|
|
}
|
|
chainKey := make([]byte, params.SecBytes)
|
|
_, _ = rand.Read(chainKey)
|
|
chainKeyCommit, chainKeyDecommit, err := r.Hash().Commit(chainKey)
|
|
if err != nil {
|
|
return r, err
|
|
}
|
|
refreshScalar := sample.Scalar(rand.Reader, r.Group())
|
|
refreshCommit, refreshDecommit, err := r.Hash().Commit(refreshScalar)
|
|
if err != nil {
|
|
return r, err
|
|
}
|
|
otMsg := r.receiver.Round1()
|
|
if err := r.SendMessage(out, &message1R{commit, chainKeyCommit, refreshCommit, otMsg}, ""); err != nil {
|
|
return r, err
|
|
}
|
|
|
|
return &round2R{
|
|
round1R: r,
|
|
proof: proof,
|
|
decommit: decommit,
|
|
chainKeyDecommit: chainKeyDecommit,
|
|
refreshDecommit: refreshDecommit,
|
|
refreshScalar: refreshScalar,
|
|
ourChainKey: chainKey,
|
|
}, nil
|
|
}
|
|
|
|
// MessageContent imlpements round.Round.
|
|
func (*round1R) MessageContent() round.Content { return nil }
|
|
|
|
// Number implements round.Round.
|
|
func (*round1R) Number() round.Number { return 1 }
|