@@ -3,7 +3,7 @@ use crate::{
33 PCVerifierKey , UVPolynomial , Vec ,
44} ;
55use ark_ec:: { PairingEngine , ProjectiveCurve } ;
6- use ark_ff:: { PrimeField , ToBytes } ;
6+ use ark_ff:: { Field , PrimeField , ToBytes , ToConstraintField } ;
77use ark_serialize:: { CanonicalDeserialize , CanonicalSerialize , SerializationError } ;
88use ark_std:: io:: { Read , Write } ;
99use ark_std:: ops:: { Add , AddAssign } ;
@@ -148,6 +148,28 @@ impl<E: PairingEngine> ToBytes for VerifierKey<E> {
148148 }
149149}
150150
151+ impl < E : PairingEngine > ToConstraintField < <E :: Fq as Field >:: BasePrimeField > for VerifierKey < E >
152+ where
153+ E :: G1Affine : ToConstraintField < <E :: Fq as Field >:: BasePrimeField > ,
154+ E :: G2Affine : ToConstraintField < <E :: Fq as Field >:: BasePrimeField > ,
155+ {
156+ fn to_field_elements ( & self ) -> Option < Vec < <E :: Fq as Field >:: BasePrimeField > > {
157+ let mut res = Vec :: new ( ) ;
158+ res. extend_from_slice ( & self . vk . to_field_elements ( ) . unwrap ( ) ) ;
159+
160+ if let Some ( degree_bounds_and_shift_powers) = & self . degree_bounds_and_shift_powers {
161+ for ( d, shift_power) in degree_bounds_and_shift_powers. iter ( ) {
162+ let d_elem: <E :: Fq as Field >:: BasePrimeField = ( * d as u64 ) . into ( ) ;
163+
164+ res. push ( d_elem) ;
165+ res. extend_from_slice ( & shift_power. to_field_elements ( ) . unwrap ( ) ) ;
166+ }
167+ }
168+
169+ Some ( res)
170+ }
171+ }
172+
151173/// `PreparedVerifierKey` is used to check evaluation proofs for a given commitment.
152174#[ derive( Derivative ) ]
153175#[ derivative( Clone ( bound = "" ) , Debug ( bound = "" ) ) ]
@@ -240,6 +262,22 @@ impl<E: PairingEngine> ToBytes for Commitment<E> {
240262 }
241263}
242264
265+ impl < E : PairingEngine > ToConstraintField < <E :: Fq as Field >:: BasePrimeField > for Commitment < E >
266+ where
267+ E :: G1Affine : ToConstraintField < <E :: Fq as Field >:: BasePrimeField > ,
268+ {
269+ fn to_field_elements ( & self ) -> Option < Vec < <E :: Fq as Field >:: BasePrimeField > > {
270+ let mut res = Vec :: new ( ) ;
271+ res. extend_from_slice ( & self . comm . to_field_elements ( ) . unwrap ( ) ) ;
272+
273+ if let Some ( shifted_comm) = & self . shifted_comm {
274+ res. extend_from_slice ( & shifted_comm. to_field_elements ( ) . unwrap ( ) ) ;
275+ }
276+
277+ Some ( res)
278+ }
279+ }
280+
243281impl < E : PairingEngine > PCCommitment for Commitment < E > {
244282 #[ inline]
245283 fn empty ( ) -> Self {
0 commit comments