ark-curves-cherry-picked/ed_on_bn254/src/curves/mod.rs
ed_on_bn254/src/curves/mod.rsRaw
1use ark_ec::{
2 models::CurveConfig,
3 twisted_edwards::{Affine, MontCurveConfig, Projective, TECurveConfig},
4};
5use ark_ff::{Field, MontFp};
6
7use crate::{Fq, Fr};
8
9#[cfg(test)]
10mod tests;
11
12pub type EdwardsAffine = Affine<EdwardsParameters>;
13pub type EdwardsProjective = Projective<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 CurveConfig 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 =
35 MontFp!("2394026564107420727433200628387514462817212225638746351800188703329891451411");
36}
37
38impl TECurveConfig for EdwardsParameters {
39 /// COEFF_A = 1
40 const COEFF_A: Fq = Fq::ONE;
41
42 #[inline(always)]
43 fn mul_by_a(elem: &Self::BaseField) -> Self::BaseField {
44 *elem
45 }
46
47 /// COEFF_D = 168696/168700 mod q
48 /// = 9706598848417545097372247223557719406784115219466060233080913168975159366771
49 const COEFF_D: Fq =
50 MontFp!("9706598848417545097372247223557719406784115219466060233080913168975159366771");
51
52 /// AFFINE_GENERATOR_COEFFS = (GENERATOR_X, GENERATOR_Y)
53 const GENERATOR: EdwardsAffine = EdwardsAffine::new_unchecked(GENERATOR_X, GENERATOR_Y);
54
55 type MontCurveConfig = EdwardsParameters;
56}
57
58impl MontCurveConfig for EdwardsParameters {
59 /// COEFF_A = 168698
60 const COEFF_A: Fq = MontFp!("168698");
61 /// COEFF_B = 168700
62 const COEFF_B: Fq = MontFp!("168700");
63
64 type TECurveConfig = EdwardsParameters;
65}
66
67const GENERATOR_X: Fq =
68 MontFp!("19698561148652590122159747500897617769866003486955115824547446575314762165298");
69
70const GENERATOR_Y: Fq =
71 MontFp!("19298250018296453272277890825869354524455968081175474282777126169995084727839");