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

fix: frost key resharing #346

Merged
merged 4 commits into from
Aug 13, 2024
Merged
Changes from 1 commit
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
43 changes: 41 additions & 2 deletions tss/frost/resharing/resharing.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package resharing

import (
"context"
"encoding/json"

"github.com/ChainSafe/sygma-relayer/comm"
"github.com/ChainSafe/sygma-relayer/keyshare"
Expand All @@ -17,9 +18,14 @@ import (
"github.com/taurusgroup/multi-party-sig/pkg/math/curve"
"github.com/taurusgroup/multi-party-sig/pkg/party"
"github.com/taurusgroup/multi-party-sig/pkg/protocol"
"github.com/taurusgroup/multi-party-sig/pkg/taproot"
"github.com/taurusgroup/multi-party-sig/protocols/frost"
)

type startParams struct {
PublicKey taproot.PublicKey
VerificationShares map[party.ID]*curve.Secp256k1Point
}
type FrostKeyshareStorer interface {
GetKeyshare() (keyshare.FrostKeyshare, error)
StoreKeyshare(keyshare keyshare.FrostKeyshare) error
Expand Down Expand Up @@ -89,8 +95,25 @@ func (r *Resharing) Run(
outChn := make(chan tss.Message)
msgChn := make(chan *comm.WrappedMessage)
r.subscriptionID = r.Communication.Subscribe(r.SessionID(), comm.TssReshareMsg, msgChn)
startParams, err := r.unmarshallStartParams(params)
if err != nil {
return err
}
r.key.Key.PublicKey = startParams.PublicKey
tcar121293 marked this conversation as resolved.
Show resolved Hide resolved
// initialize verification shares for the new relayer
if len(r.key.Key.VerificationShares) == 0 {
r.key.Key.VerificationShares = startParams.VerificationShares
}

// Add a new verification share for each party that does not already have one
partyIds := common.PartyIDSFromPeers(append(r.Host.Peerstore().Peers(), r.Host.ID()))
group := curve.Secp256k1{}
for _, k := range partyIds {
if r.key.Key.VerificationShares[k] == nil {
r.key.Key.VerificationShares[k] = group.NewPoint().(*curve.Secp256k1Point)
}
}

r.key.Key.PublicKey = params
r.Handler, err = protocol.NewMultiHandler(
frost.RefreshTaproot(
r.key.Key,
Expand Down Expand Up @@ -127,7 +150,23 @@ func (r *Resharing) ValidCoordinators() []peer.ID {
}

func (r *Resharing) StartParams(readyPeers []peer.ID) []byte {
return r.key.Key.PublicKey

mpetrun5 marked this conversation as resolved.
Show resolved Hide resolved
startParams := &startParams{
PublicKey: r.key.Key.PublicKey,
VerificationShares: r.key.Key.VerificationShares,
}
paramBytes, _ := json.Marshal(startParams)
return paramBytes
}

func (r *Resharing) unmarshallStartParams(paramBytes []byte) (startParams, error) {
var startParams startParams
err := json.Unmarshal(paramBytes, &startParams)
if err != nil {
return startParams, err
}

return startParams, nil
}

func (r *Resharing) Retryable() bool {
Expand Down
Loading