Skip to content

Commit

Permalink
update zkevm-circuits (#349)
Browse files Browse the repository at this point in the history
* update

* done

* test

* update

* done

* done

* clean

* develop

* lint
  • Loading branch information
lispc authored Oct 31, 2024
1 parent 4733ae7 commit a9a0b02
Show file tree
Hide file tree
Showing 10 changed files with 274 additions and 480 deletions.
615 changes: 249 additions & 366 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ members = [
]

[workspace.package]
version = "0.13.0"
version = "0.14.0"
edition = "2021"
license = "MIT OR Apache-2.0"

Expand All @@ -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 = "v0.13", default-features = false, features = ["parallel_syn", "scroll"] }
prover = { git = "https://github.com/scroll-tech/zkevm-circuits.git", branch = "develop", default-features = false, features = ["parallel_syn", "scroll"] }
integration = { path = "integration" }

[patch.crates-io]
Expand Down
4 changes: 0 additions & 4 deletions bin/src/chain_prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ impl ChunkBuilder {
// Condition2: ccc
let ccc_result = {
let mut checker = CircuitCapacityChecker::new();
checker.set_light_mode(false);
checker.estimate_circuit_capacity(trace.clone()).unwrap()
};
self.acc_row_usage_normalized.add(&ccc_result);
Expand Down Expand Up @@ -320,8 +319,6 @@ async fn prove_by_batch(
}
}

// Make sure tx-by-tx light_mode=false row usage >= real row usage

async fn txtx_ccc(l2geth: &l2geth::Client, begin_block: i64, end_block: i64) {
let (begin_block, end_block) = if begin_block == 0 && end_block == 0 {
// Blocks within last 24 hours
Expand Down Expand Up @@ -354,7 +351,6 @@ async fn txtx_ccc(l2geth: &l2geth::Client, begin_block: i64, end_block: i64) {
// part2: tx by tx row usage
let tx_num = tx_traces.len();
let mut checker = CircuitCapacityChecker::new();
checker.light_mode = false;
let start_time = std::time::Instant::now();
for tx in tx_traces {
checker.estimate_circuit_capacity(tx).unwrap();
Expand Down
1 change: 0 additions & 1 deletion integration/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ serde_json.workspace = true
serde_derive.workspace = true
tokio.workspace = true

revm = { version = "3.5.0", default-features = false, features = ["std"] }
snark-verifier = { git = "https://github.com/scroll-tech/snark-verifier", branch = "develop" }
snark-verifier-sdk = { git = "https://github.com/scroll-tech/snark-verifier", branch = "develop", default-features = false, features = ["loader_halo2", "loader_evm", "halo2-pse"] }

Expand Down
36 changes: 4 additions & 32 deletions integration/src/capacity_checker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use std::time::Duration;
pub enum CCCMode {
Optimal,
Siger,
FollowerLight,
FollowerFull,
}

Expand All @@ -39,7 +38,6 @@ pub fn run_circuit_capacity_checker(
match mode {
CCCMode::Optimal => ccc_by_chunk(batch_id, chunk_id, block_traces),
CCCMode::Siger => ccc_as_signer(chunk_id, block_traces),
CCCMode::FollowerLight => ccc_as_follower_light(chunk_id, block_traces),
CCCMode::FollowerFull => ccc_as_follower_full(chunk_id, block_traces),
},
)
Expand Down Expand Up @@ -155,7 +153,6 @@ fn get_ccc_result_of_chunk(
blocks: &[BlockTrace],
by_block: bool, // by block instead of by tx
norm: bool,
light_mode: bool,
tag: &str,
) -> (RowUsage, Duration) {
log::info!(
Expand All @@ -167,11 +164,6 @@ fn get_ccc_result_of_chunk(
);

let mut checker = CircuitCapacityChecker::new();
checker.light_mode = light_mode;

if !checker.light_mode && !by_block {
unimplemented!("!checker.light_mode && !by_block")
}

let start_time = std::time::Instant::now();

Expand Down Expand Up @@ -221,29 +213,14 @@ fn get_ccc_result_of_chunk(
}

#[allow(dead_code)]
fn get_ccc_result_by_whole_block(
chunk_id: u64,
light_mode: bool,
blocks: &[BlockTrace],
) -> RowUsage {
log::info!("estimating circuit rows whole block, light_mode {light_mode}");
fn get_ccc_result_by_whole_block(chunk_id: u64, blocks: &[BlockTrace]) -> RowUsage {
let mut checker = CircuitCapacityChecker::new();
checker.light_mode = light_mode;

for block in blocks {
checker.estimate_circuit_capacity(block.clone()).unwrap();
}
let ccc_result = checker.get_acc_row_usage(false);
pretty_print_row_usage(
&ccc_result,
blocks,
chunk_id,
if light_mode {
"block-light"
} else {
"block-full"
},
);
pretty_print_row_usage(&ccc_result, blocks, chunk_id, "block-full");

ccc_result
}
Expand Down Expand Up @@ -298,14 +275,9 @@ pub fn ccc_by_chunk(
}

pub fn ccc_as_signer(chunk_id: u64, blocks: &[BlockTrace]) -> (RowUsage, Duration) {
get_ccc_result_of_chunk(chunk_id, blocks, false, false, true, "chunk-signer")
}

/// current stats inside db
pub fn ccc_as_follower_light(chunk_id: u64, blocks: &[BlockTrace]) -> (RowUsage, Duration) {
get_ccc_result_of_chunk(chunk_id, blocks, true, false, true, "chunk-f-l")
get_ccc_result_of_chunk(chunk_id, blocks, false, false, "chunk-signer")
}

pub fn ccc_as_follower_full(chunk_id: u64, blocks: &[BlockTrace]) -> (RowUsage, Duration) {
get_ccc_result_of_chunk(chunk_id, blocks, true, false, false, "chunk-f-f")
get_ccc_result_of_chunk(chunk_id, blocks, true, false, "chunk-f-f")
}
59 changes: 0 additions & 59 deletions integration/src/evm.rs

This file was deleted.

1 change: 0 additions & 1 deletion integration/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
pub mod capacity_checker;
pub mod evm;
pub mod l2geth;
pub mod prove;
pub mod test_util;
Expand Down
5 changes: 3 additions & 2 deletions integration/src/verifier.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use halo2_proofs::{halo2curves::bn256::Bn256, poly::kzg::commitment::ParamsKZG};
use prover::{common::Verifier, config, consts, io::force_to_read, CompressionCircuit};
use snark_verifier_sdk::verify_evm_calldata;
use std::{collections::BTreeMap, env};

type SnarkVerifier<'a> = Verifier<'a, CompressionCircuit>;
Expand Down Expand Up @@ -57,6 +56,8 @@ impl EVMVerifier {
}

pub fn verify_evm_proof(&self, call_data: Vec<u8>) -> bool {
verify_evm_calldata(self.0.clone(), call_data)
let res = prover::deploy_and_call(self.0.clone(), call_data);
log::debug!("verify_evm_proof result {:?}", res);
res.is_ok()
}
}
4 changes: 2 additions & 2 deletions integration/tests/e2e_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ fn test_batch_bundle_verify() -> anyhow::Result<()> {
&AGG_DEGREES.iter().copied().collect_vec(),
);
let batch_tasks_paths = read_dir("./tests/test_data/batch_tasks")?;
let batch_tasks = batch_tasks_paths
let batch_tasks: Vec<BatchProvingTask> = batch_tasks_paths
.iter()
.map(|path| from_json_file::<BatchProvingTask>(&path.as_path().to_string_lossy()))
.map(from_json_file::<_, BatchProvingTask>)
.collect::<anyhow::Result<Vec<_>>>()?;

log::info!("num batch tasks = {}", batch_tasks.len());
Expand Down
25 changes: 14 additions & 11 deletions integration/tests/unit_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ fn test_evm_verifier() {
log::info!("svm use {}", version);
let bytecode = compile_yul(&String::from_utf8(yul.clone()).unwrap());
log::info!("bytecode len {}", bytecode.len());
match integration::evm::deploy_and_call(bytecode, proof.clone()) {
match prover::deploy_and_call(bytecode, proof.clone()) {
Ok(gas) => log::info!("gas cost {gas}"),
Err(e) => {
panic!("test failed {e:#?}");
Expand All @@ -57,37 +57,40 @@ fn test_evm_verifier() {
log::info!("check released bin");
let bytecode = read_all(&format!("../{version}/evm_verifier.bin"));
log::info!("bytecode len {}", bytecode.len());
match integration::evm::deploy_and_call(bytecode, proof.clone()) {
match prover::deploy_and_call(bytecode, proof.clone()) {
Ok(gas) => log::info!("gas cost {gas}"),
Err(e) => {
panic!("test failed {e:#?}");
}
}
}

// suppose a "proof.json" has been provided under the 'release'
// directory or the test would fail
#[ignore]
#[test]
fn test_evm_verifier_for_dumped_proof() {
use prover::{io::from_json_file, proof::BundleProof};
use prover::io::from_json_file;

init_env_and_log("test_evm_verifer");
log::info!("cwd {:?}", std::env::current_dir());
let version = "release-v0.12.0-rc.2";

let proof: BundleProof = from_json_file(&format!("../{version}/proof.json")).unwrap();
let search_pattern = "outputs/e2e_tests_*/full_proof_bundle_recursion.json";

let proof_dump = proof.clone().proof_to_verify();
log::info!("pi dump {:#?}", proof_dump.instances());
let paths = glob::glob(search_pattern).expect("Failed to read glob pattern");

let mut path = paths.last().unwrap().unwrap();
log::info!("proof path {}", path.display());
let proof: prover::BundleProof = from_json_file(&path).unwrap();

let proof = proof.calldata();
log::info!("calldata len {}", proof.len());

log::info!("check released bin");
let bytecode = read_all(&format!("../{version}/evm_verifier.bin"));
path.pop();
path.push("evm_verifier.bin");
let bytecode = read_all(path);
log::info!("bytecode len {}", bytecode.len());
match integration::evm::deploy_and_call(bytecode, proof.clone()) {

match prover::deploy_and_call(bytecode, proof.clone()) {
Ok(gas) => log::info!("gas cost {gas}"),
Err(e) => {
panic!("test failed {e:#?}");
Expand Down

0 comments on commit a9a0b02

Please sign in to comment.