Skip to content

Commit

Permalink
fix: Mock Challenges with different values (scroll-tech#930)
Browse files Browse the repository at this point in the history
* fix: Mock `Challenges` with different values

As mentioned in scroll-tech#926, the `Challenges::mock` function was not adding
different values for the `Challenges`. Therefore, a new function has
been added that allows mocking by passing two different values (one per
each challenge).

This allows to keep the API we previously had and also, reduce the need
to send always 2 values when only 1 can be passed.

Resolves: scroll-tech#926

* fix: Apply @han0110's suggestions
  • Loading branch information
CPerezz authored Nov 24, 2022
1 parent bfb1d1f commit d3a53ab
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
3 changes: 2 additions & 1 deletion zkevm-circuits/src/copy_circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,8 @@ pub mod dev {
) -> Result<(), halo2_proofs::plonk::Error> {
let block = self.block.as_ref().unwrap();

let challenges = Challenges::mock(Value::known(self.randomness));
let challenges =
Challenges::mock(Value::known(self.randomness), Value::known(self.randomness));

config
.tx_table
Expand Down
5 changes: 4 additions & 1 deletion zkevm-circuits/src/evm_circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,10 @@ pub mod test {
mut layouter: impl Layouter<F>,
) -> Result<(), Error> {
let block = self.block.as_ref().unwrap();
let challenges = Challenges::mock(Value::known(block.randomness));
let challenges = Challenges::mock(
Value::known(block.randomness),
Value::known(block.randomness),
);

config
.evm_circuit
Expand Down
10 changes: 8 additions & 2 deletions zkevm-circuits/src/super_circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,10 @@ impl<F: Field, const MAX_TXS: usize, const MAX_CALLDATA: usize, const MAX_RWS: u
Expression::Constant(F::from(MOCK_RANDOMNESS).pow(&[1 + i as u64, 0, 0, 0]))
});

let challenges = Challenges::mock(power_of_randomness[0].clone());
let challenges = Challenges::mock(
power_of_randomness[0].clone(),
power_of_randomness[0].clone(),
);

let keccak_circuit = KeccakConfig::configure(meta, power_of_randomness[0].clone());
let keccak_table = keccak_circuit.keccak_table.clone();
Expand Down Expand Up @@ -246,7 +249,10 @@ impl<F: Field, const MAX_TXS: usize, const MAX_CALLDATA: usize, const MAX_RWS: u
mut layouter: impl Layouter<F>,
) -> Result<(), Error> {
let block = self.block.as_ref().unwrap();
let challenges = Challenges::mock(Value::known(block.randomness));
let challenges = Challenges::mock(
Value::known(block.randomness),
Value::known(block.randomness),
);

// --- EVM Circuit ---
let rws = block.rws.table_assignments();
Expand Down
6 changes: 3 additions & 3 deletions zkevm-circuits/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,10 @@ impl<T: Clone> Challenges<T> {
self.keccak_input.clone()
}

pub(crate) fn mock(challenge: T) -> Self {
pub(crate) fn mock(evm_word: T, keccak_input: T) -> Self {
Self {
evm_word: challenge.clone(),
keccak_input: challenge,
evm_word,
keccak_input,
}
}
}
Expand Down

0 comments on commit d3a53ab

Please sign in to comment.