Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion g16ckt/examples/pairing_gate_counts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
9 changes: 3 additions & 6 deletions g16ckt/src/gadgets/bn254/fq12.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,7 @@ impl Fq12 {
}

pub fn neg<C: CircuitContext>(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<C: CircuitContext>(circuit: &mut C, a: &Fq12, b: &Fq12) -> Fq12 {
Expand Down Expand Up @@ -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)
Expand All @@ -442,7 +439,7 @@ impl Fq12 {
}

pub fn conjugate<C: CircuitContext>(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)
}
}
Expand Down
4 changes: 2 additions & 2 deletions g16ckt/src/gadgets/bn254/fq2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ impl Fq2 {
Fq2::from_components(c0, c1)
}

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

Expand Down Expand Up @@ -597,7 +597,7 @@ mod tests {
10_000,
|ctx, input| {
let [a] = input;
Fq2::neg(ctx, a.clone())
Fq2::neg(ctx, a)
},
);

Expand Down
10 changes: 5 additions & 5 deletions g16ckt/src/gadgets/bn254/fq6.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,11 @@ impl Fq6 {
)
}

pub fn neg<C: CircuitContext>(circuit: &mut C, a: Fq6) -> Fq6 {
pub fn neg<C: CircuitContext>(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]),
)
}

Expand Down Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion g16ckt/src/gadgets/bn254/g2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ impl G2Projective {
pub fn neg<C: CircuitContext>(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(),
}
}
Expand Down
12 changes: 6 additions & 6 deletions g16ckt/src/gadgets/bn254/pairing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ fn g2_frobenius_map_affine<C: CircuitContext>(
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,
Expand Down Expand Up @@ -285,7 +285,7 @@ fn g2_line_coeffs_double<C: CircuitContext>(
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);

Expand Down Expand Up @@ -323,7 +323,7 @@ fn g2_line_coeffs_add<C: CircuitContext>(
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);

Expand Down Expand Up @@ -394,7 +394,7 @@ pub fn double_in_place_circuit_montgomery<C: CircuitContext>(
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 {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -468,7 +468,7 @@ pub fn g2_affine_neg_evaluate<C: CircuitContext>(
q: &G2Projective,
) -> G2Projective {
let mut result = q.clone();
result.y = Fq2::neg(circuit, q.y.clone());
result.y = Fq2::neg(circuit, &q.y);
result
}

Expand Down
2 changes: 1 addition & 1 deletion g16ckt/src/gadgets/groth16.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ pub fn decompress_g2_from_compressed<C: CircuitContext>(

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);
Expand Down
Loading