Skip to content

Commit

Permalink
Add aggregation functions and tests (#179)
Browse files Browse the repository at this point in the history
* Add aggregation functions and tests.

* Update

* Use storage-trace of last chunk to generate padding chunk trace.

* Upgrade

* Small fix.

* Update according to tests.

* Update zkevm-circuits to `static-proof-aggregation` branch.

* Small fix for zkevm-verify bin.

* Update to zkevm-circuits develop.

* Set layer3 degree = 20.

* Fix layer3-degree = 19, and layer4-degree = 25 (num_advice = 3, may need to update).

* Refactor Proof to ChunkProof and EvmProof.

* Fix to verify EVM proof in aggregation verifier.

* Small rename.

* Fix to also use `assets_dir` for zkevm-prover, and zk filename in aggregation-tests.
  • Loading branch information
silathdiir authored Jul 31, 2023
1 parent 797b832 commit 1f1d1d9
Show file tree
Hide file tree
Showing 30 changed files with 776 additions and 253 deletions.
28 changes: 14 additions & 14 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 README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ make download-setup -e degree=DEGREE params_dir=PARAMS_DIR

### Testing

`make test-chunk-prove` is the main testing entry point for the multi-level circuit constraint system of scroll-prover. Developers could understand how the system works by reading the codes of this test.
`make test-chunk-prove` and `make test-agg-prove` are the main testing entries for multi-level circuit constraint system of scroll-prover. Developers could understand how the system works by reading the codes of these tests.

Besides it, `make test-inner-prove` could be used to test the first-level circuit.

Expand Down
12 changes: 8 additions & 4 deletions bin/src/zkevm_prove.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ struct Args {
#[clap(short, long = "params", default_value = "test_params")]
params_path: String,
/// Get BlockTrace from file or dir.
#[clap(short, long = "trace", default_value = "tests/traces/empty.json")]
#[clap(
short,
long = "trace",
default_value = "tests/traces/erc20/10_transfer.json"
)]
trace_path: String,
}

Expand Down Expand Up @@ -42,10 +46,10 @@ fn main() {

let now = Instant::now();
prover
.gen_chunk_proof(traces, Some(&output_dir))
.expect("cannot generate chunk proof");
.gen_chunk_proof(traces, Some("zkevm"), Some(&output_dir))
.expect("cannot generate chunk snark");
log::info!(
"finish generating chunk proof, elapsed: {:?}",
"finish generating chunk snark, elapsed: {:?}",
now.elapsed()
);
}
16 changes: 8 additions & 8 deletions bin/src/zkevm_verify.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use clap::Parser;
use prover::{io::read_all, utils::init_env_and_log, zkevm::Verifier, Proof};
use prover::{utils::init_env_and_log, zkevm::Verifier, ChunkProof};
use std::{env, path::PathBuf};

#[derive(Parser, Debug)]
Expand All @@ -8,7 +8,7 @@ struct Args {
/// Get params from the file.
#[clap(short, long = "params", default_value = "test_params")]
params_path: String,
/// Get vk and proof from the folder.
/// Get snark and vk from the folder.
#[clap(long = "proof", default_value = "proof_data")]
proof_path: String,
}
Expand All @@ -19,14 +19,14 @@ fn main() {
init_env_and_log("bin_zkevm_verify");

let args = Args::parse();
let proof_path = PathBuf::from(args.proof_path);
let proof_path = PathBuf::from(&args.proof_path);

let vk = read_all(&proof_path.join("chunk.vkey").to_string_lossy());
let verifier = Verifier::from_params_dir(&args.params_path, &vk);
env::set_var("CHUNK_VK_FILENAME", "vk_chunk_zkevm.vkey");
let verifier = Verifier::from_dirs(&args.params_path, &proof_path.to_string_lossy());

let proof = read_all(&proof_path.join("chunk_full_proof.json").to_string_lossy());
let proof = serde_json::from_slice::<Proof>(&proof).unwrap();
let proof =
ChunkProof::from_json_file(&args.proof_path, "zkevm").expect("Proof file doesn't exist");

let verified = verifier.verify_chunk_proof(proof);
log::info!("verify chunk proof: {}", verified)
log::info!("verify chunk snark: {}", verified)
}
19 changes: 8 additions & 11 deletions ffi/src/zkevm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ use libc::c_char;
use prover::{
utils::init_env_and_log,
zkevm::{Prover, Verifier},
Proof,
ChunkProof,
};
use std::{cell::OnceCell, fs::File, io::Read};
use std::cell::OnceCell;
use types::eth::BlockTrace;

static mut PROVER: OnceCell<Prover> = OnceCell::new();
Expand All @@ -24,16 +24,13 @@ pub unsafe extern "C" fn init_zkevm_prover(params_dir: *const c_char) {

/// # Safety
#[no_mangle]
pub unsafe extern "C" fn init_zkevm_verifier(params_dir: *const c_char, vk_path: *const c_char) {
pub unsafe extern "C" fn init_zkevm_verifier(params_dir: *const c_char, assets_dir: *const c_char) {
init_env_and_log("ffi_zkevm_verify");

let vk_path = c_char_to_str(vk_path);
let mut f = File::open(vk_path).unwrap();
let mut raw_vk = vec![];
f.read_to_end(&mut raw_vk).unwrap();

let params_dir = c_char_to_str(params_dir);
let verifier = Verifier::from_params_dir(params_dir, &raw_vk);
let assets_dir = c_char_to_str(assets_dir);

let verifier = Verifier::from_dirs(params_dir, assets_dir);

VERIFIER.set(verifier).unwrap();
}
Expand All @@ -47,7 +44,7 @@ pub unsafe extern "C" fn gen_chunk_proof(block_traces: *const c_char) -> *const
let proof = PROVER
.get_mut()
.unwrap()
.gen_chunk_proof(block_traces, OUTPUT_DIR.as_deref())
.gen_chunk_proof(block_traces, None, OUTPUT_DIR.as_deref())
.unwrap();

let proof_bytes = serde_json::to_vec(&proof).unwrap();
Expand All @@ -58,7 +55,7 @@ pub unsafe extern "C" fn gen_chunk_proof(block_traces: *const c_char) -> *const
#[no_mangle]
pub unsafe extern "C" fn verify_chunk_proof(proof: *const c_char) -> c_char {
let proof = c_char_to_vec(proof);
let proof = serde_json::from_slice::<Proof>(proof.as_slice()).unwrap();
let proof = serde_json::from_slice::<ChunkProof>(proof.as_slice()).unwrap();

let verified = VERIFIER.get().unwrap().verify_chunk_proof(proof);
verified as c_char
Expand Down
10 changes: 5 additions & 5 deletions prover/configs/layer3.config
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"strategy": "Simple",
"degree": 25,
"degree": 19,
"num_advice": [
4
80
],
"num_lookup_advice": [
1
10
],
"num_fixed": 1,
"lookup_bits": 20,
"num_fixed": 2,
"lookup_bits": 18,
"limb_bits": 88,
"num_limbs": 3
}
2 changes: 1 addition & 1 deletion prover/configs/layer4.config
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"strategy": "Simple",
"degree": 25,
"num_advice": [
2
3
],
"num_lookup_advice": [
1
Expand Down
5 changes: 5 additions & 0 deletions prover/src/aggregator.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
mod prover;
mod verifier;

pub use self::prover::Prover;
pub use verifier::Verifier;
Loading

0 comments on commit 1f1d1d9

Please sign in to comment.