Development

Github metrics:

CosmWasm

A WASM-based Smart Contract Module for the Cosmos SDK

The Cosmos SDK is written in Golang based on certain design considerations to allow for the customization of modules, however, expanding across many programming languages is crucial to growing developer adoption. Ultimately supporting the greater goal of enabling an Internet of Blockchains — or The Interchain — to support a plethora of implementations and capabilities connected by the Inter-Blockchain Communication Protocol (IBC).

June 2019 marked the first-ever Cosmos HackAtom Berlin and the beginnings of CosmWasm. The hackathon’s goal? Expanding tooling for developers interested in building on the Cosmos Network. CosmWasm, a project enabling WebAssembly (WASM) virtual machines (VMs) in the Cosmos SDK, was one of a number of projects to eventually receive a grant from the Interchain Foundation with regards to developer tooling.

The first implementation of a WASM virtual machine running on top of a Cosmos SDK application has been designed by Ethan Frey from Confio (he’s also the lead engineer at Regen Network). The team is excited to announce that it is now available for the Cosmos community! If you are a Rust developer, you can easily write smart contracts that can be uploaded to any Cosmos SDK based chain that includes the CosmWasm module. You can find more information on the technology at the links below:

Adding WebAssembly to the Cosmos SDK allows software written in many languages to run securely on a blockchain. WASM serves as an intermediate language that compiles the developer’s language of choice into a portable virtual machine. This means that you can have a simple, secure and fast virtual machine set up to sandbox or partition your application’s actions for better testing, security, performance and speed.

The entrance of a new programming language to the Cosmos Network has several benefits for the overall developer ecosystem. First, this product allows developers to write modules in Rust that integrate seamlessly with the Cosmos SDK, so they can take advantage of the mainnet-proven Cosmos-SDK modules and BPoS Tendermint consensus algorithm while developing a largely Rust-based custom application logic. Second, the ability to upload code in transactions, rather than restarting the chain, allows for a much quicker deployment of new features; the Cosmos Hub upgrade procedure is necessary only when making changes in the core logic. This enables application-specific zones to freeze the staking logic and iterate quickly on their core value proposition through custom smart contracts. Especially if they limit contract deployment to governance, this can provide an easy way for the chain to ship code quickly. If they launch a chain with the default permissionless uploading of smart contracts, you can build an Ethereum alternative on Tendermint.

An important consideration for performance when building smart contracts is the data packet size. Web Assembly code is naturally larger than Ethereum bytecode as it offers more generality. Rust has no garbage collector and the standard library can be excluded from builds, which means that a minified simple escrow contract requires around 50kB (16kB compressed). Golang or Haskell are alternatives, but would likely produce contracts of several hundred kB. This consideration, along with the popularity of Rust in the blockchain ecosystem, led the Tendermint team to use this as a first implementation language for Web Assembly contracts in the Cosmos SDK.

While the ecosystem is still nascent, the smart contract environment within CosmWasm is Turing complete. This means that you have the capability to perform any logic that could be implemented in Ethereum and execute it within the Cosmos SDK without modifying the underlying blockchain. The CosmWasm module includes a mature build and test environment and comes with an integrated development environment (IDE) thanks to Rust’s native programming features. For a more detailed guide on “Getting started with CosmWasm” visit the product’s documentation website.

If you are a Rust developer using CosmWasm with the Cosmos SDK means you:

…only need a minimal knowledge of Golang.

… can start building on the Cosmos SDK and integrate easily into the existing Cosmos Network.

…can extend your existing chain or application to the Cosmos chain with minimal overhead.

If you are a Go developer using the Cosmos SDK with CosmWasm, the benefits include:

Only a minimal knowledge of Rust is required thanks to the well-designed CosmWasm tool kit.

Adding Rust programming logic to the Cosmos SDK allows for live upgrades or custom contracts enhancing the customization and execution of your application.

You gain access to Rust’s type safety and testing and the encoding and crypto signatures relatively common in Rust — which are ideal for developing highly secure blockchain applications which could be used in DeFi.

CosmWasm enables WASM VMs to be built with Cosmos SDK

CosmWasm — Editing a Smart Contract Tutorial Part 1

In this talk Ethan Frey, lead developer of Regen Network, discusses CosmWasm, a Wasm smart contract engine for the Cosmos SDK.

CosmWasm — Editing a Smart Contract Tutorial Part 2