Skip to content

Add a WebAssembly API #2853

@turbolent

Description

@turbolent

Issue to be solved

As discussed in https://forum.onflow.org/t/idea-wasm-execution-engine-in-cadence/5164, add an API to Cadence that allows running WebAssembly programs.

Suggested Solution

An MVP should be able to:

  • Instantiate a WebAssembly module, without imports (i.e. the WebAssembly module has no access to Cadence)
  • Support function exports, where argument and return value types are i32 or i64 (i.e., not f32 or f64)
  • Allow calling such function exports from Cadence, and returning the result back to Cadence
  • Properly meter execution and abort execution if a given limit is reached. This requires defining how WebAssembly execution is metered in terms of the Cadence transaction's computation metering.

#2760 is a PoC implementation of the above. Remaining tasks:

### Tasks
- [x] Wrap user-errors produced by WebAssembly VM as Cadence user errors. Requires defining abstract user errors that are VM-agnostic. Define in `interpreter/errors.go`, as `errors.UserError`
- [x] Meter module instantiation, in terms of computation and memory. Requires getting remaining computation units and translating it
- [ ] Define Limits
- [ ] Validation?
- [ ] Tests

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions