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

Commit 3c8ce57

Browse files
authored
optimize few subcircuit synthesis call phase from 3->2 in dev mode (#1517)
### Description Remove evm_word challenge and optimize from 3->2 phase in dev phase. ### Issue Link #1516 ### Type of change - [x] Breaking change (fix or feature that would cause existing functionality to not work as expected)
1 parent e9eb6f2 commit 3c8ce57

File tree

6 files changed

+9
-43
lines changed

6 files changed

+9
-43
lines changed

zkevm-circuits/src/evm_circuit/execution.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1344,11 +1344,9 @@ impl<F: Field> ExecutionConfig<F> {
13441344
block: &Block<F>,
13451345
challenges: &Challenges<Value<F>>,
13461346
) {
1347-
let mut evm_randomness = F::ZERO;
1348-
challenges.evm_word().map(|v| evm_randomness = v);
13491347
let mut lookup_randomness = F::ZERO;
13501348
challenges.lookup_input().map(|v| lookup_randomness = v);
1351-
if evm_randomness.is_zero_vartime() || lookup_randomness.is_zero_vartime() {
1349+
if lookup_randomness.is_zero_vartime() {
13521350
// challenges not ready
13531351
return;
13541352
}

zkevm-circuits/src/evm_circuit/param.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pub const MAX_STEP_HEIGHT: usize = 19;
1616
pub(crate) const STEP_STATE_HEIGHT: usize = 1;
1717

1818
/// Number of Advice Phase2 columns in the EVM circuit
19-
pub const N_PHASE2_COLUMNS: usize = 4;
19+
pub const N_PHASE2_COLUMNS: usize = 1;
2020

2121
/// Number of Advice Phase1 columns in the EVM circuit
2222
pub const N_PHASE1_COLUMNS: usize =

zkevm-circuits/src/evm_circuit/util.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use crate::{
1313
util::{cell_manager::CMFixedWidthStrategyDistribution, int_decomposition::IntDecomposition},
1414
witness::{Block, ExecStep, Rw, RwMap},
1515
};
16-
use eth_types::{Address, Field, ToLittleEndian, U256};
16+
use eth_types::{Address, Field, U256};
1717
use halo2_proofs::{
1818
circuit::{AssignedCell, Region, Value},
1919
plonk::{Advice, Assigned, Column, ConstraintSystem, Error, Expression},
@@ -138,12 +138,6 @@ impl<'r, 'b, F: Field> CachedRegion<'r, 'b, F> {
138138
self.challenges
139139
}
140140

141-
pub fn word_rlc(&self, n: U256) -> Value<F> {
142-
self.challenges
143-
.evm_word()
144-
.map(|r| rlc::value(&n.to_le_bytes(), r))
145-
}
146-
147141
pub fn keccak_rlc(&self, le_bytes: &[u8]) -> Value<F> {
148142
self.challenges
149143
.keccak_input()

zkevm-circuits/src/evm_circuit/util/constraint_builder.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -556,10 +556,6 @@ impl<'a, F: Field> EVMConstraintBuilder<'a, F> {
556556
.query_cells(self.meta, cell_type, count)
557557
}
558558

559-
pub(crate) fn word_rlc<const N: usize>(&self, bytes: [Expression<F>; N]) -> Expression<F> {
560-
rlc::expr(&bytes, self.challenges.evm_word())
561-
}
562-
563559
pub(crate) fn keccak_rlc<const N: usize>(&self, bytes: [Expression<F>; N]) -> Expression<F> {
564560
rlc::expr(&bytes, self.challenges.keccak_input())
565561
}

zkevm-circuits/src/super_circuit.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,6 @@ impl<F: Field> SubCircuitConfig<F> for SuperCircuitConfig<F> {
144144
let challenges = Challenges::mock(
145145
power_of_randomness[0].clone(),
146146
power_of_randomness[0].clone(),
147-
power_of_randomness[0].clone(),
148147
);
149148

150149
let keccak_circuit = KeccakCircuitConfig::new(
@@ -429,7 +428,6 @@ impl<F: Field> Circuit<F> for SuperCircuit<F> {
429428
let challenges = Challenges::mock(
430429
Value::known(block.randomness),
431430
Value::known(block.randomness),
432-
Value::known(block.randomness),
433431
);
434432
let rws = &self.state_circuit.rows;
435433

zkevm-circuits/src/util.rs

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ pub(crate) fn random_linear_combine_word<F: Field>(bytes: [u8; 32], randomness:
4141
/// All challenges used in `SuperCircuit`.
4242
#[derive(Default, Clone, Copy, Debug)]
4343
pub struct Challenges<T = Challenge> {
44-
evm_word: T,
4544
keccak_input: T,
4645
lookup_input: T,
4746
}
@@ -50,27 +49,20 @@ impl Challenges {
5049
/// Construct `Challenges` by allocating challenges in specific phases.
5150
pub fn construct<F: Field>(meta: &mut ConstraintSystem<F>) -> Self {
5251
#[cfg(any(feature = "test", test, feature = "test-circuits"))]
53-
let _dummy_cols = [
54-
meta.advice_column(),
55-
meta.advice_column_in(SecondPhase),
56-
meta.advice_column_in(halo2_proofs::plonk::ThirdPhase),
57-
];
52+
let _dummy_cols = [meta.advice_column(), meta.advice_column_in(SecondPhase)];
5853

5954
Self {
60-
evm_word: meta.challenge_usable_after(FirstPhase),
6155
keccak_input: meta.challenge_usable_after(FirstPhase),
6256
lookup_input: meta.challenge_usable_after(SecondPhase),
6357
}
6458
}
6559

6660
/// Returns `Expression` of challenges from `ConstraintSystem`.
6761
pub fn exprs<F: Field>(&self, meta: &mut ConstraintSystem<F>) -> Challenges<Expression<F>> {
68-
let [evm_word, keccak_input, lookup_input] = query_expression(meta, |meta| {
69-
[self.evm_word, self.keccak_input, self.lookup_input]
70-
.map(|challenge| meta.query_challenge(challenge))
62+
let [keccak_input, lookup_input] = query_expression(meta, |meta| {
63+
[self.keccak_input, self.lookup_input].map(|challenge| meta.query_challenge(challenge))
7164
});
7265
Challenges {
73-
evm_word,
7466
keccak_input,
7567
lookup_input,
7668
}
@@ -79,19 +71,13 @@ impl Challenges {
7971
/// Returns `Value` of challenges from `Layouter`.
8072
pub fn values<F: Field>(&self, layouter: &mut impl Layouter<F>) -> Challenges<Value<F>> {
8173
Challenges {
82-
evm_word: layouter.get_challenge(self.evm_word),
8374
keccak_input: layouter.get_challenge(self.keccak_input),
8475
lookup_input: layouter.get_challenge(self.lookup_input),
8576
}
8677
}
8778
}
8879

8980
impl<T: Clone> Challenges<T> {
90-
/// Returns challenge of `evm_word`.
91-
pub fn evm_word(&self) -> T {
92-
self.evm_word.clone()
93-
}
94-
9581
/// Returns challenge of `keccak_input`.
9682
pub fn keccak_input(&self) -> T {
9783
self.keccak_input.clone()
@@ -103,13 +89,12 @@ impl<T: Clone> Challenges<T> {
10389
}
10490

10591
/// Returns the challenges indexed by the challenge index
106-
pub fn indexed(&self) -> [&T; 3] {
107-
[&self.evm_word, &self.keccak_input, &self.lookup_input]
92+
pub fn indexed(&self) -> [&T; 2] {
93+
[&self.keccak_input, &self.lookup_input]
10894
}
10995

110-
pub(crate) fn mock(evm_word: T, keccak_input: T, lookup_input: T) -> Self {
96+
pub(crate) fn mock(keccak_input: T, lookup_input: T) -> Self {
11197
Self {
112-
evm_word,
11398
keccak_input,
11499
lookup_input,
115100
}
@@ -128,11 +113,6 @@ impl<F: Field> Challenges<Expression<F>> {
128113
.unwrap()
129114
}
130115

131-
/// Returns powers of randomness for word RLC encoding
132-
pub fn evm_word_powers_of_randomness<const S: usize>(&self) -> [Expression<F>; S] {
133-
Self::powers_of(self.evm_word.clone())
134-
}
135-
136116
/// Returns powers of randomness for keccak circuit's input
137117
pub fn keccak_powers_of_randomness<const S: usize>(&self) -> [Expression<F>; S] {
138118
Self::powers_of(self.keccak_input.clone())

0 commit comments

Comments
 (0)