Aspect WASM Instrumentation Library
The Aspect WASM Instrumentation Library, utilizing wasm-instrument from Parity, is designed to instrument Artela Aspect WebAssembly (WASM) files. It seamlessly adds gas metering functionality and ensures corresponding validation, enhancing the execution efficiency and reliability of your WebAssembly applications.
Supported Platforms
The library is currently compatible with multiple operating systems across different architectures:
- Linux: Arm64, x86_64
- MacOS: Arm64, x86_64
- Windows: x86_64
Functionality
This library meticulously parses a given WASM file, injecting a gas counter as a global variable. Additionally, it integrates gas metering code into each designated code section, positioning it at the outset of the section body.
Furthermore, the library facilitates the export of both the gas counter and the start section of the WASM bytecode. These are exported as __gas_counter__ and __aspect_start__, respectively. It is crucial to initialize the gas counter prior to executing the start section to avoid execution failures.
Before and After Instrumentation
- Original WASM Code Snippet:
# Original wasm code
(;;)) ())
)
- Post-Instrumentation Code Snippet:
(;;)) ())
# Gas consumption for the section
# Consuming gas
# Executing original code
)
# Gas metering logic
(;;)) ()
if
else
)
# Global gas counter
(;;)) )
# Exported start section
()
# Gas counter alias
()
Building the Library
To compile for your current platform, run:
For compiling across all supported platforms, ensure the respective cross-compilers are installed:
For a specific platform build, such as Darwin Arm64, execute:
Build artifacts are located in target/{platform}/release directory, with a dedicated directory target/release for the current platform build.
Available Libraries
The build process generates three types of libraries to suit various project requirements:
- Static Library:
libaspect_wasm_instrument.a - Dynamic Library:
libaspect_wasm_instrument.so,libaspect_wasm_instrument.dylib,libaspect_wasm_instrument.dll - Rust Library:
aspect_wasm_instrument.rlib
Current Limitations
Some features are not yet supported due to the constraints of the underlying wasm-instrument library, including but not limited to:
- Bulk memory operations
- Reference types
- ...
Stay tuned for future updates as we continue to enhance this library's capabilities and compatibility.