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 mock-challenges 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 2905d4e
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 11 deletions.
2 changes: 1 addition & 1 deletion integration-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions zkevm-circuits/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
35 changes: 26 additions & 9 deletions zkevm-circuits/src/super_circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ pub struct SuperCircuitConfig<F: Field> {
keccak_circuit: KeccakCircuitConfig<F>,
pi_circuit: PiCircuitConfig<F>,
exp_circuit: ExpCircuitConfig<F>,
#[cfg(not(feature = "mock-challenge"))]
challenges: Challenges<halo2_proofs::plonk::Challenge>,
}

impl<F: Field> SubCircuitConfig<F> for SuperCircuitConfig<F> {
Expand Down Expand Up @@ -128,20 +130,29 @@ 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 "mock-challenge"
// 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 "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(),
},
);

Expand All @@ -155,23 +166,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 +193,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 +204,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 +239,8 @@ impl<F: Field> SubCircuitConfig<F> for SuperCircuitConfig<F> {
keccak_circuit,
pi_circuit,
exp_circuit,
#[cfg(not(feature = "mock-challenge"))]
challenges,
}
}
}
Expand Down Expand Up @@ -419,10 +432,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 = "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)?;
Expand Down
2 changes: 1 addition & 1 deletion zkevm-circuits/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ impl<T: Clone> Challenges<T> {
}

/// 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,
Expand Down

0 comments on commit 2905d4e

Please sign in to comment.