Skip to content

Commit

Permalink
fix: add batch-prove to prover test module (scroll-tech#975)
Browse files Browse the repository at this point in the history
* Return `ChunkProof` from `chunk_prove` test.

* Add `batch_prove` test.
  • Loading branch information
silathdiir authored Sep 22, 2023
1 parent 7fe99fe commit 7ddaf92
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 3 deletions.
2 changes: 2 additions & 0 deletions prover/src/test.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
mod batch;
mod chunk;
mod inner;

pub use batch::batch_prove;
pub use chunk::chunk_prove;
pub use inner::inner_prove;
55 changes: 55 additions & 0 deletions prover/src/test/batch.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
use crate::{
aggregator::{Prover, Verifier},
config::LayerId,
consts::DEPLOYMENT_CODE_FILENAME,
io::force_to_read,
utils::read_env_var,
ChunkHash, ChunkProof,
};
use once_cell::sync::Lazy;

static mut BATCH_PROVER: Lazy<Prover> = Lazy::new(|| {
let assets_dir = read_env_var("SCROLL_PROVER_ASSETS_DIR", "./test_assets".to_string());
let params_dir = read_env_var("SCROLL_PROVER_PARAMS_DIR", "./test_params".to_string());

let prover = Prover::from_dirs(&params_dir, &assets_dir);
log::info!("Constructed batch-prover");

prover
});

static mut BATCH_VERIFIER: Lazy<Verifier> = Lazy::new(|| {
let assets_dir = read_env_var("SCROLL_PROVER_ASSETS_DIR", "./test_assets".to_string());

let prover = unsafe { &mut BATCH_PROVER };
let params = prover.inner.params(LayerId::Layer4.degree()).clone();

let pk = prover
.inner
.pk(LayerId::Layer4.id())
.expect("Failed to get batch-prove PK");
let vk = pk.get_vk().clone();

let deployment_code = force_to_read(&assets_dir, &DEPLOYMENT_CODE_FILENAME);

let verifier = Verifier::new(params, vk, deployment_code);
log::info!("Constructed batch-verifier");

verifier
});

pub fn batch_prove(test: &str, chunk_hashes_proofs: Vec<(ChunkHash, ChunkProof)>) {
log::info!("{test}: batch-prove BEGIN");

let prover = unsafe { &mut BATCH_PROVER };
let proof = prover
.gen_agg_evm_proof(chunk_hashes_proofs, None, None)
.unwrap_or_else(|err| panic!("{test}: failed to generate batch proof: {err}"));
log::info!("{test}: generated batch proof");

let verifier = unsafe { &mut BATCH_VERIFIER };
let verified = verifier.verify_agg_evm_proof(proof);
assert!(verified, "{test}: failed to verify batch proof");

log::info!("{test}: batch-prove END");
}
13 changes: 10 additions & 3 deletions prover/src/test/chunk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::{
common::{Prover, Verifier},
config::{LayerId, ZKEVM_DEGREES},
utils::read_env_var,
CompressionCircuit, WitnessBlock,
ChunkHash, ChunkProof, CompressionCircuit, WitnessBlock,
};
use once_cell::sync::Lazy;
use std::env;
Expand Down Expand Up @@ -32,7 +32,7 @@ static mut CHUNK_VERIFIER: Lazy<Verifier<CompressionCircuit>> = Lazy::new(|| {
verifier
});

pub fn chunk_prove(test: &str, witness_block: &WitnessBlock) {
pub fn chunk_prove(test: &str, witness_block: &WitnessBlock) -> ChunkProof {
log::info!("{test}: chunk-prove BEGIN");

let prover = unsafe { &mut CHUNK_PROVER };
Expand Down Expand Up @@ -60,8 +60,15 @@ pub fn chunk_prove(test: &str, witness_block: &WitnessBlock) {
verifier.set_vk(vk);
}

let verified = verifier.verify_snark(snark);
let verified = verifier.verify_snark(snark.clone());
assert!(verified, "{test}: failed to verify chunk snark");

log::info!("{test}: chunk-prove END");

ChunkProof::new(
snark,
prover.pk(LayerId::Layer2.id()),
Some(ChunkHash::from_witness_block(witness_block, false)),
)
.unwrap_or_else(|err| panic!("{test}: failed to crate chunk proof: {err}"))
}

0 comments on commit 7ddaf92

Please sign in to comment.