ark_pallas/curves/
mod.rs
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 const COFACTOR: &'static [u64] = &[0x1];
22
23 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 const COEFF_A: Fq = Fq::ZERO;
33
34 const COEFF_B: Fq = MontFp!("5");
36
37 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 let mut res = (*p).clone();
66 res.x *= Self::ENDO_COEFFS[0];
67 res
68 }
69
70 fn endomorphism_affine(p: &Affine) -> Affine {
71 let mut res = (*p).clone();
75 res.x *= Self::ENDO_COEFFS[0];
76 res
77 }
78}
79
80pub const G_GENERATOR_X: Fq = MontFp!("-1");
82
83pub const G_GENERATOR_Y: Fq = MontFp!("2");