RESEARCH: WASM in the Cosmos SDK

I can think of a number of use cases(Staking derivatives, asset issuance, cross chain collateralization etc) where it on chain code would be a helpful.

WASM seems like a great target for some SDK applications for on chain code.

One option is Perlin’s Life golang Wasm engine:

Concerns are mostly that it doesn’t seem to have good support for Host functions to inject into the runtime environment. This pretty crucial if you want your wasm code to actually interact with the rest of the Cosmos SDK.

Wasmer has a C api that looks like it would wrappable in go and could be a nicer path to golang integration.

7 Likes

One downside of Wasmer is that host functions are either going to trampolines in C or rust to golang.

I would like to echo support for this being a focus. Lack of on-chain WASM support is a major downside of the current SDK, and is something thats crucially needed. Its rather trivial to integrate SNARK verifier’s (and the examples you provided). This is also something being explicitly built out for Polkadot, Eth, DFinity, so perhaps there is some potential for standardization that could happen on how WASM code interacts with the blockchain for state. (Or is there a clear way to do this in WASM, I haven’t looked too much into it?)

2 Likes

The typical way to interface on chain code with state is via host functions. For instance, a Host function that provides the ability to query data from the multistore. Serialization and deserialization of data from inside the WASM engine is an interesting challenge.

1 Like

WASM support would be great!
Rust amino should help with serialization/deserialization, right? AFAIK it is almost production ready, right?

One of the big open questions in my in integrating WASM into the SDK is how to serialize and deserialize golang structs into the WASM virtual machine.

Oasis Lab’s made has a proposal I think we can align strongly with.

2 Likes

We have just released a Go integration for the Wasmer WebAssembly runtime :tada:

It’s in average between 50 and 100x faster than Life.

We also published an article analyzing the API and comparing it with Life/Wagon:
https://medium.com/wasmer/announcing-the-fastest-webassembly-runtime-for-go-wasmer-19832d77c050

I’d love to hear your feedback! :slight_smile:

2 Likes

Rust Amino is almost done?

Hey @syrusakbary I am super interested in adding support for wasmer in the Cosmos SDK.

I think we will make a demo relatively soon.

1 Like

Awesome! Let me know if we can help in any way :slight_smile:

PS: feel free to send me an email to syrus@wasmer.io if you have feedback/suggestions so we can follow up in a faster way

One thing that seems exciting about the wasmer interface is the ability to move back and forth between the wasm memory space and golang memory space.

This enables much more complex apis between the go world and the wasm world.

In wasi interface proposed by oasis, the interface is largely confined to serialized data into $HOME and STDIN/STDOUT.

In the wasmer interface, the interface is defined by the cgo api.

A winning team from HackAtom Berlin integrated WASMER into the SDK.

See diff below