From 73ef0f8c0871c16f71d6f3e40fb3402a47585615 Mon Sep 17 00:00:00 2001 From: Ben Savage Date: Thu, 28 Mar 2024 13:19:06 +0800 Subject: [PATCH] clippy --- .../ipa_prf/malicious_security/hashing.rs | 14 ++++++++++++-- .../ipa_prf/malicious_security/prover.rs | 16 ++++++++-------- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/ipa-core/src/protocol/ipa_prf/malicious_security/hashing.rs b/ipa-core/src/protocol/ipa_prf/malicious_security/hashing.rs index f91c881ac..4d490f318 100644 --- a/ipa-core/src/protocol/ipa_prf/malicious_security/hashing.rs +++ b/ipa-core/src/protocol/ipa_prf/malicious_security/hashing.rs @@ -115,8 +115,18 @@ mod test { ); // swapping two elements should change the hash - let index_1 = rng.gen_range(0..LIST_LENGTH); - let index_2 = (index_1 + rng.gen_range(1..LIST_LENGTH)) % LIST_LENGTH; + let mut index_1 = 0; + let mut index_2 = 0; + // There is a 1 in 31 chance that these two elements are the exact same value. + // To make sure this doesn't become a flaky test, let's just pick two different + // elements to swap when that happens. + // This will be an infinite loop if all elements are the same. The chances of that + // are (1 / 31) ^ (LIST_LENGTH - 1) + // which is 1 in 923,521 when LIST_LENGTH is 5. I'm OK with that. + while list[index_1] == list[index_2] { + index_1 = rng.gen_range(0..LIST_LENGTH); + index_2 = (index_1 + rng.gen_range(1..LIST_LENGTH)) % LIST_LENGTH; + } list.swap(index_1, index_2); let hash_3 = compute_hash(&list); diff --git a/ipa-core/src/protocol/ipa_prf/malicious_security/prover.rs b/ipa-core/src/protocol/ipa_prf/malicious_security/prover.rs index b8c566bbb..175b3d977 100644 --- a/ipa-core/src/protocol/ipa_prf/malicious_security/prover.rs +++ b/ipa-core/src/protocol/ipa_prf/malicious_security/prover.rs @@ -46,7 +46,7 @@ pub type TwoNPlusOne = Sum, U1>; /// Distributed Zero Knowledge Proofs algorithm drawn from /// `https://eprint.iacr.org/2023/909.pdf` /// -#[allow(non_camel_case_types)] +#[allow(non_camel_case_types, clippy::many_single_char_names)] impl ProofGenerator where F: PrimeField, @@ -57,8 +57,8 @@ where } pub fn gen_challenge_and_recurse<λ: ArrayLength, I, J>( - proof_left: GenericArray>, - proof_right: GenericArray>, + proof_left: &GenericArray>, + proof_right: &GenericArray>, u: I, v: J, ) -> ProofGenerator @@ -84,7 +84,7 @@ where "When the output is this small, you should validate the proof with a more straightforward reveal" ); - let r: F = hash_to_field(&compute_hash(&proof_left), &compute_hash(&proof_right)); + let r: F = hash_to_field(&compute_hash(proof_left), &compute_hash(proof_right)); let mut p = GenericArray::::generate(|_| F::ZERO); let mut q = GenericArray::::generate(|_| F::ZERO); let denominator = CanonicalLagrangeDenominator::::new(); @@ -277,8 +277,8 @@ mod test { // fiat-shamir let pg_2 = ProofGenerator::gen_challenge_and_recurse::( - proof_left_1, - proof_right_1, + &proof_left_1, + &proof_right_1, U_1.into_iter().map(|x| Fp31::try_from(x).unwrap()), V_1.into_iter().map(|x| Fp31::try_from(x).unwrap()), ); @@ -302,8 +302,8 @@ mod test { // fiat-shamir let pg_3 = ProofGenerator::gen_challenge_and_recurse::( - proof_left_2, - proof_right_2, + &proof_left_2, + &proof_right_2, pg_2.u, pg_2.v, );