forked from taikoxyz/zkevm-circuits
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Circuit benchmarks addition to workspace (privacy-scaling-exploration…
…s#226) * Add bench profile to workspace Cargo.toml * Add benchmark running rules to Makefile * Change CI to test the benchmarks without run * Add circuit-benchmarks crate This crate is responsible for allowing to run the circuit benchmarks on a more easy and clean way. * Update visibility of Circuit structs to allow benchmarks * Compile crate before checking rustfmt * Fix rebase unused_imports * Add state_circuit module during build.rs run * Change to more descriptive env var error messages Co-authored-by: Eduard S. <[email protected]> * Fix Makefile and CI * Fix ethers dep to pull grom git While a new version is not published in crates.io, we need to pull from git. * Change state_circuit generation from build.rs * Update evm_circuit to latest main version Co-authored-by: Han <[email protected]> * Fix contract deployment breaking change issues `ethers-solc` had a breaking change within patch versions. This solves it while we still depend on the git dep. * Update solc version used in integration CI job to 0.8.10 Co-authored-by: Eduard S. <[email protected]> Co-authored-by: Eduard S. <[email protected]> Co-authored-by: Han <[email protected]>
- Loading branch information
1 parent
1f5c8aa
commit 8fec0e5
Showing
20 changed files
with
401 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
|
||
name: Lints | ||
|
||
# We only run these lints on trial-merges of PRs to reduce noise. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
[package] | ||
name = "circuit-benchmarks" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
ff = "0.11" | ||
halo2 = { git = "https://github.com/appliedzkp/halo2.git", rev = "b78c39cacc1c79d287032f1b5f94beb661b3fb42" } | ||
pairing = { git = 'https://github.com/appliedzkp/pairing', package = "pairing_bn256" } | ||
ark-std = { version = "0.3", features = ["print-trace"] } | ||
zkevm-circuits = { path = "../zkevm-circuits" } | ||
bus-mapping = { path = "../bus-mapping" } | ||
rand_xorshift = "0.3" | ||
rand = "0.8" | ||
|
||
[features] | ||
default = [] | ||
benches = [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
//! Generate the benchmark file for State Circuit fetching the bench parameters | ||
//! from ENV. | ||
use std::env::var; | ||
use std::fs::*; | ||
use std::io::Write; | ||
|
||
fn main() { | ||
let degree: usize = var("DEGREE") | ||
.unwrap_or_else(|_| "11".to_string()) | ||
.parse() | ||
.expect("Cannot parse DEGREE env var as usize"); | ||
let memory_address_max: usize = var("MEMORY_ADDRESS_MAX") | ||
.unwrap_or_else(|_| "2000".to_string()) | ||
.parse() | ||
.expect("Cannot parse MEMORY_ADDRESS_MAX env var as usize"); | ||
let stack_address_max: usize = var("STACK_ADDRESS_MAX") | ||
.unwrap_or_else(|_| "1300".to_string()) | ||
.parse() | ||
.expect("Cannot parse STACK_ADDRESS_MAX env var as usize"); | ||
|
||
// Add state_circuit module to `lib.rs` | ||
let consts = format!( | ||
"pub(crate) const DEGREE: usize = {}; | ||
pub(crate) const MEMORY_ADDRESS_MAX: usize = {}; | ||
pub(crate) const STACK_ADDRESS_MAX: usize = {}; | ||
", | ||
degree, memory_address_max, stack_address_max | ||
); | ||
|
||
let mut state_file = File::create("src/bench_params.rs") | ||
.expect("Error generating bench_params.rs file"); | ||
state_file | ||
.write_all(consts.as_bytes()) | ||
.expect("Error writing to bench_params.rs file"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
//! Evm circuit benchmarks | ||
use halo2::{ | ||
arithmetic::FieldExt, | ||
circuit::{Layouter, SimpleFloorPlanner}, | ||
plonk::{Circuit, ConstraintSystem, Error}, | ||
}; | ||
use zkevm_circuits::evm_circuit::{bus_mapping_tmp::Block, EvmCircuit}; | ||
|
||
#[derive(Debug, Default)] | ||
pub struct TestCircuit<F> { | ||
block: Block<F>, | ||
} | ||
|
||
impl<F: FieldExt> Circuit<F> for TestCircuit<F> { | ||
type Config = EvmCircuit<F>; | ||
type FloorPlanner = SimpleFloorPlanner; | ||
|
||
fn without_witnesses(&self) -> Self { | ||
Self::default() | ||
} | ||
|
||
fn configure(meta: &mut ConstraintSystem<F>) -> Self::Config { | ||
let tx_table = [(); 4].map(|_| meta.advice_column()); | ||
let rw_table = [(); 8].map(|_| meta.advice_column()); | ||
let bytecode_table = [(); 4].map(|_| meta.advice_column()); | ||
let randomness = meta.instance_column(); | ||
|
||
EvmCircuit::configure( | ||
meta, | ||
randomness, | ||
tx_table, | ||
rw_table, | ||
bytecode_table, | ||
) | ||
} | ||
|
||
fn synthesize( | ||
&self, | ||
config: Self::Config, | ||
mut layouter: impl Layouter<F>, | ||
) -> Result<(), Error> { | ||
config.assign_block(&mut layouter, &self.block) | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod evm_circ_benches { | ||
use super::*; | ||
use ark_std::{end_timer, start_timer}; | ||
use halo2::plonk::{create_proof, keygen_pk, keygen_vk}; | ||
use halo2::{ | ||
plonk::verify_proof, | ||
poly::commitment::Setup, | ||
transcript::{Blake2bRead, Blake2bWrite, Challenge255}, | ||
}; | ||
use pairing::bn256::Bn256; | ||
use pairing::bn256::Fr; | ||
use rand::SeedableRng; | ||
use rand_xorshift::XorShiftRng; | ||
use std::env::var; | ||
|
||
#[cfg_attr(not(feature = "benches"), ignore)] | ||
#[test] | ||
fn bench_evm_circuit_prover() { | ||
let degree: u32 = var("DEGREE") | ||
.expect("No DEGREE env var was provided") | ||
.parse() | ||
.expect("Cannot parse DEGREE env var as u32"); | ||
|
||
let circuit = TestCircuit::<Fr>::default(); | ||
let rng = XorShiftRng::from_seed([ | ||
0x59, 0x62, 0xbe, 0x5d, 0x76, 0x3d, 0x31, 0x8d, 0x17, 0xdb, 0x37, | ||
0x32, 0x54, 0x06, 0xbc, 0xe5, | ||
]); | ||
|
||
// Bench setup generation | ||
let setup_message = | ||
format!("Setup generation with degree = {}", degree); | ||
let start1 = start_timer!(|| setup_message); | ||
let params = Setup::<Bn256>::new(degree, rng); | ||
end_timer!(start1); | ||
|
||
let vk = keygen_vk(¶ms, &circuit).unwrap(); | ||
let pk = keygen_pk(¶ms, vk, &circuit).unwrap(); | ||
|
||
// Prove | ||
let mut transcript = | ||
Blake2bWrite::<_, _, Challenge255<_>>::init(vec![]); | ||
|
||
// Bench proof generation time | ||
let proof_message = | ||
format!("EVM Proof generation with {} rows", degree); | ||
let start2 = start_timer!(|| proof_message); | ||
create_proof(¶ms, &pk, &[circuit], &[&[&[]]], &mut transcript) | ||
.unwrap(); | ||
let proof = transcript.finalize(); | ||
end_timer!(start2); | ||
|
||
// Verify | ||
let params = Setup::<Bn256>::verifier_params(¶ms, 0).unwrap(); | ||
let mut transcript = | ||
Blake2bRead::<_, _, Challenge255<_>>::init(&proof[..]); | ||
|
||
// Bench verification time | ||
let start3 = start_timer!(|| "EVM Proof verification"); | ||
verify_proof(¶ms, pk.get_vk(), &[&[&[]]], &mut transcript).unwrap(); | ||
end_timer!(start3); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#[cfg(feature = "benches")] | ||
pub mod evm_circuit; | ||
|
||
#[cfg(feature = "benches")] | ||
pub mod state_circuit; | ||
|
||
#[cfg(test)] | ||
#[cfg(feature = "benches")] | ||
pub mod bench_params; |
Oops, something went wrong.