From bef42262d648e01a0cc04e375cb48c766a0d521d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Garillot?= <4142+huitseeker@users.noreply.github.com> Date: Fri, 9 Jun 2023 12:53:23 -0400 Subject: [PATCH] [test, chore]: Fix clippy and genericize one more test (#180) * genericize test_tiny_r1cs * chore: remove redundant clone in scalar_mul Makes clippy happy --- src/gadgets/ecc.rs | 4 ++-- src/nifs.rs | 23 +++++++++++++---------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/gadgets/ecc.rs b/src/gadgets/ecc.rs index 104a027..677b6cd 100644 --- a/src/gadgets/ecc.rs +++ b/src/gadgets/ecc.rs @@ -439,8 +439,8 @@ where // we assume the first bit to be 1, so we must initialize acc to self and double it // we remove this assumption below - let mut acc = p.clone(); - p = p.double_incomplete(cs.namespace(|| "double"))?; + let mut acc = p; + p = acc.double_incomplete(cs.namespace(|| "double"))?; // perform the double-and-add loop to compute the scalar mul using incomplete addition law for (i, bit) in incomplete_bits.iter().enumerate().skip(1) { diff --git a/src/nifs.rs b/src/nifs.rs index 2187a5d..645032f 100644 --- a/src/nifs.rs +++ b/src/nifs.rs @@ -126,7 +126,6 @@ mod tests { use ff::{Field, PrimeField}; use rand::rngs::OsRng; - type S = pasta_curves::pallas::Scalar; type G = pasta_curves::pallas::Point; fn synthesize_tiny_r1cs_bellperson>( @@ -266,9 +265,8 @@ mod tests { assert!(shape.is_sat_relaxed(ck, &r_U, &r_W).is_ok()); } - #[test] - fn test_tiny_r1cs() { - let one = S::one(); + fn test_tiny_r1cs_with() { + let one = ::ONE; let (num_cons, num_vars, num_io, A, B, C) = { let num_cons = 4; let num_vars = 4; @@ -285,9 +283,9 @@ mod tests { // constraint and a column for every entry in z = (vars, u, inputs) // An R1CS instance is satisfiable iff: // Az \circ Bz = u \cdot Cz + E, where z = (vars, 1, inputs) - let mut A: Vec<(usize, usize, S)> = Vec::new(); - let mut B: Vec<(usize, usize, S)> = Vec::new(); - let mut C: Vec<(usize, usize, S)> = Vec::new(); + let mut A: Vec<(usize, usize, G::Scalar)> = Vec::new(); + let mut B: Vec<(usize, usize, G::Scalar)> = Vec::new(); + let mut C: Vec<(usize, usize, G::Scalar)> = Vec::new(); // constraint 0 entries in (A,B,C) // `I0 * I0 - Z0 = 0` @@ -331,7 +329,7 @@ mod tests { <::RO as ROTrait<::Base, ::Scalar>>::Constants::new(); let rand_inst_witness_generator = - |ck: &CommitmentKey, I: &S| -> (S, R1CSInstance, R1CSWitness) { + |ck: &CommitmentKey, I: &G::Scalar| -> (G::Scalar, R1CSInstance, R1CSWitness) { let i0 = *I; // compute a satisfying (vars, X) tuple @@ -342,7 +340,7 @@ mod tests { let i1 = z2 + one + one + one + one + one; // constraint 3 // store the witness and IO for the instance - let W = vec![z0, z1, z2, S::zero()]; + let W = vec![z0, z1, z2, ::ZERO]; let X = vec![i0, i1]; (i1, W, X) }; @@ -366,7 +364,7 @@ mod tests { }; let mut csprng: OsRng = OsRng; - let I = S::random(&mut csprng); // the first input is picked randomly for the first instance + let I = G::Scalar::random(&mut csprng); // the first input is picked randomly for the first instance let (O, U1, W1) = rand_inst_witness_generator(&ck, &I); let (_O, U2, W2) = rand_inst_witness_generator(&ck, &O); @@ -382,4 +380,9 @@ mod tests { &W2, ); } + + #[test] + fn test_tiny_r1cs() { + test_tiny_r1cs_with::(); + } }