1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
use crate::pasta::*;
use ark_ec::{
    models::short_weierstrass::{Affine, Projective, SWCurveConfig},
    CurveConfig,
};
use ark_ff::{MontFp, Zero};

/// G_GENERATOR_X =
/// 1
pub const G_GENERATOR_X: Fp = MontFp!("1");

/// G1_GENERATOR_Y =
/// 12418654782883325593414442427049395787963493412651469444558597405572177144507
pub const G_GENERATOR_Y: Fp =
    MontFp!("12418654782883325593414442427049395787963493412651469444558597405572177144507");

#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct PallasParameters;

impl CurveConfig for PallasParameters {
    type BaseField = Fp;

    type ScalarField = Fq;

    /// COFACTOR = 1
    const COFACTOR: &'static [u64] = &[0x1];

    /// COFACTOR_INV = 1
    const COFACTOR_INV: Fq = MontFp!("1");
}

pub type Pallas = Affine<PallasParameters>;

pub type ProjectivePallas = Projective<PallasParameters>;

impl SWCurveConfig for PallasParameters {
    const COEFF_A: Self::BaseField = MontFp!("0");

    const COEFF_B: Self::BaseField = MontFp!("5");

    const GENERATOR: Affine<Self> = Affine::new_unchecked(G_GENERATOR_X, G_GENERATOR_Y);
}

impl PallasParameters {
    #[inline(always)]
    pub fn mul_by_a(
        _: &<PallasParameters as CurveConfig>::BaseField,
    ) -> <PallasParameters as CurveConfig>::BaseField {
        <PallasParameters as CurveConfig>::BaseField::zero()
    }
}

/// legacy curve, a copy of the normal curve to support legacy sponge params
#[derive(Copy, Clone, Default, PartialEq, Eq)]
pub struct LegacyPallasParameters;

impl CurveConfig for LegacyPallasParameters {
    type BaseField = <PallasParameters as CurveConfig>::BaseField;

    type ScalarField = <PallasParameters as CurveConfig>::ScalarField;

    const COFACTOR: &'static [u64] = <PallasParameters as CurveConfig>::COFACTOR;

    const COFACTOR_INV: Self::ScalarField = <PallasParameters as CurveConfig>::COFACTOR_INV;
}

impl SWCurveConfig for LegacyPallasParameters {
    const COEFF_A: Self::BaseField = <PallasParameters as SWCurveConfig>::COEFF_A;

    const COEFF_B: Self::BaseField = <PallasParameters as SWCurveConfig>::COEFF_B;

    const GENERATOR: Affine<Self> = Affine::new_unchecked(G_GENERATOR_X, G_GENERATOR_Y);
}

pub type LegacyPallas = Affine<LegacyPallasParameters>;