Skip to content

Commit 7450181

Browse files
committed
add frobenius rust code
1 parent debc96e commit 7450181

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/circuits/bn254/pairing.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use ark_ec::{bn::BnConfig, short_weierstrass::SWCurveConfig, CurveGroup};
2-
use ark_ff::{AdditiveGroup, Field};
2+
use ark_ff::{AdditiveGroup, Field, Fp2Config};
33
use crate::{bag::*, circuits::bn254::{fp254impl::Fp254Impl, fq::Fq, fq2::Fq2}};
44

55
pub fn double_in_place(r: &mut ark_bn254::G2Projective, half: ark_bn254::Fq) -> (ark_bn254::Fq2, ark_bn254::Fq2, ark_bn254::Fq2) {
@@ -141,11 +141,18 @@ pub fn add_in_place_circuit(r: Wires, q: Wires) -> Circuit {
141141
circuit
142142
}
143143

144+
pub fn frobenius_in_place(a: ark_bn254::Fq2, power: usize) -> ark_bn254::Fq2 {
145+
let c0 = a.c0;
146+
let mut c1 = a.c1;
147+
c1 *= &ark_bn254::Fq2Config::FROBENIUS_COEFF_FP2_C1[power % 2];
148+
ark_bn254::Fq2::new(c0, c1)
149+
}
150+
144151
pub fn mul_by_char(r: ark_bn254::G2Affine) -> ark_bn254::G2Affine {
145152
let mut s = r;
146-
s.x.frobenius_map_in_place(1);
153+
s.x = frobenius_in_place(s.x, 1);
147154
s.x *= &ark_bn254::Config::TWIST_MUL_BY_Q_X;
148-
s.y.frobenius_map_in_place(1);
155+
s.y = frobenius_in_place(s.y, 1);
149156
s.y *= &ark_bn254::Config::TWIST_MUL_BY_Q_Y;
150157
s
151158
}

0 commit comments

Comments
 (0)