-
Notifications
You must be signed in to change notification settings - Fork 370
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(verifier): verify_bytes api GRO-304 #1784
Changes from all commits
dd36a6c
63ff7a4
98ad2df
c873148
e8d2a97
78b4418
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,17 +15,21 @@ pub(crate) mod error; | |
|
||
pub(crate) use converter::{load_plonk_proof_from_bytes, load_plonk_verifying_key_from_bytes}; | ||
pub(crate) use proof::PlonkProof; | ||
pub(crate) use verify::verify_plonk_raw; | ||
pub(crate) use verify::verify_plonk_algebraic; | ||
|
||
use alloc::vec::Vec; | ||
use bn::Fr; | ||
use error::PlonkError; | ||
use sha2::{Digest, Sha256}; | ||
|
||
use crate::{bn254_public_values, decode_sp1_vkey_hash, error::Error}; | ||
use crate::{decode_sp1_vkey_hash, error::Error, hash_public_inputs}; | ||
/// A verifier for Plonk zero-knowledge proofs. | ||
#[derive(Debug)] | ||
pub struct PlonkVerifier; | ||
|
||
impl PlonkVerifier { | ||
/// Verifies an SP1 PLONK proof, as generated by the SP1 SDK. | ||
/// | ||
/// # Arguments | ||
/// | ||
/// * `proof` - The proof bytes. | ||
|
@@ -66,11 +70,40 @@ impl PlonkVerifier { | |
} | ||
|
||
let sp1_vkey_hash = decode_sp1_vkey_hash(sp1_vkey_hash)?; | ||
let public_inputs = bn254_public_values(&sp1_vkey_hash, sp1_public_inputs); | ||
|
||
let plonk_vk = load_plonk_verifying_key_from_bytes(plonk_vk)?; | ||
let proof = load_plonk_proof_from_bytes(&proof[4..], plonk_vk.qcp.len())?; | ||
Self::verify_gnark_proof( | ||
&proof[4..], | ||
&[sp1_vkey_hash, hash_public_inputs(sp1_public_inputs)], | ||
plonk_vk, | ||
) | ||
} | ||
|
||
/// Verifies a Gnark PLONK proof using raw byte inputs. | ||
/// | ||
/// WARNING: if you're verifying an SP1 proof, you should use [`verify`] instead. | ||
/// This is a lower-level verification method that works directly with raw bytes rather than | ||
/// the SP1 SDK's data structures. | ||
/// | ||
/// # Arguments | ||
/// | ||
/// * `proof` - The raw PLONK proof bytes (without the 4-byte vkey hash prefix) | ||
/// * `public_inputs` - The public inputs to the circuit | ||
/// * `plonk_vk` - The PLONK verifying key bytes | ||
/// | ||
/// # Returns | ||
/// | ||
/// A [`Result`] containing unit `()` if the proof is valid, | ||
/// or a [`PlonkError`] if verification fails. | ||
pub fn verify_gnark_proof( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: add #[must_use] |
||
proof: &[u8], | ||
public_inputs: &[[u8; 32]], | ||
plonk_vk: &[u8], | ||
) -> Result<(), PlonkError> { | ||
let plonk_vk = load_plonk_verifying_key_from_bytes(plonk_vk).unwrap(); | ||
let proof = load_plonk_proof_from_bytes(proof, plonk_vk.qcp.len()).unwrap(); | ||
|
||
verify_plonk_raw(&plonk_vk, &proof, &public_inputs) | ||
let public_inputs = | ||
public_inputs.iter().map(|input| Fr::from_slice(input).unwrap()).collect::<Vec<_>>(); | ||
verify_plonk_algebraic(&plonk_vk, &proof, &public_inputs) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,7 +33,7 @@ pub(crate) struct PlonkVerifyingKey { | |
pub(crate) commitment_constraint_indexes: Vec<usize>, | ||
} | ||
|
||
/// Verifies a PLONK proof | ||
/// Verifies a PLONK proof using algebraic inputs. | ||
/// | ||
/// # Arguments | ||
/// | ||
|
@@ -44,7 +44,7 @@ pub(crate) struct PlonkVerifyingKey { | |
/// # Returns | ||
/// | ||
/// * `Result<bool, PlonkError>` - Returns true if the proof is valid, or an error if verification fails | ||
pub(crate) fn verify_plonk_raw( | ||
pub(crate) fn verify_plonk_algebraic( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add #[must_use] so people don't forget to unwrap There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. must_use is already on by default for
|
||
vk: &PlonkVerifyingKey, | ||
proof: &PlonkProof, | ||
public_inputs: &[Fr], | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: add #[must_use]