ark-curves-cherry-picked/bn254/src/curves/g2.rs
bn254/src/curves/g2.rsRaw
1use ark_ec::{
2 models::{short_weierstrass::SWCurveConfig, CurveConfig},
3 short_weierstrass::Affine,
4};
5use ark_ff::{Field, MontFp, Zero};
6
7use crate::{Fq, Fq2, Fr};
8
9pub type G2Affine = Affine<Parameters>;
10
11#[derive(Clone, Default, PartialEq, Eq)]
12pub struct Parameters;
13
14impl CurveConfig for Parameters {
15 type BaseField = Fq2;
16 type ScalarField = Fr;
17
18 /// COFACTOR = (36 * X^4) + (36 * X^3) + (30 * X^2) + 6*X + 1
19 /// 21888242871839275222246405745257275088844257914179612981679871602714643921549
20 #[rustfmt::skip]
21 const COFACTOR: &'static [u64] = &[
22 0x345f2299c0f9fa8d,
23 0x06ceecda572a2489,
24 0xb85045b68181585e,
25 0x30644e72e131a029,
26 ];
27
28 /// COFACTOR_INV = COFACTOR^{-1} mod r
29 const COFACTOR_INV: Fr =
30 MontFp!("10944121435919637613327163357776759465618812564592884533313067514031822496649");
31}
32
33impl SWCurveConfig for Parameters {
34 /// COEFF_A = [0, 0]
35 const COEFF_A: Fq2 = Fq2::ZERO;
36
37 /// COEFF_B = 3/(u+9)
38 /// (19485874751759354771024239261021720505790618469301721065564631296452457478373, 266929791119991161246907387137283842545076965332900288569378510910307636690)
39 const COEFF_B: Fq2 = Fq2::new(
40 MontFp!("19485874751759354771024239261021720505790618469301721065564631296452457478373"),
41 MontFp!("266929791119991161246907387137283842545076965332900288569378510910307636690"),
42 );
43
44 /// AFFINE_GENERATOR_COEFFS = (G2_GENERATOR_X, G2_GENERATOR_Y)
45 const GENERATOR: G2Affine = G2Affine::new_unchecked(G2_GENERATOR_X, G2_GENERATOR_Y);
46
47 #[inline(always)]
48 fn mul_by_a(_: Self::BaseField) -> Self::BaseField {
49 Self::BaseField::zero()
50 }
51}
52
53pub const G2_GENERATOR_X: Fq2 = Fq2::new(G2_GENERATOR_X_C0, G2_GENERATOR_X_C1);
54pub const G2_GENERATOR_Y: Fq2 = Fq2::new(G2_GENERATOR_Y_C0, G2_GENERATOR_Y_C1);
55
56/// G2_GENERATOR_X_C0 =
57/// 10857046999023057135944570762232829481370756359578518086990519993285655852781
58pub const G2_GENERATOR_X_C0: Fq =
59 MontFp!("10857046999023057135944570762232829481370756359578518086990519993285655852781");
60
61/// G2_GENERATOR_X_C1 =
62/// 11559732032986387107991004021392285783925812861821192530917403151452391805634
63pub const G2_GENERATOR_X_C1: Fq =
64 MontFp!("11559732032986387107991004021392285783925812861821192530917403151452391805634");
65
66/// G2_GENERATOR_Y_C0 =
67/// 8495653923123431417604973247489272438418190587263600148770280649306958101930
68pub const G2_GENERATOR_Y_C0: Fq =
69 MontFp!("8495653923123431417604973247489272438418190587263600148770280649306958101930");
70
71/// G2_GENERATOR_Y_C1 =
72/// 4082367875863433681332203403145435568316851327593401208105741076214120093531
73pub const G2_GENERATOR_Y_C1: Fq =
74 MontFp!("4082367875863433681332203403145435568316851327593401208105741076214120093531");