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::{field_new, 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
14impl SWModelParameters for Parameters {
15    /// COEFF_A = [0, 0]
16    #[rustfmt::skip]
17    const COEFF_A: Fq2 = field_new!(Fq2, field_new!(Fq, "0"), field_new!(Fq, "0"));
18
19    /// COEFF_B = 3/(u+9)
20    ///         = (19485874751759354771024239261021720505790618469301721065564631296452457478373, 266929791119991161246907387137283842545076965332900288569378510910307636690)
21    #[rustfmt::skip]
22    const COEFF_B: Fq2 = field_new!(Fq2,
23        field_new!(Fq, "19485874751759354771024239261021720505790618469301721065564631296452457478373"),
24        field_new!(Fq, "266929791119991161246907387137283842545076965332900288569378510910307636690"),
25    );
26
27    /// COFACTOR = (36 * X^4) + (36 * X^3) + (30 * X^2) + 6*X + 1
28    ///          = 21888242871839275222246405745257275088844257914179612981679871602714643921549
29    #[rustfmt::skip]
30    const COFACTOR: &'static [u64] = &[
31        0x345f2299c0f9fa8d,
32        0x06ceecda572a2489,
33        0xb85045b68181585e,
34        0x30644e72e131a029,
35    ];
36
37    /// COFACTOR_INV = COFACTOR^{-1} mod r
38    #[rustfmt::skip]
39    const COFACTOR_INV: Fr = field_new!(Fr, "10944121435919637613327163357776759465618812564592884533313067514031822496649");
40
41    /// AFFINE_GENERATOR_COEFFS = (G2_GENERATOR_X, G2_GENERATOR_Y)
42    const AFFINE_GENERATOR_COEFFS: (Self::BaseField, Self::BaseField) =
43        (G2_GENERATOR_X, G2_GENERATOR_Y);
44
45    #[inline(always)]
46    fn mul_by_a(_: &Self::BaseField) -> Self::BaseField {
47        Self::BaseField::zero()
48    }
49}
50
51#[rustfmt::skip]
52pub const G2_GENERATOR_X: Fq2 = field_new!(Fq2, G2_GENERATOR_X_C0, G2_GENERATOR_X_C1);
53#[rustfmt::skip]
54pub const G2_GENERATOR_Y: Fq2 = field_new!(Fq2, G2_GENERATOR_Y_C0, G2_GENERATOR_Y_C1);
55
56/// G2_GENERATOR_X_C0 =
57/// 10857046999023057135944570762232829481370756359578518086990519993285655852781
58#[rustfmt::skip]
59pub const G2_GENERATOR_X_C0: Fq = field_new!(Fq, "10857046999023057135944570762232829481370756359578518086990519993285655852781");
60
61/// G2_GENERATOR_X_C1 =
62/// 11559732032986387107991004021392285783925812861821192530917403151452391805634
63#[rustfmt::skip]
64pub const G2_GENERATOR_X_C1: Fq = field_new!(Fq, "11559732032986387107991004021392285783925812861821192530917403151452391805634");
65
66/// G2_GENERATOR_Y_C0 =
67/// 8495653923123431417604973247489272438418190587263600148770280649306958101930
68#[rustfmt::skip]
69pub const G2_GENERATOR_Y_C0: Fq = field_new!(Fq, "8495653923123431417604973247489272438418190587263600148770280649306958101930");
70
71/// G2_GENERATOR_Y_C1 =
72/// 4082367875863433681332203403145435568316851327593401208105741076214120093531
73#[rustfmt::skip]
74pub const G2_GENERATOR_Y_C1: Fq = field_new!(Fq, "4082367875863433681332203403145435568316851327593401208105741076214120093531");