Cosmos Interoperability is here: a peek at multi-chain contracts

Ethan Frey
CosmWasm
Published in
5 min readFeb 8, 2021

We have recently implemented a pair of CosmWasm contracts that communicate with each other on different chains without the need of any trusted parties. This will usher in a new era of blockchain composition and programming.

Photo by Claudio Schwarz | @purzlbaum on Unsplash

In 2020, CosmWasm established itself as the premier smart contracting platform in the Cosmos ecosystem, being deployed on the mainnets of Terra and Secret Network to enable a new generation of DeFi apps. Meanwhile, the Cosmos SDK core team was busy working on constructing “Stargate”, bringing Inter-Blockchain Communication (IBC) to the CosmoVerse. In January, we managed to bring together these two powerful streams and construct the first pair of contracts designed for cross-chain communication.

What it enables

IBC ships with only one application — ICS20 which defines fungible token transfer between chains. This will allow anyone to effortlessly construct trustless token bridges between every blockchain built on “Stargate” and greatly simplifies finance. However, there is much more potential to IBC. Some people are discussing NFT transfers between chains (while maintaining metadata). Others are working on “Interchain Accounts” (where an account on Chain A can remotely control an account on Chain B). And we are only beginning to imagine the potential of this technology.

In order to add a new protocol, you have to add logic to both blockchains. It’s not enough to just add an API to your chain, the other side needs the client. However, we all know how hard it can be to coordinate an upgrade for a blockchain, and performing a soft fork is not taken lightly. Developers and innovators need a way to easy update the connectors on both sides — something Agoric has called “Dynamic IBC”. This enables you to deploy and re-deploy contracts to easily iterate on new cross-chain app protocols. But a key sticking point of Dynamic IBC is that it is not very useful if it only works on one chain.

You need both chains to support Dynamic IBC to realize its potential. Conveniently, CosmWasm is live on mainnets or testnets of around 10 Cosmos projects.

These projects are all upgrading or planning to upgrade to Stargate in the next months. When all these chains (and more) upgrade their chains to use the newest Stargate and CosmWasm releases, they will all be prepared for Dynamic IBC and rapid iteration of cross-chain protocols, ushering in a new era of blockchain.

To give you an idea of the range of projects we are working with: Terra and e-money focused on DeFi and stablecoins, Secret Network with privacy-enabled, encrypted contracts, Fetch.ai with autonomous agents, IrisNet with an enterprise offering participating in China’s BSN, Regen Network offering carbon credits and ecological restoration, and many more. Now imagine what kind of apps you can build combining these — moving stable coins onto Regen to invest in ecological regeneration, with AI agents monitoring results and focusing your portfolio for maximum impact. All based on highly secure blockchain technology.

Looking under the hood

Warning: Dev Mode only

Here at Confio, we have been working and planning for IBC for quite some time now. In fact, I wrote the original IBC specification back in 2017 while working for Tendermint, and have been dreaming about builds apps on it for years. Last winter I was discussing the potential of CosmWasm and IBC with Chris Goes, the lead researcher for IBC. Last summer we had a nice design session and defined a clear interface between the Cosmos SDK IBC modules and CosmWasm and then implemented some mock contracts (in Go) to demonstrate it.

That work was done on an older version of the SDK, and once they released a stable v0.40.0 release Jan 10th, we got to work quickly updating all the SDK integrations and building all the plumbing up to connect it to our Rust VM and CosmWasm contracts. By the end of the month, this culminated with a whole series of PRs to build the IBC APIs in CosmWasm and two contract that implement a simple protocol inspired by the “Interchain Accounts” described above. ibc-reflect, which serves as the receiver side, creating proxy addresses for each incoming connection. And ibc-reflect-send, which has can create multiple connections to other chains, and allow it’s owner to send messages to any of the remote accounts.

While the design was not novel, it handled the whole lifecycle, including automatically dispatching actions (and packets) upon channel connect. And was designed to provide easy and robust testing of our IBC contract integration. We updating wasmvm, our Rust-Go bindings, in these two separate PRs. And after lots of testing and feedback down to the contract design, Alex merged in a massive PR adding IBC integration to wasmd. Of course, none of this is released yet and is based on a quickly moving master branch, so we advice you to wait until the upcoming CosmWasm 0.14 release to try any of this out. Until then, the best way to view it and try it out is most likely our IBC integration tests in wasmd, which use the real contract in two apps and creates a channel between them.

Conclusion

Communication is key. Not only between humans, but also between blockchains. Our recent IBC-enabled contract implementation will surely bring dynamic IBC to the larger Cosmos ecosystem.

If you have questions, suggestions, or collaboration ideas, feel free to contact us on our discord any time.

Following our previous workshop in which we demoed token transfer between 2 local testnests focusing on the relayer, we are hosting a follow-up workshop this month that showcases the interaction between 2 different IBC-enabled blockchains. The timing is perfect as it would be right after the scheduled Cosmos Hub upgrade with the newest Stargate.

Please come and see with your own eyes what IBC-enabled chains could do with CosmWasm. This workshop is scheduled for Wed, Jan 24th at 3 PM CET. You can register the event by clicking here (details are subject to change).

Join all our community!

Website: CosmWasm.com

Discord: CosmWasm discord

Twitter: @CosmWasm

Medium: @Confio

--

--