Skip to content

Commit

Permalink
fix: add test function gen_and_verify_normal_proof (#261)
Browse files Browse the repository at this point in the history
Add test function `gen_and_verify_normal_proof`.
  • Loading branch information
silathdiir authored Sep 6, 2023
1 parent db5a32c commit df0417e
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 2 deletions.
2 changes: 1 addition & 1 deletion prover/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ mod prover;
mod verifier;

pub use self::{prover::Prover, verifier::Verifier};
pub use aggregator::ChunkHash;
pub use aggregator::{ChunkHash, CompressionCircuit};
2 changes: 1 addition & 1 deletion prover/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub mod types;
pub mod utils;
pub mod zkevm;

pub use common::ChunkHash;
pub use common::{ChunkHash, CompressionCircuit};
pub use evm_verifier::EvmVerifier;
pub use proof::{BatchProof, ChunkProof, EvmProof, Proof};
pub use snark_verifier_sdk::Snark;
1 change: 1 addition & 0 deletions prover/src/test_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ mod proof;

pub use proof::{
gen_and_verify_batch_proofs, gen_and_verify_chunk_proofs, gen_and_verify_normal_and_evm_proofs,
gen_and_verify_normal_proof,
};

pub const ASSETS_DIR: &str = "./test_assets";
Expand Down
34 changes: 34 additions & 0 deletions prover/src/test_util/proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,17 @@ pub fn gen_and_verify_normal_and_evm_proofs(
(normal_proof, evm_proof)
}

pub fn gen_and_verify_normal_proof(
prover: &mut common::Prover,
layer_id: LayerId,
previous_snark: Snark,
) -> (bool, Snark) {
let normal_proof = gen_normal_proof(prover, layer_id, previous_snark, None);
let verified = verify_normal_proof(prover, layer_id, normal_proof.clone());

(verified, normal_proof)
}

fn gen_evm_proof(
prover: &mut common::Prover,
layer_id: LayerId,
Expand Down Expand Up @@ -140,3 +151,26 @@ fn verify_normal_and_evm_proofs(
verifier.evm_verify(evm_proof, output_dir);
log::info!("Verified EVM proof: {id}");
}

fn verify_normal_proof(
prover: &mut common::Prover,
layer_id: LayerId,
normal_proof: Snark,
) -> bool {
let id = layer_id.id();
let degree = layer_id.degree();
let config_path = layer_id.config_path();
env::set_var("COMPRESSION_CONFIG", config_path);

let pk = prover.pk(id).unwrap();
let vk = pk.get_vk().clone();

let params = prover.params(degree).clone();
let verifier = common::Verifier::<CompressionCircuit>::new(params, vk);
log::info!("Constructed common verifier");

let verified = verifier.verify_snark(normal_proof);
log::info!("Verified normal proof: {verified}");

verified
}

0 comments on commit df0417e

Please sign in to comment.