Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adapt for "upgrade 5 refactor" #351

Merged
merged 9 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
running
  • Loading branch information
lispc committed Nov 7, 2024
commit 4b9a7d6e222a354feacacac4e05b7bcec4ab0f2c
28 changes: 15 additions & 13 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", branch = "develop", default-features = false, features = ["parallel_syn", "scroll"] }
prover = { git = "https://github.com/scroll-tech/zkevm-circuits.git", branch = "feat/upgrade5-prover", default-features = false, features = ["parallel_syn", "scroll"] }
integration = { path = "integration" }

[patch.crates-io]
Expand Down
18 changes: 10 additions & 8 deletions bin/src/chain_prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -194,15 +192,15 @@ 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) {
let mut padded_batch = batch.clone();
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,
Expand Down Expand Up @@ -234,7 +232,11 @@ fn padding_chunk(chunks: &mut Vec<ChunkInfo>) {
}
}

fn prove_chunk(batch_id: u64, chunk_id: u64, block_traces: Vec<BlockTrace>) -> Option<ChunkProof> {
fn prove_chunk(
batch_id: u64,
chunk_id: u64,
block_traces: Vec<BlockTrace>,
) -> Option<ChunkProofV2> {
let total_gas: u64 = block_traces
.iter()
.map(|b| b.header.gas_used.as_u64())
Expand Down
28 changes: 10 additions & 18 deletions bin/src/prove_utils.rs
Original file line number Diff line number Diff line change
@@ -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")]
Expand All @@ -7,7 +7,7 @@ use prover::{BatchHeader, MAX_AGG_SNARKS};
#[cfg(feature = "batch-prove")]
pub fn prove_batch(
id: &str,
chunk_proofs: Vec<ChunkProof>,
chunk_proofs: Vec<ChunkProofV2>,
batch_header: BatchHeader<MAX_AGG_SNARKS>,
) {
use integration::prove::get_blob_from_chunks;
Expand All @@ -16,15 +16,15 @@ 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 {
chunk_proofs,
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"),
Expand All @@ -41,21 +41,15 @@ pub fn prove_batch(
}
}

pub fn prove_chunk(id: &str, traces: Vec<BlockTrace>) -> Option<ChunkProof> {
pub fn prove_chunk(id: &str, traces: Vec<BlockTrace>) -> Option<ChunkProofV2> {
let result = catch_unwind(AssertUnwindSafe(|| {
#[cfg(not(feature = "chunk-prove"))]
let proof = None::<ChunkProof>;
let proof = None::<ChunkProofV2>;

#[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);
Expand Down Expand Up @@ -84,12 +78,10 @@ pub fn prove_chunk(id: &str, traces: Vec<BlockTrace>) -> Option<ChunkProof> {
}

#[cfg(not(any(feature = "inner-prove", feature = "chunk-prove")))]
fn mock_prove(id: &str, traces: Vec<BlockTrace>) {
use prover::{inner::Prover, zkevm::circuit::SuperCircuit};

fn mock_prove(id: &str, traces: Vec<prover::eth_types::l2_types::BlockTrace>) {
log::info!("{id}: mock-prove BEGIN");

Prover::<SuperCircuit>::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");
Expand Down
14 changes: 4 additions & 10 deletions bin/src/trace_prover.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions integration/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ prover.workspace = true
[features]
default = ["prove_verify"]
prove_verify = []
fix_later = [] # commented codes
11 changes: 4 additions & 7 deletions integration/src/capacity_checker.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion integration/src/l2geth.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
1 change: 1 addition & 0 deletions integration/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
pub mod capacity_checker;
pub mod l2geth;
pub mod mock;
pub mod prove;
pub mod test_util;
mod verifier;
35 changes: 35 additions & 0 deletions integration/src/mock.rs
Original file line number Diff line number Diff line change
@@ -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<BlockTrace>) -> 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::<Fr>::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(())
}
Loading
Loading