From 412e95f67289caf6be9d4e129f9b547f1c169d64 Mon Sep 17 00:00:00 2001 From: "sm.wu" Date: Wed, 5 Jul 2023 23:10:50 +0800 Subject: [PATCH] optimize challenges phase to 2 in dev --- zkevm-circuits/src/evm_circuit/execution.rs | 4 +-- zkevm-circuits/src/evm_circuit/param.rs | 2 +- zkevm-circuits/src/evm_circuit/util.rs | 8 +---- .../evm_circuit/util/constraint_builder.rs | 4 --- zkevm-circuits/src/super_circuit.rs | 2 -- zkevm-circuits/src/util.rs | 32 ++++--------------- 6 files changed, 9 insertions(+), 43 deletions(-) diff --git a/zkevm-circuits/src/evm_circuit/execution.rs b/zkevm-circuits/src/evm_circuit/execution.rs index 911d8631b01..1e4cae2d7b7 100644 --- a/zkevm-circuits/src/evm_circuit/execution.rs +++ b/zkevm-circuits/src/evm_circuit/execution.rs @@ -1365,11 +1365,9 @@ impl ExecutionConfig { block: &Block, challenges: &Challenges>, ) { - 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; } diff --git a/zkevm-circuits/src/evm_circuit/param.rs b/zkevm-circuits/src/evm_circuit/param.rs index 48d0f3ae9c9..ff9617e1327 100644 --- a/zkevm-circuits/src/evm_circuit/param.rs +++ b/zkevm-circuits/src/evm_circuit/param.rs @@ -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 = diff --git a/zkevm-circuits/src/evm_circuit/util.rs b/zkevm-circuits/src/evm_circuit/util.rs index 198c4d528f6..d313221d313 100644 --- a/zkevm-circuits/src/evm_circuit/util.rs +++ b/zkevm-circuits/src/evm_circuit/util.rs @@ -10,7 +10,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}, @@ -135,12 +135,6 @@ impl<'r, 'b, F: Field> CachedRegion<'r, 'b, F> { self.challenges } - pub fn word_rlc(&self, n: U256) -> Value { - self.challenges - .evm_word() - .map(|r| rlc::value(&n.to_le_bytes(), r)) - } - pub fn keccak_rlc(&self, le_bytes: &[u8]) -> Value { self.challenges .keccak_input() diff --git a/zkevm-circuits/src/evm_circuit/util/constraint_builder.rs b/zkevm-circuits/src/evm_circuit/util/constraint_builder.rs index 12ec2551f54..4a6cbe39cc8 100644 --- a/zkevm-circuits/src/evm_circuit/util/constraint_builder.rs +++ b/zkevm-circuits/src/evm_circuit/util/constraint_builder.rs @@ -552,10 +552,6 @@ impl<'a, F: Field> EVMConstraintBuilder<'a, F> { .query_cells(self.meta, cell_type, count) } - pub(crate) fn word_rlc(&self, bytes: [Expression; N]) -> Expression { - rlc::expr(&bytes, self.challenges.evm_word()) - } - pub(crate) fn keccak_rlc(&self, bytes: [Expression; N]) -> Expression { rlc::expr(&bytes, self.challenges.keccak_input()) } diff --git a/zkevm-circuits/src/super_circuit.rs b/zkevm-circuits/src/super_circuit.rs index e8858e14582..6f769b151eb 100644 --- a/zkevm-circuits/src/super_circuit.rs +++ b/zkevm-circuits/src/super_circuit.rs @@ -144,7 +144,6 @@ impl SubCircuitConfig for SuperCircuitConfig { let challenges = Challenges::mock( power_of_randomness[0].clone(), power_of_randomness[0].clone(), - power_of_randomness[0].clone(), ); let keccak_circuit = KeccakCircuitConfig::new( @@ -429,7 +428,6 @@ impl Circuit for SuperCircuit { let challenges = Challenges::mock( Value::known(block.randomness), Value::known(block.randomness), - Value::known(block.randomness), ); let rws = &self.state_circuit.rows; diff --git a/zkevm-circuits/src/util.rs b/zkevm-circuits/src/util.rs index 30a4fe080c2..96b9b70cee3 100644 --- a/zkevm-circuits/src/util.rs +++ b/zkevm-circuits/src/util.rs @@ -41,7 +41,6 @@ pub(crate) fn random_linear_combine_word(bytes: [u8; 32], randomness: /// All challenges used in `SuperCircuit`. #[derive(Default, Clone, Copy, Debug)] pub struct Challenges { - evm_word: T, keccak_input: T, lookup_input: T, } @@ -50,14 +49,9 @@ impl Challenges { /// Construct `Challenges` by allocating challenges in specific phases. pub fn construct(meta: &mut ConstraintSystem) -> 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), } @@ -65,12 +59,10 @@ impl Challenges { /// Returns `Expression` of challenges from `ConstraintSystem`. pub fn exprs(&self, meta: &mut ConstraintSystem) -> Challenges> { - 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, } @@ -79,7 +71,6 @@ impl Challenges { /// Returns `Value` of challenges from `Layouter`. pub fn values(&self, layouter: &mut impl Layouter) -> Challenges> { 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), } @@ -87,11 +78,6 @@ impl Challenges { } impl Challenges { - /// 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() @@ -103,13 +89,12 @@ impl Challenges { } /// 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, } @@ -128,11 +113,6 @@ impl Challenges> { .unwrap() } - /// Returns powers of randomness for word RLC encoding - pub fn evm_word_powers_of_randomness(&self) -> [Expression; S] { - Self::powers_of(self.evm_word.clone()) - } - /// Returns powers of randomness for keccak circuit's input pub fn keccak_powers_of_randomness(&self) -> [Expression; S] { Self::powers_of(self.keccak_input.clone())