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

Refactor the code structure #155

Merged
merged 6 commits into from
Jun 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ target/
.cargo

# for testing
zkevm/tests/traces/bridge/*.proof
prover/tests/traces/bridge/*.proof

# ignore local logs
*.log
Expand Down
4 changes: 2 additions & 2 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[submodule "test-traces"]
path = zkevm/tests/traces
[submodule "prover/tests/traces"]
path = prover/tests/traces
url = https://github.com/scroll-tech/test-traces
82 changes: 41 additions & 41 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[workspace]
members = [
"types",
"zkevm",
"bin",
"ffi",
"prover",
"types",
]

[patch."https://github.com/privacy-scaling-explorations/halo2.git"]
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ test: ## Run tests for all the workspace members

bridge-test:
cargo build --release
./target/release/prove --params=./test_params --seed=./test_seed --trace=zkevm/tests/traces/bridge --agg=true
./target/release/prove --params=./test_params --seed=./test_seed --trace=prover/tests/traces/bridge --agg=true

test-super-trace: ## test super circuit with real trace
cargo test --features prove_verify --release test_prove_verify
Expand Down
2 changes: 1 addition & 1 deletion batch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function check_batch() {
}

function check_block() {
for t in zkevm/tests/extra_traces/tx_storage_proof.json zkevm/tests/extra_traces/hash_precompile_2.json zkevm/tests/extra_traces/hash_precompile_1.json zkevm/tests/traces/sushi/sushi_chef-withdraw.json zkevm/tests/traces/erc20/erc20_10_transfer.json; do
for t in prover/tests/extra_traces/tx_storage_proof.json prover/tests/extra_traces/hash_precompile_2.json prover/tests/extra_traces/hash_precompile_1.json prover/tests/traces/sushi/sushi_chef-withdraw.json prover/tests/traces/erc20/erc20_10_transfer.json; do
TRACE_PATH=`realpath $t` make mock 2>&1 | tee /tmp/mock_`basename $t`.log
done
}
Expand Down
2 changes: 1 addition & 1 deletion bin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ serde_derive = "1.0"
serde_json = "1.0.66"
tokio = { version = "1", features = ["full"] }
types = { path = "../types" }
zkevm = { path = "../zkevm" }
prover = { path = "../prover" }

[[bin]]
name = "setup"
Expand Down
12 changes: 6 additions & 6 deletions bin/src/mock_testnet.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
use anyhow::Result;
use ethers_providers::{Http, Provider};
use itertools::Itertools;
use prover::utils::init_env_and_log;
use prover::zkevm::circuit::{
block_traces_to_witness_block, calculate_row_usage_of_witness_block, SuperCircuit,
SUB_CIRCUIT_NAMES,
};
use prover::zkevm::Prover;
use reqwest::Url;
use serde::Deserialize;
use std::env;
use types::eth::BlockTrace;
use zkevm::circuit::{
block_traces_to_witness_block, calculate_row_usage_of_witness_block, SuperCircuit,
SUB_CIRCUIT_NAMES,
};
use zkevm::prover::Prover;
use zkevm::utils::init_env_and_log;

const DEFAULT_BEGIN_BATCH: i64 = 1;
const DEFAULT_END_BATCH: i64 = i64::MAX;
Expand Down
10 changes: 5 additions & 5 deletions bin/src/prove.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
use clap::Parser;
use log::info;
use prover::utils::{get_block_trace_from_file, init_env_and_log, load_or_create_params};
use prover::zkevm::{
circuit::{SuperCircuit, AGG_DEGREE},
Prover,
};
use std::collections::HashMap;
use std::fs;
use std::fs::File;
use std::io::Write;
use std::path::PathBuf;
use std::time::Instant;
use zkevm::{
circuit::{SuperCircuit, AGG_DEGREE},
prover::Prover,
utils::{get_block_trace_from_file, init_env_and_log, load_or_create_params},
};

#[derive(Parser, Debug)]
#[clap(author, version, about, long_about = None)]
Expand Down
6 changes: 2 additions & 4 deletions bin/src/setup.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use clap::Parser;
use zkevm::{
circuit::DEGREE,
utils::{init_env_and_log, load_or_create_params},
};
use prover::utils::{init_env_and_log, load_or_create_params};
use prover::zkevm::circuit::DEGREE;

#[derive(Parser, Debug)]
#[clap(author, version, about, long_about = None)]
Expand Down
9 changes: 3 additions & 6 deletions bin/src/verify.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
use clap::Parser;
use log::info;
use prover::utils::{init_env_and_log, load_or_create_params};
use prover::zkevm::circuit::{SuperCircuit, AGG_DEGREE, DEGREE};
use prover::zkevm::{AggCircuitProof, TargetCircuitProof, Verifier};
use std::fs::File;
use std::io::Read;
use zkevm::prover::{AggCircuitProof, TargetCircuitProof};
use zkevm::verifier::Verifier;
use zkevm::{
circuit::{SuperCircuit, AGG_DEGREE, DEGREE},
utils::{init_env_and_log, load_or_create_params},
};

#[derive(Parser, Debug)]
#[clap(author, version, about, long_about = None)]
Expand Down
2 changes: 1 addition & 1 deletion ffi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ edition = "2021"
crate-type = ["staticlib"]

[dependencies]
zkevm = { path = "../zkevm" }
prover = { path = "../prover" }
types = { path = "../types" }

rand = "0.8"
Expand Down
8 changes: 4 additions & 4 deletions ffi/src/prove.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
use crate::utils::{c_char_to_str, c_char_to_vec, vec_to_c_char};
use libc::c_char;
use prover::utils::init_env_and_log;
use prover::zkevm;
use std::cell::OnceCell;
use types::eth::BlockTrace;
use zkevm::prover::Prover;
use zkevm::utils::init_env_and_log;

static mut PROVER: OnceCell<Prover> = OnceCell::new();
static mut PROVER: OnceCell<zkevm::Prover> = OnceCell::new();

/// # Safety
#[no_mangle]
pub unsafe extern "C" fn init_prover(params_path: *const c_char, _seed_path: *const c_char) {
init_env_and_log("ffi_prove");

let params_path = c_char_to_str(params_path);
let p = Prover::from_param_dir(params_path);
let p = zkevm::Prover::from_param_dir(params_path);
PROVER.set(p).unwrap();
}

Expand Down
11 changes: 5 additions & 6 deletions ffi/src/verify.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
use crate::utils::{c_char_to_str, c_char_to_vec};
use libc::c_char;
use prover::utils::init_env_and_log;
use prover::zkevm;
use std::fs::File;
use std::io::Read;
use zkevm::prover::AggCircuitProof;
use zkevm::utils::init_env_and_log;
use zkevm::verifier::Verifier;

static mut VERIFIER: Option<&Verifier> = None;
static mut VERIFIER: Option<&zkevm::Verifier> = None;

/// # Safety
#[no_mangle]
Expand All @@ -19,15 +18,15 @@ pub unsafe extern "C" fn init_verifier(params_path: *const c_char, agg_vk_path:
let mut agg_vk = vec![];
f.read_to_end(&mut agg_vk).unwrap();

let v = Box::new(Verifier::from_fpath(params_path, Some(agg_vk)));
let v = Box::new(zkevm::Verifier::from_fpath(params_path, Some(agg_vk)));
VERIFIER = Some(Box::leak(v))
}

/// # Safety
#[no_mangle]
pub unsafe extern "C" fn verify_agg_proof(proof: *const c_char) -> c_char {
let proof_vec = c_char_to_vec(proof);
let agg_proof = serde_json::from_slice::<AggCircuitProof>(proof_vec.as_slice()).unwrap();
let agg_proof = serde_json::from_slice::<zkevm::AggCircuitProof>(proof_vec.as_slice()).unwrap();
let verified = VERIFIER
.unwrap()
.verify_agg_circuit_proof(agg_proof)
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion zkevm/Cargo.toml → prover/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "zkevm"
name = "prover"
version = "0.4.0"
edition = "2021"

Expand Down
File renamed without changes.
2 changes: 2 additions & 0 deletions prover/src/aggregator.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub mod prover;
pub mod verifier;
1 change: 1 addition & 0 deletions prover/src/aggregator/prover.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

1 change: 1 addition & 0 deletions prover/src/aggregator/verifier.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

File renamed without changes.
11 changes: 4 additions & 7 deletions zkevm/src/lib.rs → prover/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
pub mod capacity_checker;
pub mod circuit;
pub mod aggregator;
pub mod io;
pub mod prover;
pub mod utils;
pub mod verifier;

pub mod test_util;
pub mod utils;
pub mod zkevm;

// Terminology used throughout this library.
//
Expand All @@ -24,7 +21,7 @@ pub mod test_util;
// a proof that can be verified on chain

pub mod proof {
use crate::prover::AggCircuitProof;
use crate::zkevm::AggCircuitProof;
use serde_derive::{Deserialize, Serialize};

#[derive(Serialize, Deserialize, Debug)]
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! A module for Mock Plonk circuit.
//!
use crate::circuit::TargetCircuit;
use crate::zkevm::circuit::TargetCircuit;
use halo2_proofs::halo2curves::bn256::Fr;
use halo2_proofs::{
circuit::{Layouter, SimpleFloorPlanner, Value},
Expand Down
File renamed without changes.
8 changes: 8 additions & 0 deletions prover/src/zkevm.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
mod capacity_checker;
pub mod circuit;
mod prover;
mod verifier;

pub use self::prover::{AggCircuitProof, Prover, TargetCircuitProof};
pub use capacity_checker::CircuitCapacityChecker;
pub use verifier::{EvmVerifier, Verifier};
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use mpt_zktrie::state::ZktrieState;
use serde_derive::{Deserialize, Serialize};
use types::eth::BlockTrace;

use crate::circuit::{
use super::circuit::{
block_traces_to_witness_block_with_updated_state, calculate_row_usage_of_witness_block,
update_state, DEGREE, SUB_CIRCUIT_NAMES,
};
Expand Down Expand Up @@ -93,7 +93,7 @@ impl CircuitCapacityChecker {
}
pub fn estimate_circuit_capacity(
&mut self,
txs: &[BlockTrace],
txs: &[TxTrace],
) -> Result<(RowUsage, RowUsage), anyhow::Error> {
assert!(!txs.is_empty());
if self.state.is_none() {
Expand Down
File renamed without changes.
Loading
Loading