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