Skip to content

Commit 6885c16

Browse files
committed
pass arg by reference in fq2 and fq6 neg
1 parent 0834f30 commit 6885c16

File tree

7 files changed

+19
-22
lines changed

7 files changed

+19
-22
lines changed

g16ckt/examples/pairing_gate_counts.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ fn main() {
326326
let b = Fq2::as_montgomery(ark::g2::Config::COEFF_B);
327327
let y2 = Fq2::add_constant(ctx, &x3, &b);
328328
let y = Fq2::sqrt_general_montgomery(ctx, &y2);
329-
let neg_y = Fq2::neg(ctx, y.clone());
329+
let neg_y = Fq2::neg(ctx, &y);
330330
let y0 = gsv::gadgets::bigint::select(
331331
ctx,
332332
y.c0(),

g16ckt/src/gadgets/bn254/fq12.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,7 @@ impl Fq12 {
175175
}
176176

177177
pub fn neg<C: CircuitContext>(circuit: &mut C, a: &Fq12) -> Fq12 {
178-
Fq12::from_components(
179-
Fq6::neg(circuit, a.0[0].clone()),
180-
Fq6::neg(circuit, a.0[1].clone()),
181-
)
178+
Fq12::from_components(Fq6::neg(circuit, &a.0[0]), Fq6::neg(circuit, &a.0[1]))
182179
}
183180

184181
pub fn sub<C: CircuitContext>(circuit: &mut C, a: &Fq12, b: &Fq12) -> Fq12 {
@@ -421,7 +418,7 @@ impl Fq12 {
421418
let inverse_norm = Fq6::inverse_montgomery(circuit, &norm);
422419

423420
let res_c0 = Fq6::mul_montgomery(circuit, a.c0(), &inverse_norm);
424-
let neg_a_c1 = Fq6::neg(circuit, a.c1().clone());
421+
let neg_a_c1 = Fq6::neg(circuit, a.c1());
425422
let res_c1 = Fq6::mul_montgomery(circuit, &inverse_norm, &neg_a_c1);
426423

427424
Fq12::from_components(res_c0, res_c1)
@@ -442,7 +439,7 @@ impl Fq12 {
442439
}
443440

444441
pub fn conjugate<C: CircuitContext>(circuit: &mut C, a: &Fq12) -> Fq12 {
445-
let new_c1 = Fq6::neg(circuit, a.c1().clone());
442+
let new_c1 = Fq6::neg(circuit, a.c1());
446443
Fq12::from_components(a.c0().clone(), new_c1)
447444
}
448445
}

g16ckt/src/gadgets/bn254/fq2.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ impl Fq2 {
176176
Fq2::from_components(c0, c1)
177177
}
178178

179-
pub fn neg<C: CircuitContext>(circuit: &mut C, a: Fq2) -> Fq2 {
179+
pub fn neg<C: CircuitContext>(circuit: &mut C, a: &Fq2) -> Fq2 {
180180
assert_eq!(a.c0().len(), Self::N_BITS / 2);
181181
assert_eq!(a.c1().len(), Self::N_BITS / 2);
182182

@@ -597,7 +597,7 @@ mod tests {
597597
10_000,
598598
|ctx, input| {
599599
let [a] = input;
600-
Fq2::neg(ctx, a.clone())
600+
Fq2::neg(ctx, a)
601601
},
602602
);
603603

g16ckt/src/gadgets/bn254/fq6.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -159,11 +159,11 @@ impl Fq6 {
159159
)
160160
}
161161

162-
pub fn neg<C: CircuitContext>(circuit: &mut C, a: Fq6) -> Fq6 {
162+
pub fn neg<C: CircuitContext>(circuit: &mut C, a: &Fq6) -> Fq6 {
163163
Fq6::from_components(
164-
Fq2::neg(circuit, a.0[0].clone()),
165-
Fq2::neg(circuit, a.0[1].clone()),
166-
Fq2::neg(circuit, a.0[2].clone()),
164+
Fq2::neg(circuit, &a.0[0]),
165+
Fq2::neg(circuit, &a.0[1]),
166+
Fq2::neg(circuit, &a.0[2]),
167167
)
168168
}
169169

@@ -718,7 +718,7 @@ mod tests {
718718
let result =
719719
CircuitBuilder::streaming_execute::<_, _, Fq6Output>(input, 10_000, |ctx, input| {
720720
let [a] = input;
721-
Fq6::neg(ctx, a.clone())
721+
Fq6::neg(ctx, a)
722722
});
723723
assert_eq!(result.output_value.value, expected);
724724
}

g16ckt/src/gadgets/bn254/g2.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ impl G2Projective {
520520
pub fn neg<C: CircuitContext>(circuit: &mut C, p: &G2Projective) -> G2Projective {
521521
G2Projective {
522522
x: p.x.clone(),
523-
y: Fq2::neg(circuit, p.y.clone()),
523+
y: Fq2::neg(circuit, &p.y),
524524
z: p.z.clone(),
525525
}
526526
}

g16ckt/src/gadgets/bn254/pairing.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ fn g2_frobenius_map_affine<C: CircuitContext>(
247247
let y_f2 = Fq2::frobenius_montgomery(circuit, &y1, 1);
248248
let x2 = Fq2::mul_by_constant_montgomery(circuit, &x_f2, &Fq2::as_montgomery(cx));
249249
let mut y2 = Fq2::mul_by_constant_montgomery(circuit, &y_f2, &Fq2::as_montgomery(cy));
250-
y2 = Fq2::neg(circuit, y2);
250+
y2 = Fq2::neg(circuit, &y2);
251251
G2Projective {
252252
x: x2,
253253
y: y2,
@@ -285,7 +285,7 @@ fn g2_line_coeffs_double<C: CircuitContext>(
285285
let one_c0 = Fq::new_constant(&Fq::as_montgomery(ark_bn254::Fq::ONE)).expect("const one");
286286
let zero_c1 = Fq::new_constant(&Fq::as_montgomery(ark_bn254::Fq::ZERO)).expect("const zero");
287287
let c0 = Fq2::from_components(one_c0, zero_c1);
288-
let c1 = Fq2::neg(circuit, lambda.clone());
288+
let c1 = Fq2::neg(circuit, &lambda);
289289
let lambda_x = Fq2::mul_montgomery(circuit, &lambda, &x);
290290
let c2 = Fq2::sub(circuit, &lambda_x, &y);
291291

@@ -323,7 +323,7 @@ fn g2_line_coeffs_add<C: CircuitContext>(
323323
let one_c0 = Fq::new_constant(&Fq::as_montgomery(ark_bn254::Fq::ONE)).expect("const one");
324324
let zero_c1 = Fq::new_constant(&Fq::as_montgomery(ark_bn254::Fq::ZERO)).expect("const zero");
325325
let c0 = Fq2::from_components(one_c0, zero_c1);
326-
let c1 = Fq2::neg(circuit, lambda.clone());
326+
let c1 = Fq2::neg(circuit, &lambda);
327327
let lambda_xr = Fq2::mul_montgomery(circuit, &lambda, &xr);
328328
let c2 = Fq2::sub(circuit, &lambda_xr, &yr);
329329

@@ -394,7 +394,7 @@ pub fn double_in_place_circuit_montgomery<C: CircuitContext>(
394394
let gs = Fq2::square_montgomery(circuit, &g);
395395
let new_y = Fq2::sub(circuit, &gs, &es_triple);
396396
let new_z = Fq2::mul_montgomery(circuit, &b, &h);
397-
let hn = Fq2::neg(circuit, h);
397+
let hn = Fq2::neg(circuit, &h);
398398

399399
(
400400
G2Projective {
@@ -438,7 +438,7 @@ pub fn add_in_place_montgomery(
438438
let wires_4 = Fq2::double(circuit, &g);
439439
let h = Fq2::sub(circuit, &wires_3, &wires_4);
440440

441-
let neg_theta = Fq2::neg(circuit, theta.clone());
441+
let neg_theta = Fq2::neg(circuit, &theta);
442442

443443
let wires_5 = Fq2::mul_montgomery(circuit, &theta, qx);
444444
let wires_6 = Fq2::mul_montgomery(circuit, &lambda, qy);
@@ -468,7 +468,7 @@ pub fn g2_affine_neg_evaluate<C: CircuitContext>(
468468
q: &G2Projective,
469469
) -> G2Projective {
470470
let mut result = q.clone();
471-
result.y = Fq2::neg(circuit, q.y.clone());
471+
result.y = Fq2::neg(circuit, &q.y);
472472
result
473473
}
474474

g16ckt/src/gadgets/groth16.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ pub fn decompress_g2_from_compressed<C: CircuitContext>(
161161

162162
let y = Fq2Wire::sqrt_general_montgomery(circuit, &y2);
163163

164-
let neg_y = Fq2Wire::neg(circuit, y.clone());
164+
let neg_y = Fq2Wire::neg(circuit, &y);
165165

166166
let final_y_0 = bigint::select(circuit, y.c0(), neg_y.c0(), *y_flag);
167167
let final_y_1 = bigint::select(circuit, y.c1(), neg_y.c1(), *y_flag);

0 commit comments

Comments
 (0)