#gas #unc #contracts #run-time #smart-contracts #execution #blockchain


This crate implements the specification of the interface that unc blockchain exposes to the smart contracts

12 releases (5 breaking)

new 0.10.2 May 15, 2024
0.10.0 May 8, 2024
0.7.3 Apr 12, 2024
0.7.0 Mar 29, 2024
0.1.0 Mar 6, 2024

#1969 in Magic Beans

Download history 135/week @ 2024-03-01 360/week @ 2024-03-08 287/week @ 2024-03-15 96/week @ 2024-03-22 189/week @ 2024-03-29 427/week @ 2024-04-05 276/week @ 2024-04-12 10/week @ 2024-04-19 2/week @ 2024-04-26 132/week @ 2024-05-03 174/week @ 2024-05-10

405 downloads per month
Used in 16 crates (2 directly)


26K SLoC


An engine that runs smart contracts compiled to Wasm. This is the main crate of the "contract runtime" part of framework.

"Running smart contracts" is:

  • Wasm instrumentation for gas metering and various safety checks (prepare.rs).
  • Compiling Wasm to a particular VM representation (cache.rs).
  • Exposing blockchain-specific functionality to Wasm code. That is, defining a corresponding host function for each function in unc-vm-logic (imports.rs).
  • Actual code execution (wasmer_runner.rs).

The particular runtime used for Wasm execution is an implementation detail. At the moment we support Wasmer 0.x, Wasmer 2.0 and Wasmtime, with Wasmer 2.0 being default.

The primary client of Wasm execution services is the blockchain proper. The second client is the contract sdk tooling. vm-runner provides additional API for contract developers to, for example, get a gas costs breakdown.

See the [FAQ][./faq.md] document for high-level design constraints discussion.

Entry Point

The entry point is the runner::run function.


There are a bunch of unit-tests in this crate. You can run them with

cargo t -p unc-vm-runner --features wasmer0_vm,wasmer2_vm,wasmtime_vm,unc_vm

The tests use either a short wasm snippet specified inline, or a couple of larger test contracts from the unc-test-contracts crate.

We also have a fuzzing setup:

cd runtime/unc-vm-runner && RUSTC_BOOTSTRAP=1 cargo fuzz run runner


tracing crate is used to collect Rust code profile data via manual instrumentation. If you want to know how long a particular function executes, use the following pattern:

fn compute_thing() {
    let _span = tracing::debug_span!(target: "vm", "compute_thing").entered();
    for i in 0..99 {

This will record when the _span object is created and dropped, including the time diff between the two events.

To get human-readable output out of these events, you can use the built-in tracing subscriber:



Alternatively, there's an alternative hierarchical profiler



The result would look like this:

      112.33ms deserialize_wasmer
      2.64ms run_wasmer/instantiate
      96.34µs run_wasmer/call
    123.15ms run_wasmer
  123.17ms run_vm


~681K SLoC