Skip to content

Commit 40f6b25

Browse files
committed
clippy
1 parent 862d20e commit 40f6b25

File tree

2 files changed

+47
-47
lines changed

2 files changed

+47
-47
lines changed

nym-validator-rewarder/build.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
// Copyright 2023 - Nym Technologies SA <[email protected]>
22
// SPDX-License-Identifier: GPL-3.0-only
33

4+
// it's fine if compilation fails
5+
#[allow(clippy::unwrap_used)]
6+
#[allow(clippy::expect_used)]
47
#[tokio::main]
58
async fn main() {
69
use sqlx::{Connection, SqliteConnection};

nym-validator-rewarder/src/rewarder/ticketbook_issuance/verifier.rs

+44-47
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use nym_validator_client::ecash::models::{
1616
CommitedDeposit, DepositId, IssuedTicketbooksChallengeCommitmentResponse,
1717
IssuedTicketbooksDataRequestBody, IssuedTicketbooksDataResponse,
1818
IssuedTicketbooksDataResponseBody, IssuedTicketbooksForResponse, SignableMessageBody,
19+
SignedMessage,
1920
};
2021
use nym_validator_client::nyxd::AccountId;
2122
use rand::distributions::{Distribution, WeightedIndex};
@@ -175,6 +176,21 @@ impl IssuerUnderTest {
175176
})
176177
}
177178

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+
178194
async fn get_ticketbooks_data(
179195
&mut self,
180196
signing_key: &ed25519::PrivateKey,
@@ -241,16 +257,7 @@ impl IssuerUnderTest {
241257
}
242258

243259
// 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) {
254261
return;
255262
}
256263

@@ -271,7 +278,7 @@ impl IssuerUnderTest {
271278
if !data_response
272279
.body
273280
.partial_ticketbooks
274-
.contains_key(&deposit_id)
281+
.contains_key(deposit_id)
275282
{
276283
let evidence = self.produce_cheating_evidence(data_response);
277284
self.set_banned_issuer(
@@ -329,7 +336,7 @@ impl IssuerUnderTest {
329336
}
330337
};
331338

332-
// verify the signature on the response
339+
// 1. check if the signature on the response matches
333340
if !issued_ticketbooks.verify_signature(&self.details.public_key) {
334341
let evidence = self.produce_basic_cheating_evidence();
335342
self.set_banned_issuer(
@@ -339,27 +346,29 @@ impl IssuerUnderTest {
339346
return;
340347
}
341348

349+
// 2. check if the signature on original request still matches
350+
if self.ban_if_tampered_request(&issued_ticketbooks) {
351+
return;
352+
}
353+
342354
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;
353366
}
354367

355368
self.issued_commitment = Some(issued_ticketbooks)
356369
}
357370

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) {
363372
// no point in continuing
364373
if self.caught_cheating() {
365374
return;
@@ -422,16 +431,7 @@ impl IssuerUnderTest {
422431
}
423432

424433
// 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) {
435435
return;
436436
}
437437

@@ -463,13 +463,12 @@ impl IssuerUnderTest {
463463

464464
// 6.2. check if the provided merkle proof has the same number of deposits as initially committed to
465465
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;
473472
}
474473

475474
self.challenge_commitment_response = Some(challenge_commitment)
@@ -792,9 +791,7 @@ impl<'a> TicketbookIssuanceVerifier<'a> {
792791

793792
// 5. issue the challenge to the issuer (if applicable) and get its commitment to the response
794793
// 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;
798795

799796
// 6. retrieve binary data of ticketbooks corresponding to the original challenge
800797
issuer

0 commit comments

Comments
 (0)