1- use std:: io:: { Error , ErrorKind , Read , Result , Write } ;
1+ use std:: {
2+ fmt:: { self , Debug , Formatter } ,
3+ io:: { Error , ErrorKind , Read , Result , Write } ,
4+ } ;
25
36use bn:: { arith:: U256 , AffineG1 , AffineG2 , Fq , Fq2 , G1 , G2 } ;
47use borsh:: { BorshDeserialize , BorshSerialize } ;
@@ -19,7 +22,7 @@ pub(crate) struct Groth16G2 {
1922}
2023
2124/// Verification key for the Groth16 proof.
22- #[ derive( Clone , PartialEq , BorshSerialize , BorshDeserialize ) ]
25+ #[ derive( Clone , Debug , PartialEq , BorshSerialize , BorshDeserialize ) ]
2326pub ( crate ) struct Groth16VerifyingKey {
2427 pub ( crate ) g1 : Groth16G1 ,
2528 pub ( crate ) g2 : Groth16G2 ,
@@ -158,6 +161,29 @@ fn deserialize_fq2<R: Read>(reader: &mut R) -> Result<Fq2> {
158161 Ok ( Fq2 :: new ( real, imaginary) )
159162}
160163
164+ impl Debug for Groth16G1 {
165+ fn fmt ( & self , f : & mut Formatter < ' _ > ) -> fmt:: Result {
166+ f. debug_struct ( "Groth16G1" )
167+ . field ( "alpha" , & self . alpha ) // AffineG1 already implements Debug
168+ . field ( "k" , & self . k ) // Vec<AffineG1> implements Debug
169+ . finish ( )
170+ }
171+ }
172+
173+ impl Debug for Groth16G2 {
174+ fn fmt ( & self , f : & mut Formatter < ' _ > ) -> fmt:: Result {
175+ f. debug_struct ( "Groth16G2" )
176+ // We call `{:?}` on the inner `groups::AffineG2` via `self.beta.0`
177+ . field ( "beta_x" , & format_args ! ( "{:?}" , self . beta. x( ) ) )
178+ . field ( "beta_y" , & format_args ! ( "{:?}" , self . beta. y( ) ) )
179+ . field ( "delta_x" , & format_args ! ( "{:?}" , self . delta. x( ) ) )
180+ . field ( "delta_y" , & format_args ! ( "{:?}" , self . delta. y( ) ) )
181+ . field ( "gamma_x" , & format_args ! ( "{:?}" , self . gamma. x( ) ) )
182+ . field ( "gamma_y" , & format_args ! ( "{:?}" , self . gamma. y( ) ) )
183+ . finish ( )
184+ }
185+ }
186+
161187#[ cfg( test) ]
162188mod tests {
163189 use sp1_verifier:: GROTH16_VK_BYTES ;
@@ -171,6 +197,6 @@ mod tests {
171197 let serialized = borsh:: to_vec ( & vk) . unwrap ( ) ;
172198 let deserialized: Groth16VerifyingKey = borsh:: from_slice ( & serialized) . unwrap ( ) ;
173199
174- assert ! ( vk == deserialized) ;
200+ assert_eq ! ( vk, deserialized) ;
175201 }
176202}
0 commit comments