Skip to content

Commit

Permalink
fix code style
Browse files Browse the repository at this point in the history
  • Loading branch information
junyu0312 committed Dec 14, 2023
1 parent b54a506 commit 09b8638
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 30 deletions.
3 changes: 2 additions & 1 deletion crates/zkwasm/src/circuits/jtable/assign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,9 @@ impl<F: FieldExt> JumpTableChip<F> {
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;
Expand Down
2 changes: 1 addition & 1 deletion crates/zkwasm/src/circuits/jtable/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
38 changes: 19 additions & 19 deletions crates/zkwasm/src/circuits/mtable/assign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ impl<F: FieldExt> MemoryTableChip<F> {

#[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(),
)?;
}
Expand All @@ -55,16 +55,16 @@ impl<F: FieldExt> MemoryTableChip<F> {
}

#[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<AssignedCell<F, F>, 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)
}
Expand Down Expand Up @@ -94,7 +94,7 @@ impl<F: FieldExt> MemoryTableChip<F> {
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) => {
Expand Down Expand Up @@ -195,8 +195,8 @@ impl<F: FieldExt> MemoryTableChip<F> {

#[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!(
Expand All @@ -220,13 +220,13 @@ impl<F: FieldExt> MemoryTableChip<F> {
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;
}
}

Expand Down Expand Up @@ -269,7 +269,7 @@ impl<F: FieldExt> MemoryTableChip<F> {
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();
Expand Down Expand Up @@ -309,11 +309,11 @@ impl<F: FieldExt> MemoryTableChip<F> {
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)?;
Expand All @@ -322,15 +322,15 @@ impl<F: FieldExt> MemoryTableChip<F> {
* 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)))
}
}
}
Expand Down
14 changes: 5 additions & 9 deletions crates/zkwasm/src/circuits/mtable/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,6 @@ pub struct MemoryTableConfig<F: FieldExt> {
end_eid_cell: AllocatedU32StateCell<F>,
eid_diff_cell: AllocatedU32StateCell<F>,
rest_mops_cell: AllocatedCommonRangeCell<F>,
// offset_align_left: AllocatedU32Cell<F>,
// offset_align_right: AllocatedU32Cell<F>,
// offset_align_left_diff_cell: AllocatedU32Cell<F>,
// offset_align_right_diff_cell: AllocatedU32Cell<F>,
offset_cell: AllocatedU32Cell<F>,
offset_diff_cell: AllocatedU32Cell<F>,

Expand All @@ -59,7 +55,7 @@ pub struct MemoryTableConfig<F: FieldExt> {
init_encode_cell: AllocatedUnlimitedCell<F>,

#[cfg(feature = "continuation")]
rest_memory_updating_ops: AllocatedUnlimitedCell<F>,
rest_memory_finalize_ops: AllocatedUnlimitedCell<F>,

value: AllocatedU64Cell<F>,
}
Expand Down Expand Up @@ -103,7 +99,7 @@ impl<F: FieldExt> MemoryTableConfig<F> {
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);
Expand Down Expand Up @@ -347,8 +343,8 @@ impl<F: FieldExt> MemoryTableConfig<F> {
{
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)),
]
Expand Down Expand Up @@ -387,7 +383,7 @@ impl<F: FieldExt> MemoryTableConfig<F> {
encode_cell,

#[cfg(feature = "continuation")]
rest_memory_updating_ops,
rest_memory_finalize_ops,
}
}
}
Expand Down

0 comments on commit 09b8638

Please sign in to comment.