Skip to content

Commit

Permalink
perf: remove assertion for perf
Browse files Browse the repository at this point in the history
  • Loading branch information
junyu0312 committed May 29, 2024
1 parent 0bc0d65 commit 90f9da1
Show file tree
Hide file tree
Showing 6 changed files with 5 additions and 36 deletions.
15 changes: 0 additions & 15 deletions crates/zkwasm/src/circuits/cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,6 @@ macro_rules! define_cell {
ctx: &mut Context<'_, F>,
value: F,
) -> Result<AssignedCell<F, F>, Error> {
assert!(
value <= $limit,
"assigned value {:?} exceeds the limit {:?}",
value,
$limit
);

self.cell.assign(ctx, value)
}
}
Expand All @@ -145,7 +138,6 @@ define_cell!(AllocatedUnlimitedCell, -F::one());
#[derive(Debug, Clone, Copy)]
pub(crate) struct AllocatedCommonRangeCell<F: FieldExt> {
pub(crate) cell: AllocatedCell<F>,
pub(crate) upper_bound: F,
}

impl<F: FieldExt> CellExpression<F> for AllocatedCommonRangeCell<F> {
Expand All @@ -154,13 +146,6 @@ impl<F: FieldExt> CellExpression<F> for AllocatedCommonRangeCell<F> {
}

fn assign(&self, ctx: &mut Context<'_, F>, value: F) -> Result<AssignedCell<F, F>, Error> {
assert!(
value <= self.upper_bound,
"assigned value {:?} exceeds the limit {:?}",
value,
self.upper_bound
);

self.cell.assign(ctx, value)
}
}
Expand Down
8 changes: 1 addition & 7 deletions crates/zkwasm/src/circuits/etable/allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use super::AllocatedU32StateCell;
use super::EVENT_TABLE_ENTRY_ROWS;
use crate::circuits::bit_table::BitTableOp;
use crate::circuits::cell::*;
use crate::circuits::config::common_range_max;
use crate::circuits::etable::ConstraintBuilder;
use crate::circuits::rtable::RangeTableConfig;
use crate::circuits::traits::ConfigureLookupTable;
Expand Down Expand Up @@ -269,7 +268,6 @@ impl AllocatorFreeCellsProfiler {

#[derive(Debug, Clone)]
pub(crate) struct EventTableCellAllocator<F: FieldExt> {
k: u32,
pub(crate) free_cells: BTreeMap<EventTableCellType, (usize, u32)>,
all_cols: BTreeMap<EventTableCellType, Vec<Vec<Column<Advice>>>>,
free_u32_cells: Vec<AllocatedU32Cell<F>>,
Expand Down Expand Up @@ -348,13 +346,12 @@ impl<F: FieldExt> EventTableCellAllocator<F> {

pub(super) fn new(
meta: &mut ConstraintSystem<F>,
k: u32,
sel: Column<Fixed>,
rtable: &RangeTableConfig<F>,
mtable: &impl ConfigureLookupTable<F>,
cols: &mut impl Iterator<Item = Column<Advice>>,
) -> Self {
let mut allocator = Self::_new(meta, k, sel, rtable, mtable, cols);
let mut allocator = Self::_new(meta, sel, rtable, mtable, cols);
for _ in 0..U32_CELLS {
let cell = allocator.prepare_alloc_u32_cell();
allocator.free_u32_cells.push(cell);
Expand All @@ -373,7 +370,6 @@ impl<F: FieldExt> EventTableCellAllocator<F> {

fn _new(
meta: &mut ConstraintSystem<F>,
k: u32,
sel: Column<Fixed>,
rtable: &RangeTableConfig<F>,
mtable: &impl ConfigureLookupTable<F>,
Expand Down Expand Up @@ -442,7 +438,6 @@ impl<F: FieldExt> EventTableCellAllocator<F> {
);

Self {
k,
all_cols,
free_cells: BTreeMap::from_iter(
vec![
Expand Down Expand Up @@ -510,7 +505,6 @@ impl<F: FieldExt> EventTableCellAllocator<F> {
pub(crate) fn alloc_common_range_cell(&mut self) -> AllocatedCommonRangeCell<F> {
AllocatedCommonRangeCell {
cell: self.alloc(&EventTableCellType::CommonRange),
upper_bound: F::from(common_range_max(self.k) as u64),
}
}

Expand Down
3 changes: 1 addition & 2 deletions crates/zkwasm/src/circuits/etable/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,6 @@ pub struct EventTableConfig<F: FieldExt> {
impl<F: FieldExt> EventTableConfig<F> {
pub(crate) fn configure(
meta: &mut ConstraintSystem<F>,
k: u32,
cols: &mut (impl Iterator<Item = Column<Advice>> + Clone),
rtable: &RangeTableConfig<F>,
image_table: &ImageTableConfig<F>,
Expand All @@ -243,7 +242,7 @@ impl<F: FieldExt> EventTableConfig<F> {
) -> EventTableConfig<F> {
let step_sel = meta.fixed_column();

let mut allocator = EventTableCellAllocator::new(meta, k, step_sel, rtable, mtable, cols);
let mut allocator = EventTableCellAllocator::new(meta, step_sel, rtable, mtable, cols);

let ops = [0; OP_CAPABILITY].map(|_| allocator.alloc_bit_cell());
let enabled_cell = allocator.alloc_bit_cell();
Expand Down
8 changes: 1 addition & 7 deletions crates/zkwasm/src/circuits/mtable/allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use halo2_proofs::plonk::Fixed;
use halo2_proofs::plonk::VirtualCells;

use crate::circuits::cell::*;
use crate::circuits::config::common_range_max;
use crate::circuits::rtable::RangeTableConfig;
use crate::circuits::utils::bit::BitColumn;
use crate::circuits::utils::common_range::CommonRangeColumn;
Expand Down Expand Up @@ -83,7 +82,6 @@ const U64_CELLS: usize = 1;

#[derive(Debug, Clone)]
pub(super) struct MemoryTableCellAllocator<F: FieldExt> {
k: u32,
all_cols: BTreeMap<MemoryTableCellType, Vec<Column<Advice>>>,
free_cells: BTreeMap<MemoryTableCellType, (usize, u32)>,
free_u32_cells: Vec<AllocatedU32Cell<F>>,
Expand Down Expand Up @@ -153,12 +151,11 @@ impl<F: FieldExt> MemoryTableCellAllocator<F> {

pub(super) fn new(
meta: &mut ConstraintSystem<F>,
k: u32,
sel: Column<Fixed>,
rtable: &RangeTableConfig<F>,
cols: &mut impl Iterator<Item = Column<Advice>>,
) -> Self {
let mut allocator = Self::_new(meta, k, sel.clone(), rtable, cols);
let mut allocator = Self::_new(meta, sel.clone(), rtable, cols);
for _ in 0..U32_CELLS {
let cell = allocator.prepare_alloc_u32_cell();
allocator.free_u32_cells.push(cell);
Expand All @@ -172,7 +169,6 @@ impl<F: FieldExt> MemoryTableCellAllocator<F> {

fn _new(
meta: &mut ConstraintSystem<F>,
k: u32,
sel: Column<Fixed>,
rtable: &RangeTableConfig<F>,
cols: &mut impl Iterator<Item = Column<Advice>>,
Expand Down Expand Up @@ -209,7 +205,6 @@ impl<F: FieldExt> MemoryTableCellAllocator<F> {
.collect(),
);
Self {
k,
all_cols,
free_cells: BTreeMap::from_iter(
vec![
Expand Down Expand Up @@ -252,7 +247,6 @@ impl<F: FieldExt> MemoryTableCellAllocator<F> {
pub(super) fn alloc_common_range_cell(&mut self) -> AllocatedCommonRangeCell<F> {
AllocatedCommonRangeCell {
cell: self.alloc(&MemoryTableCellType::CommonRange),
upper_bound: F::from(common_range_max(self.k) as u64),
}
}

Expand Down
3 changes: 1 addition & 2 deletions crates/zkwasm/src/circuits/mtable/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,13 @@ pub struct MemoryTableConfig<F: FieldExt> {
impl<F: FieldExt> MemoryTableConfig<F> {
pub(crate) fn configure(
meta: &mut ConstraintSystem<F>,
k: u32,
cols: &mut (impl Iterator<Item = Column<Advice>> + Clone),
rtable: &RangeTableConfig<F>,
image_table: &ImageTableConfig<F>,
) -> Self {
let entry_sel = meta.fixed_column();

let mut allocator = MemoryTableCellAllocator::new(meta, k, entry_sel, rtable, cols);
let mut allocator = MemoryTableCellAllocator::new(meta, entry_sel, rtable, cols);
allocator.enable_equality(meta, &MemoryTableCellType::CommonRange);

let enabled_cell = allocator.alloc_bit_cell();
Expand Down
4 changes: 1 addition & 3 deletions crates/zkwasm/src/circuits/zkwasm_circuit/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,7 @@ macro_rules! impl_zkwasm_circuit {

let rtable = RangeTableConfig::configure(meta);
let image_table = ImageTableConfig::configure(meta, memory_addr_sel);
let mtable =
MemoryTableConfig::configure(meta, k, &mut cols, &rtable, &image_table);
let mtable = MemoryTableConfig::configure(meta, &mut cols, &rtable, &image_table);
let frame_table = JumpTableConfig::configure(meta, $last_slice);
let post_image_table = PostImageTableConfig::configure(
meta,
Expand Down Expand Up @@ -197,7 +196,6 @@ macro_rules! impl_zkwasm_circuit {

let etable = EventTableConfig::configure(
meta,
k,
&mut cols,
&rtable,
&image_table,
Expand Down

0 comments on commit 90f9da1

Please sign in to comment.