ark-curves-cherry-picked/ed_on_bn254/src/curves/mod.rs
ed_on_bn254/src/curves/mod.rsRaw
1use ark_ec::{
2 models::{ModelParameters, MontgomeryModelParameters, TEModelParameters},
3 twisted_edwards_extended::{GroupAffine, GroupProjective},
4};
5use ark_ff::MontFp;
6
7use crate::{Fq, Fr};
8
9#[cfg(test)]
10mod tests;
11
12pub type EdwardsAffine = GroupAffine<EdwardsParameters>;
13pub type EdwardsProjective = GroupProjective<EdwardsParameters>;
14
15/// `Baby-JubJub` is a twisted Edwards curve. These curves have equations of the
16/// form: ax² + y² = 1 + dx²y².
17/// over some base finite field Fq.
18///
19/// Baby-JubJub's curve equation: x² + y² = 1 + (168696/168700)x²y²
20///
21/// q = 21888242871839275222246405745257275088548364400416034343698204186575808495617
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 const COFACTOR_INV: Fr = MontFp!(
35 Fr,
36 "2394026564107420727433200628387514462817212225638746351800188703329891451411"
37 );
38}
39
40impl TEModelParameters for EdwardsParameters {
41 /// COEFF_A = 1
42 const COEFF_A: Fq = MontFp!(Fq, "1");
43
44 #[inline(always)]
45 fn mul_by_a(elem: &Self::BaseField) -> Self::BaseField {
46 *elem
47 }
48
49 /// COEFF_D = 168696/168700 mod q
50 /// = 9706598848417545097372247223557719406784115219466060233080913168975159366771
51 const COEFF_D: Fq = MontFp!(
52 Fq,
53 "9706598848417545097372247223557719406784115219466060233080913168975159366771"
54 );
55
56 /// AFFINE_GENERATOR_COEFFS = (GENERATOR_X, GENERATOR_Y)
57 const AFFINE_GENERATOR_COEFFS: (Self::BaseField, Self::BaseField) = (GENERATOR_X, GENERATOR_Y);
58
59 type MontgomeryModelParameters = EdwardsParameters;
60}
61
62impl MontgomeryModelParameters for EdwardsParameters {
63 /// COEFF_A = 168698
64 const COEFF_A: Fq = MontFp!(Fq, "168698");
65 /// COEFF_B = 168700
66 const COEFF_B: Fq = MontFp!(Fq, "168700");
67
68 type TEModelParameters = EdwardsParameters;
69}
70
71const GENERATOR_X: Fq = MontFp!(
72 Fq,
73 "19698561148652590122159747500897617769866003486955115824547446575314762165298"
74);
75
76const GENERATOR_Y: Fq = MontFp!(
77 Fq,
78 "19298250018296453272277890825869354524455968081175474282777126169995084727839"
79);