1use ark_ec::short_weierstrass::{Affine, SWCurveConfig};
9use ark_ff::PrimeField;
10use kimchi::curve::{pallas_endos, vesta_endos};
11use mina_curves::pasta::curves::{pallas::PallasParameters, vesta::VestaParameters};
12use mina_poseidon::{
13 constants::SpongeConstants, poseidon::ArithmeticSpongeParams, sponge::DefaultFqSponge, FqSponge,
14};
15use poly_commitment::commitment::{CommitmentCurve, EndoCurve};
16
17#[derive(Clone)]
18pub struct PlonkSpongeConstants {}
19
20impl SpongeConstants for PlonkSpongeConstants {
21 const SPONGE_CAPACITY: usize = 1;
22 const SPONGE_WIDTH: usize = 3;
23 const SPONGE_RATE: usize = 2;
24 const PERM_ROUNDS_FULL: usize = 60;
25 const PERM_ROUNDS_PARTIAL: usize = 0;
26 const PERM_HALF_ROUNDS_FULL: usize = 0;
27 const PERM_SBOX: u32 = 5;
28 const PERM_FULL_MDS: bool = true;
29 const PERM_INITIAL_ARK: bool = false;
30}
31
32pub trait ArrabbiataCurve: CommitmentCurve + EndoCurve
38where
39 Self::BaseField: PrimeField,
40{
41 const NAME: &'static str;
43
44 type SpongeConstants: SpongeConstants;
48
49 const SPONGE_CONSTANTS: Self::SpongeConstants;
50
51 fn sponge_params() -> &'static ArithmeticSpongeParams<Self::ScalarField>;
53
54 fn other_curve_sponge_params() -> &'static ArithmeticSpongeParams<Self::BaseField>;
56
57 fn endos() -> &'static (Self::BaseField, Self::ScalarField);
60
61 fn other_curve_endo() -> &'static Self::ScalarField;
64
65 fn get_curve_params() -> (Self::BaseField, Self::BaseField);
68
69 fn create_new_sponge() -> DefaultFqSponge<Self::Params, Self::SpongeConstants>;
71
72 fn absorb_fq(
78 sponge: &mut DefaultFqSponge<Self::Params, Self::SpongeConstants>,
79 fq: Self::BaseField,
80 );
81
82 fn absorb_curve_points(
88 sponge: &mut DefaultFqSponge<Self::Params, Self::SpongeConstants>,
89 comms: &[Self],
90 );
91
92 fn squeeze_challenge(
103 sponge: &mut DefaultFqSponge<Self::Params, Self::SpongeConstants>,
104 ) -> Self::ScalarField;
105}
106
107impl ArrabbiataCurve for Affine<PallasParameters> {
108 const NAME: &'static str = "pallas";
109
110 type SpongeConstants = PlonkSpongeConstants;
111
112 const SPONGE_CONSTANTS: Self::SpongeConstants = PlonkSpongeConstants {};
113
114 fn sponge_params() -> &'static ArithmeticSpongeParams<Self::ScalarField> {
115 crate::poseidon_3_60_0_5_5_fq::static_params()
116 }
117
118 fn other_curve_sponge_params() -> &'static ArithmeticSpongeParams<Self::BaseField> {
119 crate::poseidon_3_60_0_5_5_fp::static_params()
120 }
121
122 fn endos() -> &'static (Self::BaseField, Self::ScalarField) {
123 pallas_endos()
124 }
125
126 fn other_curve_endo() -> &'static Self::ScalarField {
127 &vesta_endos().0
128 }
129
130 fn get_curve_params() -> (Self::BaseField, Self::BaseField) {
131 (PallasParameters::COEFF_A, PallasParameters::COEFF_B)
132 }
133
134 fn create_new_sponge() -> DefaultFqSponge<Self::Params, Self::SpongeConstants> {
135 let sponge: DefaultFqSponge<PallasParameters, PlonkSpongeConstants> =
136 DefaultFqSponge::new(Self::other_curve_sponge_params());
137 sponge
138 }
139
140 fn absorb_fq(
141 sponge: &mut DefaultFqSponge<Self::Params, Self::SpongeConstants>,
142 fq: Self::BaseField,
143 ) {
144 sponge.absorb_fq(&[fq])
145 }
146
147 fn absorb_curve_points(
148 sponge: &mut DefaultFqSponge<Self::Params, Self::SpongeConstants>,
149 comms: &[Self],
150 ) {
151 sponge.absorb_g(comms)
152 }
153
154 fn squeeze_challenge(
155 sponge: &mut DefaultFqSponge<Self::Params, Self::SpongeConstants>,
156 ) -> Self::ScalarField {
157 sponge.challenge()
159 }
160}
161
162impl ArrabbiataCurve for Affine<VestaParameters> {
163 const NAME: &'static str = "vesta";
164
165 type SpongeConstants = PlonkSpongeConstants;
166
167 const SPONGE_CONSTANTS: Self::SpongeConstants = PlonkSpongeConstants {};
168
169 fn sponge_params() -> &'static ArithmeticSpongeParams<Self::ScalarField> {
170 crate::poseidon_3_60_0_5_5_fp::static_params()
171 }
172
173 fn other_curve_sponge_params() -> &'static ArithmeticSpongeParams<Self::BaseField> {
174 crate::poseidon_3_60_0_5_5_fq::static_params()
175 }
176
177 fn endos() -> &'static (Self::BaseField, Self::ScalarField) {
178 vesta_endos()
179 }
180
181 fn other_curve_endo() -> &'static Self::ScalarField {
182 &pallas_endos().0
183 }
184
185 fn get_curve_params() -> (Self::BaseField, Self::BaseField) {
186 (VestaParameters::COEFF_A, VestaParameters::COEFF_B)
187 }
188
189 fn create_new_sponge() -> DefaultFqSponge<Self::Params, Self::SpongeConstants> {
190 let sponge: DefaultFqSponge<VestaParameters, PlonkSpongeConstants> =
191 DefaultFqSponge::new(Self::other_curve_sponge_params());
192 sponge
193 }
194
195 fn absorb_fq(
196 sponge: &mut DefaultFqSponge<Self::Params, Self::SpongeConstants>,
197 fq: Self::BaseField,
198 ) {
199 sponge.absorb_fq(&[fq])
200 }
201
202 fn absorb_curve_points(
203 sponge: &mut DefaultFqSponge<Self::Params, Self::SpongeConstants>,
204 comms: &[Self],
205 ) {
206 sponge.absorb_g(comms)
207 }
208
209 fn squeeze_challenge(
210 sponge: &mut DefaultFqSponge<Self::Params, Self::SpongeConstants>,
211 ) -> Self::ScalarField {
212 sponge.challenge()
214 }
215}