diff --git a/Cargo.lock b/Cargo.lock index a84d43a9..c6e8083e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -31,11 +31,12 @@ dependencies = [ [[package]] name = "aggregator" version = "0.14.0" -source = "git+https://github.com/scroll-tech/zkevm-circuits.git?branch=develop#72bb2a80a21b954642f02315d64292c7b8ec657f" +source = "git+https://github.com/scroll-tech/zkevm-circuits.git?branch=develop#7fd6b6d7397a91daac347523748d58209becb140" dependencies = [ "ark-std 0.3.0", "bitstream-io", "c-kzg", + "cfg-if 1.0.0", "ctor", "encoder", "env_logger", @@ -631,7 +632,7 @@ checksum = "0d261e256854913907f67ed06efbc3338dfe6179796deefc1ff763fc1aee5535" [[package]] name = "bus-mapping" version = "0.14.0" -source = "git+https://github.com/scroll-tech/zkevm-circuits.git?branch=develop#72bb2a80a21b954642f02315d64292c7b8ec657f" +source = "git+https://github.com/scroll-tech/zkevm-circuits.git?branch=develop#7fd6b6d7397a91daac347523748d58209becb140" dependencies = [ "eth-types", "ethers-core", @@ -1214,7 +1215,7 @@ dependencies = [ [[package]] name = "encoder" version = "0.1.0" -source = "git+https://github.com/scroll-tech/da-codec.git?tag=v0.1.0#5a28b752d4504bf0966734fe4a6a5433981c74c2" +source = "git+https://github.com/scroll-tech/da-codec.git?tag=v0.1.2#8c5d2f0cd707153151a5154fef702204f6ca40b3" dependencies = [ "zstd", ] @@ -1322,7 +1323,7 @@ dependencies = [ [[package]] name = "eth-types" version = "0.14.0" -source = "git+https://github.com/scroll-tech/zkevm-circuits.git?branch=develop#72bb2a80a21b954642f02315d64292c7b8ec657f" +source = "git+https://github.com/scroll-tech/zkevm-circuits.git?branch=develop#7fd6b6d7397a91daac347523748d58209becb140" dependencies = [ "base64 0.13.1", "ethers-core", @@ -1478,7 +1479,7 @@ dependencies = [ [[package]] name = "external-tracer" version = "0.14.0" -source = "git+https://github.com/scroll-tech/zkevm-circuits.git?branch=develop#72bb2a80a21b954642f02315d64292c7b8ec657f" +source = "git+https://github.com/scroll-tech/zkevm-circuits.git?branch=develop#7fd6b6d7397a91daac347523748d58209becb140" dependencies = [ "eth-types", "geth-utils", @@ -1666,7 +1667,7 @@ dependencies = [ [[package]] name = "gadgets" version = "0.14.0" -source = "git+https://github.com/scroll-tech/zkevm-circuits.git?branch=develop#72bb2a80a21b954642f02315d64292c7b8ec657f" +source = "git+https://github.com/scroll-tech/zkevm-circuits.git?branch=develop#7fd6b6d7397a91daac347523748d58209becb140" dependencies = [ "eth-types", "halo2_proofs", @@ -1689,7 +1690,7 @@ dependencies = [ [[package]] name = "geth-utils" version = "0.14.0" -source = "git+https://github.com/scroll-tech/zkevm-circuits.git?branch=develop#72bb2a80a21b954642f02315d64292c7b8ec657f" +source = "git+https://github.com/scroll-tech/zkevm-circuits.git?branch=develop#7fd6b6d7397a91daac347523748d58209becb140" dependencies = [ "env_logger", "gobuild", @@ -2509,7 +2510,7 @@ dependencies = [ [[package]] name = "mock" version = "0.14.0" -source = "git+https://github.com/scroll-tech/zkevm-circuits.git?branch=develop#72bb2a80a21b954642f02315d64292c7b8ec657f" +source = "git+https://github.com/scroll-tech/zkevm-circuits.git?branch=develop#7fd6b6d7397a91daac347523748d58209becb140" dependencies = [ "eth-types", "ethers-core", @@ -2524,7 +2525,7 @@ dependencies = [ [[package]] name = "mpt-zktrie" version = "0.14.0" -source = "git+https://github.com/scroll-tech/zkevm-circuits.git?branch=develop#72bb2a80a21b954642f02315d64292c7b8ec657f" +source = "git+https://github.com/scroll-tech/zkevm-circuits.git?branch=develop#7fd6b6d7397a91daac347523748d58209becb140" dependencies = [ "eth-types", "halo2curves", @@ -3057,7 +3058,7 @@ dependencies = [ [[package]] name = "prover" version = "0.14.0" -source = "git+https://github.com/scroll-tech/zkevm-circuits.git?branch=develop#72bb2a80a21b954642f02315d64292c7b8ec657f" +source = "git+https://github.com/scroll-tech/zkevm-circuits.git?branch=develop#7fd6b6d7397a91daac347523748d58209becb140" dependencies = [ "aggregator", "anyhow", @@ -3086,6 +3087,7 @@ dependencies = [ "sha2", "snark-verifier", "snark-verifier-sdk", + "thiserror", "zkevm-circuits", ] @@ -3771,9 +3773,9 @@ checksum = "cd0b0ec5f1c1ca621c432a25813d8d60c88abe6d3e08a3eb9cf37d97a0fe3d73" [[package]] name = "serde" -version = "1.0.159" +version = "1.0.210" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c04e8343c3daeec41f58990b9d77068df31209f2af111e059e9fe9646693065" +checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" dependencies = [ "serde_derive", ] @@ -3789,9 +3791,9 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.159" +version = "1.0.210" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c614d17805b093df4b147b51339e7e44bf05ef59fba1e45d83500bcfb4d8585" +checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" dependencies = [ "proc-macro2", "quote", @@ -3945,7 +3947,7 @@ checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" [[package]] name = "snark-verifier" version = "0.1.0" -source = "git+https://github.com/scroll-tech/snark-verifier?branch=develop#572ef69d1595fca82213d3b05e859eaf355a5fa1" +source = "git+https://github.com/scroll-tech/snark-verifier?branch=develop#948671cac73f11e66187a15483e38ab3626dc2a3" dependencies = [ "bytes", "ethereum-types", @@ -3968,7 +3970,7 @@ dependencies = [ [[package]] name = "snark-verifier-sdk" version = "0.0.1" -source = "git+https://github.com/scroll-tech/snark-verifier?branch=develop#572ef69d1595fca82213d3b05e859eaf355a5fa1" +source = "git+https://github.com/scroll-tech/snark-verifier?branch=develop#948671cac73f11e66187a15483e38ab3626dc2a3" dependencies = [ "bincode", "ethereum-types", @@ -4904,7 +4906,7 @@ dependencies = [ [[package]] name = "zkevm-circuits" version = "0.14.0" -source = "git+https://github.com/scroll-tech/zkevm-circuits.git?branch=develop#72bb2a80a21b954642f02315d64292c7b8ec657f" +source = "git+https://github.com/scroll-tech/zkevm-circuits.git?branch=develop#7fd6b6d7397a91daac347523748d58209becb140" dependencies = [ "array-init", "bus-mapping", diff --git a/bin/src/chain_prover.rs b/bin/src/chain_prover.rs index 4ecdeec7..5f8a41c7 100644 --- a/bin/src/chain_prover.rs +++ b/bin/src/chain_prover.rs @@ -10,10 +10,8 @@ use integration::{ l2geth, }; use prover::{ - aggregator, - utils::init_env_and_log, - zkevm::{circuit::block_traces_to_witness_block, CircuitCapacityChecker, RowUsage}, - BatchData, BlockTrace, ChunkInfo, ChunkProof, MAX_AGG_SNARKS, + eth_types::l2_types::BlockTrace, init_env_and_log, BatchData, ChunkInfo, ChunkProofV2, + CircuitCapacityChecker, RowUsage, MAX_AGG_SNARKS, }; use std::env; @@ -81,7 +79,7 @@ impl BatchBuilder { } let batch_bytes = self.batch_data.get_batch_data_bytes(); - let blob_bytes = aggregator::eip4844::get_blob_bytes(&batch_bytes); + let blob_bytes = prover::get_blob_bytes(&batch_bytes); let compressed_da_size = blob_bytes.len(); let uncompressed_da_size = self .batch_data @@ -194,7 +192,7 @@ async fn prove_by_block(l2geth: &l2geth::Client, begin_block: i64, end_block: i6 unimplemented!("uncomment below"); //ChunkInfo::from_block_traces(&chunk) } else { - let witness_block = block_traces_to_witness_block(chunk).unwrap(); + let witness_block = prover::chunk_trace_to_witness_block(chunk).unwrap(); ChunkInfo::from_witness_block(&witness_block, false) }; if let Some(batch) = batch_builder.add(chunk_info) { @@ -202,7 +200,7 @@ async fn prove_by_block(l2geth: &l2geth::Client, begin_block: i64, end_block: i6 padding_chunk(&mut padded_batch); let batch_data = BatchData::<{ MAX_AGG_SNARKS }>::new(batch.len(), &padded_batch); let compressed_da_size = - aggregator::eip4844::get_blob_bytes(&batch_data.get_batch_data_bytes()).len(); + prover::get_blob_bytes(&batch_data.get_batch_data_bytes()).len(); log::info!( "batch built: blob usage {:.3}, chunk num {}, block num {}, block range {} to {}", compressed_da_size as f32 / constants::N_BLOB_BYTES as f32, @@ -234,7 +232,11 @@ fn padding_chunk(chunks: &mut Vec) { } } -fn prove_chunk(batch_id: u64, chunk_id: u64, block_traces: Vec) -> Option { +fn prove_chunk( + batch_id: u64, + chunk_id: u64, + block_traces: Vec, +) -> Option { let total_gas: u64 = block_traces .iter() .map(|b| b.header.gas_used.as_u64()) diff --git a/bin/src/prove_utils.rs b/bin/src/prove_utils.rs index 95b9d352..1f50ad6a 100644 --- a/bin/src/prove_utils.rs +++ b/bin/src/prove_utils.rs @@ -1,4 +1,4 @@ -use prover::{BlockTrace, ChunkProof}; +use prover::{eth_types::l2_types::BlockTrace, ChunkProofV2}; use std::panic::{catch_unwind, AssertUnwindSafe}; #[cfg(feature = "batch-prove")] @@ -7,7 +7,7 @@ use prover::{BatchHeader, MAX_AGG_SNARKS}; #[cfg(feature = "batch-prove")] pub fn prove_batch( id: &str, - chunk_proofs: Vec, + chunk_proofs: Vec, batch_header: BatchHeader, ) { use integration::prove::get_blob_from_chunks; @@ -16,7 +16,7 @@ pub fn prove_batch( let chunk_infos = chunk_proofs .iter() - .map(|p| p.chunk_info.clone()) + .map(|p| p.inner.chunk_info().clone()) .collect_vec(); let blob_bytes = get_blob_from_chunks(&chunk_infos); let batch = BatchProvingTask { @@ -24,7 +24,7 @@ pub fn prove_batch( batch_header, blob_bytes, }; - let result = catch_unwind(AssertUnwindSafe(|| prover::test::batch_prove(id, batch))); + let result = catch_unwind(AssertUnwindSafe(|| prover::batch_prove(id, batch))); match result { Ok(_) => log::info!("{id}: succeeded to prove batch"), @@ -41,21 +41,15 @@ pub fn prove_batch( } } -pub fn prove_chunk(id: &str, traces: Vec) -> Option { +pub fn prove_chunk(id: &str, traces: Vec) -> Option { let result = catch_unwind(AssertUnwindSafe(|| { #[cfg(not(feature = "chunk-prove"))] - let proof = None::; + let proof = None::; - #[cfg(feature = "inner-prove")] - { - let witness_block = - prover::zkevm::circuit::block_traces_to_witness_block(traces.clone()).unwrap(); - prover::test::inner_prove(id, &witness_block); - } #[cfg(feature = "chunk-prove")] - let proof = Some(prover::test::chunk_prove( + let proof = Some(prover::chunk_prove( id, - prover::ChunkProvingTask::from(traces), + prover::ChunkProvingTask::new(traces), )); #[cfg(not(any(feature = "inner-prove", feature = "chunk-prove")))] mock_prove(id, traces); @@ -84,12 +78,10 @@ pub fn prove_chunk(id: &str, traces: Vec) -> Option { } #[cfg(not(any(feature = "inner-prove", feature = "chunk-prove")))] -fn mock_prove(id: &str, traces: Vec) { - use prover::{inner::Prover, zkevm::circuit::SuperCircuit}; - +fn mock_prove(id: &str, traces: Vec) { log::info!("{id}: mock-prove BEGIN"); - Prover::::mock_prove_target_circuit_chunk(traces) + integration::mock::mock_prove_target_circuit_chunk(traces) .unwrap_or_else(|err| panic!("{id}: failed to mock-prove: {err}")); log::info!("{id}: mock-prove END"); diff --git a/bin/src/trace_prover.rs b/bin/src/trace_prover.rs index 1931b9ce..d8ea598c 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}; +use prover::{init_env_and_log, ChunkProvingTask}; use std::env; #[derive(Parser, Debug)] @@ -31,15 +31,9 @@ fn main() { let traces = load_chunk(&args.trace_path).1; prover::eth_types::constants::set_scroll_block_constants_with_trace(&traces[0]); - let chunk = ChunkProvingTask::from(traces); - let params_map = prover::common::Prover::load_params_map( - &args.params_path, - &[ - *prover::config::INNER_DEGREE, - *prover::config::LAYER1_DEGREE, - *prover::config::LAYER2_DEGREE, - ], - ); + let chunk = ChunkProvingTask::new(traces); + let params_map = + prover::Prover::load_params_map(&args.params_path, &prover::CHUNK_PROVER_DEGREES); prove_and_verify_chunk( chunk, Some("0"), // same with `make test-chunk-prove`, to load vk diff --git a/integration/Cargo.toml b/integration/Cargo.toml index c969975f..58be85f0 100644 --- a/integration/Cargo.toml +++ b/integration/Cargo.toml @@ -26,3 +26,4 @@ prover.workspace = true [features] default = ["prove_verify"] prove_verify = [] +fix_later = [] # commented codes diff --git a/integration/configs/layer3.config b/integration/configs/layer3.config index be4fea74..6b6b86a7 100644 --- a/integration/configs/layer3.config +++ b/integration/configs/layer3.config @@ -2,7 +2,7 @@ "strategy": "Simple", "degree": 21, "num_advice": [ - 63 + 85 ], "num_lookup_advice": [ 8 diff --git a/integration/src/capacity_checker.rs b/integration/src/capacity_checker.rs index 2b37b81c..fdcc937a 100644 --- a/integration/src/capacity_checker.rs +++ b/integration/src/capacity_checker.rs @@ -1,11 +1,8 @@ use itertools::Itertools; use prover::{ - zkevm::{ - circuit::{block_traces_to_witness_block, calculate_row_usage_of_witness_block}, - CircuitCapacityChecker, RowUsage, SubCircuitRowUsage, - }, - zkevm_circuits::evm_circuit::ExecutionState, - BlockTrace, + calculate_row_usage_of_witness_block, chunk_trace_to_witness_block, + eth_types::l2_types::BlockTrace, zkevm_circuits::evm_circuit::ExecutionState, + CircuitCapacityChecker, RowUsage, SubCircuitRowUsage, }; use std::time::Duration; @@ -262,7 +259,7 @@ pub fn ccc_by_chunk( log::info!("ccc_by_chunk: run ccc for batch-{batch_id} chunk-{chunk_id}"); let start_time = std::time::Instant::now(); - let witness_block = block_traces_to_witness_block(Vec::from(block_traces)).unwrap(); + let witness_block = chunk_trace_to_witness_block(Vec::from(block_traces)).unwrap(); let rows = calculate_row_usage_of_witness_block(&witness_block).unwrap(); let row_usage = RowUsage::from_row_usage_details(rows); pretty_print_row_usage(&row_usage, block_traces, chunk_id, "chunk-opt"); diff --git a/integration/src/l2geth.rs b/integration/src/l2geth.rs index d96bd238..52a12f43 100644 --- a/integration/src/l2geth.rs +++ b/integration/src/l2geth.rs @@ -1,6 +1,6 @@ use anyhow::Result; use ethers_providers::{Http, Middleware, Provider}; -use prover::BlockTrace; +use prover::eth_types::l2_types::BlockTrace; use serde::Serialize; pub struct Client { diff --git a/integration/src/lib.rs b/integration/src/lib.rs index 34e4e2ce..b069aa44 100644 --- a/integration/src/lib.rs +++ b/integration/src/lib.rs @@ -1,5 +1,6 @@ pub mod capacity_checker; pub mod l2geth; +pub mod mock; pub mod prove; pub mod test_util; mod verifier; diff --git a/integration/src/mock.rs b/integration/src/mock.rs new file mode 100644 index 00000000..5a82f332 --- /dev/null +++ b/integration/src/mock.rs @@ -0,0 +1,35 @@ +use anyhow::bail; +use halo2_proofs::{dev::MockProver, halo2curves::bn256::Fr}; +use prover::{ + eth_types::l2_types::BlockTrace, + zkevm_circuits::{super_circuit::params::ScrollSuperCircuit, util::SubCircuit, witness::Block}, +}; +use snark_verifier_sdk::CircuitExt; + +use prover::{chunk_trace_to_witness_block, metric_of_witness_block, INNER_DEGREE}; + +pub fn mock_prove_target_circuit_chunk(block_traces: Vec) -> anyhow::Result<()> { + let witness_block = chunk_trace_to_witness_block(block_traces)?; + mock_prove_witness_block(&witness_block) +} + +pub fn mock_prove_witness_block(witness_block: &Block) -> anyhow::Result<()> { + log::info!( + "mock proving chunk, chunk metric {:?}", + metric_of_witness_block(witness_block) + ); + let circuit = ScrollSuperCircuit::new_from_block(witness_block); + let prover = MockProver::::run(*INNER_DEGREE, &circuit, circuit.instances())?; + if let Err(errs) = prover.verify_par() { + log::error!("err num: {}", errs.len()); + for err in &errs { + log::error!("{}", err); + } + bail!("{:#?}", errs); + } + log::info!( + "mock prove done. chunk metric: {:?}", + metric_of_witness_block(witness_block), + ); + Ok(()) +} diff --git a/integration/src/prove.rs b/integration/src/prove.rs index 53ae2c0c..93d98e5b 100644 --- a/integration/src/prove.rs +++ b/integration/src/prove.rs @@ -1,18 +1,19 @@ use halo2_proofs::{halo2curves::bn256::Bn256, poly::kzg::commitment::ParamsKZG}; use prover::{ - aggregator::Prover as BatchProver, zkevm::Prover as ChunkProver, BatchData, BatchProof, - BatchProvingTask, BundleProvingTask, ChunkInfo, ChunkProvingTask, MAX_AGG_SNARKS, + get_blob_bytes, BatchData, BatchProofV2, BatchProver, BatchProvingTask, BatchVerifier, + BundleProvingTask, ChunkInfo, ChunkProver, ChunkProvingTask, ChunkVerifier, MAX_AGG_SNARKS, }; use std::{collections::BTreeMap, env, time::Instant}; -use crate::verifier::{new_batch_verifier, new_chunk_verifier, EVMVerifier}; +use crate::verifier::EVMVerifier; /// The `output_dir` is assumed to output_dir of chunk proving. pub fn new_batch_prover<'a>( params_map: &'a BTreeMap>, output_dir: &str, ) -> BatchProver<'a> { - env::set_var("CHUNK_PROTOCOL_FILENAME", "chunk_chunk_0.protocol"); + env::set_var("HALO2_CHUNK_PROTOCOL", "protocol_chunk_0.protocol"); + env::set_var("SP1_CHUNK_PROTOCOL", "protocol_chunk_0.protocol"); let prover = BatchProver::from_params_and_assets(params_map, output_dir); log::info!("Constructed batch prover"); @@ -34,7 +35,7 @@ pub fn prove_and_verify_chunk( let now = Instant::now(); let chunk_proof = prover - .gen_chunk_proof(chunk, Some(&chunk_identifier), None, Some(output_dir)) + .gen_halo2_chunk_proof(chunk, Some(&chunk_identifier), None, Some(output_dir)) .expect("cannot generate chunk snark"); log::info!( "finish generating chunk snark, elapsed: {:?}", @@ -46,8 +47,10 @@ pub fn prove_and_verify_chunk( "CHUNK_VK_FILENAME", &format!("vk_chunk_{chunk_identifier}.vkey"), ); - let verifier = new_chunk_verifier(params_map, output_dir); - assert!(verifier.verify_snark(chunk_proof.to_snark())); + let verifier = ChunkVerifier::from_params_and_assets(params_map, output_dir); + verifier + .verify_chunk_proof(&chunk_proof) + .expect("should verify"); log::info!("Verified chunk proof"); } @@ -56,10 +59,11 @@ pub fn prove_and_verify_batch( output_dir: &str, batch_prover: &mut BatchProver, batch: BatchProvingTask, -) -> BatchProof { +) -> BatchProofV2 { let chunk_num = batch.chunk_proofs.len(); log::info!("Prove batch BEGIN: chunk_num = {chunk_num}"); + let batch_id = batch.identifier(); let res_batch_proof = batch_prover.gen_batch_proof(batch, None, Some(output_dir)); if let Err(e) = res_batch_proof { log::error!("proving err: {e}"); @@ -67,11 +71,13 @@ pub fn prove_and_verify_batch( } let batch_proof = res_batch_proof.unwrap(); - env::set_var("BATCH_VK_FILENAME", "vk_batch_agg.vkey"); - let verifier = new_batch_verifier(params_map, output_dir); + env::set_var("BATCH_VK_FILENAME", format!("vk_batch_{batch_id}.vkey")); + let verifier = BatchVerifier::from_params_and_assets(params_map, output_dir); log::info!("Constructed aggregator verifier"); - assert!(verifier.verify_snark((&batch_proof).into())); + verifier + .verify_batch_proof(&batch_proof) + .expect("should verify"); log::info!("Verified batch proof"); log::info!("Prove batch END: chunk_num = {chunk_num}"); @@ -115,7 +121,7 @@ pub fn get_blob_from_chunks(chunks: &[ChunkInfo]) -> Vec { .concat(); let batch_data = BatchData::<{ MAX_AGG_SNARKS }>::new(chunks.len(), &chunks_with_padding); let batch_bytes = batch_data.get_batch_data_bytes(); - let blob_bytes = prover::aggregator::eip4844::get_blob_bytes(&batch_bytes); + let blob_bytes = get_blob_bytes(&batch_bytes); log::info!("blob_bytes len {}", blob_bytes.len()); blob_bytes } diff --git a/integration/src/test_util.rs b/integration/src/test_util.rs index b163d395..f5177ff7 100644 --- a/integration/src/test_util.rs +++ b/integration/src/test_util.rs @@ -1,14 +1,24 @@ -use std::path::{Path, PathBuf}; +use std::{ + io::Read, + path::{Path, PathBuf}, +}; use glob::glob; -use prover::{ - utils::{get_block_trace_from_file, read_env_var}, - BlockTrace, -}; +use prover::{eth_types::l2_types::BlockTrace, get_block_trace_from_file, read_env_var}; pub const ASSETS_DIR: &str = "./test_assets"; pub const PARAMS_DIR: &str = "./params"; +pub fn read_all

(filename: P) -> Vec +where + P: AsRef, +{ + let mut buf = vec![]; + let mut fd = std::fs::File::open(filename).unwrap(); + fd.read_to_end(&mut buf).unwrap(); + buf +} + pub fn trace_path_for_test() -> String { // use trace file of post-curie upgrade read_env_var( diff --git a/integration/src/verifier.rs b/integration/src/verifier.rs index 18a01244..459c203a 100644 --- a/integration/src/verifier.rs +++ b/integration/src/verifier.rs @@ -1,47 +1,6 @@ -use halo2_proofs::{halo2curves::bn256::Bn256, poly::kzg::commitment::ParamsKZG}; -use prover::{common::Verifier, config, consts, io::force_to_read, CompressionCircuit}; -use std::{collections::BTreeMap, env}; +use std::path::PathBuf; -type SnarkVerifier<'a> = Verifier<'a, CompressionCircuit>; - -// FIXME: why we use common::Verifier instead of ChunkVerifier here? -pub fn new_chunk_verifier<'a>( - params_map: &'a BTreeMap>, - assets_dir: &str, -) -> SnarkVerifier<'a> { - let raw_vk = force_to_read(assets_dir, &consts::chunk_vk_filename()); - if raw_vk.is_empty() { - panic!( - "empty vk read from {}/{}", - assets_dir, - &consts::chunk_vk_filename() - ); - } - env::set_var("COMPRESSION_CONFIG", &*config::LAYER2_CONFIG_PATH); - let params = params_map - .get(&config::LAYER2_DEGREE) - .expect("should be loaded"); - SnarkVerifier::from_params(params, &raw_vk) -} - -pub fn new_batch_verifier<'a>( - params_map: &'a BTreeMap>, - assets_dir: &str, -) -> SnarkVerifier<'a> { - let raw_vk = force_to_read(assets_dir, &consts::batch_vk_filename()); - if raw_vk.is_empty() { - panic!( - "empty vk read from {}/{}", - assets_dir, - &consts::batch_vk_filename() - ); - } - env::set_var("COMPRESSION_CONFIG", &*config::LAYER4_CONFIG_PATH); - let params = params_map - .get(&config::LAYER4_DEGREE) - .expect("should be loaded"); - SnarkVerifier::from_params(params, &raw_vk) -} +use prover::{force_read, DEPLOYMENT_CODE_FILENAME}; #[derive(Debug)] pub struct EVMVerifier(Vec); @@ -52,7 +11,8 @@ impl EVMVerifier { } pub fn from_dirs(assets_dir: &str) -> Self { - Self::new(force_to_read(assets_dir, &consts::DEPLOYMENT_CODE_FILENAME)) + let path = PathBuf::from(assets_dir).join(DEPLOYMENT_CODE_FILENAME.clone()); + Self::new(force_read(&path)) } pub fn verify_evm_proof(&self, call_data: Vec) -> bool { diff --git a/integration/tests/batch_tests.rs b/integration/tests/batch_tests.rs index 5e3b4cdf..0ff42a05 100644 --- a/integration/tests/batch_tests.rs +++ b/integration/tests/batch_tests.rs @@ -1,5 +1,5 @@ use integration::prove::{new_batch_prover, prove_and_verify_batch}; -use prover::{io::from_json_file, utils::init_env_and_log, BatchProvingTask}; +use prover::{init_env_and_log, read_json_deep, BatchProvingTask}; use std::{fs, path::PathBuf}; #[cfg(feature = "prove_verify")] @@ -7,14 +7,14 @@ use std::{fs, path::PathBuf}; fn test_batch_prove_verify() { use integration::test_util::PARAMS_DIR; use itertools::Itertools; - use prover::config::AGG_DEGREES; + use prover::BATCH_PROVER_DEGREES; let output_dir = init_env_and_log("batch_tests"); log::info!("Initialized ENV and created output-dir {output_dir}"); - let params_map = prover::common::Prover::load_params_map( + let params_map = prover::Prover::load_params_map( PARAMS_DIR, - &AGG_DEGREES.iter().copied().collect_vec(), + &BATCH_PROVER_DEGREES.iter().copied().collect_vec(), ); //let task_path = "tests/test_data/batch-task-with-blob.json"; // zstd @@ -26,7 +26,7 @@ fn test_batch_prove_verify() { .chunk_proofs .clone() .into_iter() - .map(|p| p.chunk_info) + .map(|p| p.inner.chunk_info().clone()) .collect::>(); let corrected_batch_header = prover::BatchHeader::construct_from_chunks( batch.batch_header.version, @@ -50,14 +50,13 @@ fn test_batch_prove_verify() { fn test_batches_with_each_chunk_num_prove_verify() { use integration::test_util::PARAMS_DIR; use itertools::Itertools; - use prover::config::AGG_DEGREES; let output_dir = init_env_and_log("batches_with_each_chunk_num_tests"); log::info!("Initialized ENV and created output-dir {output_dir}"); - let params_map = prover::common::Prover::load_params_map( + let params_map = prover::Prover::load_params_map( PARAMS_DIR, - &AGG_DEGREES.iter().copied().collect_vec(), + &prover::BATCH_PROVER_DEGREES.iter().copied().collect_vec(), ); let batch = load_batch_proving_task("tests/test_data/full_proof_1.json"); @@ -85,11 +84,11 @@ fn test_batches_with_each_chunk_num_prove_verify() { } fn load_batch_proving_task(batch_task_file: &str) -> BatchProvingTask { - let batch: BatchProvingTask = from_json_file(batch_task_file).unwrap(); + let batch: BatchProvingTask = read_json_deep(batch_task_file).unwrap(); let tx_bytes_total_len: usize = batch .chunk_proofs .iter() - .map(|c| c.chunk_info.tx_bytes.len()) + .map(|c| c.inner.chunk_info().tx_bytes.len()) .sum(); log::info!("Loaded chunk-hashes and chunk-proofs, batch info: chunk num {}, tx_bytes_total_len {tx_bytes_total_len}", batch.chunk_proofs.len()); batch diff --git a/integration/tests/bundle_tests.rs b/integration/tests/bundle_tests.rs index 82a62593..0cc07ba5 100644 --- a/integration/tests/bundle_tests.rs +++ b/integration/tests/bundle_tests.rs @@ -1,5 +1,5 @@ use integration::prove::{new_batch_prover, prove_and_verify_bundle}; -use prover::{io::from_json_file, utils::init_env_and_log, BatchProof, BundleProvingTask}; +use prover::{init_env_and_log, read_json, BatchProofV2, BundleProvingTask}; //use std::{fs, path::PathBuf}; #[cfg(feature = "prove_verify")] @@ -7,14 +7,14 @@ use prover::{io::from_json_file, utils::init_env_and_log, BatchProof, BundleProv fn test_bundle_prove_verify() { use integration::test_util::PARAMS_DIR; use itertools::Itertools; - use prover::config::AGG_DEGREES; + use prover::BATCH_PROVER_DEGREES; let output_dir = init_env_and_log("bundle_tests"); log::info!("Initialized ENV and created output-dir {output_dir}"); - let params_map = prover::common::Prover::load_params_map( + let params_map = prover::Prover::load_params_map( PARAMS_DIR, - &AGG_DEGREES.iter().copied().collect_vec(), + &BATCH_PROVER_DEGREES.iter().copied().collect_vec(), ); let bundle_task = gen_bundle_proving_task(&[ @@ -30,8 +30,11 @@ fn gen_bundle_proving_task(batch_proof_files: &[&str]) -> BundleProvingTask { let mut batch_proofs = Vec::new(); for proof_file in batch_proof_files { - let batch_proof: BatchProof = from_json_file(proof_file).unwrap(); - log::debug!("Loaded batch-proofs, header {:#?}", batch_proof.batch_hash,); + let batch_proof: BatchProofV2 = read_json(proof_file).unwrap(); + log::debug!( + "Loaded batch-proofs, header {:#?}", + batch_proof.inner.batch_hash + ); batch_proofs.push(batch_proof); } diff --git a/integration/tests/chunk_tests.rs b/integration/tests/chunk_tests.rs index aac3d605..8e1d488d 100644 --- a/integration/tests/chunk_tests.rs +++ b/integration/tests/chunk_tests.rs @@ -1,5 +1,5 @@ use integration::test_util::{ASSETS_DIR, PARAMS_DIR}; -use prover::utils::init_env_and_log; +use prover::init_env_and_log; #[cfg(feature = "prove_verify")] #[test] @@ -9,18 +9,18 @@ fn test_chunk_prove_verify() { test_util::{load_chunk, trace_path_for_test}, }; use itertools::Itertools; - use prover::{config::ZKEVM_DEGREES, ChunkProvingTask}; + use prover::{ChunkProvingTask, CHUNK_PROVER_DEGREES}; let output_dir = init_env_and_log("chunk_tests"); log::info!("Initialized ENV and created output-dir {output_dir}"); - let params_map = prover::common::Prover::load_params_map( + let params_map = prover::Prover::load_params_map( PARAMS_DIR, - &ZKEVM_DEGREES.iter().copied().collect_vec(), + &CHUNK_PROVER_DEGREES.iter().copied().collect_vec(), ); let trace_path = trace_path_for_test(); let traces = load_chunk(&trace_path).1; - let chunk = ChunkProvingTask::from(traces); + let chunk = ChunkProvingTask::new(traces); prove_and_verify_chunk(chunk, None, ¶ms_map, ASSETS_DIR, &output_dir); } diff --git a/integration/tests/e2e_tests.rs b/integration/tests/e2e_tests.rs index 897519ad..c0645026 100644 --- a/integration/tests/e2e_tests.rs +++ b/integration/tests/e2e_tests.rs @@ -1,45 +1,43 @@ use halo2_proofs::{halo2curves::bn256::Bn256, poly::kzg::commitment::ParamsKZG}; use integration::{ prove::get_blob_from_chunks, - test_util::{load_batch, load_chunk, load_chunk_for_test, ASSETS_DIR, PARAMS_DIR}, + test_util::{load_batch, load_chunk, ASSETS_DIR, PARAMS_DIR}, }; use prover::{ - eth_types::H256, - proof::dump_as_json, - utils::{chunk_trace_to_witness_block, init_env_and_log, read_env_var}, - zkevm, BatchHash, BatchHeader, BatchProvingTask, ChunkInfo, ChunkProvingTask, MAX_AGG_SNARKS, + eth_types::H256, init_env_and_log, BatchHeader, BatchProvingTask, ChunkProver, + ChunkProvingTask, MAX_AGG_SNARKS, }; -use std::{collections::BTreeMap, env}; - -fn load_test_batch() -> anyhow::Result> { - let batch_dir = read_env_var("TRACE_PATH", "./tests/extra_traces/batch_25".to_string()); - load_batch(&batch_dir) -} +use std::collections::BTreeMap; +/* +#[cfg(feature = "fix_later")] #[test] fn test_batch_pi_consistency() { let output_dir = init_env_and_log("batch_pi"); log::info!("Initialized ENV and created output-dir {output_dir}"); - let trace_paths = load_test_batch().unwrap(); + + let batch_dir = prover::read_env_var("TRACE_PATH", "./tests/extra_traces/batch_25".to_string()); + let trace_paths = load_batch(&batch_dir).unwrap(); log_batch_pi(&trace_paths); } +*/ #[cfg(feature = "prove_verify")] #[test] fn test_e2e_prove_verify() { use integration::prove::{new_batch_prover, prove_and_verify_batch, prove_and_verify_bundle}; use itertools::Itertools; - use prover::config::{AGG_DEGREES, ZKEVM_DEGREES}; + use prover::{dump_as_json, BATCH_PROVER_DEGREES, CHUNK_PROVER_DEGREES}; let output_dir = init_env_and_log("e2e_tests"); log::info!("Initialized ENV and created output-dir {output_dir}"); - let params_map = prover::common::Prover::load_params_map( + let params_map = prover::Prover::load_params_map( PARAMS_DIR, - &ZKEVM_DEGREES + &CHUNK_PROVER_DEGREES .iter() .copied() - .chain(AGG_DEGREES.iter().copied()) + .chain(BATCH_PROVER_DEGREES.iter().copied()) .collect_vec(), ); @@ -77,7 +75,7 @@ fn test_e2e_prove_verify() { "batch proof {}, prev hash {:x?}, current {:x?}", i, batch_header.parent_batch_hash, - batch_proof.batch_hash, + batch_proof.inner.batch_hash, ); opt_batch_header.replace(batch_header); batch_proofs.push(batch_proof); @@ -96,19 +94,19 @@ fn test_batch_bundle_verify() -> anyhow::Result<()> { test_util::read_dir, }; use itertools::Itertools; - use prover::{config::AGG_DEGREES, io::from_json_file, BundleProvingTask}; + use prover::{read_json_deep, BundleProvingTask, ProverError, BATCH_PROVER_DEGREES}; let output_dir = init_env_and_log("batch_bundle_tests"); - let params_map = prover::common::Prover::load_params_map( + let params_map = prover::Prover::load_params_map( PARAMS_DIR, - &AGG_DEGREES.iter().copied().collect_vec(), + &BATCH_PROVER_DEGREES.iter().copied().collect_vec(), ); let batch_tasks_paths = read_dir("./tests/test_data/batch_tasks")?; let batch_tasks: Vec = batch_tasks_paths .iter() - .map(from_json_file::<_, BatchProvingTask>) - .collect::>>()?; + .map(read_json_deep) + .collect::, ProverError>>()?; log::info!("num batch tasks = {}", batch_tasks.len()); @@ -184,14 +182,14 @@ fn gen_batch_proving_task( .map_or(0, |block_trace| block_trace.header.timestamp.as_u64()) }); - let mut zkevm_prover = zkevm::Prover::from_params_and_assets(params_map, ASSETS_DIR); + let mut zkevm_prover = ChunkProver::from_params_and_assets(params_map, ASSETS_DIR); log::info!("Constructed zkevm prover"); let chunk_proofs: Vec<_> = chunks .into_iter() .map(|block_traces| { zkevm_prover - .gen_chunk_proof( - ChunkProvingTask::from(block_traces), + .gen_halo2_chunk_proof( + ChunkProvingTask::new(block_traces), None, None, Some(output_dir), @@ -207,10 +205,11 @@ fn gen_batch_proving_task( 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, ]); + let chunks = chunk_proofs .clone() .into_iter() - .map(|cp| cp.chunk_info) + .map(|cp| cp.inner.chunk_info().clone()) .collect::>(); let blob_bytes = get_blob_from_chunks(&chunks); @@ -238,6 +237,8 @@ fn gen_batch_proving_task( ) } +/* +#[cfg(feature = "fix_later")] fn log_batch_pi(trace_paths: &[String]) { let max_num_snarks = prover::MAX_AGG_SNARKS; let chunk_traces: Vec<_> = trace_paths @@ -305,6 +306,7 @@ fn log_batch_pi(trace_paths: &[String]) { println!("blob.coeffs[{}]: {elem:x}", i); } } +*/ fn dump_chunk_protocol(batch: &BatchProvingTask, output_dir: &str) { // Dump chunk-procotol to "chunk_chunk_0.protocol" for batch proving. diff --git a/integration/tests/inner_tests.rs b/integration/tests/inner_tests.rs deleted file mode 100644 index 983fe020..00000000 --- a/integration/tests/inner_tests.rs +++ /dev/null @@ -1,32 +0,0 @@ -use integration::test_util::{load_chunk_for_test, PARAMS_DIR}; -use prover::{inner::Verifier, utils::init_env_and_log, zkevm::circuit::SuperCircuit}; - -#[cfg(feature = "prove_verify")] -#[test] -fn test_inner_prove_verify() { - use itertools::Itertools; - use prover::config::ZKEVM_DEGREES; - - let test_name = "inner_tests"; - let output_dir = init_env_and_log(test_name); - log::info!("Initialized ENV and created output-dir {output_dir}"); - - let params_map = prover::common::Prover::load_params_map( - PARAMS_DIR, - &ZKEVM_DEGREES.iter().copied().collect_vec(), - ); - - let chunk_trace = load_chunk_for_test().1; - log::info!("Loaded chunk trace"); - - let inner_prover = prover::common::Prover::from_params_map(¶ms_map); - let mut prover = prover::inner::Prover::::from(inner_prover); - log::info!("Constructed prover"); - - let snark = prover.gen_inner_snark("inner", chunk_trace).unwrap(); - log::info!("Got inner snark"); - - let verifier = Verifier::::from_params_map(¶ms_map, None); - assert!(verifier.verify_inner_snark(snark)); - log::info!("Finish inner snark verification"); -} diff --git a/integration/tests/integration.rs b/integration/tests/integration.rs index d17212e7..be92d2cc 100644 --- a/integration/tests/integration.rs +++ b/integration/tests/integration.rs @@ -1,15 +1,6 @@ -use halo2_proofs::{ - plonk::{keygen_pk2, keygen_vk}, - poly::commitment::Params, -}; -use integration::test_util::{load_chunk_for_test, PARAMS_DIR}; -use prover::{ - config::INNER_DEGREE, - io::serialize_vk, - utils::{init_env_and_log, load_params}, - zkevm::circuit::{block_traces_to_witness_block, SuperCircuit, TargetCircuit}, - zkevm_circuits::util::SubCircuit, -}; +use halo2_proofs::poly::commitment::Params; +use integration::test_util::PARAMS_DIR; +use prover::{init_env_and_log, load_params}; #[ignore] #[test] @@ -30,8 +21,8 @@ fn test_load_params() { assert_eq!(params19.g2(), downsized_params19.g2()); assert_eq!(params19.s_g2(), downsized_params19.s_g2()); } - -#[ignore] +/* +#[cfg(feature = "fix_later")] #[test] fn test_cs_same_for_vk_consistent() { let params = load_params(PARAMS_DIR, *INNER_DEGREE, None).unwrap(); @@ -46,7 +37,7 @@ fn test_cs_same_for_vk_consistent() { ); let block_traces = load_chunk_for_test().1; - let witness_block = block_traces_to_witness_block(block_traces).unwrap(); + let witness_block = chunk_trace_to_witness_block(block_traces).unwrap(); let real_circuit = SuperCircuit::from_witness_block(&witness_block).unwrap(); let pk = keygen_pk2(¶ms, &real_circuit).unwrap(); @@ -57,7 +48,7 @@ fn test_cs_same_for_vk_consistent() { ); } -#[cfg(feature = "prove_verify")] +#[cfg(feature = "fix_later")] #[test] fn test_deterministic() { use halo2_proofs::dev::MockProver; @@ -91,7 +82,7 @@ fn test_deterministic() { log::info!("test_deterministic done"); } -#[cfg(feature = "prove_verify")] +#[cfg(feature = "fix_later")] #[test] fn test_vk_same() { use halo2_proofs::dev::MockProver; @@ -181,3 +172,4 @@ fn test_vk_same() { assert_eq!(vk_empty.transcript_repr(), vk_real.transcript_repr()); } } + */ diff --git a/integration/tests/mock_tests.rs b/integration/tests/mock_tests.rs index d47f902a..c71b358e 100644 --- a/integration/tests/mock_tests.rs +++ b/integration/tests/mock_tests.rs @@ -1,11 +1,12 @@ use integration::test_util::load_chunk_for_test; -use prover::{inner::Prover, utils::init_env_and_log, zkevm::circuit::SuperCircuit}; - #[cfg(feature = "prove_verify")] #[test] fn test_mock_prove() { + use integration::mock::mock_prove_target_circuit_chunk; + use prover::init_env_and_log; + init_env_and_log("mock_tests"); let block_traces = load_chunk_for_test().1; - Prover::::mock_prove_target_circuit_chunk(block_traces).unwrap(); + mock_prove_target_circuit_chunk(block_traces).unwrap(); } diff --git a/integration/tests/unit_tests.rs b/integration/tests/unit_tests.rs index ae06c186..a7b061a0 100644 --- a/integration/tests/unit_tests.rs +++ b/integration/tests/unit_tests.rs @@ -2,12 +2,11 @@ use integration::{ capacity_checker::{prepare_circuit_capacity_checker, run_circuit_capacity_checker, CCCMode}, - test_util::load_chunk_for_test, + test_util::{load_chunk_for_test, read_all}, }; use prover::{ - io::read_all, - utils::{init_env_and_log, short_git_version}, - zkevm::circuit::{block_traces_to_witness_block, TargetCircuit}, + calculate_row_usage_of_witness_block, chunk_trace_to_witness_block, init_env_and_log, + read_json, short_git_version, }; #[test] @@ -68,8 +67,6 @@ fn test_evm_verifier() { #[ignore] #[test] fn test_evm_verifier_for_dumped_proof() { - use prover::io::from_json_file; - init_env_and_log("test_evm_verifer"); log::info!("cwd {:?}", std::env::current_dir()); @@ -79,7 +76,7 @@ fn test_evm_verifier_for_dumped_proof() { let mut path = paths.last().unwrap().unwrap(); log::info!("proof path {}", path.display()); - let proof: prover::BundleProof = from_json_file(&path).unwrap(); + let proof: prover::BundleProof = read_json(&path).unwrap(); let proof = proof.calldata(); log::info!("calldata len {}", proof.len()); @@ -122,13 +119,13 @@ fn estimate_circuit_rows() { prepare_circuit_capacity_checker(); let (_, block_trace) = load_chunk_for_test(); - let witness_block = block_traces_to_witness_block(block_trace).unwrap(); + let witness_block = chunk_trace_to_witness_block(block_trace).unwrap(); log::info!("estimating used rows"); - let row_usage = ::Inner::min_num_rows_block_subcircuits(&witness_block); + let row_usage = calculate_row_usage_of_witness_block(&witness_block).unwrap(); let r = row_usage .iter() - .max_by_key(|x| x.row_num_real) + .max_by_key(|x| x.row_number) .unwrap() .clone(); - log::info!("final rows: {} {}", r.row_num_real, r.name); + log::info!("final rows: {} {}", r.row_number, r.name); }