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
15
16/// `Baby-JubJub` is a twisted Edwards curve. These curves have equations of the
17/// form: ax² + y² = 1 + dx²y².
18/// over some base finite field Fq.
19///
20/// Baby-JubJub's curve equation: x² + y² = 1 + (168696/168700)x²y²
21///
22/// q = 21888242871839275222246405745257275088548364400416034343698204186575808495617
23///
24#[derive(Clone, Default, PartialEq, Eq)]
25pub struct EdwardsParameters;
26
27impl ModelParameters for EdwardsParameters {
28    type BaseField = Fq;
29    type ScalarField = Fr;
30}
31
32impl TEModelParameters for EdwardsParameters {
33    /// COEFF_A = 1
34    #[rustfmt::skip]
35    const COEFF_A: Fq = field_new!(Fq, "1");
36
37    #[inline(always)]
38    fn mul_by_a(elem: &Self::BaseField) -> Self::BaseField {
39        *elem
40    }
41
42    /// COEFF_D = 168696/168700 mod q
43    ///         = 9706598848417545097372247223557719406784115219466060233080913168975159366771
44    #[rustfmt::skip]
45    const COEFF_D: Fq = field_new!(Fq, "9706598848417545097372247223557719406784115219466060233080913168975159366771");
46
47    /// COFACTOR = 8
48    const COFACTOR: &'static [u64] = &[8];
49
50    /// COFACTOR^(-1) mod r =
51    /// 2394026564107420727433200628387514462817212225638746351800188703329891451411
52    #[rustfmt::skip]
53    const COFACTOR_INV: Fr = field_new!(Fr, "2394026564107420727433200628387514462817212225638746351800188703329891451411");
54
55    /// AFFINE_GENERATOR_COEFFS = (GENERATOR_X, GENERATOR_Y)
56    const AFFINE_GENERATOR_COEFFS: (Self::BaseField, Self::BaseField) = (GENERATOR_X, GENERATOR_Y);
57
58    type MontgomeryModelParameters = EdwardsParameters;
59}
60
61impl MontgomeryModelParameters for EdwardsParameters {
62    /// COEFF_A = 168698
63    #[rustfmt::skip]
64    const COEFF_A: Fq = field_new!(Fq, "168698");
65    /// COEFF_B = 168700
66    #[rustfmt::skip]
67    const COEFF_B: Fq = field_new!(Fq, "168700");
68
69    type TEModelParameters = EdwardsParameters;
70}
71
72#[rustfmt::skip]
73const GENERATOR_X: Fq = field_new!(Fq, "19698561148652590122159747500897617769866003486955115824547446575314762165298");
74#[rustfmt::skip]
75const GENERATOR_Y: Fq = field_new!(Fq, "19298250018296453272277890825869354524455968081175474282777126169995084727839");