Skip to content

Commit d679948

Browse files
authored
Merge pull request #86 from fystack/fix-resharing-for-old-keys
Fix resharing for old keys
2 parents 066d2ca + e3db678 commit d679948

6 files changed

Lines changed: 33 additions & 18 deletions

File tree

.github/workflows/ci.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,11 @@ jobs:
100100
echo "Files in current directory:"
101101
ls -la
102102
govulncheck -format=sarif ./... > govulncheck-results.sarif
103-
103+
104104
govulncheck -json ./... > vuln.json
105105
count=$(jq '[.[] | select(.finding != null and .finding.trace != null)] | length' vuln.json || echo 0)
106106
echo "Found $count vulnerabilities"
107-
107+
108108
if [ "$count" -gt 0 ]; then
109109
echo "⚠️ Vulnerabilities found by govulncheck (see Security tab for details)"
110110
else
@@ -259,9 +259,10 @@ jobs:
259259
run: |
260260
curl -sSfL https://raw.githubusercontent.com/anchore/grype/main/install.sh | sh -s -- -b /usr/local/bin
261261
262-
- name: Scan SBOM with Grype
262+
# Keep SBOM generation & artifact upload as-is (no SARIF upload from SBOM)
263+
- name: Grype SARIF (directory scan)
263264
run: |
264-
grype sbom.spdx.json -o sarif --file grype-results.sarif
265+
grype dir:. -o sarif --file grype-results.sarif
265266
continue-on-error: true
266267

267268
- name: Upload Grype results to GitHub Security tab

pkg/eventconsumer/event_consumer.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,6 @@ func (ec *eventConsumer) consumeReshareEvent() error {
603603
return ec.node.CreateReshareSession(
604604
sessionType,
605605
walletID,
606-
ec.mpcThreshold,
607606
msg.NewThreshold,
608607
msg.NodeIDs,
609608
isNewPeer,
@@ -638,11 +637,19 @@ func (ec *eventConsumer) consumeReshareEvent() error {
638637
ctx := context.Background()
639638
var wg sync.WaitGroup
640639
if oldSession != nil {
641-
oldSession.Init()
640+
err := oldSession.Init()
641+
if err != nil {
642+
ec.handleReshareSessionError(walletID, keyType, msg.NewThreshold, err, "Failed to init old reshare session", natMsg)
643+
return
644+
}
642645
oldSession.ListenToIncomingMessageAsync()
643646
}
644647
if newSession != nil {
645-
newSession.Init()
648+
err := newSession.Init()
649+
if err != nil {
650+
ec.handleReshareSessionError(walletID, keyType, msg.NewThreshold, err, "Failed to init new reshare session", natMsg)
651+
return
652+
}
646653
newSession.ListenToIncomingMessageAsync()
647654
}
648655

pkg/mpc/ecdsa_resharing_session.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818

1919
type ReshareSession interface {
2020
Session
21-
Init()
21+
Init() error
2222
Reshare(done func())
2323
GetPubKeyResult() []byte
2424
}
@@ -99,7 +99,7 @@ func NewECDSAReshareSession(
9999
}
100100
}
101101

102-
func (s *ecdsaReshareSession) Init() {
102+
func (s *ecdsaReshareSession) Init() error {
103103
logger.Infof("Initializing resharing session with partyID: %s, newPartyIDs %s", s.selfPartyID, s.partyIDs)
104104
var share keygen.LocalPartySaveData
105105

@@ -110,15 +110,15 @@ func (s *ecdsaReshareSession) Init() {
110110
} else {
111111
err := s.loadOldShareDataGeneric(s.walletID, s.GetVersion(), &share)
112112
if err != nil {
113-
s.ErrCh <- err
114-
return
113+
return fmt.Errorf("failed to load old share data ecdsa: %w", err)
115114
}
116115
}
117116

118117
s.party = resharing.NewLocalParty(s.reshareParams, share, s.outCh, s.endCh)
119118

120119
logger.Infof("[INITIALIZED] Initialized resharing session successfully partyID: %s, peerIDs %s, walletID %s, oldThreshold = %d, newThreshold = %d",
121120
s.selfPartyID, s.partyIDs, s.walletID, s.threshold, s.reshareParams.NewThreshold())
121+
return nil
122122
}
123123

124124
func (s *ecdsaReshareSession) Reshare(done func()) {

pkg/mpc/eddsa_resharing_session.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ func NewEDDSAReshareSession(
9191
}
9292
}
9393

94-
func (s *eddsaReshareSession) Init() {
94+
func (s *eddsaReshareSession) Init() error {
9595
logger.Infof("Initializing resharing session with partyID: %s, peerIDs %s", s.selfPartyID, s.partyIDs)
9696
var share keygen.LocalPartySaveData
9797
if s.isNewParty {
@@ -100,13 +100,14 @@ func (s *eddsaReshareSession) Init() {
100100
} else {
101101
err := s.loadOldShareDataGeneric(s.walletID, s.GetVersion(), &share)
102102
if err != nil {
103-
s.ErrCh <- err
104-
return
103+
return fmt.Errorf("failed to load old share data eddsa: %w", err)
105104
}
106105
}
107106
s.party = resharing.NewLocalParty(s.reshareParams, share, s.outCh, s.endCh)
108107
logger.Infof("[INITIALIZED] Initialized resharing session successfully partyID: %s, peerIDs %s, walletID %s, oldThreshold = %d, newThreshold = %d",
109108
s.selfPartyID, s.partyIDs, s.walletID, s.threshold, s.reshareParams.NewThreshold())
109+
110+
return nil
110111
}
111112

112113
func (s *eddsaReshareSession) Reshare(done func()) {

pkg/mpc/node.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,6 @@ func (p *Node) ensureNodeIsParticipant(keyInfo *keyinfo.KeyInfo) error {
272272
func (p *Node) CreateReshareSession(
273273
sessionType SessionType,
274274
walletID string,
275-
oldThreshold int,
276275
newThreshold int,
277276
newPeerIDs []string,
278277
isNewPeer bool,
@@ -334,6 +333,7 @@ func (p *Node) CreateReshareSession(
334333
"ready count", len(readyOldParticipantIDs),
335334
"min ready", oldKeyInfo.Threshold+1,
336335
"version", oldKeyInfo.Version,
336+
"isNewPeer", isNewPeer,
337337
)
338338

339339
if len(readyOldParticipantIDs) < oldKeyInfo.Threshold+1 {
@@ -380,7 +380,7 @@ func (p *Node) CreateReshareSession(
380380
selfPartyID,
381381
oldAllPartyIDs,
382382
newAllPartyIDs,
383-
oldThreshold,
383+
oldKeyInfo.Threshold,
384384
newThreshold,
385385
preParams,
386386
p.kvstore,
@@ -401,7 +401,7 @@ func (p *Node) CreateReshareSession(
401401
selfPartyID,
402402
oldAllPartyIDs,
403403
newAllPartyIDs,
404-
oldThreshold,
404+
oldKeyInfo.Threshold,
405405
newThreshold,
406406
p.kvstore,
407407
p.keyinfoStore,

pkg/mpc/session.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,12 +242,18 @@ func (s *session) loadOldShareDataGeneric(walletID string, version int, dest int
242242
if version > 0 {
243243
key = s.composeKey(walletIDWithVersion(walletID, version))
244244
keyData, err = s.kvstore.Get(key)
245+
if err != nil {
246+
return err
247+
}
245248
}
246249

247250
// If version == 0 or previous key not found, fall back to unversioned key
248-
if err != nil || version == 0 {
251+
if version == 0 {
249252
key = s.composeKey(walletID)
250253
keyData, err = s.kvstore.Get(key)
254+
if err != nil {
255+
return err
256+
}
251257
}
252258

253259
if err != nil {

0 commit comments

Comments
 (0)