Skip to content

Commit 1070c15

Browse files
committed
feat: implement Debug for VK
1 parent 8e572e2 commit 1070c15

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

adapters/sp1/groth16-verifier/src/types.rs

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
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

36
use bn::{arith::U256, AffineG1, AffineG2, Fq, Fq2, G1, G2};
47
use 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)]
2326
pub(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)]
162188
mod 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
}

adapters/sp1/groth16-verifier/src/verifier.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ pub(crate) const VK_HASH_PREFIX_LENGTH: usize = 4;
2323
/// 2. The Groth16 proof is valid with respect to two public inputs:
2424
/// - `program_vk_hash`: a unique identifier for the SP1 program (as an Fr element).
2525
/// - a hash of the supplied public values (either SHA-256 or Blake3).
26+
#[derive(Clone, Debug)]
2627
pub struct SP1Groth16Verifier {
2728
/// The (uncompressed) Groth16 verifying key for the SP1 circuit.
2829
vk: Groth16VerifyingKey,

0 commit comments

Comments
 (0)