dtvm-instrument

Crates.iodtvm-instrument
lib.rsdtvm-instrument
version0.1.0
created_at2025-08-18 14:13:21.659018+00
updated_at2025-08-18 14:13:21.659018+00
descriptionInstrument and transform wasm modules.
homepage
repositoryhttps://github.com/XuHugo/dtvm-instrument
max_upload_size
id1800527
size40,426
Kent (XuHugo)

documentation

README

dtvm-instrument

This Rust library, which is for the Rust crate of dtvm, implements a gas metering function.

Gas Metering

Add gas metering to your platform by injecting the necessary code directly into the wasm module. This is only suitable for DTVM.

DTVM has built-in optimized support for the gas mechanism (using CPU registers to save gas instead of memory as much as possible during execution), which is built into DTVM's JIT compiler. This mechanism has a few requirements for gas: 1. The gas function actually requires the gas-meter to add an empty export function __instrumented_use_gas (with an int64 parameter) at the end of the converted wasm module, rather than having a special host API. 2. The original wasm module needs to not use the __instrumented_use_gas export function name. Then DTVM's JIT compiler optimizes this stub function during the compilation phase to use CPU registers to save gas update and check instructions.

Within DTVM, using our method, gas update checks require only about two CPU instructions in most scenarios, and these are all register-based operations. Compared to maintaining gas in memory or through host APIs, the performance cost is much lower. Because WASM basic blocks are actually quite numerous and gas operations are frequent, a high-performance gas mechanism is still very meaningful.

License

LICENSE-MIT.

Commit count: 0

cargo fmt