From 4addc1caf121e44d336bb8fd01ec55c9bee4a97b Mon Sep 17 00:00:00 2001 From: Zhang Zhuo Date: Mon, 2 Jan 2023 20:06:02 +0800 Subject: [PATCH] speedup bytecode circuit assignment --- .../src/bytecode_circuit/bytecode_unroller.rs | 27 +++++++++++++ zkevm-circuits/src/evm_circuit/execution.rs | 2 +- .../src/keccak_circuit/keccak_packed_multi.rs | 38 +++++++++---------- 3 files changed, 47 insertions(+), 20 deletions(-) diff --git a/zkevm-circuits/src/bytecode_circuit/bytecode_unroller.rs b/zkevm-circuits/src/bytecode_circuit/bytecode_unroller.rs index 2b701d1ba..e2c050fc6 100644 --- a/zkevm-circuits/src/bytecode_circuit/bytecode_unroller.rs +++ b/zkevm-circuits/src/bytecode_circuit/bytecode_unroller.rs @@ -427,9 +427,36 @@ impl BytecodeCircuitConfig { assert!(size > self.minimum_rows); let last_row_offset = size - self.minimum_rows + 1; + let mut is_first_time = true; + layouter.assign_region( || "assign bytecode", |mut region| { + if is_first_time { + is_first_time = false; + self.set_row( + &mut region, + &push_rindex_is_zero_chip, + &length_is_zero_chip, + last_row_offset, + false, + true, + Value::known(F::zero()), + F::from(BytecodeFieldTag::Padding as u64), + F::zero(), + F::one(), + F::zero(), + 0, + Value::known(F::zero()), + F::zero(), + F::zero(), + true, + true, + F::zero(), + )?; + return Ok(()); + } + let mut offset = 0; let mut push_rindex_prev = 0; for bytecode in witness.iter() { diff --git a/zkevm-circuits/src/evm_circuit/execution.rs b/zkevm-circuits/src/evm_circuit/execution.rs index 7eb27d656..a9d31a52a 100644 --- a/zkevm-circuits/src/evm_circuit/execution.rs +++ b/zkevm-circuits/src/evm_circuit/execution.rs @@ -813,7 +813,7 @@ impl ExecutionConfig { .try_into() .unwrap(); - let mut is_first_time = false; + let mut is_first_time = true; layouter.assign_region( || "Execution step", diff --git a/zkevm-circuits/src/keccak_circuit/keccak_packed_multi.rs b/zkevm-circuits/src/keccak_circuit/keccak_packed_multi.rs index 759160560..a9f72a16f 100644 --- a/zkevm-circuits/src/keccak_circuit/keccak_packed_multi.rs +++ b/zkevm-circuits/src/keccak_circuit/keccak_packed_multi.rs @@ -21,7 +21,7 @@ use halo2_proofs::{ plonk::{Advice, Circuit, Column, ConstraintSystem, Error, Expression, Fixed, TableColumn}, poly::Rotation, }; -use log::{debug, info, trace}; +use log::{debug, trace}; use std::{env::var, marker::PhantomData, vec}; const MAX_DEGREE: usize = 9; @@ -947,9 +947,9 @@ impl SubCircuitConfig for KeccakCircuitConfig { decode::expr(absorb_res), absorb_result.expr(), ); - info!("- Post absorb:"); - info!("Lookups: {}", lookup_counter); - info!("Columns: {}", cell_manager.get_width()); + debug!("- Post absorb:"); + debug!("Lookups: {}", lookup_counter); + debug!("Columns: {}", cell_manager.get_width()); total_lookup_counter += lookup_counter; // Squeeze @@ -993,9 +993,9 @@ impl SubCircuitConfig for KeccakCircuitConfig { is_paddings.push(cell_manager.query_cell(meta)); data_rlcs.push(cell_manager.query_cell(meta)); } - info!("- Post padding:"); - info!("Lookups: {}", lookup_counter); - info!("Columns: {}", cell_manager.get_width()); + debug!("- Post padding:"); + debug!("Lookups: {}", lookup_counter); + debug!("Columns: {}", cell_manager.get_width()); total_lookup_counter += lookup_counter; // Theta @@ -1053,9 +1053,9 @@ impl SubCircuitConfig for KeccakCircuitConfig { } } s = os.clone(); - info!("- Post theta:"); - info!("Lookups: {}", lookup_counter); - info!("Columns: {}", cell_manager.get_width()); + debug!("- Post theta:"); + debug!("Lookups: {}", lookup_counter); + debug!("Columns: {}", cell_manager.get_width()); total_lookup_counter += lookup_counter; // Rho/Pi @@ -1142,9 +1142,9 @@ impl SubCircuitConfig for KeccakCircuitConfig { }); lookup_counter += 1; } - info!("- Post rho/pi:"); - info!("Lookups: {}", lookup_counter); - info!("Columns: {}", cell_manager.get_width()); + debug!("- Post rho/pi:"); + debug!("Lookups: {}", lookup_counter); + debug!("Columns: {}", cell_manager.get_width()); total_lookup_counter += lookup_counter; // Chi @@ -1231,9 +1231,9 @@ impl SubCircuitConfig for KeccakCircuitConfig { cb.require_equal("next row check", s[i][j].clone(), s_next[i][j].clone()); } } - info!("- Post chi:"); - info!("Lookups: {}", lookup_counter); - info!("Columns: {}", cell_manager.get_width()); + debug!("- Post chi:"); + debug!("Lookups: {}", lookup_counter); + debug!("Columns: {}", cell_manager.get_width()); total_lookup_counter += lookup_counter; let mut lookup_counter = 0; @@ -1279,9 +1279,9 @@ impl SubCircuitConfig for KeccakCircuitConfig { .unwrap(), true, ); - info!("- Post squeeze:"); - info!("Lookups: {}", lookup_counter); - info!("Columns: {}", cell_manager.get_width()); + debug!("- Post squeeze:"); + debug!("Lookups: {}", lookup_counter); + debug!("Columns: {}", cell_manager.get_width()); total_lookup_counter += lookup_counter; // The round constraints that we've been building up till now