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

Commit

Permalink
Combine LookupU8 and LookupU16 under Lookup(Table)
Browse files Browse the repository at this point in the history
  • Loading branch information
zemse committed Jul 4, 2023
1 parent 8030de3 commit 5c2b437
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 37 deletions.
26 changes: 2 additions & 24 deletions zkevm-circuits/src/evm_circuit/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -819,6 +819,8 @@ impl<F: Field> ExecutionConfig<F> {
meta.lookup_any(Box::leak(name.into_boxed_str()), |meta| {
let table_expressions = match table {
Table::Fixed => fixed_table,
Table::U8 => u8_table,
Table::U16 => u16_table,
Table::Tx => tx_table,
Table::Rw => rw_table,
Table::Bytecode => bytecode_table,
Expand All @@ -835,30 +837,6 @@ impl<F: Field> ExecutionConfig<F> {
});
}
}
for column in cell_manager.columns().iter() {
let column_expr = column.expr(meta);
match column.cell_type {
CellType::LookupU8 => {
meta.lookup_any("u8 lookup", |meta| {
vec![column_expr]
.into_iter()
.zip(u8_table.table_exprs(meta).into_iter())
.map(|(expr, table)| (expr, table))
.collect()
});
}
CellType::LookupU16 => {
meta.lookup_any("u16 lookup", |meta| {
vec![column_expr]
.into_iter()
.zip(u16_table.table_exprs(meta).into_iter())
.map(|(expr, table)| (expr, table))
.collect()
});
}
_ => (),
}
}
}

/// Assign columns related to step counter
Expand Down
2 changes: 2 additions & 0 deletions zkevm-circuits/src/evm_circuit/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ impl FixedTableTag {

#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, EnumIter)]
pub enum Table {
U8,
U16,
Fixed,
Tx,
Rw,
Expand Down
11 changes: 7 additions & 4 deletions zkevm-circuits/src/evm_circuit/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ pub use crate::util::{
Challenges, Expr,
};
use crate::{
evm_circuit::param::{
LOOKUP_CONFIG, N_BYTES_MEMORY_ADDRESS, N_COPY_COLUMNS, N_PHASE2_COLUMNS, N_U8_LOOKUPS,
evm_circuit::{
param::{
LOOKUP_CONFIG, N_BYTES_MEMORY_ADDRESS, N_COPY_COLUMNS, N_PHASE2_COLUMNS, N_U8_LOOKUPS,
},
table::Table,
},
util::{cell_manager::CMFixedWidthStrategyDistribution, int_decomposition::IntDecomposition},
witness::{Block, ExecStep, Rw, RwMap},
Expand Down Expand Up @@ -250,15 +253,15 @@ pub(crate) fn evm_cm_distribute_advice<F: Field>(
// Mark columns used for byte lookup
#[allow(clippy::reversed_empty_ranges)]
for _ in 0..N_U8_LOOKUPS {
dist.add(CellType::LookupU8, advices[column_idx]);
dist.add(CellType::Lookup(Table::U8), advices[column_idx]);
assert_eq!(advices[column_idx].column_type().phase(), 0);
column_idx += 1;
}

// Mark columns used for byte lookup
#[allow(clippy::reversed_empty_ranges)]
for _ in 0..N_U16_LOOKUPS {
dist.add(CellType::LookupU16, advices[column_idx]);
dist.add(CellType::Lookup(Table::U8), advices[column_idx]);
assert_eq!(advices[column_idx].column_type().phase(), 0);
column_idx += 1;
}
Expand Down
8 changes: 4 additions & 4 deletions zkevm-circuits/src/evm_circuit/util/constraint_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::{
evm_circuit::{
param::STACK_CAPACITY,
step::{ExecutionState, Step},
table::{FixedTableTag, Lookup, RwValues},
table::{FixedTableTag, Lookup, RwValues, Table},
util::{Cell, RandomLinearCombination},
},
table::{
Expand Down Expand Up @@ -438,7 +438,7 @@ impl<'a, F: Field> EVMConstraintBuilder<'a, F> {
}

pub(crate) fn query_byte(&mut self) -> Cell<F> {
self.query_cell_with_type(CellType::LookupU8)
self.query_cell_with_type(CellType::Lookup(Table::U8))
}

// default query_word is 2 limbs. Each limb is not guaranteed to be 128 bits.
Expand Down Expand Up @@ -509,15 +509,15 @@ impl<'a, F: Field> EVMConstraintBuilder<'a, F> {
}

pub(crate) fn query_u8_dyn(&mut self, count: usize) -> Vec<Cell<F>> {
self.query_cells(CellType::LookupU8, count)
self.query_cells(CellType::Lookup(Table::U8), 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)
self.query_cells(CellType::Lookup(Table::U16), count)
}

pub(crate) fn query_cell(&mut self) -> Cell<F> {
Expand Down
4 changes: 2 additions & 2 deletions zkevm-circuits/src/evm_circuit/util/instrumentation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ impl Instrument {
CellType::StoragePermutation => {
report.storage_perm = data_entry;
}
CellType::LookupU8 => {
CellType::Lookup(Table::U8) => {
report.u8_lookup = data_entry;
}
CellType::LookupU16 => {
CellType::Lookup(Table::U16) => {
report.u16_lookup = data_entry;
}
CellType::Lookup(Table::Fixed) => {
Expand Down
3 changes: 0 additions & 3 deletions zkevm-circuits/src/util/cell_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ pub(crate) enum CellType {
StoragePhase1,
StoragePhase2,
StoragePermutation,
// TODO combine LookupU8, LookupU16 with Lookup(Table::U8 | Table::U16)
LookupU8,
LookupU16,
Lookup(Table),
}

Expand Down

0 comments on commit 5c2b437

Please sign in to comment.