Skip to content
This repository was archived by the owner on Jul 5, 2024. It is now read-only.
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 Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ debug-assertions = true
overflow-checks = true
rpath = false
lto = "thin"
incremental = false
incremental = true
51 changes: 51 additions & 0 deletions zkevm-circuits/src/evm_circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,57 @@ pub(crate) fn detect_fixed_table_tags<F: Field>(block: &Block<F>) -> Vec<FixedTa
.collect()
}

#[cfg(any(feature = "test", test))]
pub(crate) mod cached {
use super::*;
use halo2_proofs::halo2curves::bn256::Fr;
use lazy_static::lazy_static;

/// Cache
struct Cache {
cs: ConstraintSystem<Fr>,
config: (EvmCircuitConfig<Fr>, Challenges),
}

lazy_static! {
static ref CACHE: Cache = {
let mut meta = ConstraintSystem::<Fr>::default();
let config = EvmCircuit::<Fr>::configure(&mut meta);
Cache { cs: meta, config }
};
}

pub struct EvmCircuitCached(EvmCircuit<Fr>);

impl Circuit<Fr> for EvmCircuitCached {
type Config = (EvmCircuitConfig<Fr>, Challenges);
type FloorPlanner = SimpleFloorPlanner;

fn without_witnesses(&self) -> Self {
Self(self.0.without_witnesses())
}

fn configure(meta: &mut ConstraintSystem<Fr>) -> Self::Config {
*meta = CACHE.cs.clone();
CACHE.config.clone()
}

fn synthesize(
&self,
config: Self::Config,
layouter: impl Layouter<Fr>,
) -> Result<(), Error> {
self.0.synthesize(config, layouter)
}
}

impl EvmCircuitCached {
pub fn get_test_cicuit_from_block(block: Block<Fr>) -> Self {
Self(EvmCircuit::<Fr>::get_test_cicuit_from_block(block))
}
}
}

// Always exported because of `EXECUTION_STATE_HEIGHT_MAP`
impl<F: Field> Circuit<F> for EvmCircuit<F> {
type Config = (EvmCircuitConfig<F>, Challenges);
Expand Down
4 changes: 2 additions & 2 deletions zkevm-circuits/src/test_util.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Testing utilities

use crate::{
evm_circuit::EvmCircuit,
evm_circuit::{cached::EvmCircuitCached, EvmCircuit},
state_circuit::StateCircuit,
util::SubCircuit,
witness::{Block, Rw},
Expand Down Expand Up @@ -211,7 +211,7 @@ impl<const NACC: usize, const NTX: usize> CircuitTestBuilder<NACC, NTX> {

let (active_gate_rows, active_lookup_rows) = EvmCircuit::<Fr>::get_active_rows(&block);

let circuit = EvmCircuit::<Fr>::get_test_cicuit_from_block(block.clone());
let circuit = EvmCircuitCached::get_test_cicuit_from_block(block.clone());
let prover = MockProver::<Fr>::run(k, &circuit, vec![]).unwrap();

self.evm_checks.as_ref()(prover, &active_gate_rows, &active_lookup_rows)
Expand Down