From e87e53196193e4be2f1f0293e9506385e31a0602 Mon Sep 17 00:00:00 2001 From: Eduard S Date: Fri, 16 Feb 2024 10:59:50 +0000 Subject: [PATCH] feat(supercircuit): use real challenge when test-circuits is disabled --- zkevm-circuits/Cargo.toml | 3 ++- zkevm-circuits/src/super_circuit.rs | 34 ++++++++++++++++++++--------- 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/zkevm-circuits/Cargo.toml b/zkevm-circuits/Cargo.toml index 9b96aae8355..288694f1e75 100644 --- a/zkevm-circuits/Cargo.toml +++ b/zkevm-circuits/Cargo.toml @@ -60,7 +60,8 @@ test-circuits = [] # Test utilities for testool crate to consume test-util = ["dep:mock"] warn-unimplemented = ["eth-types/warn-unimplemented"] -stats = ["warn-unimplemented", "dep:cli-table", "test-util", "test-circuits"] +# stats = ["warn-unimplemented", "dep:cli-table", "test-util", "test-circuits"] +stats = ["warn-unimplemented", "dep:cli-table"] [[bin]] name = "stats" diff --git a/zkevm-circuits/src/super_circuit.rs b/zkevm-circuits/src/super_circuit.rs index 786d235fedf..e683dc8e745 100644 --- a/zkevm-circuits/src/super_circuit.rs +++ b/zkevm-circuits/src/super_circuit.rs @@ -76,7 +76,7 @@ use bus_mapping::{ use eth_types::{geth_types::GethData, Field}; use halo2_proofs::{ circuit::{Layouter, SimpleFloorPlanner, Value}, - plonk::{Circuit, ConstraintSystem, Error, Expression}, + plonk::{Challenge, Circuit, ConstraintSystem, Error, Expression}, }; use std::array; @@ -97,6 +97,7 @@ pub struct SuperCircuitConfig { keccak_circuit: KeccakCircuitConfig, pi_circuit: PiCircuitConfig, exp_circuit: ExpCircuitConfig, + challenges: Challenges, } impl SubCircuitConfig for SuperCircuitConfig { @@ -128,20 +129,28 @@ impl SubCircuitConfig for SuperCircuitConfig { let u16_table = UXTable::construct(meta); // Use a mock randomness instead of the randomness derived from the challenge - // (either from mock or real prover) to help debugging assignments. + // (either from mock or real prover) to help debugging assignments, when "test-circuits" + // feature is enabled. + #[allow(unused_variables)] let power_of_randomness: [Expression; 31] = array::from_fn(|i| Expression::Constant(mock_randomness.pow([1 + i as u64, 0, 0, 0]))); - let challenges = Challenges::mock( + // Use the real challenges for real use, when "test-circuits" feature is disabled. + let challenges = Challenges::construct(meta); + + #[cfg(feature = "test-circuits")] + let challenges_exprs = Challenges::mock( power_of_randomness[0].clone(), power_of_randomness[0].clone(), ); + #[cfg(not(feature = "test-circuits"))] + let challenges_exprs = { challenges.exprs(meta) }; let keccak_circuit = KeccakCircuitConfig::new( meta, KeccakCircuitConfigArgs { keccak_table: keccak_table.clone(), - challenges: challenges.clone(), + challenges: challenges_exprs.clone(), }, ); @@ -155,7 +164,7 @@ impl SubCircuitConfig for SuperCircuitConfig { tx_table: tx_table.clone(), wd_table, keccak_table: keccak_table.clone(), - challenges: challenges.clone(), + challenges: challenges_exprs.clone(), }, ); let tx_circuit = TxCircuitConfig::new( @@ -163,7 +172,7 @@ impl SubCircuitConfig for SuperCircuitConfig { TxCircuitConfigArgs { tx_table: tx_table.clone(), keccak_table: keccak_table.clone(), - challenges: challenges.clone(), + challenges: challenges_exprs.clone(), }, ); let bytecode_circuit = BytecodeCircuitConfig::new( @@ -171,7 +180,7 @@ impl SubCircuitConfig for SuperCircuitConfig { BytecodeCircuitConfigArgs { bytecode_table: bytecode_table.clone(), keccak_table: keccak_table.clone(), - challenges: challenges.clone(), + challenges: challenges_exprs.clone(), }, ); let copy_circuit = CopyCircuitConfig::new( @@ -182,7 +191,7 @@ impl SubCircuitConfig for SuperCircuitConfig { bytecode_table: bytecode_table.clone(), copy_table, q_enable: q_copy_table, - challenges: challenges.clone(), + challenges: challenges_exprs.clone(), }, ); let state_circuit = StateCircuitConfig::new( @@ -193,14 +202,14 @@ impl SubCircuitConfig for SuperCircuitConfig { u8_table, u10_table, u16_table, - challenges: challenges.clone(), + challenges: challenges_exprs.clone(), }, ); let exp_circuit = ExpCircuitConfig::new(meta, exp_table); let evm_circuit = EvmCircuitConfig::new( meta, EvmCircuitConfigArgs { - challenges, + challenges: challenges_exprs, tx_table, rw_table, bytecode_table, @@ -228,6 +237,7 @@ impl SubCircuitConfig for SuperCircuitConfig { keccak_circuit, pi_circuit, exp_circuit, + challenges, } } } @@ -419,10 +429,14 @@ impl Circuit for SuperCircuit { mut layouter: impl Layouter, ) -> Result<(), Error> { let block = self.evm_circuit.block.as_ref().unwrap(); + #[cfg(feature = "test-circuits")] let challenges = Challenges::mock( Value::known(block.randomness), Value::known(block.randomness), ); + #[cfg(not(feature = "test-circuits"))] + let challenges = config.challenges.values(&mut layouter); + let rws = &self.state_circuit.rows; config.block_table.load(&mut layouter, &block.context)?;