@@ -11,7 +11,12 @@ use ark_std::{
1111
1212/// `UniversalParams` are the universal parameters for the KZG10 scheme.
1313#[ derive( Derivative ) ]
14- #[ derivative( Clone ( bound = "" ) , Debug ( bound = "" ) ) ]
14+ #[ derivative(
15+ Clone ( bound = "" ) ,
16+ Debug ( bound = "" ) ,
17+ PartialEq ( bound = "" ) ,
18+ Eq ( bound = "" )
19+ ) ]
1520pub struct UniversalParams < E : PairingEngine > {
1621 /// Group elements of the form `{ \beta^i G }`, where `i` ranges from 0 to `degree`.
1722 pub powers_of_g : Vec < E :: G1Affine > ,
@@ -24,10 +29,10 @@ pub struct UniversalParams<E: PairingEngine> {
2429 /// Group elements of the form `{ \beta^i G2 }`, where `i` ranges from `0` to `-degree`.
2530 pub neg_powers_of_h : BTreeMap < usize , E :: G2Affine > ,
2631 /// The generator of G2, prepared for use in pairings.
27- #[ derivative( Debug = "ignore" ) ]
32+ #[ derivative( Debug = "ignore" , PartialEq = "ignore" ) ]
2833 pub prepared_h : E :: G2Prepared ,
2934 /// \beta times the above generator of G2, prepared for use in pairings.
30- #[ derivative( Debug = "ignore" ) ]
35+ #[ derivative( Debug = "ignore" , PartialEq = "ignore" ) ]
3136 pub prepared_beta_h : E :: G2Prepared ,
3237}
3338
@@ -153,7 +158,8 @@ impl<E: PairingEngine> CanonicalDeserialize for UniversalParams<E> {
153158 Default ( bound = "" ) ,
154159 Hash ( bound = "" ) ,
155160 Clone ( bound = "" ) ,
156- Debug ( bound = "" )
161+ Debug ( bound = "" ) ,
162+ PartialEq
157163) ]
158164pub struct Powers < ' a , E : PairingEngine > {
159165 /// Group elements of the form `β^i G`, for different values of `i`.
@@ -169,9 +175,64 @@ impl<E: PairingEngine> Powers<'_, E> {
169175 }
170176}
171177
178+ impl < ' a , E : PairingEngine > CanonicalSerialize for Powers < ' a , E > {
179+ fn serialize < W : Write > ( & self , mut writer : W ) -> Result < ( ) , SerializationError > {
180+ self . powers_of_g . serialize ( & mut writer) ?;
181+ self . powers_of_gamma_g . serialize ( & mut writer)
182+ }
183+
184+ fn serialized_size ( & self ) -> usize {
185+ self . powers_of_g . serialized_size ( ) + self . powers_of_gamma_g . serialized_size ( )
186+ }
187+
188+ fn serialize_unchecked < W : Write > ( & self , mut writer : W ) -> Result < ( ) , SerializationError > {
189+ self . powers_of_g . serialize_unchecked ( & mut writer) ?;
190+ self . powers_of_gamma_g . serialize_unchecked ( & mut writer)
191+ }
192+
193+ fn serialize_uncompressed < W : Write > ( & self , mut writer : W ) -> Result < ( ) , SerializationError > {
194+ self . powers_of_g . serialize_uncompressed ( & mut writer) ?;
195+ self . powers_of_gamma_g . serialize_uncompressed ( & mut writer)
196+ }
197+ }
198+
199+ impl < ' a , E : PairingEngine > CanonicalDeserialize for Powers < ' a , E > {
200+ fn deserialize < R : Read > ( mut reader : R ) -> Result < Self , SerializationError > {
201+ let powers_of_g = Vec :: < E :: G1Affine > :: deserialize ( & mut reader) ?;
202+ let powers_of_gamma_g = Vec :: < E :: G1Affine > :: deserialize ( & mut reader) ?;
203+ Ok ( Self {
204+ powers_of_g : Cow :: Owned ( powers_of_g) ,
205+ powers_of_gamma_g : Cow :: Owned ( powers_of_gamma_g) ,
206+ } )
207+ }
208+
209+ fn deserialize_unchecked < R : Read > ( mut reader : R ) -> Result < Self , SerializationError > {
210+ let powers_of_g = Vec :: < E :: G1Affine > :: deserialize_unchecked ( & mut reader) ?;
211+ let powers_of_gamma_g = Vec :: < E :: G1Affine > :: deserialize_unchecked ( & mut reader) ?;
212+ Ok ( Self {
213+ powers_of_g : Cow :: Owned ( powers_of_g) ,
214+ powers_of_gamma_g : Cow :: Owned ( powers_of_gamma_g) ,
215+ } )
216+ }
217+
218+ fn deserialize_uncompressed < R : Read > ( mut reader : R ) -> Result < Self , SerializationError > {
219+ let powers_of_g = Vec :: < E :: G1Affine > :: deserialize_uncompressed ( & mut reader) ?;
220+ let powers_of_gamma_g = Vec :: < E :: G1Affine > :: deserialize_uncompressed ( & mut reader) ?;
221+ Ok ( Self {
222+ powers_of_g : Cow :: Owned ( powers_of_g) ,
223+ powers_of_gamma_g : Cow :: Owned ( powers_of_gamma_g) ,
224+ } )
225+ }
226+ }
172227/// `VerifierKey` is used to check evaluation proofs for a given commitment.
173228#[ derive( Derivative ) ]
174- #[ derivative( Default ( bound = "" ) , Clone ( bound = "" ) , Debug ( bound = "" ) ) ]
229+ #[ derivative(
230+ Default ( bound = "" ) ,
231+ Clone ( bound = "" ) ,
232+ Debug ( bound = "" ) ,
233+ PartialEq ( bound = "" ) ,
234+ Eq ( bound = "" )
235+ ) ]
175236pub struct VerifierKey < E : PairingEngine > {
176237 /// The generator of G1.
177238 pub g : E :: G1Affine ,
@@ -182,10 +243,10 @@ pub struct VerifierKey<E: PairingEngine> {
182243 /// \beta times the above generator of G2.
183244 pub beta_h : E :: G2Affine ,
184245 /// The generator of G2, prepared for use in pairings.
185- #[ derivative( Debug = "ignore" ) ]
246+ #[ derivative( Debug = "ignore" , PartialEq = "ignore" ) ]
186247 pub prepared_h : E :: G2Prepared ,
187248 /// \beta times the above generator of G2, prepared for use in pairings.
188- #[ derivative( Debug = "ignore" ) ]
249+ #[ derivative( Debug = "ignore" , PartialEq = "ignore" ) ]
189250 pub prepared_beta_h : E :: G2Prepared ,
190251}
191252
0 commit comments