@@ -16,6 +16,7 @@ use nym_validator_client::ecash::models::{
16
16
CommitedDeposit , DepositId , IssuedTicketbooksChallengeCommitmentResponse ,
17
17
IssuedTicketbooksDataRequestBody , IssuedTicketbooksDataResponse ,
18
18
IssuedTicketbooksDataResponseBody , IssuedTicketbooksForResponse , SignableMessageBody ,
19
+ SignedMessage ,
19
20
} ;
20
21
use nym_validator_client:: nyxd:: AccountId ;
21
22
use rand:: distributions:: { Distribution , WeightedIndex } ;
@@ -175,6 +176,21 @@ impl IssuerUnderTest {
175
176
} )
176
177
}
177
178
179
+ // returns bool to indicate if the issuer got banned
180
+ fn ban_if_tampered_request < T > ( & mut self , original_request : & SignedMessage < T > ) -> bool
181
+ where
182
+ T : SignableMessageBody ,
183
+ {
184
+ if !original_request. verify_signature ( & self . rewarder_pubkey ) {
185
+ let evidence = self . produce_cheating_evidence ( TamperedOriginalRequest {
186
+ signed_response : original_request,
187
+ } ) ;
188
+ self . set_banned_issuer ( "original request body was tampered with" , evidence) ;
189
+ return true ;
190
+ }
191
+ false
192
+ }
193
+
178
194
async fn get_ticketbooks_data (
179
195
& mut self ,
180
196
signing_key : & ed25519:: PrivateKey ,
@@ -241,16 +257,7 @@ impl IssuerUnderTest {
241
257
}
242
258
243
259
// 2. check if the signature on original request still matches
244
- if !data_response
245
- . body
246
- . original_request
247
- . verify_signature ( & self . rewarder_pubkey )
248
- {
249
- // if the message on the actual response matches, then we know they must have messed with the inner content
250
- let evidence = self . produce_cheating_evidence ( TamperedOriginalRequest {
251
- signed_response : data_response,
252
- } ) ;
253
- self . set_banned_issuer ( "original request body was tampered with" , evidence) ;
260
+ if self . ban_if_tampered_request ( & data_response) {
254
261
return ;
255
262
}
256
263
@@ -271,7 +278,7 @@ impl IssuerUnderTest {
271
278
if !data_response
272
279
. body
273
280
. partial_ticketbooks
274
- . contains_key ( & deposit_id)
281
+ . contains_key ( deposit_id)
275
282
{
276
283
let evidence = self . produce_cheating_evidence ( data_response) ;
277
284
self . set_banned_issuer (
@@ -329,7 +336,7 @@ impl IssuerUnderTest {
329
336
}
330
337
} ;
331
338
332
- // verify the signature on the response
339
+ // 1. check if the signature on the response matches
333
340
if !issued_ticketbooks. verify_signature ( & self . details . public_key ) {
334
341
let evidence = self . produce_basic_cheating_evidence ( ) ;
335
342
self . set_banned_issuer (
@@ -339,27 +346,29 @@ impl IssuerUnderTest {
339
346
return ;
340
347
}
341
348
349
+ // 2. check if the signature on original request still matches
350
+ if self . ban_if_tampered_request ( & issued_ticketbooks) {
351
+ return ;
352
+ }
353
+
342
354
if expiration_date != issued_ticketbooks. body . expiration_date {
343
- todo ! ( "include response in evidence" ) ;
344
- // let evidence = self.produce_cheating_evidence(MismatchResponse {
345
- // requested: expiration_date,
346
- // received: issued_ticketbooks.body.expiration_date,
347
- // });
348
- // self.set_banned_issuer(
349
- // format!("bad ticketbook commitments for {expiration_date}"),
350
- // evidence,
351
- // );
352
- // return;
355
+ // we know our request wasn't tampered with, so the issuer simply returned data for wrong date
356
+ let evidence = self . produce_cheating_evidence ( MismatchResponse {
357
+ requested : expiration_date,
358
+ received : issued_ticketbooks. body . expiration_date ,
359
+ signed_response : issued_ticketbooks,
360
+ } ) ;
361
+ self . set_banned_issuer (
362
+ format ! ( "bad ticketbooks data for {expiration_date}" ) ,
363
+ evidence,
364
+ ) ;
365
+ return ;
353
366
}
354
367
355
368
self . issued_commitment = Some ( issued_ticketbooks)
356
369
}
357
370
358
- async fn issue_deposit_challenge (
359
- & mut self ,
360
- expiration_date : Date ,
361
- rewarder_pubkey : ed25519:: PublicKey ,
362
- ) {
371
+ async fn issue_deposit_challenge ( & mut self , expiration_date : Date ) {
363
372
// no point in continuing
364
373
if self . caught_cheating ( ) {
365
374
return ;
@@ -422,16 +431,7 @@ impl IssuerUnderTest {
422
431
}
423
432
424
433
// 4. check if the signature on original request still matches
425
- if !challenge_commitment
426
- . body
427
- . original_request
428
- . verify_signature ( & rewarder_pubkey)
429
- {
430
- // if the message on the actual response matches, then we know they must have messed with the inner content
431
- let evidence = self . produce_cheating_evidence ( TamperedOriginalRequest {
432
- signed_response : challenge_commitment,
433
- } ) ;
434
- self . set_banned_issuer ( "original request body was tampered with" , evidence) ;
434
+ if !self . ban_if_tampered_request ( & challenge_commitment) {
435
435
return ;
436
436
}
437
437
@@ -463,13 +463,12 @@ impl IssuerUnderTest {
463
463
464
464
// 6.2. check if the provided merkle proof has the same number of deposits as initially committed to
465
465
if merkle_proof. total_leaves ( ) != sampled. len ( ) {
466
- todo ! ( )
467
- // let evidence = self.produce_cheating_evidence(MismatchClaim {
468
- // actual: merkle_proof.total_leaves(),
469
- // claimed: issued.body.deposits.len(),
470
- // });
471
- // self.set_banned_issuer("inconsistent number of merkle leaves", evidence);
472
- // return;
466
+ let evidence = self . produce_basic_cheating_evidence ( ) ;
467
+ self . set_banned_issuer (
468
+ format ! ( "invalid merkle proof for {expiration_date} - {} leaves present whilst {} deposits got sampled" , merkle_proof. total_leaves( ) , sampled. len( ) ) ,
469
+ evidence,
470
+ ) ;
471
+ return ;
473
472
}
474
473
475
474
self . challenge_commitment_response = Some ( challenge_commitment)
@@ -792,9 +791,7 @@ impl<'a> TicketbookIssuanceVerifier<'a> {
792
791
793
792
// 5. issue the challenge to the issuer (if applicable) and get its commitment to the response
794
793
// that includes the merkle proof to our sampled deposits
795
- issuer
796
- . issue_deposit_challenge ( self . expiration_date , * self . rewarder_keypair . public_key ( ) )
797
- . await ;
794
+ issuer. issue_deposit_challenge ( self . expiration_date ) . await ;
798
795
799
796
// 6. retrieve binary data of ticketbooks corresponding to the original challenge
800
797
issuer
0 commit comments