From 2905d4e9654181e16c24e74f9bcdd609bc7825e5 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 mock-challenges is disabled --- integration-tests/Cargo.toml | 2 +- zkevm-circuits/Cargo.toml | 1 + zkevm-circuits/src/super_circuit.rs | 35 +++++++++++++++++++++-------- zkevm-circuits/src/util.rs | 2 +- 4 files changed, 29 insertions(+), 11 deletions(-) diff --git a/integration-tests/Cargo.toml b/integration-tests/Cargo.toml index 068341dcdf0..bd8e732c20f 100644 --- a/integration-tests/Cargo.toml +++ b/integration-tests/Cargo.toml @@ -13,7 +13,7 @@ serde_json = { version = "1.0.66", features = ["unbounded_depth"] } serde = { version = "1.0.130", features = ["derive"] } bus-mapping = { path = "../bus-mapping", features = ["test"] } eth-types = { path = "../eth-types" } -zkevm-circuits = { path = "../zkevm-circuits", features = ["test-circuits"] } +zkevm-circuits = { path = "../zkevm-circuits", features = ["test-circuits", "mock-challenge"] } tokio = { version = "1.13", features = ["macros", "rt-multi-thread"] } url = "2.2.2" pretty_assertions = "1.0.0" diff --git a/zkevm-circuits/Cargo.toml b/zkevm-circuits/Cargo.toml index 9b96aae8355..b33470bc382 100644 --- a/zkevm-circuits/Cargo.toml +++ b/zkevm-circuits/Cargo.toml @@ -61,6 +61,7 @@ test-circuits = [] test-util = ["dep:mock"] warn-unimplemented = ["eth-types/warn-unimplemented"] stats = ["warn-unimplemented", "dep:cli-table", "test-util", "test-circuits"] +mock-challenge = [] [[bin]] name = "stats" diff --git a/zkevm-circuits/src/super_circuit.rs b/zkevm-circuits/src/super_circuit.rs index 786d235fedf..2270c208852 100644 --- a/zkevm-circuits/src/super_circuit.rs +++ b/zkevm-circuits/src/super_circuit.rs @@ -97,6 +97,8 @@ pub struct SuperCircuitConfig { keccak_circuit: KeccakCircuitConfig, pi_circuit: PiCircuitConfig, exp_circuit: ExpCircuitConfig, + #[cfg(not(feature = "mock-challenge"))] + challenges: Challenges, } impl SubCircuitConfig for SuperCircuitConfig { @@ -128,20 +130,29 @@ 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 "mock-challenge" + // 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 "mock-challenge" feature is disabled. + #[cfg(not(feature = "mock-challenge"))] + let challenges = Challenges::construct(meta); + + #[cfg(feature = "mock-challenge")] + let challenges_exprs = Challenges::mock( power_of_randomness[0].clone(), power_of_randomness[0].clone(), ); + #[cfg(not(feature = "mock-challenge"))] + 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 +166,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 +174,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 +182,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 +193,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 +204,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 +239,8 @@ impl SubCircuitConfig for SuperCircuitConfig { keccak_circuit, pi_circuit, exp_circuit, + #[cfg(not(feature = "mock-challenge"))] + challenges, } } } @@ -419,10 +432,14 @@ impl Circuit for SuperCircuit { mut layouter: impl Layouter, ) -> Result<(), Error> { let block = self.evm_circuit.block.as_ref().unwrap(); + #[cfg(feature = "mock-challenge")] let challenges = Challenges::mock( Value::known(block.randomness), Value::known(block.randomness), ); + #[cfg(not(feature = "mock-challenge"))] + let challenges = config.challenges.values(&mut layouter); + let rws = &self.state_circuit.rows; config.block_table.load(&mut layouter, &block.context)?; diff --git a/zkevm-circuits/src/util.rs b/zkevm-circuits/src/util.rs index aa7882e928d..b0d8d0449f0 100644 --- a/zkevm-circuits/src/util.rs +++ b/zkevm-circuits/src/util.rs @@ -93,7 +93,7 @@ impl Challenges { } /// Returns a mock Challenges for testing purposes - #[cfg(feature = "test-circuits")] + #[cfg(feature = "mock-challenge")] pub fn mock(keccak_input: T, lookup_input: T) -> Self { Self { keccak_input,