CosmWasm 1.3

Simon Warta
CosmWasm
Published in
3 min readJul 28, 2023

The next CosmWasm feature release has been tagged, bringing some major improvements to contract developers and node operators.

Photo by Mike Kononov on Unsplash

Rust 1.70+ support and sign extensions

WebAssembly is a standard that consists of a basic version called MVP plus a set of proposals for additions. Those proposals are in various stages of development and bring things like multi-threading, exceptions, SIMD, and so on.

Unknown opcode errors like this are caused by the Sign-Extension proposal.

A simple and harmless one is Sign-extension operators. Starting from Rust 1.70, those new Wasm operations are emitted by the compiler by default, leading to slightly more efficient code in some cases. As those operators are simple and straightforward, we decided to open up CosmWasm static analysis and Wasm middleware to allow using this extension. This reduces the friction for developers.

This was first reported by developers from Secret and then analyzed and fixed by Confio.

Signed integers

The popular cosmwasm_std::{Uint64,Uint128,Uint256,Uint512} types now have signed counterparts Int64, Int128, Int256 and Int512 that are crafted in a CosmWasm specific way. All types are serialized as a string on the JSON level and use error types that can be converted easily to StdError. A rich set of operators and APIs are available that is as close as possible to the Rust standard library.

Int128 is particularly important to migrate away from u128/i128 in message fields. u128/i128 serialization is currently buggy and subject to change in CosmWasm 2.0. Don’t use them.

Coin and Coins

Coin::from_str now allows parsing coin strings like “123uatom”. Coins is a container that allows managing multiple coins and doing basic math on them. Thank you, Larry, for the draft version, which was refined and finalized by Confio.

New queries and messages

The following queries have been added, and I’m sure you can guess what they do:

  • BankQuery::AllDenomMetadata and ::DenomMetadata
  • DistributionQuery::DelegatorWithdrawAddress

The new message DistributionMsg::FundCommunityPool allows sending funds from a contract to the community pool.

New queries and messages require a chain running CosmWasm 1.3 and the cosmwasm_1_3 cargo feature to be enabled.

Add CPU type to cache folder

Before executing Wasm contracts, they are compiled to machine code (so-called modules). To ensure fast execution times, this code is cached in a directory on disk. However, those modules may lead to crashes when executed on a different CPU than the original target. This happens when you change the CPU on a virtual server or copy the cache directory to a different machine as part of a snapshot. Adding the CPU type to the folder invalidates the cache on a CPU change such that modules get recompiled on demand for the new architecture.

So instead of a directory like ~/.appd/wasm/wasm/cache/modules/v4-wasmer1/ we now have one of those:

~/.appd/wasm/wasm/cache/modules/v4-wasmer1/aarch64-apple-darwin-656374122
~/.appd/wasm/wasm/cache/modules/v4-wasmer1/x86_64-unknown-linux-gnu-72354762
~/.appd/wasm/wasm/cache/modules/v4-wasmer1/x86_64-unknown-linux-gnu-91214657847

Storage::range_keys and ::range_values

There are many cases in which you do not need both key+value as part of an iteration. This can be deletions that only need keys, value lists that don’t need keys, and skip implementations that need neither of them. Code like .map(|r| r.map(|(_, v)| v)) that is discarding data is not uncommon in storage libraries. In order to avoid the overhead of copying unused data from the environment into the Wasm, we are working on more granularity during the iteration. range_keys and range_values can be used today and will be implemented more and more efficiently in the course of the upcoming releases.

cosmwasm-storage deprecation

The crate cosmwasm-storage is now officially deprecated and scheduled for removal in 2.0. Please migrate to cw-storage-plus for high-level storage access or cosmwasm-std for raw key/value access.

The full set of changes is available in the CHANGELOG. The migrating guide helps you update your contracts. CosmWasm 1.3 is bundled as part of the upcoming wasmd 0.41 (Cosmos SDK 0.47) and 0.33 (Cosmos SDK 0.45).

--

--

Simon Warta
CosmWasm

Building CosmWasm and CosmJS at Confio | Ex IOV | Co-Founder of Kullo | Board member prolina Foundation