Skip to content

add metering for bulk memory opcodes - #79

Open
laurci wants to merge 35 commits into
rc/after-supernovafrom
mem-ops-wasm
Open

laurci wants to merge 35 commits into
rc/after-supernovafrom
mem-ops-wasm

Conversation

@laurci

@laurci laurci commented Jul 21, 2025 •

Copy link
Copy Markdown

The implementation is mostly complete, but it needs gas testing.

Also contains opcode versioning.

@andrei-marinica
andrei-marinica marked this pull request as draft July 21, 2025 11:40
@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.

Pull request overview

This PR adds metering support for bulk memory operations (MemoryCopy and MemoryFill) in WebAssembly through an opcode versioning mechanism. The implementation introduces V2 opcodes that include these bulk memory operations, while V1 maintains backward compatibility.

Changes:

  • Introduced opcode versioning (V1/V2) to enable/disable bulk memory operations
  • Added metering for MemoryCopy and MemoryFill with per-byte cost calculation
  • Refactored API from set_opcode_cost to set_opcode_config to include version information

Reviewed changes

Copilot reviewed 25 out of 25 changed files in this pull request and generated 13 comments.

Show a summary per file
File Description
vm-executor/src/opcode_version.rs New enum defining opcode versions V1 and V2 with i32 conversion
vm-executor/src/opcode_config.rs New struct combining opcode version and cost configuration
vm-executor/src/opcode_cost.rs Added cost fields for MemoryCopy and MemoryFill operations
vm-executor/src/lib.rs Exported new OpcodeConfig and OpcodeVersion types
vm-executor/src/executor.rs Updated trait method from set_opcode_cost to set_opcode_config
vm-executor-wasmer/src/wasmer_opcode_cost.rs Split opcode cost logic into V1 and V2 functions, added bulk memory ops to V2
vm-executor-wasmer/src/wasmer_metering.rs Added bulk memory metering with size backup global and per-byte cost injection
vm-executor-wasmer/src/wasmer_helpers.rs Added helper to identify supported bulk memory operators
vm-executor-wasmer/src/wasmer_instance.rs Updated to use OpcodeConfig instead of OpcodeCost
vm-executor-wasmer/src/wasmer_executor.rs Updated executor to use OpcodeConfig with improved error handling
vm-executor-wasmer/src/lib.rs Renamed metering_helpers to opcode_cost module
vm-executor-wasmer/tests/opcode_version_test.rs Added test verifying V1 rejects and V2 accepts bulk memory ops
vm-executor-wasmer/tests/memory-copy.wat Test WAT file demonstrating memory.copy operation
vm-executor-wasmer/Cargo.toml Added std feature to log dependency
vm-executor-experimental/* Updated to use OpcodeConfig (but missing bulk memory metering)
c-api/src/capi_metering.rs Updated C API to accept opcode version parameter
c-api/libvmexeccapi.h Updated C header with new function signature

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread vm-executor-wasmer/src/wasmer_helpers.rs Outdated
Comment thread vm-executor/src/opcode_version.rs
Comment thread vm-executor/src/executor.rs
Comment thread c-api/src/capi_metering.rs Outdated
Comment thread vm-executor-wasmer/src/wasmer_metering.rs Outdated
Comment thread c-api/src/capi_metering.rs Outdated
Comment thread c-api/libvmexeccapi.h Outdated
Comment thread vm-executor-wasmer/src/wasmer_metering.rs Outdated
Comment thread vm-executor-experimental/src/middlewares/we_metering.rs Outdated
Comment thread vm-executor-wasmer/tests/opcode_version_test.rs

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
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