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
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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 12 additions & 28 deletions integration-tests/tests/circuits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use lazy_static::lazy_static;
use log::trace;
use zkevm_circuits::evm_circuit::witness::block_convert;
use zkevm_circuits::state_circuit::StateCircuit;

lazy_static! {
pub static ref GEN_DATA: GenDataOutput = GenDataOutput::load();
}
Expand All @@ -30,11 +29,12 @@ mod test_evm_circuit {
witness::{Block, Bytecode, RwMap, Transaction},
EvmCircuit,
};
use zkevm_circuits::rw_table::RwTable;

#[derive(Clone)]
struct TestCircuitConfig<F> {
tx_table: [Column<Advice>; 4],
rw_table: [Column<Advice>; 10],
rw_table: RwTable,
bytecode_table: [Column<Advice>; 4],
evm_circuit: EvmCircuit<F>,
}
Expand All @@ -50,7 +50,7 @@ mod test_evm_circuit {
|| "tx table",
|mut region| {
let mut offset = 0;
for column in self.rw_table {
for column in self.tx_table {
region.assign_advice(
|| "tx table all-zero row",
column,
Expand Down Expand Up @@ -88,27 +88,16 @@ mod test_evm_circuit {
|| "rw table",
|mut region| {
let mut offset = 0;
for column in self.rw_table {
region.assign_advice(
|| "rw table all-zero row",
column,
offset,
|| Ok(F::zero()),
)?;
}
self.rw_table
.assign(&mut region, offset, &Default::default())?;
offset += 1;

for rw in rws.0.values().flat_map(|rws| rws.iter()) {
for (column, value) in
self.rw_table.iter().zip(rw.table_assignment(randomness))
{
region.assign_advice(
|| format!("rw table row {}", offset),
*column,
offset,
|| Ok(value),
)?;
}
self.rw_table.assign(
&mut region,
offset,
&rw.table_assignment(randomness),
)?;
offset += 1;
}
Ok(())
Expand Down Expand Up @@ -180,7 +169,7 @@ mod test_evm_circuit {

fn configure(meta: &mut ConstraintSystem<F>) -> Self::Config {
let tx_table = [(); 4].map(|_| meta.advice_column());
let rw_table = [(); 10].map(|_| meta.advice_column());
let rw_table = RwTable::construct(meta);
let bytecode_table = [(); 4].map(|_| meta.advice_column());
let block_table = [(); 3].map(|_| meta.advice_column());

Expand Down Expand Up @@ -327,12 +316,7 @@ async fn test_state_circuit_block(block_num: u64) {
STACK_ROWS_MAX,
STACK_ADDRESS_MAX,
STORAGE_ROWS_MAX,
> {
randomness: Fr::rand(),
memory_ops,
stack_ops,
storage_ops,
};
>::new(Fr::rand(), memory_ops, stack_ops, storage_ops);

use pairing::bn256::Fr as Fp;
let prover = MockProver::<Fp>::run(DEGREE as u32, &circuit, vec![]).unwrap();
Expand Down
15 changes: 3 additions & 12 deletions prover/src/bin/prover_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use bus_mapping::rpc::GethClient;
use env_logger::Env;
use ethers_providers::Http;
use halo2::{
arithmetic::BaseExt,
plonk::*,
poly::commitment::Params,
transcript::{Blake2bWrite, Challenge255},
Expand Down Expand Up @@ -66,10 +65,10 @@ async fn main() {
// TODO: only {evm,state}_proof are implemented right now
let evm_proof;
let state_proof;
let block = block_convert(&builder.block, &builder.code_db);
{
// generate evm_circuit proof
let block = block_convert(&builder.block, &builder.code_db);
let circuit = TestCircuit::<Fr>::new(block, FixedTableTag::iterator().collect());
let circuit = TestCircuit::<Fr>::new(block.clone(), FixedTableTag::iterator().collect());

// TODO: can this be pre-generated to a file?
// related
Expand All @@ -95,9 +94,6 @@ async fn main() {
const STORAGE_ROWS_MAX: usize = 16384;
const GLOBAL_COUNTER_MAX: usize = MEMORY_ROWS_MAX + STACK_ROWS_MAX + STORAGE_ROWS_MAX;

let stack_ops = builder.block.container.sorted_stack();
let memory_ops = builder.block.container.sorted_memory();
let storage_ops = builder.block.container.sorted_storage();
let circuit = StateCircuit::<
Fr,
true,
Expand All @@ -107,12 +103,7 @@ async fn main() {
STACK_ROWS_MAX,
STACK_ADDRESS_MAX,
STORAGE_ROWS_MAX,
> {
randomness: Fr::rand(),
memory_ops,
stack_ops,
storage_ops,
};
>::new_from_rw_map(block.randomness, &block.rws);

// TODO: same quest like in the first scope
let vk = keygen_vk(&params, &circuit).expect("keygen_vk for params, state_circuit");
Expand Down
1 change: 1 addition & 0 deletions zkevm-circuits/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ eth-types = { path = "../eth-types" }
serde_json = "1.0.66"
rand_xorshift = "0.3"
rand = "0.8"
itertools = "0.10.3"
keccak256 = { path = "../keccak256"}

[dev-dependencies]
Expand Down
30 changes: 10 additions & 20 deletions zkevm-circuits/src/evm_circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ pub mod test {
witness::{Block, BlockContext, Bytecode, RwMap, Transaction},
EvmCircuit,
},
rw_table::RwTable,
util::Expr,
};
use eth_types::{evm_types::GasCost, Word};
Expand Down Expand Up @@ -150,7 +151,7 @@ pub mod test {
#[derive(Clone)]
pub struct TestCircuitConfig<F> {
tx_table: [Column<Advice>; 4],
rw_table: [Column<Advice>; 10],
rw_table: RwTable,
bytecode_table: [Column<Advice>; 4],
block_table: [Column<Advice>; 3],
evm_circuit: EvmCircuit<F>,
Expand Down Expand Up @@ -205,27 +206,16 @@ pub mod test {
|| "rw table",
|mut region| {
let mut offset = 0;
for column in self.rw_table {
region.assign_advice(
|| "rw table all-zero row",
column,
offset,
|| Ok(F::zero()),
)?;
}
self.rw_table
.assign(&mut region, offset, &Default::default())?;
offset += 1;

for rw in rws.0.values().flat_map(|rws| rws.iter()) {
for (column, value) in
self.rw_table.iter().zip(rw.table_assignment(randomness))
{
region.assign_advice(
|| format!("rw table row {}", offset),
*column,
offset,
|| Ok(value),
)?;
}
self.rw_table.assign(
&mut region,
offset,
&rw.table_assignment(randomness),
)?;
offset += 1;
}
Ok(())
Expand Down Expand Up @@ -334,7 +324,7 @@ pub mod test {

fn configure(meta: &mut ConstraintSystem<F>) -> Self::Config {
let tx_table = [(); 4].map(|_| meta.advice_column());
let rw_table = [(); 10].map(|_| meta.advice_column());
let rw_table = RwTable::construct(meta);
let bytecode_table = [(); 4].map(|_| meta.advice_column());
let block_table = [(); 3].map(|_| meta.advice_column());

Expand Down
4 changes: 2 additions & 2 deletions zkevm-circuits/src/evm_circuit/execution/bitwise.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ mod test {
use crate::{
evm_circuit::test::rand_word,
test_util::{
get_fixed_table, run_test_circuits_with_config, BytecodeTestConfig, FixedTableConfig,
get_fixed_table, test_circuits_using_bytecode, BytecodeTestConfig, FixedTableConfig,
},
};
use eth_types::{bytecode, Word};
Expand All @@ -127,7 +127,7 @@ mod test {
evm_circuit_lookup_tags: get_fixed_table(FixedTableConfig::Complete),
..Default::default()
};
assert_eq!(run_test_circuits_with_config(bytecode, test_config), Ok(()));
assert_eq!(test_circuits_using_bytecode(bytecode, test_config), Ok(()));
}

#[test]
Expand Down
4 changes: 2 additions & 2 deletions zkevm-circuits/src/evm_circuit/execution/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ impl<F: FieldExt> ExecutionGadget<F> for MemoryGadget<F> {
mod test {
use crate::{
evm_circuit::test::rand_word,
test_util::{run_test_circuits_with_config, BytecodeTestConfig},
test_util::{test_circuits_using_bytecode, BytecodeTestConfig},
};
use eth_types::bytecode;
use eth_types::evm_types::{GasCost, OpcodeId};
Expand All @@ -222,7 +222,7 @@ mod test {
enable_state_circuit_test: false,
..Default::default()
};
assert_eq!(run_test_circuits_with_config(bytecode, test_config), Ok(()));
assert_eq!(test_circuits_using_bytecode(bytecode, test_config), Ok(()));
}

#[test]
Expand Down
8 changes: 4 additions & 4 deletions zkevm-circuits/src/evm_circuit/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,15 @@ pub enum BlockContextFieldTag {

#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum RwTableTag {
TxAccessListAccount = 1,
Stack = 2,
Memory,
AccountStorage,
TxAccessListAccount,
TxAccessListAccountStorage,
TxRefund,
Account,
AccountStorage,
AccountDestructed,
CallContext,
Stack,
Memory,
}

impl RwTableTag {
Expand Down
22 changes: 22 additions & 0 deletions zkevm-circuits/src/evm_circuit/util/math_gadget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -783,3 +783,25 @@ impl<F: FieldExt, const N_BYTES: usize> MinMaxGadget<F, N_BYTES> {
})
}
}

// This function generates a Lagrange polynomial in the range [start, end) which
// will be evaluated to 1 when `exp == value`, otherwise 0
pub(crate) fn generate_lagrange_base_polynomial<
F: FieldExt,
Exp: Expr<F>,
R: Iterator<Item = usize>,
>(
exp: Exp,
val: usize,
range: R,
) -> Expression<F> {
let mut numerator = 1u64.expr();
let mut denominator = F::from(1);
for x in range {
if x != val {
numerator = numerator * (exp.expr() - x.expr());
Comment thread
ed255 marked this conversation as resolved.
denominator *= F::from(val as u64) - F::from(x as u64);
}
}
numerator * denominator.invert().unwrap()
}
Loading