mirror of
https://github.com/luxfi/threshold.git
synced 2026-10-30 15:15:53 +00:00
Every round in this package sat at zero coverage: the tests built a session and asserted it was non-nil, so no share had ever been produced and the key check inside round 3 had never executed. Run for the first time it refused, and each thing it refused for was a separate defect. The resharing polynomial's constant term was the party's bare share xⱼ, so the new shares summed to Σxⱼ instead of the secret Σλⱼxⱼ — a different key. It is now the share weighted by its Lagrange coefficient over the old committee. The round-1 broadcast carried commitments as curve.Point, an interface CBOR has no concrete type to decode into, so it failed on every receiver. Points and scalars travel as bytes now, as keygen's messages already do. The broadcast declares round 1, so the handler routed it to round1, whose StoreBroadcastMessage discarded it with a note that round 2 would store it — and round 2 declared no broadcast. The maps live on round 1, where the message lands; round 2 reads them through the embed. A party's own commitments were never in that map, since a broadcast is not delivered back to its sender, while round 3 added the party's own share separately — public shares one contribution short of private ones. Seeded. Round 2 sent a share to itself. Whether that arrives depends on the transport, so the party's contribution counted once or twice. It is stored directly now and never sent, and round 3 sums the map once with no special case. The test network delivered self-addressed messages; production refuses them (Message.IsFor is false when From is the recipient). It refuses them now, which is what makes the last fix testable: send-to-self passed under the old network and fails under this one. The test runs the reshare, checks every new share against its own public share, then signs with the new shares and verifies under the ORIGINAL key. Each fix, reverted alone, fails it. Co-authored-by: Hanzo Dev <[email protected]>
93 lines
2.4 KiB
Go
93 lines
2.4 KiB
Go
// Package reshare implements the LSS dynamic resharing protocol.
|
|
package reshare
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/luxfi/threshold/internal/types"
|
|
|
|
"github.com/luxfi/threshold/internal/round"
|
|
"github.com/luxfi/threshold/pkg/party"
|
|
"github.com/luxfi/threshold/pkg/pool"
|
|
"github.com/luxfi/threshold/pkg/protocol"
|
|
"github.com/luxfi/threshold/protocols/lss/config"
|
|
)
|
|
|
|
// Start initiates the LSS resharing protocol.
|
|
func Start(oldConfig *config.Config, newParticipants []party.ID, newThreshold int, pl *pool.Pool) protocol.StartFunc {
|
|
return func(sessionID []byte) (round.Session, error) {
|
|
// Validate parameters
|
|
if len(newParticipants) == 0 {
|
|
return nil, fmt.Errorf("new participant list cannot be empty")
|
|
}
|
|
if newThreshold <= 0 {
|
|
return nil, fmt.Errorf("threshold must be positive")
|
|
}
|
|
if newThreshold >= len(newParticipants) {
|
|
return nil, fmt.Errorf("threshold %d must be less than number of parties %d", newThreshold, len(newParticipants))
|
|
}
|
|
|
|
// Determine if we're in the old group, new group, or both
|
|
oldID := oldConfig.ID
|
|
inOldGroup := false
|
|
inNewGroup := false
|
|
|
|
for _, id := range oldConfig.PartyIDs() {
|
|
if id == oldID {
|
|
inOldGroup = true
|
|
break
|
|
}
|
|
}
|
|
|
|
for _, id := range newParticipants {
|
|
if id == oldID {
|
|
inNewGroup = true
|
|
break
|
|
}
|
|
}
|
|
|
|
// Combine old and new participants for the protocol
|
|
allParticipants := make(map[party.ID]bool)
|
|
for _, id := range oldConfig.PartyIDs() {
|
|
allParticipants[id] = true
|
|
}
|
|
for _, id := range newParticipants {
|
|
allParticipants[id] = true
|
|
}
|
|
|
|
participantList := make([]party.ID, 0, len(allParticipants))
|
|
for id := range allParticipants {
|
|
participantList = append(participantList, id)
|
|
}
|
|
|
|
info := round.Info{
|
|
ProtocolID: "lss/reshare",
|
|
FinalRoundNumber: 3,
|
|
SelfID: oldID,
|
|
PartyIDs: participantList,
|
|
Threshold: newThreshold,
|
|
Group: oldConfig.Group,
|
|
}
|
|
|
|
helper, err := round.NewSession(info, sessionID, pl)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &round1{
|
|
Base: helper,
|
|
oldConfig: oldConfig,
|
|
newParticipants: newParticipants,
|
|
newThreshold: newThreshold,
|
|
inOldGroup: inOldGroup,
|
|
inNewGroup: inNewGroup,
|
|
commitments: make(map[party.ID]map[party.ID][]byte),
|
|
chainKeys: make(map[party.ID]types.RID),
|
|
}, nil
|
|
}
|
|
}
|
|
|
|
// Result contains the final output of the reshare protocol
|
|
type Result struct {
|
|
Config *config.Config
|
|
}
|