From 90f9da1c305878ba529d909ad9a72997aabb18ba Mon Sep 17 00:00:00 2001 From: Zhang Junyu Date: Tue, 28 May 2024 14:04:31 +0000 Subject: [PATCH] perf: remove assertion for perf --- crates/zkwasm/src/circuits/cell.rs | 15 --------------- crates/zkwasm/src/circuits/etable/allocator.rs | 8 +------- crates/zkwasm/src/circuits/etable/mod.rs | 3 +-- crates/zkwasm/src/circuits/mtable/allocator.rs | 8 +------- crates/zkwasm/src/circuits/mtable/mod.rs | 3 +-- crates/zkwasm/src/circuits/zkwasm_circuit/mod.rs | 4 +--- 6 files changed, 5 insertions(+), 36 deletions(-) diff --git a/crates/zkwasm/src/circuits/cell.rs b/crates/zkwasm/src/circuits/cell.rs index 62a038c0e..2c9f1b0ee 100644 --- a/crates/zkwasm/src/circuits/cell.rs +++ b/crates/zkwasm/src/circuits/cell.rs @@ -124,13 +124,6 @@ macro_rules! define_cell { ctx: &mut Context<'_, F>, value: F, ) -> Result, Error> { - assert!( - value <= $limit, - "assigned value {:?} exceeds the limit {:?}", - value, - $limit - ); - self.cell.assign(ctx, value) } } @@ -145,7 +138,6 @@ define_cell!(AllocatedUnlimitedCell, -F::one()); #[derive(Debug, Clone, Copy)] pub(crate) struct AllocatedCommonRangeCell { pub(crate) cell: AllocatedCell, - pub(crate) upper_bound: F, } impl CellExpression for AllocatedCommonRangeCell { @@ -154,13 +146,6 @@ impl CellExpression for AllocatedCommonRangeCell { } fn assign(&self, ctx: &mut Context<'_, F>, value: F) -> Result, Error> { - assert!( - value <= self.upper_bound, - "assigned value {:?} exceeds the limit {:?}", - value, - self.upper_bound - ); - self.cell.assign(ctx, value) } } diff --git a/crates/zkwasm/src/circuits/etable/allocator.rs b/crates/zkwasm/src/circuits/etable/allocator.rs index 798da643b..88048130a 100644 --- a/crates/zkwasm/src/circuits/etable/allocator.rs +++ b/crates/zkwasm/src/circuits/etable/allocator.rs @@ -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; @@ -269,7 +268,6 @@ impl AllocatorFreeCellsProfiler { #[derive(Debug, Clone)] pub(crate) struct EventTableCellAllocator { - k: u32, pub(crate) free_cells: BTreeMap, all_cols: BTreeMap>>>, free_u32_cells: Vec>, @@ -348,13 +346,12 @@ impl EventTableCellAllocator { pub(super) fn new( meta: &mut ConstraintSystem, - k: u32, sel: Column, rtable: &RangeTableConfig, mtable: &impl ConfigureLookupTable, cols: &mut impl Iterator>, ) -> 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); @@ -373,7 +370,6 @@ impl EventTableCellAllocator { fn _new( meta: &mut ConstraintSystem, - k: u32, sel: Column, rtable: &RangeTableConfig, mtable: &impl ConfigureLookupTable, @@ -442,7 +438,6 @@ impl EventTableCellAllocator { ); Self { - k, all_cols, free_cells: BTreeMap::from_iter( vec![ @@ -510,7 +505,6 @@ impl EventTableCellAllocator { pub(crate) fn alloc_common_range_cell(&mut self) -> AllocatedCommonRangeCell { AllocatedCommonRangeCell { cell: self.alloc(&EventTableCellType::CommonRange), - upper_bound: F::from(common_range_max(self.k) as u64), } } diff --git a/crates/zkwasm/src/circuits/etable/mod.rs b/crates/zkwasm/src/circuits/etable/mod.rs index e0dd23403..fe77218ec 100644 --- a/crates/zkwasm/src/circuits/etable/mod.rs +++ b/crates/zkwasm/src/circuits/etable/mod.rs @@ -231,7 +231,6 @@ pub struct EventTableConfig { impl EventTableConfig { pub(crate) fn configure( meta: &mut ConstraintSystem, - k: u32, cols: &mut (impl Iterator> + Clone), rtable: &RangeTableConfig, image_table: &ImageTableConfig, @@ -243,7 +242,7 @@ impl EventTableConfig { ) -> EventTableConfig { 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(); diff --git a/crates/zkwasm/src/circuits/mtable/allocator.rs b/crates/zkwasm/src/circuits/mtable/allocator.rs index deb4b723c..e640ac26d 100644 --- a/crates/zkwasm/src/circuits/mtable/allocator.rs +++ b/crates/zkwasm/src/circuits/mtable/allocator.rs @@ -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; @@ -83,7 +82,6 @@ const U64_CELLS: usize = 1; #[derive(Debug, Clone)] pub(super) struct MemoryTableCellAllocator { - k: u32, all_cols: BTreeMap>>, free_cells: BTreeMap, free_u32_cells: Vec>, @@ -153,12 +151,11 @@ impl MemoryTableCellAllocator { pub(super) fn new( meta: &mut ConstraintSystem, - k: u32, sel: Column, rtable: &RangeTableConfig, cols: &mut impl Iterator>, ) -> 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); @@ -172,7 +169,6 @@ impl MemoryTableCellAllocator { fn _new( meta: &mut ConstraintSystem, - k: u32, sel: Column, rtable: &RangeTableConfig, cols: &mut impl Iterator>, @@ -209,7 +205,6 @@ impl MemoryTableCellAllocator { .collect(), ); Self { - k, all_cols, free_cells: BTreeMap::from_iter( vec![ @@ -252,7 +247,6 @@ impl MemoryTableCellAllocator { pub(super) fn alloc_common_range_cell(&mut self) -> AllocatedCommonRangeCell { AllocatedCommonRangeCell { cell: self.alloc(&MemoryTableCellType::CommonRange), - upper_bound: F::from(common_range_max(self.k) as u64), } } diff --git a/crates/zkwasm/src/circuits/mtable/mod.rs b/crates/zkwasm/src/circuits/mtable/mod.rs index 9766ff030..5713276d9 100644 --- a/crates/zkwasm/src/circuits/mtable/mod.rs +++ b/crates/zkwasm/src/circuits/mtable/mod.rs @@ -69,14 +69,13 @@ pub struct MemoryTableConfig { impl MemoryTableConfig { pub(crate) fn configure( meta: &mut ConstraintSystem, - k: u32, cols: &mut (impl Iterator> + Clone), rtable: &RangeTableConfig, image_table: &ImageTableConfig, ) -> 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(); diff --git a/crates/zkwasm/src/circuits/zkwasm_circuit/mod.rs b/crates/zkwasm/src/circuits/zkwasm_circuit/mod.rs index 18055631d..1df19ea24 100644 --- a/crates/zkwasm/src/circuits/zkwasm_circuit/mod.rs +++ b/crates/zkwasm/src/circuits/zkwasm_circuit/mod.rs @@ -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, @@ -197,7 +196,6 @@ macro_rules! impl_zkwasm_circuit { let etable = EventTableConfig::configure( meta, - k, &mut cols, &rtable, &image_table,