Skip to content
This repository was archived by the owner on Jul 5, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
6d1b258
Challange in EVM circuit WIP
Dec 13, 2022
f6da00f
Fixed copy_circuit_valid_sha3
Dec 15, 2022
eaafdf9
Remove leftovers
Dec 16, 2022
8120bd4
lookup_input wip
Dec 16, 2022
74b9b8b
fix _dummy_cols, cleanup, fmt
Jan 2, 2023
c9dd231
revert fast id, split_expression phase fix
Jan 2, 2023
c390abf
Merge branch 'main' of github.com:privacy-scaling-explorations/zkevm-…
Jan 2, 2023
d41b85c
limit 12 pows in lookup_powers_of_randomness
Jan 3, 2023
5ba2cf1
EVM lookup columns in phase3
Jan 3, 2023
f23089a
Extract Value contents to order instead ordering by Value
Jan 9, 2023
8aa678d
Removed leftovers & misspells
Jan 9, 2023
3ded707
Move Value::transpose from halo2 to this crate
Jan 9, 2023
8bfda72
Fix phases in is_zero gagets
Jan 9, 2023
c755ee2
Revert: use halo2 from git
Jan 10, 2023
df71e45
Merge branch 'main' of github.com:privacy-scaling-explorations/zkevm-…
Jan 10, 2023
cc01aab
Merge branch 'main' into feat/challenge-evm-circuit
adria0 Jan 10, 2023
61710e8
Fix phase computation for inv
Jan 11, 2023
248969b
fmt
Jan 11, 2023
55680a5
Merge branch 'feat/challenge-evm-circuit' of github.com:privacy-scali…
Jan 11, 2023
713107e
Merge branch 'main' of github.com:privacy-scaling-explorations/zkevm-…
Jan 11, 2023
f4ab554
@han0110 nitpicks
Jan 11, 2023
693e4d5
Re-add comment
Jan 11, 2023
93dc400
Add empty_hash_rlc, cleanup comments
Jan 12, 2023
92e9cd8
Merge branch 'main' of github.com:privacy-scaling-explorations/zkevm-…
Jan 12, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions integration-tests/src/integration_test_circuits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use std::collections::HashMap;
use std::sync::Mutex;
use zkevm_circuits::bytecode_circuit::bytecode_unroller::BytecodeCircuit;
use zkevm_circuits::copy_circuit::CopyCircuit;
use zkevm_circuits::evm_circuit::test::{get_test_degree, get_test_instance};
use zkevm_circuits::evm_circuit::test::get_test_degree;
use zkevm_circuits::evm_circuit::{test::get_test_cicuit_from_block, witness::block_convert};
use zkevm_circuits::state_circuit::StateCircuit;
use zkevm_circuits::super_circuit::SuperCircuit;
Expand Down Expand Up @@ -245,13 +245,12 @@ pub async fn test_evm_circuit_block(block_num: u64, actual: bool) {
let block = block_convert(&builder.block, &builder.code_db).unwrap();

let degree = get_test_degree(&block);
let instance = get_test_instance(&block);
let circuit = get_test_cicuit_from_block(block);

if actual {
test_actual(degree, circuit, instance, None);
test_actual(degree, circuit, vec![], None);
} else {
test_mock(degree, &circuit, instance);
test_mock(degree, &circuit, vec![]);
}
}

Expand Down
2 changes: 1 addition & 1 deletion zkevm-circuits/src/copy_circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ impl<F: Field> SubCircuitConfig<F> for CopyCircuitConfig<F> {
cb.require_equal(
"rows[2].value == rows[0].value * r + rows[1].value",
meta.query_advice(value, Rotation(2)),
meta.query_advice(value, Rotation::cur()) * challenges.evm_word()
meta.query_advice(value, Rotation::cur()) * challenges.keccak_input()
+ meta.query_advice(value, Rotation::next()),
);

Expand Down
79 changes: 36 additions & 43 deletions zkevm-circuits/src/evm_circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ pub struct EvmCircuitConfig<F> {

/// Circuit configuration arguments
pub struct EvmCircuitConfigArgs<F: Field> {
/// Power of randomness
pub power_of_randomness: [Expression<F>; 31],
/// Challenge
pub challenges: Challenges<Expression<F>>,
/// TxTable
pub tx_table: TxTable,
/// RwTable
Expand All @@ -68,7 +68,7 @@ impl<F: Field> SubCircuitConfig<F> for EvmCircuitConfig<F> {
fn new(
meta: &mut ConstraintSystem<F>,
Self::ConfigArgs {
power_of_randomness,
challenges,
tx_table,
rw_table,
bytecode_table,
Expand All @@ -82,7 +82,7 @@ impl<F: Field> SubCircuitConfig<F> for EvmCircuitConfig<F> {
let byte_table = [(); 1].map(|_| meta.fixed_column());
let execution = Box::new(ExecutionConfig::configure(
meta,
power_of_randomness,
challenges,
&fixed_table,
&byte_table,
&tx_table,
Expand Down Expand Up @@ -233,14 +233,14 @@ impl<F: Field> SubCircuit<F> for EvmCircuit<F> {
fn synthesize_sub(
&self,
config: &Self::Config,
_challenges: &Challenges<Value<F>>,
challenges: &Challenges<Value<F>>,
layouter: &mut impl Layouter<F>,
) -> Result<(), Error> {
let block = self.block.as_ref().unwrap();

config.load_fixed_table(layouter, self.fixed_table_tags.clone())?;
config.load_byte_table(layouter)?;
config.execution.assign_block(layouter, block)
config.execution.assign_block(layouter, block, challenges)
}
}

Expand Down Expand Up @@ -274,14 +274,14 @@ pub mod test {
evm_circuit::{witness::Block, EvmCircuitConfig},
exp_circuit::OFFSET_INCREMENT,
table::{BlockTable, BytecodeTable, CopyTable, ExpTable, KeccakTable, RwTable, TxTable},
util::{power_of_randomness_from_instance, Challenges},
util::Challenges,
witness::block_convert,
};
use bus_mapping::{circuit_input_builder::CircuitsParams, mock::BlockData};
use eth_types::{geth_types::GethData, Field, Word};
use halo2_proofs::halo2curves::bn256::Fr;
use halo2_proofs::{
circuit::{Layouter, SimpleFloorPlanner, Value},
circuit::{Layouter, SimpleFloorPlanner},
dev::{MockProver, VerifyFailure},
plonk::{Circuit, ConstraintSystem, Error},
};
Expand Down Expand Up @@ -311,7 +311,7 @@ pub mod test {
}

impl<F: Field> Circuit<F> for EvmCircuit<F> {
type Config = EvmCircuitConfig<F>;
type Config = (EvmCircuitConfig<F>, Challenges);
type FloorPlanner = SimpleFloorPlanner;

fn without_witnesses(&self) -> Self {
Expand All @@ -327,20 +327,24 @@ pub mod test {
let copy_table = CopyTable::construct(meta, q_copy_table);
let keccak_table = KeccakTable::construct(meta);
let exp_table = ExpTable::construct(meta);

let power_of_randomness = power_of_randomness_from_instance(meta);
EvmCircuitConfig::new(
meta,
EvmCircuitConfigArgs {
power_of_randomness,
tx_table,
rw_table,
bytecode_table,
block_table,
copy_table,
keccak_table,
exp_table,
},
let challenges = Challenges::construct(meta);
let challenges_expr = challenges.exprs(meta);

(
EvmCircuitConfig::new(
meta,
EvmCircuitConfigArgs {
challenges: challenges_expr,
tx_table,
rw_table,
bytecode_table,
block_table,
copy_table,
keccak_table,
exp_table,
},
),
challenges,
)
}

Expand All @@ -350,10 +354,9 @@ 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),
Value::known(block.randomness),
);

let (config, challenges) = config;
let challenges = challenges.values(&mut layouter);

config.tx_table.load(
&mut layouter,
Expand All @@ -366,14 +369,14 @@ pub mod test {
&mut layouter,
&block.rws.table_assignments(),
block.circuits_params.max_rws,
Value::known(block.randomness),
challenges.evm_word(),
)?;
config
.bytecode_table
.load(&mut layouter, block.bytecodes.values(), &challenges)?;
config
.block_table
.load(&mut layouter, &block.context, block.randomness)?;
.load(&mut layouter, &block.context, challenges.evm_word())?;
config.copy_table.load(&mut layouter, block, &challenges)?;
config
.keccak_table
Expand All @@ -388,13 +391,13 @@ pub mod test {
pub fn get_num_rows_required(block: &Block<F>) -> usize {
let mut cs = ConstraintSystem::default();
let config = EvmCircuit::<F>::configure(&mut cs);
config.get_num_rows_required(block)
config.0.get_num_rows_required(block)
}

pub fn get_active_rows(block: &Block<F>) -> (Vec<usize>, Vec<usize>) {
let mut cs = ConstraintSystem::default();
let config = EvmCircuit::<F>::configure(&mut cs);
config.get_active_rows(block)
config.0.get_active_rows(block)
}
}

Expand Down Expand Up @@ -482,23 +485,13 @@ pub mod test {
EvmCircuit::<F>::new_dev(block, fixed_table_tags)
}

pub fn get_test_instance<F: Field>(block: &Block<F>) -> Vec<Vec<F>> {
let k = get_test_degree(block);

(1..32)
.map(|exp| vec![block.randomness.pow(&[exp, 0, 0, 0]); (1 << k) - 64])
.collect()
}

pub fn run_test_circuit<F: Field>(block: Block<F>) -> Result<(), Vec<VerifyFailure>> {
let k = get_test_degree(&block);

let (active_gate_rows, active_lookup_rows) = EvmCircuit::<F>::get_active_rows(&block);

let power_of_randomness = get_test_instance(&block);

let circuit = get_test_cicuit_from_block(block);
let prover = MockProver::<F>::run(k, &circuit, power_of_randomness).unwrap();
let prover = MockProver::<F>::run(k, &circuit, vec![]).unwrap();
prover.verify_at_rows_par(active_gate_rows.into_iter(), active_lookup_rows.into_iter())
}
}
Expand Down Expand Up @@ -559,7 +552,7 @@ mod evm_circuit_stats {

let mut implemented_states = Vec::new();
for state in ExecutionState::iter() {
let height = circuit.execution.get_step_height_option(state);
let height = circuit.0.execution.get_step_height_option(state);
if let Some(h) = height {
implemented_states.push((state, h));
}
Expand Down
Loading