ark-curves-cherry-picked/pallas/src/curves/mod.rs
pallas/src/curves/mod.rsRaw
1use ark_ec::{
2 models::CurveConfig,
3 scalar_mul::glv::GLVConfig,
4 short_weierstrass::{self as sw, SWCurveConfig},
5};
6use ark_ff::{AdditiveGroup, BigInt, Field, MontFp, PrimeField, Zero};
7
8use crate::{fq::Fq, fr::Fr};
9
10#[cfg(test)]
11mod tests;
12
13#[derive(Copy, Clone, Default, PartialEq, Eq)]
14pub struct PallasConfig;
15
16impl CurveConfig for PallasConfig {
17 type BaseField = Fq;
18 type ScalarField = Fr;
19
20 /// COFACTOR = 1
21 const COFACTOR: &'static [u64] = &[0x1];
22
23 /// COFACTOR_INV = 1
24 const COFACTOR_INV: Fr = Fr::ONE;
25}
26
27pub type Affine = sw::Affine<PallasConfig>;
28pub type Projective = sw::Projective<PallasConfig>;
29
30impl SWCurveConfig for PallasConfig {
31 /// COEFF_A = 0
32 const COEFF_A: Fq = Fq::ZERO;
33
34 /// COEFF_B = 5
35 const COEFF_B: Fq = MontFp!("5");
36
37 /// AFFINE_GENERATOR_COEFFS = (G1_GENERATOR_X, G1_GENERATOR_Y)
38 const GENERATOR: Affine = Affine::new_unchecked(G_GENERATOR_X, G_GENERATOR_Y);
39
40 #[inline(always)]
41 fn mul_by_a(_: Self::BaseField) -> Self::BaseField {
42 Self::BaseField::zero()
43 }
44}
45
46impl GLVConfig for PallasConfig {
47 const ENDO_COEFFS: &'static [Self::BaseField] = &[MontFp!(
48 "20444556541222657078399132219657928148671392403212669005631716460534733845831"
49 )];
50
51 const LAMBDA: Self::ScalarField =
52 MontFp!("26005156700822196841419187675678338661165322343552424574062261873906994770353");
53
54 const SCALAR_DECOMP_COEFFS: [(bool, <Self::ScalarField as PrimeField>::BigInt); 4] = [
55 (false, BigInt!("98231058071100081932162823354453065728")),
56 (true, BigInt!("98231058071186745657228807397848383489")),
57 (false, BigInt!("196462116142286827589391630752301449217")),
58 (false, BigInt!("98231058071100081932162823354453065728")),
59 ];
60
61 fn endomorphism(p: &Projective) -> Projective {
62 // Endomorphism of the points on the curve.
63 // endomorphism_p(x,y) = (BETA * x, y)
64 // where BETA is a non-trivial cubic root of unity in Fq.
65 let mut res = (*p).clone();
66 res.x *= Self::ENDO_COEFFS[0];
67 res
68 }
69
70 fn endomorphism_affine(p: &Affine) -> Affine {
71 // Endomorphism of the points on the curve.
72 // endomorphism_p(x,y) = (BETA * x, y)
73 // where BETA is a non-trivial cubic root of unity in Fq.
74 let mut res = (*p).clone();
75 res.x *= Self::ENDO_COEFFS[0];
76 res
77 }
78}
79
80/// G_GENERATOR_X = -1
81pub const G_GENERATOR_X: Fq = MontFp!("-1");
82
83/// G_GENERATOR_Y = 2
84pub const G_GENERATOR_Y: Fq = MontFp!("2");