Wasmer 1.0 integrated into CosmWasm

Simon Warta
CosmWasm
Published in
3 min readDec 23, 2020

TL;DR: It’s faster and safer and nicer.

Earlier this year we learned that the WebAssembly runtime that powers contract execution in CosmWasm was going to get a major refactoring. At that point, it became clear we cannot release a CosmWasm 1.0 that depends on an unmaintained Wasmer 0.x. So we changed plans and started looking into the changes of the upcoming release.

Photo by David Armstrong on Unsplash

Today, after about three months of integration work, we’re happy to announce that CosmWasm successfully integrated the latest beta release of the upcoming Wasmer 1.0. And this has many direct and indirect consequences for all CosmWasm users.

Faster

As part of the transition, we wrote a benchmarking suite directly in the cosmwasm repo. This allows us to compare the performance consequence of a change easily. And the results are amazing (even on my laptop from 2015):

  • 2x Wasm compilation performance (to 50ms)
  • 2x Wasm execution performance (to 50 µs)
  • 6x module loading performance (to 6ms)

Safer

Before there upgrade, a lot of the internal functionality was based on raw pointer management. While this provided a powerful way to manage data during execution, we had to be extremely careful to not create bugs. The new interfaces allow us to benefit from all the safety that comes with the strict Rust type system.

New APIs now allow us to easily set memory limits during contract execution. Before a contract execution could take up to 4 GiB of memory, which is a result of the 32-bit address space in Wasm. Memory can now be limited to any amount ≤ 4 GiB. Since this memory limit is consensus critical, each blockchain needs to set it as a parameter.

Nicer

This is probably the most developer visible part: the CosmWasm stack as a whole gets nicer. The two available Wasm backends Singlepass and Cranelift now both support gas metering and protection from undeterministic float operations. Both can now be used with Rust stable. The only remaining caveat is that Singlepass does not yet support Windows, such that Cranelift remains the default development backend while Singlepass is used on-chain.

Kudos to the Wasmer team

On behalf of Confio, I’d like to take the opportunity to congratulate the Wasmer team for this major achievement and want to say thank you for the effort put into this open source project. When we considered alternative Wasm runtime projects that worked better with our initial timeline it quickly became clear that we want to stick with Wasmer for what we see in the project: technical excellence, great people, and a culture welcoming external contributions. When the collaboration intensified this month, this decision was proven exactly right.

What’s next?

The integration of Wasmer brings us much closer to a CosmWasm 1.0 release. It gives us a solid base to fine tune the Wasm engine with respect to gas metering, resource limiting and performance. We are actively reviewing internal features and changes we need to feel confident of the CosmWasm stack, but externally we are only blocked by a final Wasmer 1.0.0 release as well as a final Cosmos SDK Stargate release.

If you want to have a closer look into the relevant changes migrating from Wasmer 0.17 to 1.0, see the upgrade part 1, part 2 and part3 as well as the new metering and deterministic middleware.

--

--

Simon Warta
CosmWasm

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