Skip to main content

mina_curves/pasta/curves/
pallas.rs

1use crate::pasta::{Fp, Fq};
2use ark_ec::{
3    models::short_weierstrass::{Affine, Projective, SWCurveConfig},
4    CurveConfig,
5};
6use ark_ff::{MontFp, Zero};
7
8/// `G_GENERATOR_X` =
9/// 1
10pub const G_GENERATOR_X: Fp = MontFp!("1");
11
12/// `G1_GENERATOR_Y` =
13/// 12418654782883325593414442427049395787963493412651469444558597405572177144507
14pub const G_GENERATOR_Y: Fp =
15    MontFp!("12418654782883325593414442427049395787963493412651469444558597405572177144507");
16
17#[derive(Debug, Clone, Default, PartialEq, Eq)]
18pub struct PallasParameters;
19
20impl CurveConfig for PallasParameters {
21    type BaseField = Fp;
22
23    type ScalarField = Fq;
24
25    /// COFACTOR = 1
26    const COFACTOR: &'static [u64] = &[0x1];
27
28    /// `COFACTOR_INV` = 1
29    const COFACTOR_INV: Fq = MontFp!("1");
30}
31
32pub type Pallas = Affine<PallasParameters>;
33
34pub type ProjectivePallas = Projective<PallasParameters>;
35
36impl SWCurveConfig for PallasParameters {
37    const COEFF_A: Self::BaseField = MontFp!("0");
38
39    const COEFF_B: Self::BaseField = MontFp!("5");
40
41    const GENERATOR: Affine<Self> = Affine::new_unchecked(G_GENERATOR_X, G_GENERATOR_Y);
42}
43
44impl PallasParameters {
45    #[inline]
46    #[must_use]
47    pub fn mul_by_a(_: &<Self as CurveConfig>::BaseField) -> <Self as CurveConfig>::BaseField {
48        <Self as CurveConfig>::BaseField::zero()
49    }
50}
51
52/// legacy curve, a copy of the normal curve to support legacy sponge params
53#[derive(Copy, Clone, Default, PartialEq, Eq)]
54pub struct LegacyPallasParameters;
55
56impl CurveConfig for LegacyPallasParameters {
57    type BaseField = <PallasParameters as CurveConfig>::BaseField;
58
59    type ScalarField = <PallasParameters as CurveConfig>::ScalarField;
60
61    const COFACTOR: &'static [u64] = <PallasParameters as CurveConfig>::COFACTOR;
62
63    const COFACTOR_INV: Self::ScalarField = <PallasParameters as CurveConfig>::COFACTOR_INV;
64}
65
66impl SWCurveConfig for LegacyPallasParameters {
67    const COEFF_A: Self::BaseField = <PallasParameters as SWCurveConfig>::COEFF_A;
68
69    const COEFF_B: Self::BaseField = <PallasParameters as SWCurveConfig>::COEFF_B;
70
71    const GENERATOR: Affine<Self> = Affine::new_unchecked(G_GENERATOR_X, G_GENERATOR_Y);
72}
73
74pub type LegacyPallas = Affine<LegacyPallasParameters>;