Skip to content
This repository has been archived by the owner on Jul 5, 2024. It is now read-only.

optimize few subcircuit synthesis call phase from 3->2 in dev mode #1517

Merged
merged 1 commit into from
Jul 7, 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
4 changes: 1 addition & 3 deletions zkevm-circuits/src/evm_circuit/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1343,11 +1343,9 @@ impl<F: Field> ExecutionConfig<F> {
block: &Block<F>,
challenges: &Challenges<Value<F>>,
) {
let mut evm_randomness = F::ZERO;
challenges.evm_word().map(|v| evm_randomness = v);
let mut lookup_randomness = F::ZERO;
challenges.lookup_input().map(|v| lookup_randomness = v);
if evm_randomness.is_zero_vartime() || lookup_randomness.is_zero_vartime() {
if lookup_randomness.is_zero_vartime() {
// challenges not ready
return;
}
Expand Down
2 changes: 1 addition & 1 deletion zkevm-circuits/src/evm_circuit/param.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub const MAX_STEP_HEIGHT: usize = 19;
pub(crate) const STEP_STATE_HEIGHT: usize = 1;

/// Number of Advice Phase2 columns in the EVM circuit
pub const N_PHASE2_COLUMNS: usize = 4;
pub const N_PHASE2_COLUMNS: usize = 1;

/// Number of Advice Phase1 columns in the EVM circuit
pub const N_PHASE1_COLUMNS: usize =
Expand Down
8 changes: 1 addition & 7 deletions zkevm-circuits/src/evm_circuit/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::{
util::{cell_manager::CMFixedWidthStrategyDistribution, int_decomposition::IntDecomposition},
witness::{Block, ExecStep, Rw, RwMap},
};
use eth_types::{Address, Field, ToLittleEndian, U256};
use eth_types::{Address, Field, U256};
use halo2_proofs::{
circuit::{AssignedCell, Region, Value},
plonk::{Advice, Assigned, Column, ConstraintSystem, Error, Expression},
Expand Down Expand Up @@ -138,12 +138,6 @@ impl<'r, 'b, F: Field> CachedRegion<'r, 'b, F> {
self.challenges
}

pub fn word_rlc(&self, n: U256) -> Value<F> {
self.challenges
.evm_word()
.map(|r| rlc::value(&n.to_le_bytes(), r))
}

pub fn keccak_rlc(&self, le_bytes: &[u8]) -> Value<F> {
self.challenges
.keccak_input()
Expand Down
4 changes: 0 additions & 4 deletions zkevm-circuits/src/evm_circuit/util/constraint_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -552,10 +552,6 @@ impl<'a, F: Field> EVMConstraintBuilder<'a, F> {
.query_cells(self.meta, cell_type, count)
}

pub(crate) fn word_rlc<const N: usize>(&self, bytes: [Expression<F>; N]) -> Expression<F> {
rlc::expr(&bytes, self.challenges.evm_word())
}

pub(crate) fn keccak_rlc<const N: usize>(&self, bytes: [Expression<F>; N]) -> Expression<F> {
rlc::expr(&bytes, self.challenges.keccak_input())
}
Expand Down
2 changes: 0 additions & 2 deletions zkevm-circuits/src/super_circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ impl<F: Field> SubCircuitConfig<F> for SuperCircuitConfig<F> {
let challenges = Challenges::mock(
power_of_randomness[0].clone(),
power_of_randomness[0].clone(),
power_of_randomness[0].clone(),
);

let keccak_circuit = KeccakCircuitConfig::new(
Expand Down Expand Up @@ -429,7 +428,6 @@ impl<F: Field> Circuit<F> for SuperCircuit<F> {
let challenges = Challenges::mock(
Value::known(block.randomness),
Value::known(block.randomness),
Value::known(block.randomness),
);
let rws = &self.state_circuit.rows;

Expand Down
32 changes: 6 additions & 26 deletions zkevm-circuits/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ pub(crate) fn random_linear_combine_word<F: Field>(bytes: [u8; 32], randomness:
/// All challenges used in `SuperCircuit`.
#[derive(Default, Clone, Copy, Debug)]
pub struct Challenges<T = Challenge> {
evm_word: T,
keccak_input: T,
lookup_input: T,
}
Expand All @@ -50,27 +49,20 @@ impl Challenges {
/// Construct `Challenges` by allocating challenges in specific phases.
pub fn construct<F: Field>(meta: &mut ConstraintSystem<F>) -> Self {
#[cfg(any(feature = "test", test, feature = "test-circuits"))]
let _dummy_cols = [
meta.advice_column(),
meta.advice_column_in(SecondPhase),
meta.advice_column_in(halo2_proofs::plonk::ThirdPhase),
];
let _dummy_cols = [meta.advice_column(), meta.advice_column_in(SecondPhase)];

Self {
evm_word: meta.challenge_usable_after(FirstPhase),
keccak_input: meta.challenge_usable_after(FirstPhase),
lookup_input: meta.challenge_usable_after(SecondPhase),
}
}

/// Returns `Expression` of challenges from `ConstraintSystem`.
pub fn exprs<F: Field>(&self, meta: &mut ConstraintSystem<F>) -> Challenges<Expression<F>> {
let [evm_word, keccak_input, lookup_input] = query_expression(meta, |meta| {
[self.evm_word, self.keccak_input, self.lookup_input]
.map(|challenge| meta.query_challenge(challenge))
let [keccak_input, lookup_input] = query_expression(meta, |meta| {
[self.keccak_input, self.lookup_input].map(|challenge| meta.query_challenge(challenge))
});
Challenges {
evm_word,
keccak_input,
lookup_input,
}
Expand All @@ -79,19 +71,13 @@ impl Challenges {
/// Returns `Value` of challenges from `Layouter`.
pub fn values<F: Field>(&self, layouter: &mut impl Layouter<F>) -> Challenges<Value<F>> {
Challenges {
evm_word: layouter.get_challenge(self.evm_word),
keccak_input: layouter.get_challenge(self.keccak_input),
lookup_input: layouter.get_challenge(self.lookup_input),
}
}
}

impl<T: Clone> Challenges<T> {
/// Returns challenge of `evm_word`.
pub fn evm_word(&self) -> T {
self.evm_word.clone()
}

/// Returns challenge of `keccak_input`.
pub fn keccak_input(&self) -> T {
self.keccak_input.clone()
Expand All @@ -103,13 +89,12 @@ impl<T: Clone> Challenges<T> {
}

/// Returns the challenges indexed by the challenge index
pub fn indexed(&self) -> [&T; 3] {
[&self.evm_word, &self.keccak_input, &self.lookup_input]
pub fn indexed(&self) -> [&T; 2] {
[&self.keccak_input, &self.lookup_input]
}

pub(crate) fn mock(evm_word: T, keccak_input: T, lookup_input: T) -> Self {
pub(crate) fn mock(keccak_input: T, lookup_input: T) -> Self {
Self {
evm_word,
keccak_input,
lookup_input,
}
Expand All @@ -128,11 +113,6 @@ impl<F: Field> Challenges<Expression<F>> {
.unwrap()
}

/// Returns powers of randomness for word RLC encoding
pub fn evm_word_powers_of_randomness<const S: usize>(&self) -> [Expression<F>; S] {
Self::powers_of(self.evm_word.clone())
}

/// Returns powers of randomness for keccak circuit's input
pub fn keccak_powers_of_randomness<const S: usize>(&self) -> [Expression<F>; S] {
Self::powers_of(self.keccak_input.clone())
Expand Down
Loading