diff --git a/crates/zkwasm/src/circuits/jtable/assign.rs b/crates/zkwasm/src/circuits/jtable/assign.rs index 4dfda5e4a..49ddb26f1 100644 --- a/crates/zkwasm/src/circuits/jtable/assign.rs +++ b/crates/zkwasm/src/circuits/jtable/assign.rs @@ -195,8 +195,9 @@ impl JumpTableChip { self.init(ctx)?; ctx.reset(); + // non-static entry includes `call`` and `return`` op let mut rest_jops = jtable.entries().len() as u64 * 2; - + // static entry only includes `return` op for entry in static_entries { if entry.enable { rest_jops += 1; diff --git a/crates/zkwasm/src/circuits/jtable/mod.rs b/crates/zkwasm/src/circuits/jtable/mod.rs index 34132e87a..5450888f1 100644 --- a/crates/zkwasm/src/circuits/jtable/mod.rs +++ b/crates/zkwasm/src/circuits/jtable/mod.rs @@ -11,7 +11,7 @@ mod assign; mod configure; pub(crate) mod expression; -// enable and data should encode in image table +// enable and data should be encoded in image table pub(crate) const STATIC_FRAME_ENTRY_IMAGE_TABLE_ENTRY: usize = STATIC_FRAME_ENTRY_NUMBER * 2; pub enum JtableOffset { diff --git a/crates/zkwasm/src/circuits/mtable/assign.rs b/crates/zkwasm/src/circuits/mtable/assign.rs index 437b12284..0be113dc0 100644 --- a/crates/zkwasm/src/circuits/mtable/assign.rs +++ b/crates/zkwasm/src/circuits/mtable/assign.rs @@ -41,9 +41,9 @@ impl MemoryTableChip { #[cfg(feature = "continuation")] ctx.region.assign_advice_from_constant( - || "rest_memory_updating_ops terminate", - self.config.rest_memory_updating_ops.0.col, - ctx.offset + self.config.rest_memory_updating_ops.0.rot as usize, + || "rest_memory_finalize_ops terminate", + self.config.rest_memory_finalize_ops.0.col, + ctx.offset + self.config.rest_memory_finalize_ops.0.rot as usize, F::zero(), )?; } @@ -55,16 +55,16 @@ impl MemoryTableChip { } #[cfg(feature = "continuation")] - fn constrain_rest_memory_updating_ops( + fn constrain_rest_memory_finalize_ops( &self, ctx: &mut Context<'_, F>, - rest_memory_updating_ops: u32, + rest_memory_finalize_ops: u32, ) -> Result, Error> { // Overwrite in assign_entries let cell = self .config - .rest_memory_updating_ops - .assign(ctx, F::from(rest_memory_updating_ops as u64))?; + .rest_memory_finalize_ops + .assign(ctx, F::from(rest_memory_finalize_ops as u64))?; Ok(cell) } @@ -94,7 +94,7 @@ impl MemoryTableChip { mtable: &MemoryWritingTable, init_rest_mops: u64, _imtable: &InitMemoryTable, - mut _rest_memory_updating_ops: u32, + mut _rest_memory_finalize_ops: u32, ) -> Result<(), Error> { macro_rules! assign_advice { ($cell:ident, $value:expr) => { @@ -195,8 +195,8 @@ impl MemoryTableChip { #[cfg(feature = "continuation")] assign_advice!( - rest_memory_updating_ops, - F::from(_rest_memory_updating_ops as u64) + rest_memory_finalize_ops, + F::from(_rest_memory_finalize_ops as u64) ); assign_advice!( @@ -220,13 +220,13 @@ impl MemoryTableChip { if entry.entry.atype == AccessType::Write && !entry.entry.is_same_location(&next_entry.entry) { - _rest_memory_updating_ops -= 1; + _rest_memory_finalize_ops -= 1; } } else { // It's last entry if entry.entry.atype == AccessType::Write { - _rest_memory_updating_ops -= 1; + _rest_memory_finalize_ops -= 1; } } @@ -269,7 +269,7 @@ impl MemoryTableChip { Ok(()) } - fn compute_rest_memory_updating_ops(&self, mtable: &MemoryWritingTable) -> u32 { + fn compute_rest_memory_finalize_ops(&self, mtable: &MemoryWritingTable) -> u32 { let mut ops = 0u32; let mut iter = mtable.0.iter().peekable(); @@ -309,11 +309,11 @@ impl MemoryTableChip { self.assign_fixed(ctx)?; ctx.reset(); - let rest_memory_updating_ops = self.compute_rest_memory_updating_ops(mtable); + let rest_memory_finalize_ops = self.compute_rest_memory_finalize_ops(mtable); #[cfg(feature = "continuation")] - let rest_memory_updating_ops_cell = - self.constrain_rest_memory_updating_ops(ctx, rest_memory_updating_ops)?; + let rest_memory_finalize_ops_cell = + self.constrain_rest_memory_finalize_ops(ctx, rest_memory_finalize_ops)?; let rest_mops_cell = self.constrain_rest_mops_permutation(ctx, etable_rest_mops_cell, rest_mops)?; @@ -322,15 +322,15 @@ impl MemoryTableChip { * Skip subsequent advice assignment in the first pass to enhance performance. */ if rest_mops_cell.value().is_some() { - self.assign_entries(ctx, mtable, rest_mops, imtable, rest_memory_updating_ops)?; + self.assign_entries(ctx, mtable, rest_mops, imtable, rest_memory_finalize_ops)?; ctx.reset(); } cfg_if::cfg_if! { if #[cfg(feature="continuation")] { - Ok((Some(rest_memory_updating_ops_cell), F::from(rest_memory_updating_ops as u64))) + Ok((Some(rest_memory_finalize_ops_cell), F::from(rest_memory_finalize_ops as u64))) } else { - Ok((None, F::from(rest_memory_updating_ops as u64))) + Ok((None, F::from(rest_memory_finalize_ops as u64))) } } } diff --git a/crates/zkwasm/src/circuits/mtable/mod.rs b/crates/zkwasm/src/circuits/mtable/mod.rs index 2eace1f46..59f4b0df9 100644 --- a/crates/zkwasm/src/circuits/mtable/mod.rs +++ b/crates/zkwasm/src/circuits/mtable/mod.rs @@ -46,10 +46,6 @@ pub struct MemoryTableConfig { end_eid_cell: AllocatedU32StateCell, eid_diff_cell: AllocatedU32StateCell, rest_mops_cell: AllocatedCommonRangeCell, - // offset_align_left: AllocatedU32Cell, - // offset_align_right: AllocatedU32Cell, - // offset_align_left_diff_cell: AllocatedU32Cell, - // offset_align_right_diff_cell: AllocatedU32Cell, offset_cell: AllocatedU32Cell, offset_diff_cell: AllocatedU32Cell, @@ -59,7 +55,7 @@ pub struct MemoryTableConfig { init_encode_cell: AllocatedUnlimitedCell, #[cfg(feature = "continuation")] - rest_memory_updating_ops: AllocatedUnlimitedCell, + rest_memory_finalize_ops: AllocatedUnlimitedCell, value: AllocatedU64Cell, } @@ -103,7 +99,7 @@ impl MemoryTableConfig { let init_encode_cell = allocator.alloc_unlimited_cell(); #[cfg(feature = "continuation")] - let rest_memory_updating_ops = { + let rest_memory_finalize_ops = { let cell = allocator.alloc_unlimited_cell(); // FIXME: try to avoid this? meta.enable_equality(cell.0.col); @@ -347,8 +343,8 @@ impl MemoryTableConfig { { meta.create_gate("mc13. rest memory updating ops", |meta| { vec![ - rest_memory_updating_ops.curr_expr(meta) - - rest_memory_updating_ops.next_expr(meta) + rest_memory_finalize_ops.curr_expr(meta) + - rest_memory_finalize_ops.next_expr(meta) - (constant_from!(1) - is_next_same_offset_cell.curr_expr(meta)) * (constant_from!(1) - is_init_cell.curr_expr(meta)), ] @@ -387,7 +383,7 @@ impl MemoryTableConfig { encode_cell, #[cfg(feature = "continuation")] - rest_memory_updating_ops, + rest_memory_finalize_ops, } } }