DelphinusLab / zkWasm

Apache License 2.0
479 stars 95 forks source link

feat: add support or workaround for bulk-memory-operations #54

Closed aseaday closed 1 year ago

aseaday commented 1 year ago

Description

We now need to support compiled wasm from assembly script. The assembly script use bulk-memory-operations to implement array in typescript. The Opcode are in 0xfc or 252.

export function test_array(): Array<i32> {
  return [42]
}

which will generate wasm code:

 (func $~lib/rt/__newBuffer (param $0 i32) (param $1 i32) (param $2 i32) (result i32)
  (local $3 i32)
  local.get $0
  local.get $1
  call $~lib/rt/itcms/__new
  local.set $3
  local.get $2
  if
   local.get $3
   local.get $2
   local.get $0
   memory.copy $0 $0 ;; This is what we lacked now!
  end
  local.get $3
 )

We use wasmi and it didn't support bulk-memory-operations. When wasmi run this script, it will throw:

read file from /Users/nullday/Workplace/zkWasm/asctest/array.wasm
thread 'main' panicked at 'failed to load wasm: Validation("Unknown opcode 252")', src/runtime/wasmi_interpreter.rs:51:55
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

we have two ways to solve this problem:

Goal

Pass https://github.com/DelphinusLab/zkWasm/pull/55

lanbones commented 1 year ago

We won't support bulk-memory-operations in short-term because our framework only supports instructions that involves limited memory access. But I would like to have it once I ensure there is no performance issue. Let's first ask user to use --disable bulk-memory and wait for their feedback.

xgaozoyoe commented 1 year ago

Let's close this since a PR for bulk memory support is ready (see https://github.com/DelphinusLab/zkWasm/pull/86)