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

Commit

Permalink
fix build error
Browse files Browse the repository at this point in the history
  • Loading branch information
hero78119 committed Jun 1, 2023
1 parent c3d2c2b commit 1774d5e
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 34 deletions.
8 changes: 4 additions & 4 deletions zkevm-circuits/src/evm_circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ impl<F: Field> SubCircuitConfig<F> for EvmCircuitConfig<F> {
&exp_table,
));

meta.annotate_lookup_any_column(u8_table[0], || "u8_range");
meta.annotate_lookup_any_column(u16_table[0], || "u16_range");
u8_table.annotate_columns(meta);
u16_table.annotate_columns(meta);
fixed_table.iter().enumerate().for_each(|(idx, &col)| {
meta.annotate_lookup_any_column(col, || format!("fix_table_{}", idx))
});
Expand Down Expand Up @@ -426,8 +426,8 @@ impl<F: Field> Circuit<F> for EvmCircuit<F> {
.dev_load(&mut layouter, &block.sha3_inputs, &challenges)?;
config.exp_table.load(&mut layouter, block)?;

config.u8_table.load(&mut layouter);
config.u16_table.load(&mut layouter);
config.u8_table.load(&mut layouter)?;
config.u16_table.load(&mut layouter)?;

self.synthesize_sub(&config, &challenges, &mut layouter)
}
Expand Down
16 changes: 10 additions & 6 deletions zkevm-circuits/src/evm_circuit/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -836,18 +836,22 @@ impl<F: Field> ExecutionConfig<F> {
for column in cell_manager.columns().iter() {
if let CellType::LookupU8 = column.cell_type {
meta.lookup_any("u8 lookup", |meta| {
debug_assert_eq!(u8_table.table_exprs(meta).len(), 1);
let u8_table_expression = u8_table.table_exprs(meta)[0].clone();
vec![(column.expr(), u8_table_expression)]
vec![column.expr()]
.into_iter()
.zip(u8_table.table_exprs(meta).into_iter())
.map(|(expr, table)| (expr, table))
.collect()
});
}
}
for column in cell_manager.columns().iter() {
if let CellType::LookupU16 = column.cell_type {
debug_assert_eq!(u16_table.table_exprs(meta).len(), 1);
meta.lookup_any("u16 lookup", |meta| {
let u16_table_expression = u16_table.table_exprs(meta)[0].clone();
vec![(column.expr(), u16_table_expression)]
vec![column.expr()]
.into_iter()
.zip(u16_table.table_exprs(meta).into_iter())
.map(|(expr, table)| (expr, table))
.collect()
});
}
}
Expand Down
6 changes: 5 additions & 1 deletion zkevm-circuits/src/evm_circuit/util/constraint_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ impl<'a, F: Field> EVMConstraintBuilder<'a, F> {

// each limb is 16 bits, and any conversion to smaller limbs inherits the type check.
pub(crate) fn query_word16<const N: usize>(&mut self) -> Word16<Cell<F>> {
Word16::new(self.query_u16_dyn(N))
Word16::new(self.query_u16())
}

// query_word32 each limb is 8 bits, and any conversion to smaller limbs inherits the type
Expand Down Expand Up @@ -497,6 +497,10 @@ impl<'a, F: Field> EVMConstraintBuilder<'a, F> {
self.query_cells(CellType::LookupU8, count)
}

pub(crate) fn query_u16<const N: usize>(&mut self) -> [Cell<F>; N] {
self.query_u16_dyn(N).try_into().unwrap()
}

pub(crate) fn query_u16_dyn(&mut self, count: usize) -> Vec<Cell<F>> {
self.query_cells(CellType::LookupU16, count)
}
Expand Down
6 changes: 3 additions & 3 deletions zkevm-circuits/src/state_circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@ pub struct StateCircuitConfigArgs<F: Field> {
/// MptTable
pub mpt_table: MptTable,
/// U8Table
u8_table: MaxNBitTable<8>,
pub u8_table: MaxNBitTable<8>,
/// U10Table
u10_table: MaxNBitTable<10>,
pub u10_table: MaxNBitTable<10>,
/// U16Table
u16_table: MaxNBitTable<16>,
pub u16_table: MaxNBitTable<16>,
/// Challenges
pub challenges: Challenges<Expression<F>>,
}
Expand Down
40 changes: 25 additions & 15 deletions zkevm-circuits/src/state_circuit/lookups.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use halo2_proofs::{
plonk::{Column, ConstraintSystem, Error, Expression, Fixed, VirtualCells},
poly::Rotation,
};
use itertools::Itertools;
use std::marker::PhantomData;
use strum::IntoEnumIterator;

Expand All @@ -14,9 +15,9 @@ use super::test::{LookupTable, MaxNBitTable};
pub struct Config {
// Can these be TableColumn's?
// https://github.com/zcash/halo2/blob/642efc1536d3ea2566b04814bd60a00c4745ae22/halo2_proofs/src/plonk/circuit.rs#L266
u8: Column<Fixed>,
u10: Column<Fixed>,
u16: Column<Fixed>,
u8_table: MaxNBitTable<8>,
u10_table: MaxNBitTable<10>,
u16_table: MaxNBitTable<16>,
pub call_context_field_tag: Column<Fixed>,
}

Expand All @@ -29,7 +30,11 @@ impl Config {
) {
meta.lookup_any(msg, |meta| {
let exp = exp_fn(meta);
vec![(exp, meta.query_fixed(self.u8, Rotation::cur()))]
vec![exp]
.into_iter()
.zip_eq(self.u8_table.table_exprs(meta))
.map(|(exp, table_expr)| (exp, table_expr))
.collect()
});
}
pub fn range_check_u10<F: Field>(
Expand All @@ -40,7 +45,11 @@ impl Config {
) {
meta.lookup_any(msg, |meta| {
let exp = exp_fn(meta);
vec![(exp, meta.query_fixed(self.u10, Rotation::cur()))]
vec![exp]
.into_iter()
.zip_eq(self.u10_table.table_exprs(meta))
.map(|(exp, table_expr)| (exp, table_expr))
.collect()
});
}
pub fn range_check_u16<F: Field>(
Expand All @@ -51,7 +60,11 @@ impl Config {
) {
meta.lookup_any(msg, |meta| {
let exp = exp_fn(meta);
vec![(exp, meta.query_fixed(self.u16, Rotation::cur()))]
vec![exp]
.into_iter()
.zip_eq(self.u16_table.table_exprs(meta))
.map(|(exp, table_expr)| (exp, table_expr))
.collect()
});
}
}
Expand All @@ -67,9 +80,9 @@ pub struct Queries<F> {
impl<F: Field> Queries<F> {
pub fn new(meta: &mut VirtualCells<'_, F>, c: Config) -> Self {
Self {
u8: meta.query_fixed(c.u8, Rotation::cur()),
u10: meta.query_fixed(c.u10, Rotation::cur()),
u16: meta.query_fixed(c.u16, Rotation::cur()),
u8: c.u8_table.table_exprs(meta)[0].clone(),
u10: c.u10_table.table_exprs(meta)[0].clone(),
u16: c.u16_table.table_exprs(meta)[0].clone(),
call_context_field_tag: meta.query_fixed(c.call_context_field_tag, Rotation::cur()),
}
}
Expand All @@ -94,13 +107,10 @@ impl<F: Field> Chip<F> {
u10_table: MaxNBitTable<10>,
u16_table: MaxNBitTable<16>,
) -> Config {
debug_assert_eq!(u8_table.columns().len(), 1);
debug_assert_eq!(u10_table.columns().len(), 1);
debug_assert_eq!(u16_table.columns().len(), 1);
let config = Config {
u8: u8_table.columns()[0],
u10: u10_table.columns()[0],
u16: u16_table.columns()[0],
u8_table,
u10_table,
u16_table,
call_context_field_tag: meta.fixed_column(),
};
u8_table.annotate_columns(meta);
Expand Down
6 changes: 3 additions & 3 deletions zkevm-circuits/src/super_circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -429,9 +429,9 @@ impl<F: Field, const MAX_TXS: usize, const MAX_CALLDATA: usize, const MOCK_RANDO
Value::known(block.randomness),
)?;

config.u8_table.load(&mut layouter);
config.u10_table.load(&mut layouter);
config.u16_table.load(&mut layouter);
config.u8_table.load(&mut layouter)?;
config.u10_table.load(&mut layouter)?;
config.u16_table.load(&mut layouter)?;

self.synthesize_sub(&config, &challenges, &mut layouter)
}
Expand Down
6 changes: 4 additions & 2 deletions zkevm-circuits/src/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1561,7 +1561,8 @@ impl<F: Field> LookupTable<F> for ExpTable {
}
}

// fixed table to serve max unsigned N bits range lookup
/// Lookup table for max n bits range check
#[derive(Clone, Copy, Debug)]
pub struct MaxNBitTable<const N_BITS: usize> {
col: Column<Fixed>,
}
Expand All @@ -1574,6 +1575,7 @@ impl<const N_BITS: usize> MaxNBitTable<N_BITS> {
}
}

/// Load the `MaxNBitTable` for range check
pub fn load<F: Field>(&self, layouter: &mut impl Layouter<F>) -> Result<(), Error> {
layouter.assign_region(
|| format!("assign u{} fixed column", 8),
Expand All @@ -1599,7 +1601,7 @@ impl<F: Field, const N_BITS: usize> LookupTable<F> for MaxNBitTable<N_BITS> {
}

fn annotations(&self) -> Vec<String> {
vec![String::from(format!("u{}_col", N_BITS))]
vec![format!("u{}_col", N_BITS)]
}

fn table_exprs(&self, meta: &mut VirtualCells<F>) -> Vec<Expression<F>> {
Expand Down

0 comments on commit 1774d5e

Please sign in to comment.