Skip to content

Commit

Permalink
Merge branch 'master' into pull-out-random
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhAnGeek committed Jan 12, 2024
2 parents 8abf1d5 + f67a429 commit 6c233c6
Show file tree
Hide file tree
Showing 26 changed files with 115 additions and 58 deletions.
2 changes: 1 addition & 1 deletion common/random.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func GetRandomPositiveInt(rand io.Reader, lessThan *big.Int) *big.Int {
var try *big.Int
for {
try = MustGetRandomInt(rand, lessThan.BitLen())
if try.Cmp(lessThan) < 0 && try.Cmp(zero) >= 0 {
if try.Cmp(lessThan) < 0 {
break
}
}
Expand Down
4 changes: 2 additions & 2 deletions common/safe_prime.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func GetRandomSafePrimesConcurrent(ctx context.Context, bitLen, numPrimes int, c
}

primeCh := make(chan *GermainSafePrime, concurrency*numPrimes)
errCh := make(chan error, concurrency*numPrimes)
errCh := make(chan error, concurrency)
primes := make([]*GermainSafePrime, 0, numPrimes)

waitGroup := &sync.WaitGroup{}
Expand Down Expand Up @@ -193,7 +193,7 @@ func GetRandomSafePrimesConcurrent(ctx context.Context, bitLen, numPrimes int, c
// `q` in point 2. If `p` is not coprime to at least one element of the
// `smallPrimes`, then go back to point 1.
// If `p` is coprime to all the elements of `smallPrimes`, go to point 5.
// 5. At this point, we know `q` is potentially prime, and `p=q+1` is also
// 5. At this point, we know `q` is potentially prime, and `p=2q+1` is also
// potentially prime. We need to execute a final primality test for `q`.
// We apply Miller-Rabin and Baillie-PSW tests. If they succeed, it means
// that `q` is prime with a very high probability. Knowing `q` is prime,
Expand Down
2 changes: 1 addition & 1 deletion crypto/vss/feldman_vss.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func Create(ec elliptic.Curve, threshold int, secret *big.Int, indexes []*big.In
}

poly := samplePolynomial(ec, threshold, secret, rand)
poly[0] = secret // becomes sigma*G in v

v := make(Vs, len(poly))
for i, ai := range poly {
v[i] = crypto.ScalarBaseMult(ec, ai)
Expand Down
6 changes: 4 additions & 2 deletions ecdsa/keygen/round_1.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,17 +139,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 {
Expand Down
9 changes: 6 additions & 3 deletions ecdsa/keygen/round_2.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
11 changes: 6 additions & 5 deletions ecdsa/keygen/round_3.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,9 @@ func (round *round3) Start() *tss.Error {
var multiErr error
if len(culprits) > 0 {
for _, vssResult := range vssResults {
if vssResult.unWrappedErr == nil {
continue
if vssResult.unWrappedErr != nil {
multiErr = multierror.Append(multiErr, vssResult.unWrappedErr)
}
multiErr = multierror.Append(multiErr, vssResult.unWrappedErr)
}
return round.WrapError(multiErr, culprits...)
}
Expand Down Expand Up @@ -229,17 +228,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 {
Expand Down
10 changes: 8 additions & 2 deletions ecdsa/resharing/round_1_old_step_1.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,16 +98,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 {
Expand All @@ -120,7 +126,7 @@ func (round *round1) Update() (bool, *tss.Error) {
}
round.save.ECDSAPub = candidate
}
return true, nil
return ret, nil
}

func (round *round1) NextRound() tss.Round {
Expand Down
15 changes: 10 additions & 5 deletions ecdsa/resharing/round_2_new_step_1.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,19 +132,22 @@ 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 {
if round.newOK[j] {
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
}
Expand All @@ -155,7 +158,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
}
Expand All @@ -166,14 +170,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 {
Expand Down
6 changes: 4 additions & 2 deletions ecdsa/signing/round_2.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,16 +124,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 {
Expand Down
6 changes: 4 additions & 2 deletions ecdsa/signing/round_3.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 4 additions & 2 deletions ecdsa/signing/round_4.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 4 additions & 2 deletions ecdsa/signing/round_5.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 4 additions & 2 deletions ecdsa/signing/round_6.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 4 additions & 2 deletions ecdsa/signing/round_7.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 4 additions & 2 deletions ecdsa/signing/round_8.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 4 additions & 2 deletions ecdsa/signing/round_9.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 4 additions & 2 deletions eddsa/keygen/round_1.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,17 +95,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 {
Expand Down
Loading

0 comments on commit 6c233c6

Please sign in to comment.