arnaucube
arnaucube/ark-curves-cherry-pickedPublic Self-hosted repository
ark-curves-cherry-picked/ed_on_bn254/src/curves/mod.rs
ed_on_bn254/src/curves/mod.rsRaw
 1use crate::{Fq, Fr};
 2use ark_ec::{
 3    models::{ModelParameters, MontgomeryModelParameters, TEModelParameters},
 4    twisted_edwards_extended::{GroupAffine, GroupProjective},
 5};
 6use ark_ff::field_new;
 7
 8#[cfg(test)]
 9mod tests;
10
11pub type EdwardsAffine = GroupAffine<EdwardsParameters>;
12pub type EdwardsProjective = GroupProjective<EdwardsParameters>;
13
14/// `Baby-JubJub` is a twisted Edwards curve. These curves have equations of the
15/// form: ax² + y² = 1 + dx²y².
16/// over some base finite field Fq.
17///
18/// Baby-JubJub's curve equation: x² + y² = 1 + (168696/168700)x²y²
19///
20/// q = 21888242871839275222246405745257275088548364400416034343698204186575808495617
21///
22#[derive(Clone, Default, PartialEq, Eq)]
23pub struct EdwardsParameters;
24
25impl ModelParameters for EdwardsParameters {
26    type BaseField = Fq;
27    type ScalarField = Fr;
28
29    /// COFACTOR = 8
30    const COFACTOR: &'static [u64] = &[8];
31
32    /// COFACTOR^(-1) mod r =
33    /// 2394026564107420727433200628387514462817212225638746351800188703329891451411
34    #[rustfmt::skip]
35    const COFACTOR_INV: Fr = field_new!(Fr, "2394026564107420727433200628387514462817212225638746351800188703329891451411");
36}
37
38impl TEModelParameters for EdwardsParameters {
39    /// COEFF_A = 1
40    #[rustfmt::skip]
41    const COEFF_A: Fq = field_new!(Fq, "1");
42
43    #[inline(always)]
44    fn mul_by_a(elem: &Self::BaseField) -> Self::BaseField {
45        *elem
46    }
47
48    /// COEFF_D = 168696/168700 mod q
49    ///         = 9706598848417545097372247223557719406784115219466060233080913168975159366771
50    #[rustfmt::skip]
51    const COEFF_D: Fq = field_new!(Fq, "9706598848417545097372247223557719406784115219466060233080913168975159366771");
52
53    /// AFFINE_GENERATOR_COEFFS = (GENERATOR_X, GENERATOR_Y)
54    const AFFINE_GENERATOR_COEFFS: (Self::BaseField, Self::BaseField) = (GENERATOR_X, GENERATOR_Y);
55
56    type MontgomeryModelParameters = EdwardsParameters;
57}
58
59impl MontgomeryModelParameters for EdwardsParameters {
60    /// COEFF_A = 168698
61    #[rustfmt::skip]
62    const COEFF_A: Fq = field_new!(Fq, "168698");
63    /// COEFF_B = 168700
64    #[rustfmt::skip]
65    const COEFF_B: Fq = field_new!(Fq, "168700");
66
67    type TEModelParameters = EdwardsParameters;
68}
69
70#[rustfmt::skip]
71const GENERATOR_X: Fq = field_new!(Fq, "19698561148652590122159747500897617769866003486955115824547446575314762165298");
72#[rustfmt::skip]
73const GENERATOR_Y: Fq = field_new!(Fq, "19298250018296453272277890825869354524455968081175474282777126169995084727839");