Skip to content

Commit

Permalink
fix: frost key resharing (#346)
Browse files Browse the repository at this point in the history
  • Loading branch information
tcar121293 authored Aug 13, 2024
1 parent 6cfbbcc commit 7b35e11
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
- name: Checkout code
uses: actions/checkout@v2
- name: Run nodes
run: docker-compose -f ./example/docker-compose.yml up -d
run: docker compose -f ./example/docker-compose.yml up -d
- name: Run tests
run: make e2e-test
- name: Print logs
Expand Down
42 changes: 40 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
}
// initialize verification shares for the new relayer
if len(r.key.Key.VerificationShares) == 0 {
r.key.Key.VerificationShares = startParams.VerificationShares
r.key.Key.PublicKey = startParams.PublicKey
}

// 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,22 @@ func (r *Resharing) ValidCoordinators() []peer.ID {
}

func (r *Resharing) StartParams(readyPeers []peer.ID) []byte {
return r.key.Key.PublicKey
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

0 comments on commit 7b35e11

Please sign in to comment.