@@ -135,6 +135,119 @@ func (s *CCVTestSuite) TestGetByzantineValidators() {
135
135
nil ,
136
136
false ,
137
137
},
138
+ {
139
+ "incorrect valset - shouldn't pass" ,
140
+ func () * ibctmtypes.Misbehaviour {
141
+ clientHeader := s .consumerChain .CreateTMClientHeader (
142
+ s .consumerChain .ChainID ,
143
+ int64 (clientHeight .RevisionHeight + 1 ),
144
+ clientHeight ,
145
+ altTime .Add (time .Minute ),
146
+ clientTMValset ,
147
+ clientTMValset ,
148
+ clientTMValset ,
149
+ clientSigners ,
150
+ )
151
+
152
+ clientHeaderWithCorruptedValset := s .consumerChain .CreateTMClientHeader (
153
+ s .consumerChain .ChainID ,
154
+ int64 (clientHeight .RevisionHeight + 1 ),
155
+ clientHeight ,
156
+ altTime .Add (time .Hour ),
157
+ clientTMValset ,
158
+ clientTMValset ,
159
+ clientTMValset ,
160
+ clientSigners ,
161
+ )
162
+
163
+ // change a validator public key in one the second header
164
+ testutil .CorruptValidatorPubkeyInHeader (clientHeaderWithCorruptedValset , clientTMValset .Validators [0 ].Address )
165
+
166
+ return & ibctmtypes.Misbehaviour {
167
+ ClientId : s .path .EndpointA .ClientID ,
168
+ Header1 : clientHeader ,
169
+ Header2 : clientHeaderWithCorruptedValset ,
170
+ }
171
+ },
172
+ []* tmtypes.Validator {},
173
+ false ,
174
+ },
175
+ {
176
+ "incorrect valset 2 - shouldn't pass" ,
177
+ func () * ibctmtypes.Misbehaviour {
178
+ clientHeader := s .consumerChain .CreateTMClientHeader (
179
+ s .consumerChain .ChainID ,
180
+ int64 (clientHeight .RevisionHeight + 1 ),
181
+ clientHeight ,
182
+ altTime .Add (time .Minute ),
183
+ clientTMValset ,
184
+ clientTMValset ,
185
+ clientTMValset ,
186
+ clientSigners ,
187
+ )
188
+
189
+ clientHeaderWithCorruptedSigs := s .consumerChain .CreateTMClientHeader (
190
+ s .consumerChain .ChainID ,
191
+ int64 (clientHeight .RevisionHeight + 1 ),
192
+ clientHeight ,
193
+ altTime .Add (time .Hour ),
194
+ clientTMValset ,
195
+ clientTMValset ,
196
+ clientTMValset ,
197
+ clientSigners ,
198
+ )
199
+
200
+ // change the valset in the header
201
+ vs , _ := altValset .ToProto ()
202
+ clientHeader .ValidatorSet .Validators = vs .Validators [:3 ]
203
+ clientHeaderWithCorruptedSigs .ValidatorSet .Validators = vs .Validators [:3 ]
204
+
205
+ return & ibctmtypes.Misbehaviour {
206
+ ClientId : s .path .EndpointA .ClientID ,
207
+ Header1 : clientHeader ,
208
+ Header2 : clientHeaderWithCorruptedSigs ,
209
+ }
210
+ },
211
+ []* tmtypes.Validator {},
212
+ false ,
213
+ },
214
+ {
215
+ "incorrect signatures - shouldn't pass" ,
216
+ func () * ibctmtypes.Misbehaviour {
217
+ clientHeader := s .consumerChain .CreateTMClientHeader (
218
+ s .consumerChain .ChainID ,
219
+ int64 (clientHeight .RevisionHeight + 1 ),
220
+ clientHeight ,
221
+ altTime .Add (time .Minute ),
222
+ clientTMValset ,
223
+ clientTMValset ,
224
+ clientTMValset ,
225
+ clientSigners ,
226
+ )
227
+
228
+ clientHeaderWithCorruptedSigs := s .consumerChain .CreateTMClientHeader (
229
+ s .consumerChain .ChainID ,
230
+ int64 (clientHeight .RevisionHeight + 1 ),
231
+ clientHeight ,
232
+ altTime .Add (time .Hour ),
233
+ clientTMValset ,
234
+ clientTMValset ,
235
+ clientTMValset ,
236
+ clientSigners ,
237
+ )
238
+
239
+ // change the signature of one of the validator in the header
240
+ testutil .CorruptCommitSigsInHeader (clientHeaderWithCorruptedSigs , clientTMValset .Validators [0 ].Address )
241
+
242
+ return & ibctmtypes.Misbehaviour {
243
+ ClientId : s .path .EndpointA .ClientID ,
244
+ Header1 : clientHeader ,
245
+ Header2 : clientHeaderWithCorruptedSigs ,
246
+ }
247
+ },
248
+ []* tmtypes.Validator {},
249
+ false ,
250
+ },
138
251
{
139
252
"light client attack - lunatic attack" ,
140
253
func () * ibctmtypes.Misbehaviour {
@@ -212,43 +325,6 @@ func (s *CCVTestSuite) TestGetByzantineValidators() {
212
325
[]* tmtypes.Validator {},
213
326
true ,
214
327
},
215
- {
216
- "validators who did vote nil should not be returned" ,
217
- func () * ibctmtypes.Misbehaviour {
218
- clientHeader := s .consumerChain .CreateTMClientHeader (
219
- s .consumerChain .ChainID ,
220
- int64 (clientHeight .RevisionHeight + 1 ),
221
- clientHeight ,
222
- altTime .Add (time .Minute ),
223
- clientTMValset ,
224
- clientTMValset ,
225
- clientTMValset ,
226
- clientSigners ,
227
- )
228
-
229
- // create conflicting header with 2/4 validators voting nil
230
- clientHeaderWithNilVotes := s .consumerChain .CreateTMClientHeader (
231
- s .consumerChain .ChainID ,
232
- int64 (clientHeight .RevisionHeight + 1 ),
233
- clientHeight ,
234
- altTime .Add (time .Hour ),
235
- clientTMValset ,
236
- clientTMValset ,
237
- clientTMValset ,
238
- clientSigners ,
239
- )
240
- testutil .UpdateHeaderCommitWithNilVotes (clientHeaderWithNilVotes , clientTMValset .Validators [:2 ])
241
-
242
- return & ibctmtypes.Misbehaviour {
243
- ClientId : s .path .EndpointA .ClientID ,
244
- Header1 : clientHeader ,
245
- Header2 : clientHeaderWithNilVotes ,
246
- }
247
- },
248
- // Expect validators who did NOT vote nil
249
- clientTMValset .Validators [2 :],
250
- true ,
251
- },
252
328
}
253
329
254
330
for _ , tc := range testCases {
@@ -262,7 +338,7 @@ func (s *CCVTestSuite) TestGetByzantineValidators() {
262
338
s .Equal (len (tc .expByzantineValidators ), len (byzantineValidators ))
263
339
264
340
// For both lunatic and equivocation attacks, all the validators
265
- // who signed both headers and didn't vote nil should be returned
341
+ // who signed both headers
266
342
if len (tc .expByzantineValidators ) > 0 {
267
343
expValset := tmtypes .NewValidatorSet (tc .expByzantineValidators )
268
344
s .NoError (err )
@@ -299,10 +375,15 @@ func (s *CCVTestSuite) TestCheckMisbehaviour() {
299
375
300
376
// create an alternative validator set using more than 1/3 of the trusted validator set
301
377
altValset := tmtypes .NewValidatorSet (s .consumerChain .Vals .Validators [0 :2 ])
302
- altSigners := make (map [string ]tmtypes.PrivValidator , 1 )
378
+ altSigners := make (map [string ]tmtypes.PrivValidator , 2 )
303
379
altSigners [clientTMValset .Validators [0 ].Address .String ()] = clientSigners [clientTMValset .Validators [0 ].Address .String ()]
304
380
altSigners [clientTMValset .Validators [1 ].Address .String ()] = clientSigners [clientTMValset .Validators [1 ].Address .String ()]
305
381
382
+ // create an alternative validator set using less than 1/3 of the trusted validator set
383
+ altValset2 := tmtypes .NewValidatorSet (s .consumerChain .Vals .Validators [0 :1 ])
384
+ altSigners2 := make (map [string ]tmtypes.PrivValidator , 1 )
385
+ altSigners2 [clientTMValset .Validators [0 ].Address .String ()] = clientSigners [clientTMValset .Validators [0 ].Address .String ()]
386
+
306
387
clientHeader := s .consumerChain .CreateTMClientHeader (
307
388
s .consumerChain .ChainID ,
308
389
int64 (clientHeight .RevisionHeight + 1 ),
@@ -315,19 +396,17 @@ func (s *CCVTestSuite) TestCheckMisbehaviour() {
315
396
)
316
397
317
398
// create a conflicting client header with insufficient voting power
318
- // by changing 3/4 of its validators votes to nil
319
- clientHeaderWithNilVotes := s .consumerChain .CreateTMClientHeader (
399
+ clientHeader2 := s .consumerChain .CreateTMClientHeader (
320
400
s .consumerChain .ChainID ,
321
401
int64 (clientHeight .RevisionHeight + 1 ),
322
402
clientHeight ,
323
403
// use a different block time to change the header BlockID
324
404
headerTs .Add (time .Hour ),
405
+ altValset2 ,
406
+ altValset2 ,
325
407
clientTMValset ,
326
- clientTMValset ,
327
- clientTMValset ,
328
- clientSigners ,
408
+ altSigners2 ,
329
409
)
330
- testutil .UpdateHeaderCommitWithNilVotes (clientHeaderWithNilVotes , clientTMValset .Validators [:4 ])
331
410
332
411
testCases := []struct {
333
412
name string
@@ -402,7 +481,7 @@ func (s *CCVTestSuite) TestCheckMisbehaviour() {
402
481
& ibctmtypes.Misbehaviour {
403
482
ClientId : s .path .EndpointA .ClientID ,
404
483
Header1 : clientHeader ,
405
- Header2 : clientHeaderWithNilVotes ,
484
+ Header2 : clientHeader2 ,
406
485
},
407
486
false ,
408
487
},
0 commit comments