[test, chore]: Fix clippy and genericize one more test (#180) * genericize test_tiny_r1cs * chore: remove redundant clone in scalar_mul Makes clippy happy
François Garillot 4142+huitseeker@users.noreply.github.com
Fri, 09 Jun 2023 12:53:23 -0400
2 files changed,
15 insertions(+),
12 deletions(-)
M
src/gadgets/ecc.rs
→
src/gadgets/ecc.rs
@@ -439,8 +439,8 @@ let mut p = AllocatedPointNonInfinity::from_allocated_point(self);
// 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) {
M
src/nifs.rs
→
src/nifs.rs
@@ -126,7 +126,6 @@ use ::bellperson::{gadgets::num::AllocatedNum, ConstraintSystem, SynthesisError};
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<Scalar: PrimeField, CS: ConstraintSystem<Scalar>>(@@ -266,9 +265,8 @@ // check if the running instance is satisfiable
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<G: Group>() { + let one = <G::Scalar as Field>::ONE; let (num_cons, num_vars, num_io, A, B, C) = { let num_cons = 4; let num_vars = 4;@@ -285,9 +283,9 @@ // Relaxed R1CS is a set of three sparse matrices (A B C), where there is a row for every
// 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 @@ let ro_consts =
<<G as Group>::RO as ROTrait<<G as Group>::Base, <G as Group>::Scalar>>::Constants::new(); let rand_inst_witness_generator = - |ck: &CommitmentKey<G>, I: &S| -> (S, R1CSInstance<G>, R1CSWitness<G>) { + |ck: &CommitmentKey<G>, I: &G::Scalar| -> (G::Scalar, R1CSInstance<G>, R1CSWitness<G>) { let i0 = *I; // compute a satisfying (vars, X) tuple@@ -342,7 +340,7 @@ let z2 = z1 + i0; // constraint 2
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, <G::Scalar as Field>::ZERO]; let X = vec![i0, i1]; (i1, W, X) };@@ -366,7 +364,7 @@ (O, U, W)
}; 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);@@ -381,5 +379,10 @@ &W1,
&U2, &W2, ); + } + + #[test] + fn test_tiny_r1cs() { + test_tiny_r1cs_with::<pasta_curves::pallas::Point>(); } }