From ccdaa76a0db7dec0eeed30b2389a3cda16c33920 Mon Sep 17 00:00:00 2001 From: Zhang Junyu Date: Mon, 6 Nov 2023 12:49:29 +0800 Subject: [PATCH] second slice pass --- Cargo.lock | 1 - Cargo.toml | 3 + crates/specs/src/etable.rs | 83 +++++ crates/specs/src/imtable.rs | 70 ++-- crates/specs/src/lib.rs | 24 +- crates/specs/src/mtable.rs | 95 ++++- .../zkwasm/src/circuits/bit_table/assign.rs | 2 +- .../zkwasm/src/circuits/etable/allocator.rs | 25 +- crates/zkwasm/src/circuits/etable/assign.rs | 52 ++- crates/zkwasm/src/circuits/etable/mod.rs | 8 +- .../circuits/etable/op_configure/op_bin.rs | 2 +- .../etable/op_configure/op_bin_bit.rs | 2 +- .../etable/op_configure/op_bin_shift.rs | 2 +- .../src/circuits/etable/op_configure/op_br.rs | 2 +- .../circuits/etable/op_configure/op_br_if.rs | 2 +- .../etable/op_configure/op_br_if_eqz.rs | 2 +- .../etable/op_configure/op_br_table.rs | 2 +- .../circuits/etable/op_configure/op_call.rs | 2 +- .../op_call_host_foreign_circuit.rs | 2 +- .../etable/op_configure/op_call_indirect.rs | 2 +- .../circuits/etable/op_configure/op_const.rs | 2 +- .../etable/op_configure/op_conversion.rs | 2 +- .../circuits/etable/op_configure/op_drop.rs | 2 +- .../etable/op_configure/op_global_get.rs | 2 +- .../etable/op_configure/op_global_set.rs | 2 +- .../circuits/etable/op_configure/op_load.rs | 2 +- .../etable/op_configure/op_local_get.rs | 2 +- .../etable/op_configure/op_local_set.rs | 2 +- .../etable/op_configure/op_local_tee.rs | 2 +- .../etable/op_configure/op_memory_grow.rs | 2 +- .../etable/op_configure/op_memory_size.rs | 2 +- .../circuits/etable/op_configure/op_rel.rs | 2 +- .../circuits/etable/op_configure/op_return.rs | 2 +- .../circuits/etable/op_configure/op_select.rs | 2 +- .../circuits/etable/op_configure/op_store.rs | 2 +- .../circuits/etable/op_configure/op_test.rs | 2 +- .../circuits/etable/op_configure/op_unary.rs | 2 +- crates/zkwasm/src/circuits/mtable/assign.rs | 2 +- crates/zkwasm/src/circuits/mtable/mod.rs | 2 + .../zkwasm/src/circuits/test_circuit/mod.rs | 20 +- .../zkwasm/src/circuits/utils/table_entry.rs | 340 +++++++++--------- crates/zkwasm/src/continuation/slice.rs | 19 +- .../foreign/context/etable_op_configure.rs | 2 +- .../require_helper/etable_op_configure.rs | 2 +- .../wasm_input_helper/etable_op_configure.rs | 2 +- crates/zkwasm/src/runtime/state.rs | 105 +++++- .../zkwasm/src/runtime/wasmi_interpreter.rs | 16 +- third-party/wasmi | 2 +- 48 files changed, 640 insertions(+), 289 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 53c052919..930a3c71d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -741,7 +741,6 @@ dependencies = [ [[package]] name = "halo2_proofs" version = "0.1.0-beta.1" -source = "git+https://github.com/DelphinusLab/halo2-gpu-specific.git#64ccffddc97faff24a00d248270fe84f6693c130" dependencies = [ "ark-std", "blake2b_simd", diff --git a/Cargo.toml b/Cargo.toml index 275fbbfbc..4208963a6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,3 +12,6 @@ wasmi = { path = "third-party/wasmi" } [profile.dev] opt-level = 3 + +[patch."https://github.com/DelphinusLab/halo2-gpu-specific.git"] +halo2_proofs = { path = "./halo2-gpu-specific/halo2_proofs" } diff --git a/crates/specs/src/etable.rs b/crates/specs/src/etable.rs index 4b4613cc7..153667502 100644 --- a/crates/specs/src/etable.rs +++ b/crates/specs/src/etable.rs @@ -2,6 +2,8 @@ use serde::Serialize; use super::itable::InstructionTableEntry; use crate::host_function::HostPlugin; +use crate::mtable::AccessType; +use crate::mtable::MemoryWritingTable; use crate::step::StepInfo; #[derive(Clone, Debug, Serialize)] @@ -69,3 +71,84 @@ impl EventTable { .collect::>() } } + +use std::cmp::Ordering; + +use crate::mtable::MemoryTableEntry; + +#[derive(Debug)] +pub struct MemoryRWEntry { + pub entry: MemoryTableEntry, + pub start_eid: u32, + pub end_eid: u32, +} + +#[derive(Debug)] +pub struct EventTableEntryWithMemoryInfo<'a> { + pub eentry: &'a EventTableEntry, + pub memory_rw_entires: Vec, +} + +#[derive(Debug)] +pub struct EventTableWithMemoryInfo<'a>(pub Vec>); + +impl<'a> EventTableWithMemoryInfo<'a> { + pub fn new( + event_table: &'a EventTable, + memory_writing_table: &MemoryWritingTable, + memory_event_of_step: fn(&EventTableEntry, &mut u32) -> Vec, + ) -> Self { + let lookup = memory_writing_table.build_lookup_mapping(); + + let lookup_mtable_eid = |(eid, ltype, offset, is_writing)| { + let records = lookup.get(&(ltype, offset)).unwrap(); + + if is_writing { + let idx = records + .binary_search_by(|(start_eid, _)| start_eid.cmp(eid)) + .unwrap(); + records[idx] + } else { + let idx = records + .binary_search_by(|(start_eid, end_eid)| { + if eid <= start_eid { + Ordering::Greater + } else if eid > end_eid { + Ordering::Less + } else { + Ordering::Equal + } + }) + .unwrap(); + records[idx] + } + }; + + EventTableWithMemoryInfo( + event_table + .entries() + .iter() + .map(|eentry| EventTableEntryWithMemoryInfo { + eentry, + memory_rw_entires: memory_event_of_step(eentry, &mut 1) + .into_iter() + .map(|mentry| { + let (start_eid, end_eid) = lookup_mtable_eid(( + &eentry.eid, + mentry.ltype, + mentry.offset, + mentry.atype == AccessType::Write, + )); + + MemoryRWEntry { + entry: mentry, + start_eid, + end_eid, + } + }) + .collect(), + }) + .collect(), + ) + } +} diff --git a/crates/specs/src/imtable.rs b/crates/specs/src/imtable.rs index 8e7081279..1c33a1bd4 100644 --- a/crates/specs/src/imtable.rs +++ b/crates/specs/src/imtable.rs @@ -1,10 +1,11 @@ use std::cmp::Ordering; +use std::collections::BTreeMap; use crate::mtable::LocationType; use crate::mtable::VarType; use serde::Serialize; -#[derive(Serialize, Debug, Clone)] +#[derive(Serialize, Debug, Clone, PartialEq)] pub struct InitMemoryTableEntry { pub ltype: LocationType, pub is_mutable: bool, @@ -13,35 +14,27 @@ pub struct InitMemoryTableEntry { pub vtype: VarType, /// convert from [u8; 8] via u64::from_le_bytes pub value: u64, + + // for stack + pub start_eid: u32, + pub end_eid: u32, } #[derive(Serialize, Default, Debug, Clone)] pub struct InitMemoryTable { entries: Vec, - sorted_global_init_entries: Vec, + sorted_global_init_entries: BTreeMap, sorted_heap_init_entries: Vec, + sorted_stack_init_entries: BTreeMap, } impl InitMemoryTable { - pub fn new(entries: Vec, k: u32) -> Self { + pub fn new(entries: Vec) -> Self { let mut imtable = Self { - entries: entries - .into_iter() - .map(|entry| InitMemoryTableEntry { - ltype: entry.ltype, - is_mutable: entry.is_mutable, - start_offset: entry.start_offset, - end_offset: if entry.end_offset == u32::MAX { - (1u32 << (k - 1)) - 1 - } else { - entry.end_offset - }, - vtype: entry.vtype, - value: entry.value, - }) - .collect(), - sorted_global_init_entries: vec![], + entries, + sorted_global_init_entries: BTreeMap::new(), sorted_heap_init_entries: vec![], + sorted_stack_init_entries: BTreeMap::new(), }; imtable.sort(); imtable.merge(); @@ -56,7 +49,13 @@ impl InitMemoryTable { .entries .iter() .filter(|entry| entry.ltype == LocationType::Global) - .map(|entry| entry.clone()) + .map(|entry| (entry.start_offset, entry.clone())) + .collect(); + imtable.sorted_stack_init_entries = imtable + .entries + .iter() + .filter(|entry| entry.ltype == LocationType::Stack) + .map(|entry| (entry.start_offset, entry.clone())) .collect(); imtable @@ -93,16 +92,18 @@ impl InitMemoryTable { )); } LocationType::Global => { - for entry in self.sorted_global_init_entries.iter() { - if entry.start_offset == offset { - return Some((offset, offset, entry.value)); - } - } + return self + .sorted_global_init_entries + .get(&offset) + .map(|entry| (offset, offset, entry.value)) + } + LocationType::Stack => { + return self + .sorted_stack_init_entries + .get(&offset) + .map(|entry| (offset, offset, entry.value)) } - LocationType::Stack => unreachable!(), } - - None } fn sort(&mut self) { @@ -114,7 +115,7 @@ impl InitMemoryTable { let mut merged_entries: Vec<_> = self .entries() .iter() - .filter(|entry| entry.ltype == LocationType::Global) + .filter(|entry| entry.ltype != LocationType::Heap) .map(|entry| entry.clone()) .collect(); @@ -128,7 +129,10 @@ impl InitMemoryTable { let mut scan = 0; let mut cursor = scan + 1; while scan < heap_initial.len() && cursor < heap_initial.len() { - if heap_initial[scan].value == heap_initial[cursor].value { + if heap_initial[scan].value == heap_initial[cursor].value + && heap_initial[scan].start_eid == heap_initial[cursor].start_eid + && heap_initial[scan].end_eid == heap_initial[cursor].end_eid + { cursor += 1; } else { merged_entries.push(InitMemoryTableEntry { @@ -138,6 +142,9 @@ impl InitMemoryTable { end_offset: heap_initial[cursor - 1].end_offset, vtype: VarType::I64, value: heap_initial[scan].value, + + start_eid: heap_initial[scan].start_eid, + end_eid: heap_initial[scan].end_eid, }); scan = cursor; @@ -151,6 +158,9 @@ impl InitMemoryTable { end_offset: heap_initial[cursor - 1].end_offset, vtype: VarType::I64, value: heap_initial[scan].value, + + start_eid: heap_initial[scan].start_eid, + end_eid: heap_initial[scan].end_eid, }); } diff --git a/crates/specs/src/lib.rs b/crates/specs/src/lib.rs index e290f8afd..e09dd8e9a 100644 --- a/crates/specs/src/lib.rs +++ b/crates/specs/src/lib.rs @@ -16,7 +16,6 @@ use itable::InstructionTable; use jtable::JumpTable; use jtable::StaticFrameEntry; use mtable::AccessType; -use mtable::LocationType; use mtable::MTable; use mtable::MemoryTableEntry; use rayon::prelude::IntoParallelRefIterator; @@ -155,14 +154,13 @@ pub struct Tables { pub is_last_slice: bool, } -impl Tables { +impl EventTable { pub fn create_memory_table( &self, + imtable: &InitMemoryTable, memory_event_of_step: fn(&EventTableEntry, &mut u32) -> Vec, ) -> MTable { let mut memory_entries = self - .execution_tables - .etable .entries() .par_iter() .map(|entry| memory_event_of_step(entry, &mut 1)) @@ -172,17 +170,9 @@ impl Tables { let init_value = memory_entries .par_iter() .map(|entry| { - if entry.ltype == LocationType::Heap || entry.ltype == LocationType::Global { - let (_, _, value) = self - .compilation_tables - .imtable - .try_find(entry.ltype, entry.offset) - .unwrap(); - - Some(value) - } else { - None - } + imtable + .try_find(entry.ltype, entry.offset) + .map(|(_, _, value)| value) }) .collect::>(); @@ -213,13 +203,13 @@ impl Tables { MTable::new(memory_entries) } +} +impl Tables { pub fn is_last_slice(&self) -> bool { self.is_last_slice } -} -impl Tables { pub fn write_json(&self, dir: Option) { fn write_file(folder: &PathBuf, filename: &str, buf: &String) { let mut folder = folder.clone(); diff --git a/crates/specs/src/mtable.rs b/crates/specs/src/mtable.rs index 07ce40950..a4d39a08f 100644 --- a/crates/specs/src/mtable.rs +++ b/crates/specs/src/mtable.rs @@ -1,3 +1,5 @@ +use std::collections::BTreeMap; + use serde::Serialize; use strum_macros::EnumIter; @@ -138,7 +140,7 @@ impl MemoryTableEntry { } #[derive(Default, Debug, Serialize, Clone)] -pub struct MTable(Vec); +pub struct MTable(pub Vec); impl MTable { pub fn to_string(&self) -> String { @@ -153,3 +155,94 @@ impl MTable { MTable(entries) } } + +#[derive(Clone, Debug, Serialize)] +pub struct MemoryWritingEntry { + index: usize, + pub entry: MemoryTableEntry, + pub end_eid: u32, +} + +impl MemoryWritingEntry { + fn is_same_memory_address(&self, other: &Self) -> bool { + self.entry.is_same_location(&other.entry) + } +} + +#[derive(Debug, Serialize)] +pub struct MemoryWritingTable(pub Vec); + +impl From for MemoryWritingTable { + fn from(value: MTable) -> Self { + let mut index = 0; + + let mut entries: Vec = value + .0 + .into_iter() + .filter_map(|entry| { + if entry.atype != AccessType::Read { + let entry = Some(MemoryWritingEntry { + index, + entry, + end_eid: u32::MAX, + }); + + index += 1; + + entry + } else { + None + } + }) + .collect(); + + let entries_next = entries.clone(); + let next_iter = entries_next.iter().skip(1); + + entries.iter_mut().zip(next_iter).for_each(|(curr, next)| { + if curr.is_same_memory_address(next) { + curr.end_eid = next.entry.eid; + } + }); + + MemoryWritingTable(entries) + } +} + +impl MemoryWritingTable { + // (location, offset) |-> Vec<(start_eid, end_eid)> + pub fn build_lookup_mapping(&self) -> BTreeMap<(LocationType, u32), Vec<(u32, u32)>> { + let mut mapping = BTreeMap::<_, Vec<(u32, u32)>>::new(); + + for entry in &self.0 { + let ltype = entry.entry.ltype; + let offset = entry.entry.offset; + let start_eid = entry.entry.eid; + let end_eid = entry.end_eid; + + if let Some(entries) = mapping.get_mut(&(ltype, offset)) { + entries.push((start_eid, end_eid)); + } else { + mapping.insert((ltype, offset), vec![(start_eid, end_eid)]); + } + } + + mapping + } + + // pub fn write_json(&self, dir: Option) { + // fn write_file(folder: &PathBuf, filename: &str, buf: &String) { + // let mut folder = folder.clone(); + // folder.push(filename); + // let mut fd = std::fs::File::create(folder.as_path()).unwrap(); + // folder.pop(); + + // fd.write(buf.as_bytes()).unwrap(); + // } + + // let mtable = serde_json::to_string(self).unwrap(); + + // let dir = dir.unwrap_or(env::current_dir().unwrap()); + // write_file(&dir, "memory_writing_table.json", &mtable); + // } +} diff --git a/crates/zkwasm/src/circuits/bit_table/assign.rs b/crates/zkwasm/src/circuits/bit_table/assign.rs index 70397600f..1a5ce20a6 100644 --- a/crates/zkwasm/src/circuits/bit_table/assign.rs +++ b/crates/zkwasm/src/circuits/bit_table/assign.rs @@ -2,10 +2,10 @@ use halo2_proofs::arithmetic::FieldExt; use halo2_proofs::plonk::Advice; use halo2_proofs::plonk::Column; use halo2_proofs::plonk::Error; +use specs::etable::EventTableWithMemoryInfo; use specs::itable::UnaryOp; use specs::step::StepInfo; -use crate::circuits::utils::table_entry::EventTableWithMemoryInfo; use crate::circuits::utils::Context; use super::BitTableChip; diff --git a/crates/zkwasm/src/circuits/etable/allocator.rs b/crates/zkwasm/src/circuits/etable/allocator.rs index 017a137cf..a61a9b165 100644 --- a/crates/zkwasm/src/circuits/etable/allocator.rs +++ b/crates/zkwasm/src/circuits/etable/allocator.rs @@ -90,8 +90,8 @@ pub(crate) struct AllocatedMemoryTableLookupReadCell { pub(crate) encode_cell: AllocatedUnlimitedCell, pub(crate) start_eid_cell: AllocatedUnlimitedCell, pub(crate) end_eid_cell: AllocatedUnlimitedCell, - pub(crate) start_eid_diff_cell: AllocatedCommonRangeCell, - pub(crate) end_eid_diff_cell: AllocatedCommonRangeCell, + pub(crate) start_eid_diff_cell: AllocatedU32Cell, + pub(crate) end_eid_diff_cell: AllocatedU32Cell, pub(crate) value_cell: AllocatedUnlimitedCell, } @@ -124,10 +124,9 @@ impl AllocatedMemoryTableLookupReadCell { ), )?; self.start_eid_cell.assign_u32(ctx, start_eid)?; - self.start_eid_diff_cell - .assign_u32(ctx, eid - start_eid - 1)?; + self.start_eid_diff_cell.assign(ctx, eid - start_eid - 1)?; self.end_eid_cell.assign_u32(ctx, end_eid)?; - self.end_eid_diff_cell.assign_u32(ctx, end_eid - eid)?; + self.end_eid_diff_cell.assign(ctx, end_eid - eid)?; self.value_cell.assign(ctx, value.into())?; Ok(()) @@ -175,11 +174,15 @@ pub(crate) enum EventTableCellType { const BIT_COLUMNS: usize = 12; const U8_COLUMNS: usize = 1; // Should be the multiple of 2. -const U32_CELLS: usize = if cfg!(feature = "continuation") { 2 } else { 0 }; +const U32_CELLS: usize = if cfg!(feature = "continuation") { 10 } else { 0 }; const U64_CELLS: usize = 5; const U16_COLUMNS: usize = U64_CELLS + (U32_CELLS / 2); const COMMON_RANGE_COLUMNS: usize = 7; -const UNLIMITED_COLUMNS: usize = if cfg!(feature = "continuation") { 8 } else { 7 }; +const UNLIMITED_COLUMNS: usize = if cfg!(feature = "continuation") { + 12 +} else { + 7 +}; const MEMORY_TABLE_LOOKUP_COLUMNS: usize = 2; const JUMP_TABLE_LOOKUP_COLUMNS: usize = 1; @@ -500,8 +503,8 @@ impl EventTableCellAllocator { end_eid_cell: cells[1], encode_cell: cells[2], value_cell: cells[3], - start_eid_diff_cell: self.alloc_common_range_cell(), - end_eid_diff_cell: self.alloc_common_range_cell(), + start_eid_diff_cell: self.alloc_u32_cell(), + end_eid_diff_cell: self.alloc_u32_cell(), }; constraint_builder.constraints.push(( @@ -590,8 +593,8 @@ impl EventTableCellAllocator { end_eid_cell: cells[1], encode_cell: cells[2], value_cell: cells[3], - start_eid_diff_cell: self.alloc_common_range_cell(), - end_eid_diff_cell: self.alloc_common_range_cell(), + start_eid_diff_cell: self.alloc_u32_cell(), + end_eid_diff_cell: self.alloc_u32_cell(), }; constraint_builder.constraints.push(( diff --git a/crates/zkwasm/src/circuits/etable/assign.rs b/crates/zkwasm/src/circuits/etable/assign.rs index 4ef64b9f4..99a642d25 100644 --- a/crates/zkwasm/src/circuits/etable/assign.rs +++ b/crates/zkwasm/src/circuits/etable/assign.rs @@ -3,11 +3,11 @@ use halo2_proofs::circuit::Cell; use halo2_proofs::plonk::Error; use log::debug; use specs::configure_table::ConfigureTable; +use specs::etable::EventTableWithMemoryInfo; use specs::itable::Opcode; use specs::itable::OpcodeClassPlain; use specs::jtable::JumpTable; use specs::jtable::StaticFrameEntry; -use specs::mtable::MTable; use specs::InitializationState; use std::collections::BTreeMap; use std::rc::Rc; @@ -19,13 +19,12 @@ use crate::circuits::cell::CellExpression; use crate::circuits::utils::bn_to_field; use crate::circuits::utils::step_status::Status; use crate::circuits::utils::step_status::StepStatus; -use crate::circuits::utils::table_entry::EventTableWithMemoryInfo; use crate::circuits::utils::Context; pub(in crate::circuits) struct EventTablePermutationCells { pub(in crate::circuits) pre_initialization_state: InitializationState, pub(in crate::circuits) post_initialization_state: InitializationState, - pub(in crate::circuits) rest_jops: Cell, + pub(in crate::circuits) total_jops: Cell, } impl EventTableChip { @@ -91,6 +90,22 @@ impl EventTableChip { Ok(()) } + #[cfg(feature = "continuation")] + fn assign_total_jops_first_step( + &self, + ctx: &mut Context<'_, F>, + total_jops: u32, + ) -> Result { + let rest_mops_cell = self + .config + .common_config + .total_jops_cell + .assign(ctx, F::from(total_jops as u64))? + .cell(); + + Ok(rest_mops_cell) + } + fn assign_rest_ops_first_step( &self, ctx: &mut Context<'_, F>, @@ -201,6 +216,7 @@ impl EventTableChip { configure_table: &ConfigureTable, // rest_ops: Vec<(u32, u32)>, initialization_state: &InitializationState, + total_jops: u32, mut rest_jops: u32, mut rest_mops: u32, ) -> Result<(), Error> { @@ -310,6 +326,8 @@ impl EventTableChip { } assign_advice!(enabled_cell, F::one()); + #[cfg(feature = "continuation")] + assign_advice!(total_jops_cell, F::from(total_jops as u64)); assign_advice!(rest_mops_cell, F::from(rest_mops as u64)); assign_advice!(rest_jops_cell, F::from(rest_jops as u64)); assign_advice!(input_index_cell, F::from(host_public_inputs as u64)); @@ -473,18 +491,25 @@ impl EventTableChip { rest_ops.first().map_or(0u32, |(rest_mops, _)| *rest_mops) }; - let rest_jops = frame_table.entries().len() as u32 * 2 + static_frame_entries.len() as u32; - - #[cfg(feature = "continuation")] - println!("jops: {:?}", initialization_state.jops); - println!("rest_jops: {:?}", rest_jops); + let total_jops = frame_table.entries().len() as u32 * 2 + static_frame_entries.len() as u32; - #[cfg(feature = "continuation")] - let rest_jops = rest_jops - initialization_state.jops; + // #[cfg(feature = "continuation")] + // println!("jops: {:?}", initialization_state.jops); + // println!("total_jops: {:?}", total_jops); self.init(ctx)?; ctx.reset(); + #[cfg(feature = "continuation")] + let total_jops_cell = self.assign_total_jops_first_step(ctx, total_jops)?; + + let rest_jops = total_jops + - if cfg!(feature = "continuation") { + initialization_state.jops + } else { + 0 + }; + let (rest_mops_cell, rest_jops_cell) = self.assign_rest_ops_first_step(ctx, rest_mops, rest_jops)?; ctx.reset(); @@ -500,6 +525,7 @@ impl EventTableChip { configure_table, // rest_ops, &initialization_state, + total_jops, rest_jops, rest_mops, )?; @@ -514,7 +540,11 @@ impl EventTableChip { Ok(EventTablePermutationCells { pre_initialization_state: pre_initialization_state_cells, post_initialization_state: post_initialization_state_cells, - rest_jops: rest_jops_cell, + total_jops: if cfg!(feature = "continuation") { + total_jops_cell + } else { + rest_jops_cell + }, }) } } diff --git a/crates/zkwasm/src/circuits/etable/mod.rs b/crates/zkwasm/src/circuits/etable/mod.rs index e81df5025..c5be76ab7 100644 --- a/crates/zkwasm/src/circuits/etable/mod.rs +++ b/crates/zkwasm/src/circuits/etable/mod.rs @@ -9,7 +9,6 @@ use super::mtable::MemoryTableConfig; use super::rtable::RangeTableConfig; use super::traits::ConfigureLookupTable; use super::utils::step_status::StepStatus; -use super::utils::table_entry::EventTableEntryWithMemoryInfo; use super::utils::Context; use crate::circuits::etable::op_configure::op_bin::BinConfigBuilder; use crate::circuits::etable::op_configure::op_bin_bit::BinBitConfigBuilder; @@ -56,6 +55,7 @@ use halo2_proofs::plonk::Fixed; use halo2_proofs::plonk::VirtualCells; use specs::encode::instruction_table::encode_instruction_table_entry; use specs::etable::EventTableEntry; +use specs::etable::EventTableEntryWithMemoryInfo; use specs::itable::OpcodeClass; use specs::itable::OpcodeClassPlain; use std::collections::BTreeMap; @@ -81,6 +81,8 @@ pub struct EventTableCommonConfig { rest_jops_cell: AllocatedCommonRangeCell, #[cfg(feature = "continuation")] jops_cell: AllocatedCommonRangeCell, + #[cfg(feature = "continuation")] + total_jops_cell: AllocatedCommonRangeCell, pub(crate) input_index_cell: AllocatedCommonRangeCell, pub(crate) context_input_index_cell: AllocatedCommonRangeCell, @@ -238,6 +240,8 @@ impl EventTableConfig { let rest_jops_cell = allocator.alloc_common_range_cell(); #[cfg(feature = "continuation")] let jops_cell = allocator.alloc_common_range_cell(); + #[cfg(feature = "continuation")] + let total_jops_cell = allocator.alloc_common_range_cell(); let input_index_cell = allocator.alloc_common_range_cell(); let context_input_index_cell = allocator.alloc_common_range_cell(); let context_output_index_cell = allocator.alloc_common_range_cell(); @@ -283,6 +287,8 @@ impl EventTableConfig { rest_jops_cell, #[cfg(feature = "continuation")] jops_cell, + #[cfg(feature = "continuation")] + total_jops_cell, input_index_cell, context_input_index_cell, context_output_index_cell, diff --git a/crates/zkwasm/src/circuits/etable/op_configure/op_bin.rs b/crates/zkwasm/src/circuits/etable/op_configure/op_bin.rs index 1da10618c..acffad672 100644 --- a/crates/zkwasm/src/circuits/etable/op_configure/op_bin.rs +++ b/crates/zkwasm/src/circuits/etable/op_configure/op_bin.rs @@ -6,7 +6,7 @@ use crate::circuits::etable::EventTableOpcodeConfig; use crate::circuits::etable::EventTableOpcodeConfigBuilder; use crate::circuits::utils::bn_to_field; use crate::circuits::utils::step_status::StepStatus; -use crate::circuits::utils::table_entry::EventTableEntryWithMemoryInfo; +use specs::etable::EventTableEntryWithMemoryInfo; use crate::circuits::utils::Context; use crate::constant; use crate::constant_from; diff --git a/crates/zkwasm/src/circuits/etable/op_configure/op_bin_bit.rs b/crates/zkwasm/src/circuits/etable/op_configure/op_bin_bit.rs index 1e0c7f6ba..36296d3e1 100644 --- a/crates/zkwasm/src/circuits/etable/op_configure/op_bin_bit.rs +++ b/crates/zkwasm/src/circuits/etable/op_configure/op_bin_bit.rs @@ -7,7 +7,6 @@ use crate::circuits::etable::EventTableOpcodeConfig; use crate::circuits::etable::EventTableOpcodeConfigBuilder; use crate::circuits::utils::bn_to_field; use crate::circuits::utils::step_status::StepStatus; -use crate::circuits::utils::table_entry::EventTableEntryWithMemoryInfo; use crate::circuits::utils::Context; use crate::constant; use crate::constant_from; @@ -17,6 +16,7 @@ use halo2_proofs::plonk::Expression; use halo2_proofs::plonk::VirtualCells; use num_bigint::BigUint; use specs::etable::EventTableEntry; +use specs::etable::EventTableEntryWithMemoryInfo; use specs::itable::BitOp; use specs::itable::OpcodeClass; use specs::itable::OPCODE_ARG0_SHIFT; diff --git a/crates/zkwasm/src/circuits/etable/op_configure/op_bin_shift.rs b/crates/zkwasm/src/circuits/etable/op_configure/op_bin_shift.rs index 399cc7be8..d1e339ec1 100644 --- a/crates/zkwasm/src/circuits/etable/op_configure/op_bin_shift.rs +++ b/crates/zkwasm/src/circuits/etable/op_configure/op_bin_shift.rs @@ -7,7 +7,7 @@ use crate::circuits::etable::EventTableOpcodeConfigBuilder; use crate::circuits::rtable::pow_table_power_encode; use crate::circuits::utils::bn_to_field; use crate::circuits::utils::step_status::StepStatus; -use crate::circuits::utils::table_entry::EventTableEntryWithMemoryInfo; +use specs::etable::EventTableEntryWithMemoryInfo; use crate::circuits::utils::Context; use crate::constant; use crate::constant_from; diff --git a/crates/zkwasm/src/circuits/etable/op_configure/op_br.rs b/crates/zkwasm/src/circuits/etable/op_configure/op_br.rs index fc7aebc41..b6c680e3e 100644 --- a/crates/zkwasm/src/circuits/etable/op_configure/op_br.rs +++ b/crates/zkwasm/src/circuits/etable/op_configure/op_br.rs @@ -5,7 +5,7 @@ use crate::circuits::etable::EventTableCommonConfig; use crate::circuits::etable::EventTableOpcodeConfig; use crate::circuits::etable::EventTableOpcodeConfigBuilder; use crate::circuits::utils::step_status::StepStatus; -use crate::circuits::utils::table_entry::EventTableEntryWithMemoryInfo; +use specs::etable::EventTableEntryWithMemoryInfo; use crate::circuits::utils::Context; use crate::constant_from; use halo2_proofs::arithmetic::FieldExt; diff --git a/crates/zkwasm/src/circuits/etable/op_configure/op_br_if.rs b/crates/zkwasm/src/circuits/etable/op_configure/op_br_if.rs index 228e01fbe..e0f8fce11 100644 --- a/crates/zkwasm/src/circuits/etable/op_configure/op_br_if.rs +++ b/crates/zkwasm/src/circuits/etable/op_configure/op_br_if.rs @@ -6,7 +6,7 @@ use crate::circuits::etable::EventTableOpcodeConfig; use crate::circuits::etable::EventTableOpcodeConfigBuilder; use crate::circuits::utils::bn_to_field; use crate::circuits::utils::step_status::StepStatus; -use crate::circuits::utils::table_entry::EventTableEntryWithMemoryInfo; +use specs::etable::EventTableEntryWithMemoryInfo; use crate::circuits::utils::Context; use crate::constant; use crate::constant_from; diff --git a/crates/zkwasm/src/circuits/etable/op_configure/op_br_if_eqz.rs b/crates/zkwasm/src/circuits/etable/op_configure/op_br_if_eqz.rs index 2d4e0517c..3dfec3582 100644 --- a/crates/zkwasm/src/circuits/etable/op_configure/op_br_if_eqz.rs +++ b/crates/zkwasm/src/circuits/etable/op_configure/op_br_if_eqz.rs @@ -6,7 +6,7 @@ use crate::circuits::etable::EventTableOpcodeConfig; use crate::circuits::etable::EventTableOpcodeConfigBuilder; use crate::circuits::utils::bn_to_field; use crate::circuits::utils::step_status::StepStatus; -use crate::circuits::utils::table_entry::EventTableEntryWithMemoryInfo; +use specs::etable::EventTableEntryWithMemoryInfo; use crate::circuits::utils::Context; use crate::constant; use crate::constant_from; diff --git a/crates/zkwasm/src/circuits/etable/op_configure/op_br_table.rs b/crates/zkwasm/src/circuits/etable/op_configure/op_br_table.rs index e9e9c35f9..4da5f3aea 100644 --- a/crates/zkwasm/src/circuits/etable/op_configure/op_br_table.rs +++ b/crates/zkwasm/src/circuits/etable/op_configure/op_br_table.rs @@ -5,7 +5,7 @@ use crate::circuits::etable::EventTableCommonConfig; use crate::circuits::etable::EventTableOpcodeConfig; use crate::circuits::etable::EventTableOpcodeConfigBuilder; use crate::circuits::utils::step_status::StepStatus; -use crate::circuits::utils::table_entry::EventTableEntryWithMemoryInfo; +use specs::etable::EventTableEntryWithMemoryInfo; use crate::circuits::utils::Context; use crate::constant_from; use halo2_proofs::arithmetic::FieldExt; diff --git a/crates/zkwasm/src/circuits/etable/op_configure/op_call.rs b/crates/zkwasm/src/circuits/etable/op_configure/op_call.rs index 3f6e88976..11a6787ab 100644 --- a/crates/zkwasm/src/circuits/etable/op_configure/op_call.rs +++ b/crates/zkwasm/src/circuits/etable/op_configure/op_call.rs @@ -8,7 +8,7 @@ use crate::circuits::jtable::expression::JtableLookupEntryEncode; use crate::circuits::jtable::JumpTableConfig; use crate::circuits::utils::bn_to_field; use crate::circuits::utils::step_status::StepStatus; -use crate::circuits::utils::table_entry::EventTableEntryWithMemoryInfo; +use specs::etable::EventTableEntryWithMemoryInfo; use crate::circuits::utils::Context; use crate::constant_from; use halo2_proofs::arithmetic::FieldExt; diff --git a/crates/zkwasm/src/circuits/etable/op_configure/op_call_host_foreign_circuit.rs b/crates/zkwasm/src/circuits/etable/op_configure/op_call_host_foreign_circuit.rs index c7eef874b..77f47ab49 100644 --- a/crates/zkwasm/src/circuits/etable/op_configure/op_call_host_foreign_circuit.rs +++ b/crates/zkwasm/src/circuits/etable/op_configure/op_call_host_foreign_circuit.rs @@ -5,7 +5,7 @@ use crate::circuits::etable::EventTableCommonConfig; use crate::circuits::etable::EventTableOpcodeConfig; use crate::circuits::etable::EventTableOpcodeConfigBuilder; use crate::circuits::utils::step_status::StepStatus; -use crate::circuits::utils::table_entry::EventTableEntryWithMemoryInfo; +use specs::etable::EventTableEntryWithMemoryInfo; use crate::circuits::utils::Context; use crate::constant_from; use halo2_proofs::arithmetic::FieldExt; diff --git a/crates/zkwasm/src/circuits/etable/op_configure/op_call_indirect.rs b/crates/zkwasm/src/circuits/etable/op_configure/op_call_indirect.rs index 745df4c92..057a21238 100644 --- a/crates/zkwasm/src/circuits/etable/op_configure/op_call_indirect.rs +++ b/crates/zkwasm/src/circuits/etable/op_configure/op_call_indirect.rs @@ -7,7 +7,7 @@ use crate::circuits::etable::EventTableOpcodeConfigBuilder; use crate::circuits::jtable::expression::JtableLookupEntryEncode; use crate::circuits::jtable::JumpTableConfig; use crate::circuits::utils::step_status::StepStatus; -use crate::circuits::utils::table_entry::EventTableEntryWithMemoryInfo; +use specs::etable::EventTableEntryWithMemoryInfo; use crate::circuits::utils::Context; use crate::constant; use crate::constant_from; diff --git a/crates/zkwasm/src/circuits/etable/op_configure/op_const.rs b/crates/zkwasm/src/circuits/etable/op_configure/op_const.rs index f7c6036f1..6acade122 100644 --- a/crates/zkwasm/src/circuits/etable/op_configure/op_const.rs +++ b/crates/zkwasm/src/circuits/etable/op_configure/op_const.rs @@ -6,7 +6,7 @@ use crate::circuits::etable::EventTableOpcodeConfig; use crate::circuits::etable::EventTableOpcodeConfigBuilder; use crate::circuits::utils::bn_to_field; use crate::circuits::utils::step_status::StepStatus; -use crate::circuits::utils::table_entry::EventTableEntryWithMemoryInfo; +use specs::etable::EventTableEntryWithMemoryInfo; use crate::circuits::utils::Context; use crate::constant; use crate::constant_from; diff --git a/crates/zkwasm/src/circuits/etable/op_configure/op_conversion.rs b/crates/zkwasm/src/circuits/etable/op_configure/op_conversion.rs index 3fdc1a345..f6903af1a 100644 --- a/crates/zkwasm/src/circuits/etable/op_configure/op_conversion.rs +++ b/crates/zkwasm/src/circuits/etable/op_configure/op_conversion.rs @@ -6,7 +6,7 @@ use crate::circuits::etable::EventTableOpcodeConfig; use crate::circuits::etable::EventTableOpcodeConfigBuilder; use crate::circuits::utils::bn_to_field; use crate::circuits::utils::step_status::StepStatus; -use crate::circuits::utils::table_entry::EventTableEntryWithMemoryInfo; +use specs::etable::EventTableEntryWithMemoryInfo; use crate::circuits::utils::Context; use crate::constant_from; use halo2_proofs::arithmetic::FieldExt; diff --git a/crates/zkwasm/src/circuits/etable/op_configure/op_drop.rs b/crates/zkwasm/src/circuits/etable/op_configure/op_drop.rs index 1fad58b90..348d46f82 100644 --- a/crates/zkwasm/src/circuits/etable/op_configure/op_drop.rs +++ b/crates/zkwasm/src/circuits/etable/op_configure/op_drop.rs @@ -5,7 +5,7 @@ use crate::circuits::etable::EventTableOpcodeConfig; use crate::circuits::etable::EventTableOpcodeConfigBuilder; use crate::circuits::utils::bn_to_field; use crate::circuits::utils::step_status::StepStatus; -use crate::circuits::utils::table_entry::EventTableEntryWithMemoryInfo; +use specs::etable::EventTableEntryWithMemoryInfo; use crate::circuits::utils::Context; use crate::constant_from; use crate::constant_from_bn; diff --git a/crates/zkwasm/src/circuits/etable/op_configure/op_global_get.rs b/crates/zkwasm/src/circuits/etable/op_configure/op_global_get.rs index 885e8e30b..bdd9da368 100644 --- a/crates/zkwasm/src/circuits/etable/op_configure/op_global_get.rs +++ b/crates/zkwasm/src/circuits/etable/op_configure/op_global_get.rs @@ -5,7 +5,7 @@ use crate::circuits::etable::EventTableCommonConfig; use crate::circuits::etable::EventTableOpcodeConfig; use crate::circuits::etable::EventTableOpcodeConfigBuilder; use crate::circuits::utils::step_status::StepStatus; -use crate::circuits::utils::table_entry::EventTableEntryWithMemoryInfo; +use specs::etable::EventTableEntryWithMemoryInfo; use crate::circuits::utils::Context; use crate::constant; use crate::constant_from; diff --git a/crates/zkwasm/src/circuits/etable/op_configure/op_global_set.rs b/crates/zkwasm/src/circuits/etable/op_configure/op_global_set.rs index 9fea49cd3..3a254926f 100644 --- a/crates/zkwasm/src/circuits/etable/op_configure/op_global_set.rs +++ b/crates/zkwasm/src/circuits/etable/op_configure/op_global_set.rs @@ -5,7 +5,7 @@ use crate::circuits::etable::EventTableCommonConfig; use crate::circuits::etable::EventTableOpcodeConfig; use crate::circuits::etable::EventTableOpcodeConfigBuilder; use crate::circuits::utils::step_status::StepStatus; -use crate::circuits::utils::table_entry::EventTableEntryWithMemoryInfo; +use specs::etable::EventTableEntryWithMemoryInfo; use crate::circuits::utils::Context; use crate::constant; use crate::constant_from; diff --git a/crates/zkwasm/src/circuits/etable/op_configure/op_load.rs b/crates/zkwasm/src/circuits/etable/op_configure/op_load.rs index 9544666a0..52a99b021 100644 --- a/crates/zkwasm/src/circuits/etable/op_configure/op_load.rs +++ b/crates/zkwasm/src/circuits/etable/op_configure/op_load.rs @@ -12,7 +12,7 @@ use crate::circuits::mtable::utils::WASM_BLOCK_BYTE_SIZE; use crate::circuits::rtable::pow_table_power_encode; use crate::circuits::utils::bn_to_field; use crate::circuits::utils::step_status::StepStatus; -use crate::circuits::utils::table_entry::EventTableEntryWithMemoryInfo; +use specs::etable::EventTableEntryWithMemoryInfo; use crate::circuits::utils::Context; use crate::constant; use crate::constant_from; diff --git a/crates/zkwasm/src/circuits/etable/op_configure/op_local_get.rs b/crates/zkwasm/src/circuits/etable/op_configure/op_local_get.rs index 97fec4720..92ce6f41a 100644 --- a/crates/zkwasm/src/circuits/etable/op_configure/op_local_get.rs +++ b/crates/zkwasm/src/circuits/etable/op_configure/op_local_get.rs @@ -6,7 +6,7 @@ use crate::circuits::etable::EventTableOpcodeConfig; use crate::circuits::etable::EventTableOpcodeConfigBuilder; use crate::circuits::utils::bn_to_field; use crate::circuits::utils::step_status::StepStatus; -use crate::circuits::utils::table_entry::EventTableEntryWithMemoryInfo; +use specs::etable::EventTableEntryWithMemoryInfo; use crate::circuits::utils::Context; use crate::constant; use crate::constant_from; diff --git a/crates/zkwasm/src/circuits/etable/op_configure/op_local_set.rs b/crates/zkwasm/src/circuits/etable/op_configure/op_local_set.rs index 6c4b94b49..e19006b09 100644 --- a/crates/zkwasm/src/circuits/etable/op_configure/op_local_set.rs +++ b/crates/zkwasm/src/circuits/etable/op_configure/op_local_set.rs @@ -6,7 +6,7 @@ use crate::circuits::etable::EventTableOpcodeConfig; use crate::circuits::etable::EventTableOpcodeConfigBuilder; use crate::circuits::utils::bn_to_field; use crate::circuits::utils::step_status::StepStatus; -use crate::circuits::utils::table_entry::EventTableEntryWithMemoryInfo; +use specs::etable::EventTableEntryWithMemoryInfo; use crate::circuits::utils::Context; use crate::constant; use crate::constant_from; diff --git a/crates/zkwasm/src/circuits/etable/op_configure/op_local_tee.rs b/crates/zkwasm/src/circuits/etable/op_configure/op_local_tee.rs index 7c9d46d55..06128e6e1 100644 --- a/crates/zkwasm/src/circuits/etable/op_configure/op_local_tee.rs +++ b/crates/zkwasm/src/circuits/etable/op_configure/op_local_tee.rs @@ -6,7 +6,7 @@ use crate::circuits::etable::EventTableOpcodeConfig; use crate::circuits::etable::EventTableOpcodeConfigBuilder; use crate::circuits::utils::bn_to_field; use crate::circuits::utils::step_status::StepStatus; -use crate::circuits::utils::table_entry::EventTableEntryWithMemoryInfo; +use specs::etable::EventTableEntryWithMemoryInfo; use crate::circuits::utils::Context; use crate::constant; use crate::constant_from; diff --git a/crates/zkwasm/src/circuits/etable/op_configure/op_memory_grow.rs b/crates/zkwasm/src/circuits/etable/op_configure/op_memory_grow.rs index c21738a50..319de3c35 100644 --- a/crates/zkwasm/src/circuits/etable/op_configure/op_memory_grow.rs +++ b/crates/zkwasm/src/circuits/etable/op_configure/op_memory_grow.rs @@ -6,7 +6,7 @@ use crate::circuits::etable::EventTableOpcodeConfig; use crate::circuits::etable::EventTableOpcodeConfigBuilder; use crate::circuits::utils::bn_to_field; use crate::circuits::utils::step_status::StepStatus; -use crate::circuits::utils::table_entry::EventTableEntryWithMemoryInfo; +use specs::etable::EventTableEntryWithMemoryInfo; use crate::circuits::utils::Context; use crate::constant; use crate::constant_from; diff --git a/crates/zkwasm/src/circuits/etable/op_configure/op_memory_size.rs b/crates/zkwasm/src/circuits/etable/op_configure/op_memory_size.rs index 04ae20bc8..5b5cfa90e 100644 --- a/crates/zkwasm/src/circuits/etable/op_configure/op_memory_size.rs +++ b/crates/zkwasm/src/circuits/etable/op_configure/op_memory_size.rs @@ -6,7 +6,7 @@ use crate::circuits::etable::EventTableOpcodeConfig; use crate::circuits::etable::EventTableOpcodeConfigBuilder; use crate::circuits::utils::bn_to_field; use crate::circuits::utils::step_status::StepStatus; -use crate::circuits::utils::table_entry::EventTableEntryWithMemoryInfo; +use specs::etable::EventTableEntryWithMemoryInfo; use crate::circuits::utils::Context; use crate::constant; use crate::constant_from; diff --git a/crates/zkwasm/src/circuits/etable/op_configure/op_rel.rs b/crates/zkwasm/src/circuits/etable/op_configure/op_rel.rs index e2a23c619..2877b8279 100644 --- a/crates/zkwasm/src/circuits/etable/op_configure/op_rel.rs +++ b/crates/zkwasm/src/circuits/etable/op_configure/op_rel.rs @@ -6,7 +6,7 @@ use crate::circuits::etable::EventTableOpcodeConfig; use crate::circuits::etable::EventTableOpcodeConfigBuilder; use crate::circuits::utils::bn_to_field; use crate::circuits::utils::step_status::StepStatus; -use crate::circuits::utils::table_entry::EventTableEntryWithMemoryInfo; +use specs::etable::EventTableEntryWithMemoryInfo; use crate::circuits::utils::Context; use crate::constant; use crate::constant_from; diff --git a/crates/zkwasm/src/circuits/etable/op_configure/op_return.rs b/crates/zkwasm/src/circuits/etable/op_configure/op_return.rs index c3b6e9574..4a9e1edbd 100644 --- a/crates/zkwasm/src/circuits/etable/op_configure/op_return.rs +++ b/crates/zkwasm/src/circuits/etable/op_configure/op_return.rs @@ -8,7 +8,7 @@ use crate::circuits::jtable::expression::JtableLookupEntryEncode; use crate::circuits::jtable::JumpTableConfig; use crate::circuits::utils::bn_to_field; use crate::circuits::utils::step_status::StepStatus; -use crate::circuits::utils::table_entry::EventTableEntryWithMemoryInfo; +use specs::etable::EventTableEntryWithMemoryInfo; use crate::circuits::utils::Context; use crate::constant; use crate::constant_from; diff --git a/crates/zkwasm/src/circuits/etable/op_configure/op_select.rs b/crates/zkwasm/src/circuits/etable/op_configure/op_select.rs index a74043e88..6c663fc78 100644 --- a/crates/zkwasm/src/circuits/etable/op_configure/op_select.rs +++ b/crates/zkwasm/src/circuits/etable/op_configure/op_select.rs @@ -6,7 +6,7 @@ use crate::circuits::etable::EventTableOpcodeConfig; use crate::circuits::etable::EventTableOpcodeConfigBuilder; use crate::circuits::utils::bn_to_field; use crate::circuits::utils::step_status::StepStatus; -use crate::circuits::utils::table_entry::EventTableEntryWithMemoryInfo; +use specs::etable::EventTableEntryWithMemoryInfo; use crate::circuits::utils::Context; use crate::constant; use crate::constant_from; diff --git a/crates/zkwasm/src/circuits/etable/op_configure/op_store.rs b/crates/zkwasm/src/circuits/etable/op_configure/op_store.rs index 7f8db7d42..9401f0c9b 100644 --- a/crates/zkwasm/src/circuits/etable/op_configure/op_store.rs +++ b/crates/zkwasm/src/circuits/etable/op_configure/op_store.rs @@ -12,7 +12,7 @@ use crate::circuits::mtable::utils::WASM_BLOCK_BYTE_SIZE; use crate::circuits::rtable::pow_table_power_encode; use crate::circuits::utils::bn_to_field; use crate::circuits::utils::step_status::StepStatus; -use crate::circuits::utils::table_entry::EventTableEntryWithMemoryInfo; +use specs::etable::EventTableEntryWithMemoryInfo; use crate::circuits::utils::Context; use crate::constant; use crate::constant_from; diff --git a/crates/zkwasm/src/circuits/etable/op_configure/op_test.rs b/crates/zkwasm/src/circuits/etable/op_configure/op_test.rs index 1a239ab85..01eef38f3 100644 --- a/crates/zkwasm/src/circuits/etable/op_configure/op_test.rs +++ b/crates/zkwasm/src/circuits/etable/op_configure/op_test.rs @@ -6,7 +6,7 @@ use crate::circuits::etable::EventTableOpcodeConfig; use crate::circuits::etable::EventTableOpcodeConfigBuilder; use crate::circuits::utils::bn_to_field; use crate::circuits::utils::step_status::StepStatus; -use crate::circuits::utils::table_entry::EventTableEntryWithMemoryInfo; +use specs::etable::EventTableEntryWithMemoryInfo; use crate::circuits::utils::Context; use crate::constant; use crate::constant_from; diff --git a/crates/zkwasm/src/circuits/etable/op_configure/op_unary.rs b/crates/zkwasm/src/circuits/etable/op_configure/op_unary.rs index 295764fd7..323b304be 100644 --- a/crates/zkwasm/src/circuits/etable/op_configure/op_unary.rs +++ b/crates/zkwasm/src/circuits/etable/op_configure/op_unary.rs @@ -8,7 +8,7 @@ use crate::circuits::etable::EventTableOpcodeConfigBuilder; use crate::circuits::rtable::pow_table_power_encode; use crate::circuits::utils::bn_to_field; use crate::circuits::utils::step_status::StepStatus; -use crate::circuits::utils::table_entry::EventTableEntryWithMemoryInfo; +use specs::etable::EventTableEntryWithMemoryInfo; use crate::circuits::utils::Context; use crate::constant; use crate::constant_from; diff --git a/crates/zkwasm/src/circuits/mtable/assign.rs b/crates/zkwasm/src/circuits/mtable/assign.rs index c799cb5c6..cb7db259c 100644 --- a/crates/zkwasm/src/circuits/mtable/assign.rs +++ b/crates/zkwasm/src/circuits/mtable/assign.rs @@ -9,12 +9,12 @@ use specs::encode::init_memory_table::encode_init_memory_table_entry; use specs::encode::memory_table::encode_memory_table_entry; use specs::imtable::InitMemoryTable; use specs::mtable::LocationType; +use specs::mtable::MemoryWritingTable; use specs::mtable::VarType; use crate::circuits::cell::CellExpression; use crate::circuits::mtable::MemoryTableChip; use crate::circuits::utils::bn_to_field; -use crate::circuits::utils::table_entry::MemoryWritingTable; use crate::circuits::utils::Context; use super::MEMORY_TABLE_ENTRY_ROWS; diff --git a/crates/zkwasm/src/circuits/mtable/mod.rs b/crates/zkwasm/src/circuits/mtable/mod.rs index fabe522aa..0260fe6a4 100644 --- a/crates/zkwasm/src/circuits/mtable/mod.rs +++ b/crates/zkwasm/src/circuits/mtable/mod.rs @@ -39,10 +39,12 @@ pub struct MemoryTableConfig { is_i64_cell: AllocatedBitCell, is_init_cell: AllocatedBitCell, + // FIXME: U32 if continuation start_eid_cell: AllocatedCommonRangeCell, end_eid_cell: AllocatedCommonRangeCell, eid_diff_cell: AllocatedCommonRangeCell, rest_mops_cell: AllocatedCommonRangeCell, + // FIXME: U32 if continuation offset_align_left: AllocatedCommonRangeCell, offset_align_right: AllocatedCommonRangeCell, offset_align_left_diff_cell: AllocatedCommonRangeCell, diff --git a/crates/zkwasm/src/circuits/test_circuit/mod.rs b/crates/zkwasm/src/circuits/test_circuit/mod.rs index 4265f4083..45fe9a107 100644 --- a/crates/zkwasm/src/circuits/test_circuit/mod.rs +++ b/crates/zkwasm/src/circuits/test_circuit/mod.rs @@ -11,6 +11,8 @@ use halo2_proofs::plonk::ConstraintSystem; use halo2_proofs::plonk::Error; use halo2_proofs::plonk::Fixed; use log::debug; +use specs::etable::EventTableWithMemoryInfo; +use specs::mtable::MemoryWritingTable; use specs::CompilationTable; use specs::ExecutionTable; use specs::Tables; @@ -33,8 +35,6 @@ use crate::circuits::post_image_table::PostImageTableConfig; use crate::circuits::post_image_table::PostImageTableConfigTrait; use crate::circuits::rtable::RangeTableChip; use crate::circuits::rtable::RangeTableConfig; -use crate::circuits::utils::table_entry::EventTableWithMemoryInfo; -use crate::circuits::utils::table_entry::MemoryWritingTable; use crate::circuits::utils::Context; use crate::circuits::TestCircuit; use crate::exec_with_profile; @@ -52,7 +52,7 @@ use super::config::zkwasm_k; use super::image_table::ImageTableConfig; pub const VAR_COLUMNS: usize = if cfg!(feature = "continuation") { - 53 + 61 } else { 51 }; @@ -225,14 +225,22 @@ impl Circuit for TestCircuit { |region| { let mut ctx = Context::new(region); - let memory_writing_table: MemoryWritingTable = - self.tables.create_memory_table(memory_event_of_step).into(); + let memory_writing_table: MemoryWritingTable = self + .tables + .execution_tables + .etable + .create_memory_table( + &self.tables.compilation_tables.imtable, + memory_event_of_step, + ) + .into(); let etable = exec_with_profile!( || "Prepare memory info for etable", EventTableWithMemoryInfo::new( &self.tables.execution_tables.etable, &memory_writing_table, + memory_event_of_step, ) ); @@ -271,7 +279,7 @@ impl Circuit for TestCircuit { jchip.assign( &mut ctx, &self.tables.execution_tables.jtable, - etable_permutation_cells.rest_jops, + etable_permutation_cells.total_jops, &self.tables.compilation_tables.static_jtable, )? ) diff --git a/crates/zkwasm/src/circuits/utils/table_entry.rs b/crates/zkwasm/src/circuits/utils/table_entry.rs index ca400e374..4f490e304 100644 --- a/crates/zkwasm/src/circuits/utils/table_entry.rs +++ b/crates/zkwasm/src/circuits/utils/table_entry.rs @@ -14,173 +14,173 @@ use std::path::PathBuf; use crate::circuits::config::zkwasm_k; use crate::runtime::memory_event_of_step; -#[derive(Clone, Debug, Serialize)] -pub(in crate::circuits) struct MemoryWritingEntry { - index: usize, - pub(in crate::circuits) entry: MemoryTableEntry, - pub(in crate::circuits) end_eid: u32, -} - -impl MemoryWritingEntry { - fn is_same_memory_address(&self, other: &Self) -> bool { - self.entry.is_same_location(&other.entry) - } -} - -#[derive(Debug, Serialize)] -pub struct MemoryWritingTable(pub(in crate::circuits) Vec); - -impl From for MemoryWritingTable { - fn from(value: MTable) -> Self { - let maximal_eid = (1u32 << (zkwasm_k() - 1)) - 1; - let mut index = 0; - - let mut entries: Vec = value - .entries() - .iter() - .filter_map(|entry| { - if entry.atype != AccessType::Read { - let entry = Some(MemoryWritingEntry { - index, - entry: entry.clone(), - end_eid: maximal_eid, - }); - - index += 1; - - entry - } else { - None - } - }) - .collect(); - - let entries_next = entries.clone(); - let next_iter = entries_next.iter().skip(1); - - entries.iter_mut().zip(next_iter).for_each(|(curr, next)| { - if curr.is_same_memory_address(next) { - curr.end_eid = next.entry.eid; - } - }); - - MemoryWritingTable(entries) - } -} - -impl MemoryWritingTable { - // (location, offset) |-> Vec<(start_eid, end_eid)> - fn build_lookup_mapping(&self) -> BTreeMap<(LocationType, u32), Vec<(u32, u32)>> { - let mut mapping = BTreeMap::<_, Vec<(u32, u32)>>::new(); - - for entry in &self.0 { - let ltype = entry.entry.ltype; - let offset = entry.entry.offset; - let start_eid = entry.entry.eid; - let end_eid = entry.end_eid; - - if let Some(entries) = mapping.get_mut(&(ltype, offset)) { - entries.push((start_eid, end_eid)); - } else { - mapping.insert((ltype, offset), vec![(start_eid, end_eid)]); - } - } - - mapping - } - - pub fn write_json(&self, dir: Option) { - fn write_file(folder: &PathBuf, filename: &str, buf: &String) { - let mut folder = folder.clone(); - folder.push(filename); - let mut fd = std::fs::File::create(folder.as_path()).unwrap(); - folder.pop(); - - fd.write(buf.as_bytes()).unwrap(); - } - - let mtable = serde_json::to_string(self).unwrap(); - - let dir = dir.unwrap_or(env::current_dir().unwrap()); - write_file(&dir, "memory_writing_table.json", &mtable); - } -} - -#[derive(Debug)] -pub struct MemoryRWEntry { - pub entry: MemoryTableEntry, - pub start_eid: u32, - pub end_eid: u32, -} - -#[derive(Debug)] -pub struct EventTableEntryWithMemoryInfo<'a> { - pub eentry: &'a EventTableEntry, - pub memory_rw_entires: Vec, -} - -#[derive(Debug)] -pub(crate) struct EventTableWithMemoryInfo<'a>( - pub(in crate::circuits) Vec>, -); - -impl<'a> EventTableWithMemoryInfo<'a> { - pub(in crate::circuits) fn new( - event_table: &'a EventTable, - memory_writing_table: &MemoryWritingTable, - ) -> Self { - let lookup = memory_writing_table.build_lookup_mapping(); - - let lookup_mtable_eid = |(eid, ltype, offset, is_writing)| { - let records = lookup.get(&(ltype, offset)).unwrap(); - - if is_writing { - let idx = records - .binary_search_by(|(start_eid, _)| start_eid.cmp(eid)) - .unwrap(); - records[idx] - } else { - println!("lookup eid: {}", eid); - let idx = records - .binary_search_by(|(start_eid, end_eid)| { - if eid <= start_eid { - Ordering::Greater - } else if eid > end_eid { - Ordering::Less - } else { - Ordering::Equal - } - }) - .unwrap(); - records[idx] - } - }; - - EventTableWithMemoryInfo( - event_table - .entries() - .iter() - .map(|eentry| EventTableEntryWithMemoryInfo { - eentry: &eentry, - memory_rw_entires: memory_event_of_step(eentry, &mut 1) - .into_iter() - .map(|mentry| { - let (start_eid, end_eid) = lookup_mtable_eid(( - &eentry.eid, - mentry.ltype, - mentry.offset, - mentry.atype == AccessType::Write, - )); - - MemoryRWEntry { - entry: mentry, - start_eid, - end_eid, - } - }) - .collect(), - }) - .collect(), - ) - } -} +// #[derive(Clone, Debug, Serialize)] +// pub(in crate::circuits) struct MemoryWritingEntry { +// index: usize, +// pub(in crate::circuits) entry: MemoryTableEntry, +// pub(in crate::circuits) end_eid: u32, +// } + +// impl MemoryWritingEntry { +// fn is_same_memory_address(&self, other: &Self) -> bool { +// self.entry.is_same_location(&other.entry) +// } +// } + +// #[derive(Debug, Serialize)] +// pub struct MemoryWritingTable(pub(in crate::circuits) Vec); + +// impl From for MemoryWritingTable { +// fn from(value: MTable) -> Self { +// let mut index = 0; + +// let mut entries: Vec = value +// .0 +// .into_iter() +// .filter_map(|entry| { +// if entry.atype != AccessType::Read { +// let entry = Some(MemoryWritingEntry { +// index, +// entry, +// end_eid: u32::MAX, +// }); + +// index += 1; + +// entry +// } else { +// None +// } +// }) +// .collect(); + +// let entries_next = entries.clone(); +// let next_iter = entries_next.iter().skip(1); + +// entries.iter_mut().zip(next_iter).for_each(|(curr, next)| { +// if curr.is_same_memory_address(next) { +// curr.end_eid = next.entry.eid; +// } +// }); + +// MemoryWritingTable(entries) +// } +// } + +// impl MemoryWritingTable { +// // (location, offset) |-> Vec<(start_eid, end_eid)> +// fn build_lookup_mapping(&self) -> BTreeMap<(LocationType, u32), Vec<(u32, u32)>> { +// let mut mapping = BTreeMap::<_, Vec<(u32, u32)>>::new(); + +// for entry in &self.0 { +// let ltype = entry.entry.ltype; +// let offset = entry.entry.offset; +// let start_eid = entry.entry.eid; +// let end_eid = entry.end_eid; + +// if let Some(entries) = mapping.get_mut(&(ltype, offset)) { +// entries.push((start_eid, end_eid)); +// } else { +// mapping.insert((ltype, offset), vec![(start_eid, end_eid)]); +// } +// } + +// mapping +// } + +// pub fn write_json(&self, dir: Option) { +// fn write_file(folder: &PathBuf, filename: &str, buf: &String) { +// let mut folder = folder.clone(); +// folder.push(filename); +// let mut fd = std::fs::File::create(folder.as_path()).unwrap(); +// folder.pop(); + +// fd.write(buf.as_bytes()).unwrap(); +// } + +// let mtable = serde_json::to_string(self).unwrap(); + +// let dir = dir.unwrap_or(env::current_dir().unwrap()); +// write_file(&dir, "memory_writing_table.json", &mtable); +// } +// } + +// #[derive(Debug)] +// pub struct MemoryRWEntry { +// pub entry: MemoryTableEntry, +// pub start_eid: u32, +// pub end_eid: u32, +// } + +// #[derive(Debug)] +// pub struct EventTableEntryWithMemoryInfo<'a> { +// pub eentry: &'a EventTableEntry, +// pub memory_rw_entires: Vec, +// } + +// #[derive(Debug)] +// pub(crate) struct EventTableWithMemoryInfo<'a>( +// pub(in crate::circuits) Vec>, +// ); + +// impl<'a> EventTableWithMemoryInfo<'a> { +// pub(in crate::circuits) fn new( +// event_table: &'a EventTable, +// memory_writing_table: &MemoryWritingTable, +// ) -> Self { +// let lookup = memory_writing_table.build_lookup_mapping(); + +// let lookup_mtable_eid = |(eid, ltype, offset, is_writing)| { +// println!("ltyp: {:?}, offset: {}", ltype, offset); +// let records = lookup.get(&(ltype, offset)).unwrap(); + +// if is_writing { +// let idx = records +// .binary_search_by(|(start_eid, _)| start_eid.cmp(eid)) +// .unwrap(); +// records[idx] +// } else { +// println!("lookup eid: {}", eid); +// let idx = records +// .binary_search_by(|(start_eid, end_eid)| { +// if eid <= start_eid { +// Ordering::Greater +// } else if eid > end_eid { +// Ordering::Less +// } else { +// Ordering::Equal +// } +// }) +// .unwrap(); +// records[idx] +// } +// }; + +// EventTableWithMemoryInfo( +// event_table +// .entries() +// .iter() +// .map(|eentry| EventTableEntryWithMemoryInfo { +// eentry, +// memory_rw_entires: memory_event_of_step(eentry, &mut 1) +// .into_iter() +// .map(|mentry| { +// let (start_eid, end_eid) = lookup_mtable_eid(( +// &eentry.eid, +// mentry.ltype, +// mentry.offset, +// mentry.atype == AccessType::Write, +// )); + +// MemoryRWEntry { +// entry: mentry, +// start_eid, +// end_eid, +// } +// }) +// .collect(), +// }) +// .collect(), +// ) +// } +// } diff --git a/crates/zkwasm/src/continuation/slice.rs b/crates/zkwasm/src/continuation/slice.rs index 50223758c..7485d2ddb 100644 --- a/crates/zkwasm/src/continuation/slice.rs +++ b/crates/zkwasm/src/continuation/slice.rs @@ -1,6 +1,7 @@ use halo2_proofs::arithmetic::FieldExt; use specs::etable::EventTable; use specs::etable::EventTableEntry; +use specs::mtable::MemoryWritingTable; use specs::CompilationTable; use specs::ExecutionTable; use specs::InitializationState; @@ -8,6 +9,7 @@ use specs::Tables; use crate::circuits::TestCircuit; use crate::circuits::ZkWasmCircuitBuilder; +use crate::runtime::memory_event_of_step; use crate::runtime::state::simulate_execution; pub struct Slice { @@ -32,6 +34,8 @@ pub struct Slices { capability: usize, origin_table: Tables, + // used to build post imtable + full_memory_writing_table: MemoryWritingTable, } impl Slices { @@ -42,6 +46,11 @@ impl Slices { } pub fn new(table: Tables, capability: usize) -> Self { + let full_memory_writing_table = table + .execution_tables + .etable + .create_memory_table(&table.compilation_tables.imtable, memory_event_of_step) + .into(); let remaining_etable_entries = table.execution_tables.etable.entries().clone(); Self { @@ -49,6 +58,7 @@ impl Slices { capability, current_compilation_table: table.compilation_tables.clone(), origin_table: table, + full_memory_writing_table, } } } @@ -68,7 +78,14 @@ impl Iterator for Slices { let is_last_slice = self.remaining_etable_entries.is_empty(); - let post_state = simulate_execution(&self.current_compilation_table, &execution_tables); + let post_state = simulate_execution( + &self.current_compilation_table, + &execution_tables, + &self.full_memory_writing_table, + memory_event_of_step, + ); + + // println!("{:?}", post_state); let post_image_table = CompilationTable { itable: self.origin_table.compilation_tables.itable.clone(), diff --git a/crates/zkwasm/src/foreign/context/etable_op_configure.rs b/crates/zkwasm/src/foreign/context/etable_op_configure.rs index 7c427abbe..2d88099de 100644 --- a/crates/zkwasm/src/foreign/context/etable_op_configure.rs +++ b/crates/zkwasm/src/foreign/context/etable_op_configure.rs @@ -4,6 +4,7 @@ use halo2_proofs::plonk::Expression; use halo2_proofs::plonk::VirtualCells; use num_bigint::BigUint; use specs::etable::EventTableEntry; +use specs::etable::EventTableEntryWithMemoryInfo; use specs::host_function::HostPlugin; use specs::itable::OpcodeClass; use specs::itable::OPCODE_CLASS_SHIFT; @@ -21,7 +22,6 @@ use crate::circuits::etable::EventTableCommonConfig; use crate::circuits::etable::EventTableOpcodeConfig; use crate::circuits::utils::bn_to_field; use crate::circuits::utils::step_status::StepStatus; -use crate::circuits::utils::table_entry::EventTableEntryWithMemoryInfo; use crate::circuits::utils::Context; use crate::constant; use crate::constant_from; diff --git a/crates/zkwasm/src/foreign/require_helper/etable_op_configure.rs b/crates/zkwasm/src/foreign/require_helper/etable_op_configure.rs index 9499d82f2..eedc39ed2 100644 --- a/crates/zkwasm/src/foreign/require_helper/etable_op_configure.rs +++ b/crates/zkwasm/src/foreign/require_helper/etable_op_configure.rs @@ -3,6 +3,7 @@ use halo2_proofs::plonk::Error; use halo2_proofs::plonk::Expression; use halo2_proofs::plonk::VirtualCells; use num_bigint::BigUint; +use specs::etable::EventTableEntryWithMemoryInfo; use specs::itable::OpcodeClass; use specs::itable::OPCODE_CLASS_SHIFT; use specs::mtable::LocationType; @@ -18,7 +19,6 @@ use crate::circuits::etable::EventTableCommonConfig; use crate::circuits::etable::EventTableOpcodeConfig; use crate::circuits::utils::bn_to_field; use crate::circuits::utils::step_status::StepStatus; -use crate::circuits::utils::table_entry::EventTableEntryWithMemoryInfo; use crate::circuits::utils::Context; use crate::constant_from; use crate::constant_from_bn; diff --git a/crates/zkwasm/src/foreign/wasm_input_helper/etable_op_configure.rs b/crates/zkwasm/src/foreign/wasm_input_helper/etable_op_configure.rs index 0f6f0fa92..2856ea14f 100644 --- a/crates/zkwasm/src/foreign/wasm_input_helper/etable_op_configure.rs +++ b/crates/zkwasm/src/foreign/wasm_input_helper/etable_op_configure.rs @@ -4,6 +4,7 @@ use halo2_proofs::plonk::Expression; use halo2_proofs::plonk::VirtualCells; use num_bigint::BigUint; use specs::etable::EventTableEntry; +use specs::etable::EventTableEntryWithMemoryInfo; use specs::host_function::HostPlugin; use specs::itable::OpcodeClass; use specs::itable::OPCODE_CLASS_SHIFT; @@ -25,7 +26,6 @@ use crate::circuits::etable::EventTableCommonConfig; use crate::circuits::etable::EventTableOpcodeConfig; use crate::circuits::utils::bn_to_field; use crate::circuits::utils::step_status::StepStatus; -use crate::circuits::utils::table_entry::EventTableEntryWithMemoryInfo; use crate::circuits::utils::Context; use crate::constant_from; use crate::constant_from_bn; diff --git a/crates/zkwasm/src/runtime/state.rs b/crates/zkwasm/src/runtime/state.rs index bfaee921f..2c4b3bdb8 100644 --- a/crates/zkwasm/src/runtime/state.rs +++ b/crates/zkwasm/src/runtime/state.rs @@ -1,14 +1,108 @@ +use std::collections::BTreeMap; + +use specs::etable::EventTable; +use specs::etable::EventTableEntry; +use specs::etable::EventTableWithMemoryInfo; use specs::host_function::HostPlugin; use specs::imtable::InitMemoryTable; +use specs::imtable::InitMemoryTableEntry; use specs::itable::Opcode; +use specs::mtable::LocationType; +use specs::mtable::MemoryTableEntry; +use specs::mtable::MemoryWritingTable; use specs::step::StepInfo; use specs::CompilationTable; use specs::ExecutionTable; use specs::InitializationState; +pub fn update( + raw_init_memory_table: &InitMemoryTable, + execution_table: &EventTable, + // must be consistent for all slices + full_memory_writing_table: &MemoryWritingTable, + memory_event_of_step: fn(&EventTableEntry, &mut u32) -> Vec, +) -> InitMemoryTable { + let mut local_map = BTreeMap::::new(); + let mut global_map = BTreeMap::::new(); + let mut memory_map = BTreeMap::::new(); + + // First insert imtable entries which may be overwritten. + for entry in raw_init_memory_table.entries() { + match entry.ltype { + LocationType::Stack => { + assert_eq!(entry.start_offset, entry.end_offset); + + local_map.insert(entry.start_offset, entry.clone()); + } + LocationType::Heap => { + for offset in entry.start_offset..=entry.end_offset { + memory_map.insert( + offset, + InitMemoryTableEntry { + ltype: entry.ltype, + is_mutable: entry.is_mutable, + start_offset: offset, + end_offset: offset, + vtype: entry.vtype, + value: entry.value, + + start_eid: entry.start_eid, + end_eid: entry.end_eid, + }, + ); + } + } + LocationType::Global => { + assert_eq!(entry.start_offset, entry.end_offset); + + global_map.insert(entry.start_offset, entry.clone()); + } + } + } + + let event_table = EventTableWithMemoryInfo::new( + execution_table, + full_memory_writing_table, + memory_event_of_step, + ); + + for etable_entry in event_table.0 { + for mentry in etable_entry.memory_rw_entires { + let map = match mentry.entry.ltype { + LocationType::Stack => &mut local_map, + LocationType::Heap => &mut memory_map, + LocationType::Global => &mut global_map, + }; + + map.insert( + mentry.entry.offset, + InitMemoryTableEntry { + ltype: mentry.entry.ltype, + is_mutable: mentry.entry.is_mutable, + start_offset: mentry.entry.offset, + end_offset: mentry.entry.offset, + vtype: mentry.entry.vtype, + value: mentry.entry.value, + start_eid: mentry.start_eid, + end_eid: mentry.end_eid, + }, + ); + } + } + + let mut init_memory_entries = vec![]; + init_memory_entries.append(&mut local_map.into_iter().map(|(_, v)| v).collect::>()); + init_memory_entries.append(&mut global_map.into_iter().map(|(_, v)| v).collect::>()); + init_memory_entries.append(&mut memory_map.into_iter().map(|(_, v)| v).collect::>()); + + InitMemoryTable::new(init_memory_entries) +} + pub fn simulate_execution( compilation_table: &CompilationTable, execution_table: &ExecutionTable, + full_memory_writing_table: &MemoryWritingTable, + memory_event_of_step: fn(&EventTableEntry, &mut u32) -> Vec, ) -> (InitMemoryTable, InitializationState) { let mut host_public_inputs = compilation_table.initialization_state.host_public_inputs; let mut context_in_index = compilation_table.initialization_state.context_in_index; @@ -80,6 +174,13 @@ pub fn simulate_execution( jops, }; - // FIXME: update imtable - (compilation_table.imtable.clone(), post_initialization_state) + ( + update( + &compilation_table.imtable, + &execution_table.etable, + full_memory_writing_table, + memory_event_of_step, + ), + post_initialization_state, + ) } diff --git a/crates/zkwasm/src/runtime/wasmi_interpreter.rs b/crates/zkwasm/src/runtime/wasmi_interpreter.rs index 82d19aab1..548229c3c 100644 --- a/crates/zkwasm/src/runtime/wasmi_interpreter.rs +++ b/crates/zkwasm/src/runtime/wasmi_interpreter.rs @@ -15,8 +15,7 @@ use wasmi::ModuleInstance; use wasmi::RuntimeValue; use wasmi::DEFAULT_VALUE_STACK_LIMIT; -use crate::circuits::config::zkwasm_k; - +use super::memory_event_of_step; use super::state::simulate_execution; use super::CompiledImage; use super::ExecutionResult; @@ -79,8 +78,15 @@ impl Execution }; let post_image_table = { - let (imtable, initialization_state) = - simulate_execution(&self.tables, &execution_tables); + let (imtable, initialization_state) = simulate_execution( + &self.tables, + &execution_tables, + &(execution_tables + .etable + .create_memory_table(&self.tables.imtable, memory_event_of_step) + .into()), + memory_event_of_step, + ); CompilationTable { itable: self.tables.itable.clone(), @@ -165,7 +171,7 @@ impl WasmiRuntime { }; let itable = tracer.borrow().itable.clone(); - let imtable = tracer.borrow().imtable.finalized(zkwasm_k()); + let imtable = tracer.borrow().imtable.finalized(); let elem_table = tracer.borrow().elem_table.clone(); let configure_table = tracer.borrow().configure_table.clone(); let static_jtable = tracer.borrow().static_jtable_entries.clone(); diff --git a/third-party/wasmi b/third-party/wasmi index 69e58bf87..09d5fda65 160000 --- a/third-party/wasmi +++ b/third-party/wasmi @@ -1 +1 @@ -Subproject commit 69e58bf87a598b98e6fba71606343321bd551395 +Subproject commit 09d5fda6564960e30b067eea9c3f0d06e4023c46