#vm #unit-tests

dev cosmwasm-vm

VM bindings to run cosmwams contracts

57 releases (13 breaking)

new 0.14.0-beta2 Apr 7, 2021
0.14.0-beta1 Mar 9, 2021
0.13.2 Jan 14, 2021
0.12.2 Dec 14, 2020
0.5.1 Nov 29, 2019
Download history 57/week @ 2020-12-19 9/week @ 2020-12-26 158/week @ 2021-01-02 141/week @ 2021-01-09 154/week @ 2021-01-16 214/week @ 2021-01-23 116/week @ 2021-01-30 265/week @ 2021-02-06 454/week @ 2021-02-13 135/week @ 2021-02-20 138/week @ 2021-02-27 194/week @ 2021-03-06 332/week @ 2021-03-13 271/week @ 2021-03-20 250/week @ 2021-03-27 242/week @ 2021-04-03

927 downloads per month
Used in less than 10 crates


15K SLoC

CosmWasm VM

cosmwasm-vm on crates.io

This is an abstraction layer around the wasmer VM to expose just what we need to run cosmwasm contracts in a high-level manner. This is intended both for efficient writing of unit tests, as well as a public API to run contracts in eg. go-cosmwasm. As such it includes all glue code needed for typical actions, like fs caching.


A VM can support one or more contract-VM interface versions. The interface version is communicated by the contract via a Wasm import. This is the current compatibility list:

cosmwasm-vm Supported interface versions cosmwasm-std
0.14 interface_version_5 0.14
0.13 cosmwasm_vm_version_4 0.11-0.13
0.12 cosmwasm_vm_version_4 0.11-0.13
0.11 cosmwasm_vm_version_4 0.11-0.13
0.10 cosmwasm_vm_version_3 0.10
0.9 cosmwasm_vm_version_2 0.9
0.8 cosmwasm_vm_version_1 0.8


There are demo files in testdata/*.wasm. Those are compiled and optimized versions of contracts/hackatom and contracts/staking run through rust-optimizer.

To rebuild the test contracts, go to the repo root and do

docker run --rm -v "$(pwd)":/code \
  --mount type=volume,source="devcontract_cache_hackatom",target=/code/contracts/hackatom/target \
  --mount type=volume,source=registry_cache,target=/usr/local/cargo/registry \
  cosmwasm/rust-optimizer:0.10.9 ./contracts/hackatom \
  && cp artifacts/hackatom.wasm packages/vm/testdata/hackatom_0.14.wasm

docker run --rm -v "$(pwd)":/code \
  --mount type=volume,source="devcontract_cache_ibc_reflect",target=/code/contracts/ibc-reflect/target \
  --mount type=volume,source=registry_cache,target=/usr/local/cargo/registry \
  cosmwasm/rust-optimizer:0.10.9 ./contracts/ibc-reflect \
  && cp artifacts/ibc_reflect.wasm packages/vm/testdata/ibc_reflect_0.14.wasm


By default, this repository is built and tested with the singlepass backend. You can enable the cranelift feature to override the default backend with Cranelift

cd packages/vm
cargo test --features iterator
cargo test --features cranelift,iterator


Using Singlepass:

cd packages/vm
cargo bench --no-default-features

Using Cranelift:

cd packages/vm
cargo bench --no-default-features --features cranelift


module_size and module_size.sh

Memory profiling of compiled modules. module_size.sh executes module_size, and uses valgrind's memory profiling tool (massif) to compute the amount of heap memory used by a compiled module.

cd packages/vm
RUSTFLAGS="-g" cargo build --release --example module_size
./examples/module_size.sh ./testdata/hackatom.wasm


This package is part of the cosmwasm repository, licensed under the Apache License 2.0 (see NOTICE and LICENSE).


~193K SLoC