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

Commit

Permalink
feat(supercircuit): use real challenge when test-circuits is disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
ed255 committed Feb 16, 2024
1 parent 01c5133 commit e87e531
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
3 changes: 2 additions & 1 deletion zkevm-circuits/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
34 changes: 24 additions & 10 deletions zkevm-circuits/src/super_circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -97,6 +97,7 @@ pub struct SuperCircuitConfig<F: Field> {
keccak_circuit: KeccakCircuitConfig<F>,
pi_circuit: PiCircuitConfig<F>,
exp_circuit: ExpCircuitConfig<F>,
challenges: Challenges<Challenge>,

Check warning on line 100 in zkevm-circuits/src/super_circuit.rs

View workflow job for this annotation

GitHub Actions / Linux Build

field `challenges` is never read

Check failure on line 100 in zkevm-circuits/src/super_circuit.rs

View workflow job for this annotation

GitHub Actions / Various lints

field `challenges` is never read

Check warning on line 100 in zkevm-circuits/src/super_circuit.rs

View workflow job for this annotation

GitHub Actions / Various lints

field `challenges` is never read
}

impl<F: Field> SubCircuitConfig<F> for SuperCircuitConfig<F> {
Expand Down Expand Up @@ -128,20 +129,28 @@ impl<F: Field> SubCircuitConfig<F> for SuperCircuitConfig<F> {
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<F>; 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(),
},
);

Expand All @@ -155,23 +164,23 @@ impl<F: Field> SubCircuitConfig<F> for SuperCircuitConfig<F> {
tx_table: tx_table.clone(),
wd_table,
keccak_table: keccak_table.clone(),
challenges: challenges.clone(),
challenges: challenges_exprs.clone(),
},
);
let tx_circuit = TxCircuitConfig::new(
meta,
TxCircuitConfigArgs {
tx_table: tx_table.clone(),
keccak_table: keccak_table.clone(),
challenges: challenges.clone(),
challenges: challenges_exprs.clone(),
},
);
let bytecode_circuit = BytecodeCircuitConfig::new(
meta,
BytecodeCircuitConfigArgs {
bytecode_table: bytecode_table.clone(),
keccak_table: keccak_table.clone(),
challenges: challenges.clone(),
challenges: challenges_exprs.clone(),
},
);
let copy_circuit = CopyCircuitConfig::new(
Expand All @@ -182,7 +191,7 @@ impl<F: Field> SubCircuitConfig<F> for SuperCircuitConfig<F> {
bytecode_table: bytecode_table.clone(),
copy_table,
q_enable: q_copy_table,
challenges: challenges.clone(),
challenges: challenges_exprs.clone(),
},
);
let state_circuit = StateCircuitConfig::new(
Expand All @@ -193,14 +202,14 @@ impl<F: Field> SubCircuitConfig<F> for SuperCircuitConfig<F> {
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,
Expand Down Expand Up @@ -228,6 +237,7 @@ impl<F: Field> SubCircuitConfig<F> for SuperCircuitConfig<F> {
keccak_circuit,
pi_circuit,
exp_circuit,
challenges,
}
}
}
Expand Down Expand Up @@ -419,10 +429,14 @@ impl<F: Field> Circuit<F> for SuperCircuit<F> {
mut layouter: impl Layouter<F>,
) -> 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)?;
Expand Down

0 comments on commit e87e531

Please sign in to comment.