Skip to content

Commit

Permalink
feat: verify proof in release mode (#17)
Browse files Browse the repository at this point in the history
Verify proof before caching it as extra safety
  • Loading branch information
jonathanpwang authored May 23, 2023
1 parent 2641da5 commit 1e64c30
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
15 changes: 8 additions & 7 deletions snark-verifier-sdk/src/halo2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,10 @@ where
#[cfg(feature = "display")]
end_timer!(proof_time);

if let Some((instance_path, proof_path)) = path {
write_instances(&instances, instance_path);
fs::write(proof_path, &proof).unwrap();
}

debug_assert!({
// validate proof before caching
assert!({
let mut transcript_read =
PoseidonTranscript::<NativeLoader, &[u8]>::new::<SECURE_MDS>(proof.as_slice());
PoseidonTranscript::<NativeLoader, &[u8]>::from_spec(&proof[..], POSEIDON_SPEC.clone());
VerificationStrategy::<_, V>::finalize(
verify_proof::<_, V, _, _, _>(
params.verifier_params(),
Expand All @@ -141,6 +137,11 @@ where
)
});

if let Some((instance_path, proof_path)) = path {
write_instances(&instances, instance_path);
fs::write(proof_path, &proof).unwrap();
}

proof
}

Expand Down
3 changes: 2 additions & 1 deletion snark-verifier-sdk/src/halo2/aggregation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ use halo2_base::{
use itertools::Itertools;
use rand::{rngs::StdRng, SeedableRng};
use serde::{Deserialize, Serialize};
#[cfg(debug_assertions)]
use snark_verifier::util::arithmetic::fe_to_limbs;
use snark_verifier::{
loader::{
self,
Expand All @@ -34,7 +36,6 @@ use snark_verifier::{
kzg::{KzgAccumulator, KzgAsProvingKey, KzgAsVerifyingKey, KzgSuccinctVerifyingKey},
AccumulationScheme, AccumulationSchemeProver, PolynomialCommitmentScheme,
},
util::arithmetic::fe_to_limbs,
verifier::SnarkVerifier,
};
use std::{
Expand Down

0 comments on commit 1e64c30

Please sign in to comment.