From bb14b871a4a0143715d878593c7ab8c208c7dd12 Mon Sep 17 00:00:00 2001 From: ZhAnGeek Date: Fri, 1 Dec 2023 10:33:37 +0800 Subject: [PATCH] Fix: update always round.ok --- ecdsa/keygen/round_1.go | 6 ++++-- ecdsa/keygen/round_2.go | 9 ++++++--- ecdsa/keygen/round_3.go | 6 ++++-- ecdsa/resharing/round_1_old_step_1.go | 10 ++++++++-- ecdsa/resharing/round_2_new_step_1.go | 15 ++++++++++----- ecdsa/signing/round_2.go | 6 ++++-- ecdsa/signing/round_3.go | 6 ++++-- ecdsa/signing/round_4.go | 6 ++++-- ecdsa/signing/round_5.go | 6 ++++-- ecdsa/signing/round_6.go | 6 ++++-- ecdsa/signing/round_7.go | 6 ++++-- ecdsa/signing/round_8.go | 6 ++++-- ecdsa/signing/round_9.go | 6 ++++-- eddsa/keygen/round_1.go | 6 ++++-- eddsa/keygen/round_2.go | 9 ++++++--- eddsa/resharing/round_1_old_step_1.go | 10 ++++++++-- eddsa/resharing/round_2_new_step_1.go | 6 ++++-- eddsa/resharing/round_4_new_step_2.go | 6 ++++-- eddsa/signing/round_1.go | 6 ++++-- eddsa/signing/round_2.go | 6 ++++-- eddsa/signing/round_3.go | 6 ++++-- 21 files changed, 102 insertions(+), 47 deletions(-) diff --git a/ecdsa/keygen/round_1.go b/ecdsa/keygen/round_1.go index 4854e1c4..5e66f681 100644 --- a/ecdsa/keygen/round_1.go +++ b/ecdsa/keygen/round_1.go @@ -136,17 +136,19 @@ func (round *round1) CanAccept(msg tss.ParsedMessage) bool { } func (round *round1) Update() (bool, *tss.Error) { + ret := true for j, msg := range round.temp.kgRound1Messages { if round.ok[j] { continue } if msg == nil || !round.CanAccept(msg) { - return false, nil + ret = false + continue } // vss check is in round 2 round.ok[j] = true } - return true, nil + return ret, nil } func (round *round1) NextRound() tss.Round { diff --git a/ecdsa/keygen/round_2.go b/ecdsa/keygen/round_2.go index 3eac8eba..52e6d4eb 100644 --- a/ecdsa/keygen/round_2.go +++ b/ecdsa/keygen/round_2.go @@ -165,20 +165,23 @@ func (round *round2) CanAccept(msg tss.ParsedMessage) bool { func (round *round2) Update() (bool, *tss.Error) { // guard - VERIFY de-commit for all Pj + ret := true for j, msg := range round.temp.kgRound2Message1s { if round.ok[j] { continue } if msg == nil || !round.CanAccept(msg) { - return false, nil + ret = false + continue } msg2 := round.temp.kgRound2Message2s[j] if msg2 == nil || !round.CanAccept(msg2) { - return false, nil + ret = false + continue } round.ok[j] = true } - return true, nil + return ret, nil } func (round *round2) NextRound() tss.Round { diff --git a/ecdsa/keygen/round_3.go b/ecdsa/keygen/round_3.go index b704358a..c6871b7b 100644 --- a/ecdsa/keygen/round_3.go +++ b/ecdsa/keygen/round_3.go @@ -229,17 +229,19 @@ func (round *round3) CanAccept(msg tss.ParsedMessage) bool { } func (round *round3) Update() (bool, *tss.Error) { + ret := true for j, msg := range round.temp.kgRound3Messages { if round.ok[j] { continue } if msg == nil || !round.CanAccept(msg) { - return false, nil + ret = false + continue } // proof check is in round 4 round.ok[j] = true } - return true, nil + return ret, nil } func (round *round3) NextRound() tss.Round { diff --git a/ecdsa/resharing/round_1_old_step_1.go b/ecdsa/resharing/round_1_old_step_1.go index be8a2ec8..c178b7ba 100644 --- a/ecdsa/resharing/round_1_old_step_1.go +++ b/ecdsa/resharing/round_1_old_step_1.go @@ -97,16 +97,22 @@ func (round *round1) Update() (bool, *tss.Error) { return true, nil } // accept messages from old -> new committee + ret := true for j, msg := range round.temp.dgRound1Messages { if round.oldOK[j] { continue } if msg == nil || !round.CanAccept(msg) { - return false, nil + ret = false + continue } round.oldOK[j] = true // save the ecdsa pub received from the old committee + if round.temp.dgRound1Messages[0] == nil { + ret = false + continue + } r1msg := round.temp.dgRound1Messages[0].Content().(*DGRound1Message) candidate, err := r1msg.UnmarshalECDSAPub(round.Params().EC()) if err != nil { @@ -119,7 +125,7 @@ func (round *round1) Update() (bool, *tss.Error) { } round.save.ECDSAPub = candidate } - return true, nil + return ret, nil } func (round *round1) NextRound() tss.Round { diff --git a/ecdsa/resharing/round_2_new_step_1.go b/ecdsa/resharing/round_2_new_step_1.go index 8a47283a..3543e047 100644 --- a/ecdsa/resharing/round_2_new_step_1.go +++ b/ecdsa/resharing/round_2_new_step_1.go @@ -135,6 +135,7 @@ func (round *round2) CanAccept(msg tss.ParsedMessage) bool { } func (round *round2) Update() (bool, *tss.Error) { + ret := true if round.ReSharingParams().IsOldCommittee() && round.ReSharingParameters.IsNewCommittee() { // accept messages from new -> old committee for j, msg1 := range round.temp.dgRound2Message2s { @@ -142,12 +143,14 @@ func (round *round2) Update() (bool, *tss.Error) { continue } if msg1 == nil || !round.CanAccept(msg1) { - return false, nil + ret = false + continue } // accept message from new -> committee msg2 := round.temp.dgRound2Message1s[j] if msg2 == nil || !round.CanAccept(msg2) { - return false, nil + ret = false + continue } round.newOK[j] = true } @@ -158,7 +161,8 @@ func (round *round2) Update() (bool, *tss.Error) { continue } if msg == nil || !round.CanAccept(msg) { - return false, nil + ret = false + continue } round.newOK[j] = true } @@ -169,14 +173,15 @@ func (round *round2) Update() (bool, *tss.Error) { continue } if msg == nil || !round.CanAccept(msg) { - return false, nil + ret = false + continue } round.newOK[j] = true } } else { return false, round.WrapError(errors.New("this party is not in the old or the new committee"), round.PartyID()) } - return true, nil + return ret, nil } func (round *round2) NextRound() tss.Round { diff --git a/ecdsa/signing/round_2.go b/ecdsa/signing/round_2.go index 0568f3dd..9a23bf1e 100644 --- a/ecdsa/signing/round_2.go +++ b/ecdsa/signing/round_2.go @@ -120,16 +120,18 @@ func (round *round2) Start() *tss.Error { } func (round *round2) Update() (bool, *tss.Error) { + ret := true for j, msg := range round.temp.signRound2Messages { if round.ok[j] { continue } if msg == nil || !round.CanAccept(msg) { - return false, nil + ret = false + continue } round.ok[j] = true } - return true, nil + return ret, nil } func (round *round2) CanAccept(msg tss.ParsedMessage) bool { diff --git a/ecdsa/signing/round_3.go b/ecdsa/signing/round_3.go index 38ae9b00..918648ef 100644 --- a/ecdsa/signing/round_3.go +++ b/ecdsa/signing/round_3.go @@ -125,16 +125,18 @@ func (round *round3) Start() *tss.Error { } func (round *round3) Update() (bool, *tss.Error) { + ret := true for j, msg := range round.temp.signRound3Messages { if round.ok[j] { continue } if msg == nil || !round.CanAccept(msg) { - return false, nil + ret = false + continue } round.ok[j] = true } - return true, nil + return ret, nil } func (round *round3) CanAccept(msg tss.ParsedMessage) bool { diff --git a/ecdsa/signing/round_4.go b/ecdsa/signing/round_4.go index e7183690..7fc78993 100644 --- a/ecdsa/signing/round_4.go +++ b/ecdsa/signing/round_4.go @@ -56,16 +56,18 @@ func (round *round4) Start() *tss.Error { } func (round *round4) Update() (bool, *tss.Error) { + ret := true for j, msg := range round.temp.signRound4Messages { if round.ok[j] { continue } if msg == nil || !round.CanAccept(msg) { - return false, nil + ret = false + continue } round.ok[j] = true } - return true, nil + return ret, nil } func (round *round4) CanAccept(msg tss.ParsedMessage) bool { diff --git a/ecdsa/signing/round_5.go b/ecdsa/signing/round_5.go index 3cbe19c5..f6ecf308 100644 --- a/ecdsa/signing/round_5.go +++ b/ecdsa/signing/round_5.go @@ -98,16 +98,18 @@ func (round *round5) Start() *tss.Error { } func (round *round5) Update() (bool, *tss.Error) { + ret := true for j, msg := range round.temp.signRound5Messages { if round.ok[j] { continue } if msg == nil || !round.CanAccept(msg) { - return false, nil + ret = false + continue } round.ok[j] = true } - return true, nil + return ret, nil } func (round *round5) CanAccept(msg tss.ParsedMessage) bool { diff --git a/ecdsa/signing/round_6.go b/ecdsa/signing/round_6.go index 278d19be..0f8cdd03 100644 --- a/ecdsa/signing/round_6.go +++ b/ecdsa/signing/round_6.go @@ -42,16 +42,18 @@ func (round *round6) Start() *tss.Error { } func (round *round6) Update() (bool, *tss.Error) { + ret := true for j, msg := range round.temp.signRound6Messages { if round.ok[j] { continue } if msg == nil || !round.CanAccept(msg) { - return false, nil + ret = false + continue } round.ok[j] = true } - return true, nil + return ret, nil } func (round *round6) CanAccept(msg tss.ParsedMessage) bool { diff --git a/ecdsa/signing/round_7.go b/ecdsa/signing/round_7.go index a50be65d..e89e0fcd 100644 --- a/ecdsa/signing/round_7.go +++ b/ecdsa/signing/round_7.go @@ -93,16 +93,18 @@ func (round *round7) Start() *tss.Error { } func (round *round7) Update() (bool, *tss.Error) { + ret := true for j, msg := range round.temp.signRound7Messages { if round.ok[j] { continue } if msg == nil || !round.CanAccept(msg) { - return false, nil + ret = false + continue } round.ok[j] = true } - return true, nil + return ret, nil } func (round *round7) CanAccept(msg tss.ParsedMessage) bool { diff --git a/ecdsa/signing/round_8.go b/ecdsa/signing/round_8.go index f8b8e294..4e3f29cb 100644 --- a/ecdsa/signing/round_8.go +++ b/ecdsa/signing/round_8.go @@ -28,16 +28,18 @@ func (round *round8) Start() *tss.Error { } func (round *round8) Update() (bool, *tss.Error) { + ret := true for j, msg := range round.temp.signRound8Messages { if round.ok[j] { continue } if msg == nil || !round.CanAccept(msg) { - return false, nil + ret = false + continue } round.ok[j] = true } - return true, nil + return ret, nil } func (round *round8) CanAccept(msg tss.ParsedMessage) bool { diff --git a/ecdsa/signing/round_9.go b/ecdsa/signing/round_9.go index 3f74c21b..a1c85d7f 100644 --- a/ecdsa/signing/round_9.go +++ b/ecdsa/signing/round_9.go @@ -51,16 +51,18 @@ func (round *round9) Start() *tss.Error { } func (round *round9) Update() (bool, *tss.Error) { + ret := true for j, msg := range round.temp.signRound9Messages { if round.ok[j] { continue } if msg == nil || !round.CanAccept(msg) { - return false, nil + ret = false + continue } round.ok[j] = true } - return true, nil + return ret, nil } func (round *round9) CanAccept(msg tss.ParsedMessage) bool { diff --git a/eddsa/keygen/round_1.go b/eddsa/keygen/round_1.go index 9fc694e0..18ac2c58 100644 --- a/eddsa/keygen/round_1.go +++ b/eddsa/keygen/round_1.go @@ -96,17 +96,19 @@ func (round *round1) CanAccept(msg tss.ParsedMessage) bool { } func (round *round1) Update() (bool, *tss.Error) { + ret := true for j, msg := range round.temp.kgRound1Messages { if round.ok[j] { continue } if msg == nil || !round.CanAccept(msg) { - return false, nil + ret = false + continue } // vss check is in round 2 round.ok[j] = true } - return true, nil + return ret, nil } func (round *round1) NextRound() tss.Round { diff --git a/eddsa/keygen/round_2.go b/eddsa/keygen/round_2.go index d1a603b4..1e0a4474 100644 --- a/eddsa/keygen/round_2.go +++ b/eddsa/keygen/round_2.go @@ -72,20 +72,23 @@ func (round *round2) CanAccept(msg tss.ParsedMessage) bool { func (round *round2) Update() (bool, *tss.Error) { // guard - VERIFY de-commit for all Pj + ret := true for j, msg := range round.temp.kgRound2Message1s { if round.ok[j] { continue } if msg == nil || !round.CanAccept(msg) { - return false, nil + ret = false + continue } msg2 := round.temp.kgRound2Message2s[j] if msg2 == nil || !round.CanAccept(msg2) { - return false, nil + ret = false + continue } round.ok[j] = true } - return true, nil + return ret, nil } func (round *round2) NextRound() tss.Round { diff --git a/eddsa/resharing/round_1_old_step_1.go b/eddsa/resharing/round_1_old_step_1.go index 9f997d58..61bac309 100644 --- a/eddsa/resharing/round_1_old_step_1.go +++ b/eddsa/resharing/round_1_old_step_1.go @@ -90,15 +90,21 @@ func (round *round1) Update() (bool, *tss.Error) { return true, nil } // accept messages from old -> new committee + ret := true for j, msg := range round.temp.dgRound1Messages { if round.oldOK[j] { continue } if msg == nil || !round.CanAccept(msg) { - return false, nil + ret = false + continue } round.oldOK[j] = true + if round.temp.dgRound1Messages[0] == nil { + ret = false + continue + } // save the eddsa pub received from the old committee r1msg := round.temp.dgRound1Messages[0].Content().(*DGRound1Message) candidate, err := r1msg.UnmarshalEDDSAPub(round.Params().EC()) @@ -112,7 +118,7 @@ func (round *round1) Update() (bool, *tss.Error) { } round.save.EDDSAPub = candidate } - return true, nil + return ret, nil } func (round *round1) NextRound() tss.Round { diff --git a/eddsa/resharing/round_2_new_step_1.go b/eddsa/resharing/round_2_new_step_1.go index 38270879..703d154a 100644 --- a/eddsa/resharing/round_2_new_step_1.go +++ b/eddsa/resharing/round_2_new_step_1.go @@ -50,18 +50,20 @@ func (round *round2) Update() (bool, *tss.Error) { return true, nil } + ret := true // accept messages from new -> old committee for j, msg := range round.temp.dgRound2Messages { if round.newOK[j] { continue } if msg == nil || !round.CanAccept(msg) { - return false, nil + ret = false + continue } round.newOK[j] = true } - return true, nil + return ret, nil } func (round *round2) NextRound() tss.Round { diff --git a/eddsa/resharing/round_4_new_step_2.go b/eddsa/resharing/round_4_new_step_2.go index ab045e41..9911142f 100644 --- a/eddsa/resharing/round_4_new_step_2.go +++ b/eddsa/resharing/round_4_new_step_2.go @@ -141,16 +141,18 @@ func (round *round4) CanAccept(msg tss.ParsedMessage) bool { func (round *round4) Update() (bool, *tss.Error) { // accept messages from new -> old&new committees + ret := true for j, msg := range round.temp.dgRound4Messages { if round.newOK[j] { continue } if msg == nil || !round.CanAccept(msg) { - return false, nil + ret = false + continue } round.newOK[j] = true } - return true, nil + return ret, nil } func (round *round4) NextRound() tss.Round { diff --git a/eddsa/signing/round_1.go b/eddsa/signing/round_1.go index 629d0b4d..21f6fa38 100644 --- a/eddsa/signing/round_1.go +++ b/eddsa/signing/round_1.go @@ -63,16 +63,18 @@ func (round *round1) Start() *tss.Error { } func (round *round1) Update() (bool, *tss.Error) { + ret := true for j, msg := range round.temp.signRound1Messages { if round.ok[j] { continue } if msg == nil || !round.CanAccept(msg) { - return false, nil + ret = false + continue } round.ok[j] = true } - return true, nil + return ret, nil } func (round *round1) CanAccept(msg tss.ParsedMessage) bool { diff --git a/eddsa/signing/round_2.go b/eddsa/signing/round_2.go index 82f6c12a..1348a39a 100644 --- a/eddsa/signing/round_2.go +++ b/eddsa/signing/round_2.go @@ -55,16 +55,18 @@ func (round *round2) CanAccept(msg tss.ParsedMessage) bool { } func (round *round2) Update() (bool, *tss.Error) { + ret := true for j, msg := range round.temp.signRound2Messages { if round.ok[j] { continue } if msg == nil || !round.CanAccept(msg) { - return false, nil + ret = false + continue } round.ok[j] = true } - return true, nil + return ret, nil } func (round *round2) NextRound() tss.Round { diff --git a/eddsa/signing/round_3.go b/eddsa/signing/round_3.go index 715c3a73..b2567f54 100644 --- a/eddsa/signing/round_3.go +++ b/eddsa/signing/round_3.go @@ -104,16 +104,18 @@ func (round *round3) Start() *tss.Error { } func (round *round3) Update() (bool, *tss.Error) { + ret := true for j, msg := range round.temp.signRound3Messages { if round.ok[j] { continue } if msg == nil || !round.CanAccept(msg) { - return false, nil + ret = false + continue } round.ok[j] = true } - return true, nil + return ret, nil } func (round *round3) CanAccept(msg tss.ParsedMessage) bool {