Skip to content

Metering for Bulk Memory Opcodes + Opcode Version - #79

Merged
andrei-marinica merged 47 commits into
masterfrom
mem-ops-wasm
Oct 9, 2026
Merged

andrei-marinica merged 47 commits into
masterfrom
mem-ops-wasm

Conversation

@laurci

@laurci laurci commented Jul 21, 2025 •

Copy link
Copy Markdown

Bulk memory opcodes and versioned opcode configuration

Summary

This PR adds support for WebAssembly bulk-memory operations and makes opcode configuration explicitly versioned across the Rust and C APIs.

  • Add OpcodeVersion and OpcodeConfig; V1 remains the default legacy opcode set, while V2 enables memory.copy and memory.fill.
  • Remove unsupported exception-handling, reference-type, and table-manipulation instructions from the V2 whitelist. memory.init and data.drop remain unsupported.
  • Meter bulk-memory operations in both the production Wasmer executor and the experimental executor with independent base and per-byte costs for copy and fill.
  • Refactor opcode-cost handling into dedicated shared structures and replace the former opcode-usage mechanism.
  • Harden the C ABI with explicit repr(C) mirrors for compilation options and opcode costs, and replace vm_exec_set_opcode_costs with version-aware vm_exec_set_opcode_config.
  • Regenerate VM hooks, remove the retired hook entries, and update the Rust toolchain to 1.98.

Gas accounting

For both memory.copy and memory.fill, the charged gas is:

base_cost + (byte_count * per_byte_cost)

The base cost applies to zero-byte operations as well. The instrumentation preserves the size operand on the WebAssembly stack.

Compatibility

  • Existing users remain on OpcodeVersion::V1 by default and cannot instantiate modules that use bulk-memory operations.
  • Consumers that need memory.copy or memory.fill must configure OpcodeVersion::V2 with the corresponding opcode costs.
  • C API consumers must migrate from vm_exec_set_opcode_costs to vm_exec_set_opcode_config, passing the opcode-version code and the ABI-safe opcode-cost structure.

Tests

  • Add production and experimental executor tests covering base costs, per-byte costs, zero-byte operations, and preservation of a local size operand.
  • Add an opcode-version test confirming that a memory.copy module is rejected by V1 and accepted by V2.

@laurci
laurci changed the base branch from rc/v1.7.2 to rc/after-supernova August 20, 2025 07:27
@laurci
laurci marked this pull request as ready for review August 20, 2025 07:27
Comment thread vm-executor-wasmer/src/wasmer_metering_helpers.rs Outdated
Comment thread vm-executor-wasmer/src/wasmer_metering_helpers.rs Outdated
Comment thread vm-executor/src/opcode_check_used.rs Outdated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Critical metering correctness, cache enforcement, import compatibility, and public ABI regressions remain unresolved.

Get a fresh assessment by requesting another Copilot review.

Review effort: Balanced
Findings: 8 High severity

Open (8)

Comment thread c-api/libvmexeccapi.h
Comment thread c-api/libvmexeccapi.h Outdated
Comment thread c-api/src/capi_vm_hook_pointers.rs
Comment thread vm-executor-wasmer/src/wasmer_imports.rs
Comment thread vm-executor-wasmer/src/wasmer_instance.rs
Comment thread vm-executor-wasmer/src/wasmer_metering.rs
Comment thread vm-executor-wasmer/src/wasmer_metering.rs
Comment thread vm-executor/src/vm_hooks.rs Outdated
@andrei-marinica andrei-marinica changed the title add metering for bulk memory opcodes Metering for Bulk Memory Opcodes + Opcode Version Sep 28, 2026
@andrei-marinica
andrei-marinica changed the base branch from rc/after-supernova to master September 29, 2026 16:58
@andrei-marinica
andrei-marinica marked this pull request as draft September 29, 2026 18:25
@andrei-marinica
andrei-marinica marked this pull request as ready for review October 9, 2026 12:32
@andrei-marinica
andrei-marinica merged commit 08316a9 into master Oct 9, 2026
7 checks passed
@andrei-marinica
andrei-marinica deleted the mem-ops-wasm branch October 9, 2026 12:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants