Skip to content

Commit

Permalink
add batch-bundle proving e2e test
Browse files Browse the repository at this point in the history
  • Loading branch information
roynalnaruto committed Jul 17, 2024
1 parent c4a2489 commit 5c53d86
Show file tree
Hide file tree
Showing 16 changed files with 25,420 additions and 23 deletions.
20 changes: 10 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ serde_json = "1.0"
tokio = { version = "1.32", features = ["full"] }

halo2_proofs = { git = "https://github.com/scroll-tech/halo2.git", branch = "v1.1" }
prover = { git = "https://github.com/scroll-tech/zkevm-circuits.git", rev = "2d73894", default-features = false, features = ["parallel_syn", "scroll"] }
prover = { git = "https://github.com/scroll-tech/zkevm-circuits.git", branch = "release/v0.12.0", default-features = false, features = ["parallel_syn", "scroll"] }
integration = { path = "integration" }

[patch.crates-io]
Expand Down
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ test-bundle-prove:
test-e2e-prove:
@SCROLL_PROVER_DUMP_YUL=true cargo test --release -p integration --test e2e_tests test_e2e_prove_verify -- --exact --nocapture

test-batch-bundle-prove:
@SCROLL_PROVER_DUMP_YUL=true cargo test --release -p integration --test e2e_tests test_batch_bundle_verify -- --exact --nocapture

test-ccc:
@cargo test --release -p integration --test unit_tests test_capacity_checker -- --exact --nocapture

Expand Down
33 changes: 22 additions & 11 deletions integration/src/test_util.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::path::Path;
use std::path::{Path, PathBuf};

use glob::glob;
use prover::{
Expand Down Expand Up @@ -45,7 +45,15 @@ pub fn load_chunk(trace_path: &str) -> (Vec<String>, Vec<BlockTrace>) {
}

pub fn load_batch(batch_dir: &str) -> anyhow::Result<Vec<String>> {
let mut sorted_dirs: Vec<String> = std::fs::read_dir(batch_dir)?
let sorted_dirs = read_dir_recursive(batch_dir, "chunk_")?;
log::info!("batch content: {:?}", sorted_dirs);
Ok(sorted_dirs)
}

/// Reads inside a directory recursively and returns paths to all sub-directories that match the
/// given prefix.
pub fn read_dir_recursive(dir: impl AsRef<Path>, prefix: &str) -> anyhow::Result<Vec<String>> {
let mut sorted_dirs: Vec<String> = std::fs::read_dir(dir)?
.filter_map(|entry| entry.ok())
.map(|entry| entry.path())
.filter(|path| path.is_dir())
Expand All @@ -54,15 +62,18 @@ pub fn load_batch(batch_dir: &str) -> anyhow::Result<Vec<String>> {
sorted_dirs.sort_by_key(|s| {
let path = Path::new(s);
let dir_name = path.file_name().unwrap().to_string_lossy();
dir_name
.trim_start_matches("chunk_")
.parse::<u32>()
.unwrap()
dir_name.trim_start_matches(prefix).parse::<u32>().unwrap()
});
let fast = false;
if fast {
sorted_dirs.truncate(1);
}
log::info!("batch content: {:?}", sorted_dirs);
Ok(sorted_dirs)
}

/// Reads inside a directory and returns all files.
pub fn read_dir(dir: impl AsRef<Path>) -> anyhow::Result<Vec<PathBuf>> {
let mut sorted_files = std::fs::read_dir(dir)?
.filter_map(|entry| entry.ok())
.map(|entry| entry.path())
.filter(|path| path.is_file())
.collect::<Vec<_>>();
sorted_files.sort();
Ok(sorted_files)
}
4 changes: 3 additions & 1 deletion integration/tests/batch_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ fn test_batch_prove_verify() {
let output_dir = init_env_and_log("batch_tests");
log::info!("Initialized ENV and created output-dir {output_dir}");

let batch = load_batch_proving_task("tests/test_data/full_proof_1.json");
let batch = load_batch_proving_task("tests/test_data/full_proof_batch_prove_1.json");
log::info!("batch hash = {:?}", batch.batch_header.batch_hash());

dump_chunk_protocol(&batch, &output_dir);
let mut batch_prover = new_batch_prover(&output_dir);
prove_and_verify_batch(&output_dir, &mut batch_prover, batch);
Expand Down
38 changes: 38 additions & 0 deletions integration/tests/e2e_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,44 @@ fn test_e2e_prove_verify() {
prove_and_verify_bundle(&output_dir, batch_prover, bundle);
}

#[cfg(feature = "prove_verify")]
#[test]
fn test_batch_bundle_verify() -> anyhow::Result<()> {
use integration::{
prove::{new_batch_prover, prove_and_verify_batch, prove_and_verify_bundle},
test_util::read_dir,
};
use prover::{io::from_json_file, BundleProvingTask};

let output_dir = init_env_and_log("batch_bundle_tests");

let batch_tasks_paths = read_dir("./tests/test_data/batch_tasks")?;
let batch_tasks = batch_tasks_paths
.iter()
.map(|path| from_json_file::<BatchProvingTask>(&path.as_path().to_string_lossy()))
.collect::<anyhow::Result<Vec<_>>>()?;

log::info!("num batch tasks = {}", batch_tasks.len());

let mut prover = new_batch_prover(&output_dir);
let batch_proofs = batch_tasks
.into_iter()
.map(|batch_task| prove_and_verify_batch(&output_dir, &mut prover, batch_task))
.collect::<Vec<_>>();

let n = batch_proofs.len();
for i in 1..n {
log::info!("bundle {i} batches");
let bundle_task = BundleProvingTask {
batch_proofs: batch_proofs[0..i].to_vec(),
};
prove_and_verify_bundle(&output_dir, &mut prover, bundle_task);
log::info!("bundle {i} batches OK");
}

Ok(())
}

fn gen_batch_proving_task(
output_dir: &str,
chunk_dirs: &[String],
Expand Down
2,543 changes: 2,543 additions & 0 deletions integration/tests/test_data/batch_tasks/batch_task_293205.json

Large diffs are not rendered by default.

Loading

0 comments on commit 5c53d86

Please sign in to comment.