Skip to content

Commit c58e4b5

Browse files
Gustavo Fredericocreamwhip
authored andcommitted
Additional check when Ks mismatch in savedata and sortedID
1 parent b401af0 commit c58e4b5

File tree

4 files changed

+15
-6
lines changed

4 files changed

+15
-6
lines changed

ecdsa/keygen/save_data.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ package keygen
88

99
import (
1010
"encoding/hex"
11+
"errors"
1112
"math/big"
1213

13-
"github.com/binance-chain/tss-lib/common"
1414
"github.com/binance-chain/tss-lib/crypto"
1515
"github.com/binance-chain/tss-lib/crypto/paillier"
1616
"github.com/binance-chain/tss-lib/ecdsa"
@@ -100,7 +100,7 @@ func BuildLocalSaveDataSubset(sourceData LocalPartySaveData, sortedIDs tss.Sorte
100100
keyAndShift := new(big.Int).Add(idKey, reshareKeyOffset)
101101
savedIdx, ok := keysToIndices[hex.EncodeToString(keyAndShift.Bytes())]
102102
if !ok {
103-
common.Logger.Warn("BuildLocalSaveDataSubset: unable to find a signer party in the local save data", id)
103+
panic(errors.New("BuildLocalSaveDataSubset: unable to find a signer party in the local save data"))
104104
}
105105
newData.Ks[j] = sourceData.Ks[savedIdx]
106106
newData.NTildej[j] = sourceData.NTildej[savedIdx]

ecdsa/signing/prepare.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,13 @@ func PrepareForSigning(i, pax int, xi *big.Int, ks []*big.Int, bigXs []*crypto.E
3434
if j == i {
3535
continue
3636
}
37+
ksj := ks[j]
38+
ksi := ks[i]
39+
if ksj.Cmp(ksi) == 0 {
40+
panic(fmt.Errorf("index of two parties are equal"))
41+
}
3742
// big.Int Div is calculated as: a/b = a * modInv(b,q)
38-
coef := modQ.Mul(ks[j], modQ.Inverse(new(big.Int).Sub(ks[j], ks[i])))
43+
coef := modQ.Mul(ks[j], modQ.Inverse(new(big.Int).Sub(ksj, ksi)))
3944
wi = modQ.Mul(wi, coef)
4045
}
4146

eddsa/keygen/save_data.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"encoding/hex"
1111
"math/big"
1212

13-
"github.com/binance-chain/tss-lib/common"
1413
"github.com/binance-chain/tss-lib/crypto"
1514
"github.com/binance-chain/tss-lib/tss"
1615
)
@@ -54,7 +53,7 @@ func BuildLocalSaveDataSubset(sourceData LocalPartySaveData, sortedIDs tss.Sorte
5453
for j, id := range sortedIDs {
5554
savedIdx, ok := keysToIndices[hex.EncodeToString(id.Key)]
5655
if !ok {
57-
common.Logger.Warn("BuildLocalSaveDataSubset: unable to find a signer party in the local save data", id)
56+
panic("BuildLocalSaveDataSubset: unable to find a signer party in the local save data")
5857
}
5958
newData.Ks[j] = sourceData.Ks[savedIdx]
6059
newData.BigXj[j] = sourceData.BigXj[savedIdx]

eddsa/signing/prepare.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,13 @@ func PrepareForSigning(i, pax int, xi *big.Int, ks []*big.Int) (wi *big.Int) {
3030
if j == i {
3131
continue
3232
}
33+
ksj := ks[j]
34+
ksi := ks[i]
35+
if ksj.Cmp(ksi) == 0 {
36+
panic(fmt.Errorf("index of two parties are equal"))
37+
}
3338
// big.Int Div is calculated as: a/b = a * modInv(b,q)
34-
coef := modQ.Mul(ks[j], modQ.Inverse(new(big.Int).Sub(ks[j], ks[i])))
39+
coef := modQ.Mul(ks[j], modQ.Inverse(new(big.Int).Sub(ksj, ksi)))
3540
wi = modQ.Mul(wi, coef)
3641
}
3742

0 commit comments

Comments
 (0)