@@ -9,6 +9,7 @@ package signing
9
9
import (
10
10
"crypto/ecdsa"
11
11
"crypto/rand"
12
+ "encoding/hex"
12
13
"fmt"
13
14
"math/big"
14
15
"runtime"
@@ -56,11 +57,9 @@ func TestE2EConcurrent(t *testing.T) {
56
57
endCh := make (chan * common.SignatureData , len (signPIDs ))
57
58
58
59
updater := test .SharedPartyUpdater
59
-
60
60
// init the parties
61
61
for i := 0 ; i < len (signPIDs ); i ++ {
62
62
params := tss .NewParameters (tss .S256 (), p2pCtx , signPIDs [i ], len (signPIDs ), threshold )
63
-
64
63
P := NewLocalParty (big .NewInt (42 ), params , keys [i ], outCh , endCh ).(* LocalParty )
65
64
parties = append (parties , P )
66
65
go func (P * LocalParty ) {
@@ -132,6 +131,101 @@ signing:
132
131
}
133
132
}
134
133
134
+ func TestE2EConcurrentWithLeadingZeroInMSG (t * testing.T ) {
135
+ setUp ("info" )
136
+ threshold := testThreshold
137
+
138
+ // PHASE: load keygen fixtures
139
+ keys , signPIDs , err := keygen .LoadKeygenTestFixturesRandomSet (testThreshold + 1 , testParticipants )
140
+ assert .NoError (t , err , "should load keygen fixtures" )
141
+ assert .Equal (t , testThreshold + 1 , len (keys ))
142
+ assert .Equal (t , testThreshold + 1 , len (signPIDs ))
143
+
144
+ // PHASE: signing
145
+ // use a shuffled selection of the list of parties for this test
146
+ p2pCtx := tss .NewPeerContext (signPIDs )
147
+ parties := make ([]* LocalParty , 0 , len (signPIDs ))
148
+
149
+ errCh := make (chan * tss.Error , len (signPIDs ))
150
+ outCh := make (chan tss.Message , len (signPIDs ))
151
+ endCh := make (chan * common.SignatureData , len (signPIDs ))
152
+
153
+ updater := test .SharedPartyUpdater
154
+ msgData , _ := hex .DecodeString ("00f163ee51bcaeff9cdff5e0e3c1a646abd19885fffbab0b3b4236e0cf95c9f5" )
155
+ // init the parties
156
+ for i := 0 ; i < len (signPIDs ); i ++ {
157
+ params := tss .NewParameters (tss .S256 (), p2pCtx , signPIDs [i ], len (signPIDs ), threshold )
158
+ P := NewLocalParty (new (big.Int ).SetBytes (msgData ), params , keys [i ], outCh , endCh , len (msgData )).(* LocalParty )
159
+ parties = append (parties , P )
160
+ go func (P * LocalParty ) {
161
+ if err := P .Start (); err != nil {
162
+ errCh <- err
163
+ }
164
+ }(P )
165
+ }
166
+
167
+ var ended int32
168
+ signing:
169
+ for {
170
+ fmt .Printf ("ACTIVE GOROUTINES: %d\n " , runtime .NumGoroutine ())
171
+ select {
172
+ case err := <- errCh :
173
+ common .Logger .Errorf ("Error: %s" , err )
174
+ assert .FailNow (t , err .Error ())
175
+ break signing
176
+
177
+ case msg := <- outCh :
178
+ dest := msg .GetTo ()
179
+ if dest == nil {
180
+ for _ , P := range parties {
181
+ if P .PartyID ().Index == msg .GetFrom ().Index {
182
+ continue
183
+ }
184
+ go updater (P , msg , errCh )
185
+ }
186
+ } else {
187
+ if dest [0 ].Index == msg .GetFrom ().Index {
188
+ t .Fatalf ("party %d tried to send a message to itself (%d)" , dest [0 ].Index , msg .GetFrom ().Index )
189
+ }
190
+ go updater (parties [dest [0 ].Index ], msg , errCh )
191
+ }
192
+
193
+ case <- endCh :
194
+ atomic .AddInt32 (& ended , 1 )
195
+ if atomic .LoadInt32 (& ended ) == int32 (len (signPIDs )) {
196
+ t .Logf ("Done. Received signature data from %d participants" , ended )
197
+ R := parties [0 ].temp .bigR
198
+ r := parties [0 ].temp .rx
199
+ fmt .Printf ("sign result: R(%s, %s), r=%s\n " , R .X ().String (), R .Y ().String (), r .String ())
200
+
201
+ modN := common .ModInt (tss .S256 ().Params ().N )
202
+
203
+ // BEGIN check s correctness
204
+ sumS := big .NewInt (0 )
205
+ for _ , p := range parties {
206
+ sumS = modN .Add (sumS , p .temp .si )
207
+ }
208
+ fmt .Printf ("S: %s\n " , sumS .String ())
209
+ // END check s correctness
210
+
211
+ // BEGIN ECDSA verify
212
+ pkX , pkY := keys [0 ].ECDSAPub .X (), keys [0 ].ECDSAPub .Y ()
213
+ pk := ecdsa.PublicKey {
214
+ Curve : tss .EC (),
215
+ X : pkX ,
216
+ Y : pkY ,
217
+ }
218
+ ok := ecdsa .Verify (& pk , msgData , R .X (), sumS )
219
+ assert .True (t , ok , "ecdsa verify must pass" )
220
+ t .Log ("ECDSA signing test done." )
221
+ // END ECDSA verify
222
+
223
+ break signing
224
+ }
225
+ }
226
+ }
227
+ }
228
+
135
229
func TestE2EWithHDKeyDerivation (t * testing.T ) {
136
230
setUp ("info" )
137
231
threshold := testThreshold
@@ -170,7 +264,7 @@ func TestE2EWithHDKeyDerivation(t *testing.T) {
170
264
for i := 0 ; i < len (signPIDs ); i ++ {
171
265
params := tss .NewParameters (tss .S256 (), p2pCtx , signPIDs [i ], len (signPIDs ), threshold )
172
266
173
- P := NewLocalPartyWithKDD (big .NewInt (42 ), params , keys [i ], keyDerivationDelta , outCh , endCh ).(* LocalParty )
267
+ P := NewLocalPartyWithKDD (big .NewInt (42 ), params , keys [i ], keyDerivationDelta , outCh , endCh , 0 ).(* LocalParty )
174
268
parties = append (parties , P )
175
269
go func (P * LocalParty ) {
176
270
if err := P .Start (); err != nil {
0 commit comments