diff --git a/g16ckt/examples/pairing_gate_counts.rs b/g16ckt/examples/pairing_gate_counts.rs index 6b140d0..0100c99 100644 --- a/g16ckt/examples/pairing_gate_counts.rs +++ b/g16ckt/examples/pairing_gate_counts.rs @@ -326,7 +326,7 @@ fn main() { let b = Fq2::as_montgomery(ark::g2::Config::COEFF_B); let y2 = Fq2::add_constant(ctx, &x3, &b); let y = Fq2::sqrt_general_montgomery(ctx, &y2); - let neg_y = Fq2::neg(ctx, y.clone()); + let neg_y = Fq2::neg(ctx, &y); let y0 = gsv::gadgets::bigint::select( ctx, y.c0(), diff --git a/g16ckt/src/gadgets/bn254/fq12.rs b/g16ckt/src/gadgets/bn254/fq12.rs index f1bbf4c..b4f2798 100644 --- a/g16ckt/src/gadgets/bn254/fq12.rs +++ b/g16ckt/src/gadgets/bn254/fq12.rs @@ -175,10 +175,7 @@ impl Fq12 { } pub fn neg(circuit: &mut C, a: &Fq12) -> Fq12 { - Fq12::from_components( - Fq6::neg(circuit, a.0[0].clone()), - Fq6::neg(circuit, a.0[1].clone()), - ) + Fq12::from_components(Fq6::neg(circuit, &a.0[0]), Fq6::neg(circuit, &a.0[1])) } pub fn sub(circuit: &mut C, a: &Fq12, b: &Fq12) -> Fq12 { @@ -421,7 +418,7 @@ impl Fq12 { let inverse_norm = Fq6::inverse_montgomery(circuit, &norm); let res_c0 = Fq6::mul_montgomery(circuit, a.c0(), &inverse_norm); - let neg_a_c1 = Fq6::neg(circuit, a.c1().clone()); + let neg_a_c1 = Fq6::neg(circuit, a.c1()); let res_c1 = Fq6::mul_montgomery(circuit, &inverse_norm, &neg_a_c1); Fq12::from_components(res_c0, res_c1) @@ -442,7 +439,7 @@ impl Fq12 { } pub fn conjugate(circuit: &mut C, a: &Fq12) -> Fq12 { - let new_c1 = Fq6::neg(circuit, a.c1().clone()); + let new_c1 = Fq6::neg(circuit, a.c1()); Fq12::from_components(a.c0().clone(), new_c1) } } diff --git a/g16ckt/src/gadgets/bn254/fq2.rs b/g16ckt/src/gadgets/bn254/fq2.rs index d1f6100..4bbab7f 100644 --- a/g16ckt/src/gadgets/bn254/fq2.rs +++ b/g16ckt/src/gadgets/bn254/fq2.rs @@ -176,7 +176,7 @@ impl Fq2 { Fq2::from_components(c0, c1) } - pub fn neg(circuit: &mut C, a: Fq2) -> Fq2 { + pub fn neg(circuit: &mut C, a: &Fq2) -> Fq2 { assert_eq!(a.c0().len(), Self::N_BITS / 2); assert_eq!(a.c1().len(), Self::N_BITS / 2); @@ -597,7 +597,7 @@ mod tests { 10_000, |ctx, input| { let [a] = input; - Fq2::neg(ctx, a.clone()) + Fq2::neg(ctx, a) }, ); diff --git a/g16ckt/src/gadgets/bn254/fq6.rs b/g16ckt/src/gadgets/bn254/fq6.rs index e4d982e..d36bac2 100644 --- a/g16ckt/src/gadgets/bn254/fq6.rs +++ b/g16ckt/src/gadgets/bn254/fq6.rs @@ -159,11 +159,11 @@ impl Fq6 { ) } - pub fn neg(circuit: &mut C, a: Fq6) -> Fq6 { + pub fn neg(circuit: &mut C, a: &Fq6) -> Fq6 { Fq6::from_components( - Fq2::neg(circuit, a.0[0].clone()), - Fq2::neg(circuit, a.0[1].clone()), - Fq2::neg(circuit, a.0[2].clone()), + Fq2::neg(circuit, &a.0[0]), + Fq2::neg(circuit, &a.0[1]), + Fq2::neg(circuit, &a.0[2]), ) } @@ -718,7 +718,7 @@ mod tests { let result = CircuitBuilder::streaming_execute::<_, _, Fq6Output>(input, 10_000, |ctx, input| { let [a] = input; - Fq6::neg(ctx, a.clone()) + Fq6::neg(ctx, a) }); assert_eq!(result.output_value.value, expected); } diff --git a/g16ckt/src/gadgets/bn254/g2.rs b/g16ckt/src/gadgets/bn254/g2.rs index 441a9e8..d690183 100644 --- a/g16ckt/src/gadgets/bn254/g2.rs +++ b/g16ckt/src/gadgets/bn254/g2.rs @@ -520,7 +520,7 @@ impl G2Projective { pub fn neg(circuit: &mut C, p: &G2Projective) -> G2Projective { G2Projective { x: p.x.clone(), - y: Fq2::neg(circuit, p.y.clone()), + y: Fq2::neg(circuit, &p.y), z: p.z.clone(), } } diff --git a/g16ckt/src/gadgets/bn254/pairing.rs b/g16ckt/src/gadgets/bn254/pairing.rs index 00e5b24..0c3d73b 100644 --- a/g16ckt/src/gadgets/bn254/pairing.rs +++ b/g16ckt/src/gadgets/bn254/pairing.rs @@ -247,7 +247,7 @@ fn g2_frobenius_map_affine( let y_f2 = Fq2::frobenius_montgomery(circuit, &y1, 1); let x2 = Fq2::mul_by_constant_montgomery(circuit, &x_f2, &Fq2::as_montgomery(cx)); let mut y2 = Fq2::mul_by_constant_montgomery(circuit, &y_f2, &Fq2::as_montgomery(cy)); - y2 = Fq2::neg(circuit, y2); + y2 = Fq2::neg(circuit, &y2); G2Projective { x: x2, y: y2, @@ -285,7 +285,7 @@ fn g2_line_coeffs_double( let one_c0 = Fq::new_constant(&Fq::as_montgomery(ark_bn254::Fq::ONE)).expect("const one"); let zero_c1 = Fq::new_constant(&Fq::as_montgomery(ark_bn254::Fq::ZERO)).expect("const zero"); let c0 = Fq2::from_components(one_c0, zero_c1); - let c1 = Fq2::neg(circuit, lambda.clone()); + let c1 = Fq2::neg(circuit, &lambda); let lambda_x = Fq2::mul_montgomery(circuit, &lambda, &x); let c2 = Fq2::sub(circuit, &lambda_x, &y); @@ -323,7 +323,7 @@ fn g2_line_coeffs_add( let one_c0 = Fq::new_constant(&Fq::as_montgomery(ark_bn254::Fq::ONE)).expect("const one"); let zero_c1 = Fq::new_constant(&Fq::as_montgomery(ark_bn254::Fq::ZERO)).expect("const zero"); let c0 = Fq2::from_components(one_c0, zero_c1); - let c1 = Fq2::neg(circuit, lambda.clone()); + let c1 = Fq2::neg(circuit, &lambda); let lambda_xr = Fq2::mul_montgomery(circuit, &lambda, &xr); let c2 = Fq2::sub(circuit, &lambda_xr, &yr); @@ -394,7 +394,7 @@ pub fn double_in_place_circuit_montgomery( let gs = Fq2::square_montgomery(circuit, &g); let new_y = Fq2::sub(circuit, &gs, &es_triple); let new_z = Fq2::mul_montgomery(circuit, &b, &h); - let hn = Fq2::neg(circuit, h); + let hn = Fq2::neg(circuit, &h); ( G2Projective { @@ -438,7 +438,7 @@ pub fn add_in_place_montgomery( let wires_4 = Fq2::double(circuit, &g); let h = Fq2::sub(circuit, &wires_3, &wires_4); - let neg_theta = Fq2::neg(circuit, theta.clone()); + let neg_theta = Fq2::neg(circuit, &theta); let wires_5 = Fq2::mul_montgomery(circuit, &theta, qx); let wires_6 = Fq2::mul_montgomery(circuit, &lambda, qy); @@ -468,7 +468,7 @@ pub fn g2_affine_neg_evaluate( q: &G2Projective, ) -> G2Projective { let mut result = q.clone(); - result.y = Fq2::neg(circuit, q.y.clone()); + result.y = Fq2::neg(circuit, &q.y); result } diff --git a/g16ckt/src/gadgets/groth16.rs b/g16ckt/src/gadgets/groth16.rs index 80f0d57..52d1a65 100644 --- a/g16ckt/src/gadgets/groth16.rs +++ b/g16ckt/src/gadgets/groth16.rs @@ -161,7 +161,7 @@ pub fn decompress_g2_from_compressed( let y = Fq2Wire::sqrt_general_montgomery(circuit, &y2); - let neg_y = Fq2Wire::neg(circuit, y.clone()); + let neg_y = Fq2Wire::neg(circuit, &y); let final_y_0 = bigint::select(circuit, y.c0(), neg_y.c0(), *y_flag); let final_y_1 = bigint::select(circuit, y.c1(), neg_y.c1(), *y_flag);