diff --git a/bin/src/trace_prover.rs b/bin/src/trace_prover.rs index 466f2cb7..aa9b86f6 100644 --- a/bin/src/trace_prover.rs +++ b/bin/src/trace_prover.rs @@ -1,6 +1,6 @@ use clap::Parser; use integration::{prove::prove_and_verify_chunk, test_util::load_chunk}; -use prover::{utils::init_env_and_log, ChunkProvingTask, zkevm::Prover}; +use prover::{utils::init_env_and_log, zkevm::Prover, ChunkProvingTask}; use std::env; #[derive(Parser, Debug)] @@ -40,8 +40,8 @@ fn main() { *prover::config::LAYER2_DEGREE, ], ); - let mut prover = Prover::from_params_and_assets(¶ms_map, &args.assets_path,); - log::info!("Constructed chunk prover"); + let mut prover = Prover::from_params_and_assets(¶ms_map, &args.assets_path); + log::info!("Constructed chunk prover"); prove_and_verify_chunk( ¶ms_map, &output_dir, diff --git a/integration/src/prove.rs b/integration/src/prove.rs index ffd7af4a..cab9f251 100644 --- a/integration/src/prove.rs +++ b/integration/src/prove.rs @@ -1,7 +1,7 @@ use halo2_proofs::{halo2curves::bn256::Bn256, poly::kzg::commitment::ParamsKZG}; use prover::{ - aggregator::Prover as BatchProver, zkevm::Prover as ChunkProver, ChunkProof, BatchData, BatchProof, - BatchProvingTask, BundleProvingTask, ChunkInfo, ChunkProvingTask, MAX_AGG_SNARKS, + aggregator::Prover as BatchProver, zkevm::Prover as ChunkProver, BatchData, BatchProof, + BatchProvingTask, BundleProvingTask, ChunkInfo, ChunkProof, ChunkProvingTask, MAX_AGG_SNARKS, }; use std::{collections::BTreeMap, env, time::Instant}; @@ -19,12 +19,12 @@ pub fn new_batch_prover<'a>( prover } -use prover::{Snark, utils::chunk_trace_to_witness_block}; use anyhow::Result; +use prover::{utils::chunk_trace_to_witness_block, Snark}; /// SP1Prover simple compress a snark from sp1, so we have /// same snark (only different preprocess bytes) as zkevm's chunk proof -pub struct SP1Prover<'p> (ChunkProver<'p>); +pub struct SP1Prover<'p>(ChunkProver<'p>); impl<'params> SP1Prover<'params> { pub fn from_params_and_assets( @@ -45,12 +45,10 @@ impl<'params> SP1Prover<'params> { sp1_snark: Snark, output_dir: Option<&str>, ) -> Result { - use prover::config::LayerId::Layer2; let witness_block = chunk_trace_to_witness_block(chunk.block_traces)?; - let chunk_info = - if let Some(chunk_info_input) = chunk.chunk_info { + let chunk_info = if let Some(chunk_info_input) = chunk.chunk_info { chunk_info_input } else { log::info!("gen chunk_info {chunk_identifier:?}"); @@ -58,11 +56,11 @@ impl<'params> SP1Prover<'params> { }; let comp_snark = self.0.prover_impl.load_or_gen_comp_snark( - chunk_identifier, + chunk_identifier, Layer2.id(), - false, - Layer2.degree(), - sp1_snark, + false, + Layer2.degree(), + sp1_snark, output_dir, )?; @@ -74,12 +72,11 @@ impl<'params> SP1Prover<'params> { ); if let (Some(output_dir), Ok(proof)) = (output_dir, &result) { - proof.dump(output_dir, &chunk_identifier)?; + proof.dump(output_dir, chunk_identifier)?; } - result + result } - } /// prove_and_verify_sp1_chunk would expect a sp1 snark name "sp1_snark_.json" @@ -91,9 +88,8 @@ pub fn prove_and_verify_sp1_chunk( prover: &mut SP1Prover, chunk_identifier: Option<&str>, ) -> ChunkProof { - use prover::io::load_snark; - use std::path::Path; + use std::path::Path; let chunk_identifier = chunk_identifier.map_or_else(|| chunk.identifier(), |name| name.to_string()); @@ -102,9 +98,10 @@ pub fn prove_and_verify_sp1_chunk( let sp1_snark_name = format!("sp1_snark_{}.json", chunk_identifier); let now = Instant::now(); - let sp1_snark = load_snark( - Path::new(sp1_dir).join(&sp1_snark_name).to_str().unwrap() - ).ok().flatten().unwrap(); + let sp1_snark = load_snark(Path::new(sp1_dir).join(&sp1_snark_name).to_str().unwrap()) + .ok() + .flatten() + .unwrap(); let chunk_proof = prover .gen_chunk_proof(chunk, &chunk_identifier, sp1_snark, Some(output_dir)) .expect("cannot generate sp1 chunk snark"); @@ -125,7 +122,6 @@ pub fn prove_and_verify_sp1_chunk( chunk_proof } - pub fn prove_and_verify_chunk( params_map: &BTreeMap>, output_dir: &str, @@ -133,7 +129,6 @@ pub fn prove_and_verify_chunk( prover: &mut ChunkProver, chunk_identifier: Option<&str>, ) -> ChunkProof { - let chunk_identifier = chunk_identifier.map_or_else(|| chunk.identifier(), |name| name.to_string()); diff --git a/integration/tests/batch_tests.rs b/integration/tests/batch_tests.rs index b9be0cf4..f1f4fc9d 100644 --- a/integration/tests/batch_tests.rs +++ b/integration/tests/batch_tests.rs @@ -90,14 +90,12 @@ fn test_batches_with_each_chunk_num_prove_verify() { fn test_batch_prove_verify_after_chunk_tests() { use integration::{ prove::get_blob_from_chunks, - test_util::{PARAMS_DIR, trace_path_for_test, load_chunk}, + test_util::{load_chunk, trace_path_for_test, PARAMS_DIR}, }; use itertools::Itertools; use prover::{ - eth_types::H256, - BatchHeader, ChunkProvingTask, - config::AGG_DEGREES, - proof::ChunkProof}; + config::AGG_DEGREES, eth_types::H256, proof::ChunkProof, BatchHeader, ChunkProvingTask, + }; let output_dir = init_env_and_log("batch_tests"); log::info!("Initialized ENV and created output-dir {output_dir}"); @@ -108,7 +106,7 @@ fn test_batch_prove_verify_after_chunk_tests() { ); let trace_paths_env = trace_path_for_test(); - let trace_paths : Vec<_> = trace_paths_env.split(';').collect(); + let trace_paths: Vec<_> = trace_paths_env.split(';').collect(); log::info!("Use traces paths {trace_paths:?}"); let mut l1_message_popped = 0; @@ -118,21 +116,18 @@ fn test_batch_prove_verify_after_chunk_tests() { let chunk_proofs = trace_paths .iter() .map(|chunk_dir| load_chunk(chunk_dir).1) - .map(|traces|{ + .map(|traces| { // make use of traces before consumed by chunkproof - l1_message_popped += traces.iter().map(|tr|tr.num_l1_txs()).sum::(); - last_block_timestamp = traces.last().map_or( - last_block_timestamp, - |tr|tr.header.timestamp.as_u64() - ); + l1_message_popped += traces.iter().map(|tr| tr.num_l1_txs()).sum::(); + last_block_timestamp = traces + .last() + .map_or(last_block_timestamp, |tr| tr.header.timestamp.as_u64()); let task = ChunkProvingTask::from(traces); - ChunkProof::from_json_file( - &output_dir, - &task.identifier(), - ) + ChunkProof::from_json_file(&output_dir, &task.identifier()) }) - .collect::, _>>().unwrap(); + .collect::, _>>() + .unwrap(); let chunk_infos = chunk_proofs .iter() @@ -141,12 +136,14 @@ fn test_batch_prove_verify_after_chunk_tests() { let blob_bytes = get_blob_from_chunks(&chunk_infos); - let batch_header = BatchHeader::construct_from_chunks( - 4, 123, l1_message_popped, l1_message_popped, + 4, + 123, + l1_message_popped, + l1_message_popped, H256([ - 0xab, 0xac, 0xad, 0xae, 0xaf, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, + 0xab, 0xac, 0xad, 0xae, 0xaf, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, ]), last_block_timestamp, &chunk_infos, diff --git a/integration/tests/chunk_tests.rs b/integration/tests/chunk_tests.rs index 56bf3fa6..9ff1632e 100644 --- a/integration/tests/chunk_tests.rs +++ b/integration/tests/chunk_tests.rs @@ -1,15 +1,14 @@ -use integration::test_util::{ASSETS_DIR, PARAMS_DIR}; -use prover::utils::init_env_and_log; use integration::{ prove::{prove_and_verify_chunk, prove_and_verify_sp1_chunk, SP1Prover}, - test_util::{load_chunk, trace_path_for_test}, + test_util::{load_chunk, trace_path_for_test, ASSETS_DIR, PARAMS_DIR}, +}; +use prover::{ + config::ZKEVM_DEGREES, utils::init_env_and_log, zkevm::Prover as ChunkProver, ChunkProvingTask, }; -use prover::{config::ZKEVM_DEGREES, ChunkProvingTask, zkevm::Prover as ChunkProver}; #[cfg(feature = "prove_verify")] #[test] fn test_chunk_prove_verify() { - use itertools::Itertools; let output_dir = init_env_and_log("chunk_tests"); log::info!("Initialized ENV and created output-dir {output_dir}"); @@ -48,16 +47,22 @@ fn test_sp1_chunk_prove_verify() { let trace_asset_path = if trace_asset_path.is_dir() { trace_asset_path.to_path_buf() } else { - trace_asset_path.parent() - .map(|p| p.to_path_buf()) - .unwrap_or_else(|| Path::new(".").to_path_buf()) + trace_asset_path + .parent() + .map(|p| p.to_path_buf()) + .unwrap_or_else(|| Path::new(".").to_path_buf()) }; let traces = load_chunk(&trace_path).1; let chunk = ChunkProvingTask::from(traces); let mut prover = SP1Prover::from_params_and_assets(¶ms_map, ASSETS_DIR); log::info!("Constructed sp1 chunk prover"); - prove_and_verify_sp1_chunk(¶ms_map, &output_dir, - Some(trace_asset_path.to_str().unwrap()), chunk, &mut prover, None); - + prove_and_verify_sp1_chunk( + ¶ms_map, + &output_dir, + Some(trace_asset_path.to_str().unwrap()), + chunk, + &mut prover, + None, + ); } diff --git a/integration/tests/e2e_tests.rs b/integration/tests/e2e_tests.rs index 27588ec6..2ff9bdc6 100644 --- a/integration/tests/e2e_tests.rs +++ b/integration/tests/e2e_tests.rs @@ -1,6 +1,6 @@ use halo2_proofs::{halo2curves::bn256::Bn256, poly::kzg::commitment::ParamsKZG}; use integration::{ - prove::{prove_and_verify_chunk, prove_and_verify_sp1_chunk, get_blob_from_chunks, SP1Prover}, + prove::{get_blob_from_chunks, prove_and_verify_chunk, prove_and_verify_sp1_chunk, SP1Prover}, test_util::{load_batch, load_chunk, load_chunk_for_test, ASSETS_DIR, PARAMS_DIR}, }; use prover::{ @@ -43,9 +43,11 @@ fn test_e2e_prove_verify() { .collect_vec(), ); - let chunk_paths = read_env_var("E2E_TRACE_PATHS", - "./tests/extra_traces/batch1;./tests/extra_traces/batch2".to_string()); - let chunks = chunk_paths.split(';').map(|dir|load_batch(dir).unwrap()); + let chunk_paths = read_env_var( + "E2E_TRACE_PATHS", + "./tests/extra_traces/batch1;./tests/extra_traces/batch2".to_string(), + ); + let chunks = chunk_paths.split(';').map(|dir| load_batch(dir).unwrap()); let sp1_path = { let p = read_env_var("SP1_PATH", String::new()); @@ -61,9 +63,13 @@ fn test_e2e_prove_verify() { let mut batch_proofs = Vec::new(); for (i, chunk) in chunks.enumerate() { - let (batch, batch_header) = - gen_batch_proving_task(¶ms_map, &output_dir, - &chunk, opt_batch_header, sp1_path.as_ref().map(String::as_str)); + let (batch, batch_header) = gen_batch_proving_task( + ¶ms_map, + &output_dir, + &chunk, + opt_batch_header, + sp1_path.as_ref().map(String::as_str), + ); dump_as_json( &output_dir, format!("batch_prove_{}", i + 1).as_str(), @@ -200,33 +206,33 @@ fn gen_batch_proving_task( let mut zkevm_prover = SP1Prover::from_params_and_assets(params_map, ASSETS_DIR); log::info!("Constructed sp1 prover"); chunks - .into_iter() - .map(|block_traces| { - prove_and_verify_sp1_chunk( - params_map, - output_dir, - Some(sp1_path), - ChunkProvingTask::from(block_traces), - &mut zkevm_prover, - None, - ) - }) - .collect::>() + .into_iter() + .map(|block_traces| { + prove_and_verify_sp1_chunk( + params_map, + output_dir, + Some(sp1_path), + ChunkProvingTask::from(block_traces), + &mut zkevm_prover, + None, + ) + }) + .collect::>() } else { let mut zkevm_prover = zkevm::Prover::from_params_and_assets(params_map, ASSETS_DIR); log::info!("Constructed zkevm prover"); chunks - .into_iter() - .map(|block_traces| { - prove_and_verify_chunk( - params_map, - output_dir, - ChunkProvingTask::from(block_traces), - &mut zkevm_prover, - None, - ) - }) - .collect::>() + .into_iter() + .map(|block_traces| { + prove_and_verify_chunk( + params_map, + output_dir, + ChunkProvingTask::from(block_traces), + &mut zkevm_prover, + None, + ) + }) + .collect::>() }; log::info!("Generated chunk proofs");