decentralized finance education

How Does Thorchain Work? DeFi Explained

Intro 

So what is Thorchain all about? How does it work? And how does it make it possible to swap between native assets across different blockchains? You’ll find answers to these questions in this article. 

With billions of dollars in trading volume, decentralised exchanges have been gaining more and more traction. It’s not uncommon to see over $1B in daily trading volume on Uniswap alone.

Although protocols like Uniswap, Sushiswap or Curve are great when it comes to exchanging assets within the Ethereum ecosystem, they don’t support swaps between different blockchains. 

To accommodate this problem, a common approach is to represent external assets in the form of wrapped or synthetic tokens on Ethereum. The most popular asset on other blockchains outside of Ethereum is of course Bitcoin. There are multiple ways of representing Bitcoin on Ethereum that allows it to be traded on decentralized exchanges. Wrapped Bitcoin, renBTC, sBTC to name a few. 

Even though most of these approaches work fine, they usually make certain tradeoffs when it comes to either the custody or the security of the assets. If you want to learn more about it check out this article here

What if there was a way of swapping native assets instead? For example, making a trade between Bitcoin on the Bitcoin blockchain and Ether on the Ethereum blockchain. 

And this is exactly where Thorchain comes into play. 

Thorchain is a decentralized liquidity protocol that allows for swapping native assets between different blockchains such as Bitcoin, Ethereum or Binance Smart Chain. 

When it comes to managing liquidity, Thorchain uses a liquidity pool model known from protocols like Uniswap or Bancor. 

In this model, liquidity providers lock 2 assets in a liquidity pool. This in turn provides liquidity for traders who want to swap between these 2 assets and pay a small fee that goes back to the liquidity providers.

If you want to better understand how liquidity pools work you can check out this article here.

Thorchain is often explained as a cross-chain Uniswap. This is usually a good simplification for understanding the general idea behind Thorchain although there are some big differences between these two protocols that we’re going to explain later. 

Before we dive deeper into the mechanics of Thorchain, let’s have a quick look at how the project came into existence. 

Thorchain History

Thorchain started as a small project at the Binance hackathon in 2018.

The team behind Thorchain continued their research after the hackathon ended, but decided to put some of their effort on pause later that year as they were waiting for a few missing pieces of technology needed for creating a fully functioning cross-chain decentralized exchange. 

These were mainly Tendermint & Cosmos SDK and a working implementation of TSS – Threshold Signature Scheme.  

Seeing the viability of the product, the team decided to raise a small seed round and worked on a proof-of-concept of a decentralised exchange built on top of the Thorchain protocol, called Instaswap, which was later demonstrated during the Cosmos hackathon in Berlin. 

After that, they announced their first go-to-market product – BEPSwap –  in July 2019. The main goal of BEPSwap was to enable BEP2 asset swaps and was limited to Binance Chain. 

Also in July 2019, the team decided to raise more funds through an Initial Dex Offering on Binance Dex. The IDO resulted in $1.5M raised that was sufficient to enable further development of the project.  

The team continued their work on the protocol which resulted in the limited mainnet release, called multi-chain chaos network or MCCN, in April 2021.

Interestingly, the Thorchain team decided to remain mostly anonymous, even to this day. 

Now, let’s see how Thorchain works under the hood. 

How Does It Work 

At the core of the Thorchain protocol is a network of nodes built with Tendermint and Cosmos SDK.

This approach allowed Thorchain to create a separate blockchain with its own consensus and network layer without having to build all of its elements from scratch. 

Thorchain leverages Tendermint BFT model that allows the network to reach consensus even if up to ⅓ of all the nodes start failing. 

The consensus mechanism is important as Thorchain nodes have to work together, for example, in order to record transactions coming from other blockchains.

To see how this works in practice, let’s go through a quick example. 

Let’s say a user wants to swap their Bitcoin on the Bitcoin network to Ether on the Ethereum network. 

The user sends a standard Bitcoin transaction to the Bitcoin vault – a Bitcoin address controlled by the Thorchain network. 

Thorchain nodes keep monitoring vault addresses in order to acknowledge new transactions. 

To achieve this, each Thorchain node a.k.a THORNode consists of a few major components. The most important ones being: the service running the Thorchain blockchain itself; a full node for each of the connected blockchains, for example, a Bitcoin or an Ethereum node; and the Bifrost. 

The Bifrost Protocol acts as a connective layer between the Thorchain network and other networks such as Bitcoin or Ethereum. One of its main responsibilities is to watch the vault addresses in order to find inbound transactions that are later converted into THORChain witness transactions. 

The witness transactions are initially recorded as pending – which is one of the states in the Thorchain state machine. After the majority of nodes agree on the state of the inbound transaction, the transaction is moved to the “finalised” state. 

At this point, the user’s Bitcoin deposit is recorded on the Thorchain blockchain. 

Time for the other part of the swap – sending Ether back to the user. 

Once a new inbound transaction is finalised, the Thorchain protocol initiates a swap. The swap transaction is recorded on the Thorchain blockchain and the Bifrost Protocol is used again – this time to initiate a withdrawal of ETH from the Ether outbound vault. 

This outbound transaction is translated from Thorchain’s internal representation into a valid transaction for the destination chain using the respective chain client – in our case the Ethereum Client – and broadcast to the respective network. 

At this point, the swap is completed and the user ends up with Ether in their Ethereum wallet. 

Although this sounds quite simple, there is quite a lot of detail to make it all possible. 

TSS

In order to sign transactions, the network has to be able to control vault addresses on each of the integrated blockchains. 

Of course, storing private keys on each of the nodes would be a huge security risk and this is also why Thorchain uses the previously mentioned Threshold Signature Scheme or TSS. 

TSS is a cryptographic primitive for distributed key generation and signing. You can think about it as a better version of multisig. Both of them focus on achieving the same goal – allowing multiple parties to come together and sign a transaction only when a certain, previously set threshold is reached. The main difference is that multisig is usually implemented on the application layer of the blockchain, for example, as a smart contract on Ethereum, whereas TSS support is always possible regardless of the blockchain as it relies on basic cryptographic elements. 

This allows for making the whole process of signing transactions cheaper and more secure. 

Although TSS has a lot of benefits, it hasn’t yet been as battle-tested as other popular cryptographic elements such as ECDSA or certain hash functions. 

Vaults

Another interesting detail of Thorchain architecture is the way vaults operate. 

There are 2 types of vaults – “inbound” and “outbound”. 

Inbound vaults store most of the funds in the system. They are slower but more secure as they require ⅔ of all TSS signers to sign a transaction which can take even up to 20 seconds.  

This would be quite limiting for the whole system, so Thorchain introduced smaller, less secure outbound vaults that are run by each of the THORNodes. These vaults are faster as they require only a single signature from the node they run on. The funds in these vaults are limited to 25% of the value of its bond in assets. More on the bonding process a bit later in the article, but this basically creates incentives that prevent the node operator from stealing funds from the outbound vaults. These vaults are also being constantly topped up by the system as the funds are being used for the outbound transactions. 

PoS & Churning

As mentioned earlier, Thorchain uses Tendermint and Cosmos SDK. In this model, the Thorchain network operates as a Proof-Of-Stake (PoS) system where the nodes that want to be able to sign and verify transactions have to stake a certain amount of the RUNE tokens. 

In the Thorchain ecosystem, this process of staking RUNE tokens is also called bonding. 

At the moment of writing this article, 1,000,000 RUNE tokens worth around $18M are required to run a fully functioning Thorchain node. 

In contrast to most variations of PoS systems, the delegation of tokens is not allowed. This helps with making sure all nodes in the network are treated equally and there are no node operators that capture the majority of tokens for a long period of time. 

In fact, all nodes on the Thorchain network are anonymous and only identifiable by their IP address and public key. There is no branding or marketing of nodes like in other systems that allow delegation. 

In order to avoid having the same nodes with the highest amount of RUNE tokens always signing transactions, Thorchain introduces the concept of churning. 

The network maintains one set of nodes that are active and able to sign transactions and another set of nodes that are on standby. 

Every 50,000 blocks, which is around every 3 days, the churning process kicks in and the oldest or the most unreliable nodes from the active set are replaced by the nodes from the standby set. 

Churning makes sure that new nodes that meet the staking criteria can eventually have their turn at signing transactions. Also, each time the set of validators change, the Thorchain network moves funds to new vaults, ensuring that active nodes can still access funds. 

At the moment, there are 28 active nodes and 45 nodes in standby mode on the single-chain chaos network that supports BEPSwap and 11 active nodes and 9 nodes in standby mode on the recently released multi-chain chaos network. 

Currently, the multi-chain chaos network is in expansion mode which means that for every node that is churned out from the network, 2 nodes are churned in. 

The multi-chain network can grow to 99 nodes before hitting the Tendermint and TSS limits. 

Even when the network grows to 99 active nodes, it can still expand further by having the capability of sharded vaults.

It’s also important to note that even though a high amount of RUNE is required to run a fully functioning node, people can still run nodes without bonding RUNE. These nodes are able to validate transactions without the ability to sign transactions. 

RUNE Token 

This brings us to the last key element in the Thorchain architecture – The RUNE token. 

RUNE powers the Thorchain ecosystem and provides the economic incentives required to secure the network. 

All liquidity pools in the system consist of a native token and RUNE. For example, to swap from Bitcoin to Ether, the trade has to go through the BTC-RUNE and ETH-RUNE pools. In this model each asset has to be paired with RUNE. This usually results in a fewer number of pools than in a system that can create a pool out of any 2 assets like in case of Uniswap. 

Besides this, Thorchain nodes have to meet the staking criteria by bonding a particular amount of RUNE. This bond is then used to secure the system by underwriting the assets in the pools. If the node attempts to steal funds from the protocol, their bond is deducted by the amount of the assets they stole (1.5x) and the pools are made whole. Also, if the node doesn’t offer reliable service they put themselves at risk of their bond being slashed. 

The Thorchain protocol also encourages the node operators to always bond the optimal amount of RUNE. This is achieved by a mechanism called – The Incentive Pendulum. 

The Incentive Pendulum aims at keeping the system in the most optimal state. This is when 67% of all the RUNE in the system are bonded and 33% is pooled in pools. 

If there is too much capital in the liquidity pools, the network increases rewards for node operators and reduces rewards for liquidity providers. If there is too much capital bonded by the nodes, the system boosts rewards for liquidity providers and reduces rewards for node operators. 

In the optimal state, for every $1M worth of assets in the pools there would be $2M worth of RUNE bonded by the nodes. 

On top of this, RUNE is used to pay transaction fees on the network, subsidise gas needed for sending outbound transactions to different networks and participate in the Thorchain governance where users can signal which chains and assets the network should add next. 

Uniswap 

As I mentioned earlier, there are some big differences between Thorchain and Uniswap or in fact any other decentralized exchange on Ethereum. Let’s have a look at some of them. 

First of all, Uniswap allows for swapping ERC-20 tokens only, so if we want to trade assets from other blockchains they have to be represented in the form of wrapped or synthetic tokens. Thorchain allows for swapping native assets without wrapping them. 

Swaps on Thorchain are charged both a fixed network fee, as well as a dynamic slip-based fee. This means that swaps incurring more slippage are charged more in trading fees. This makes it harder for bots to extract value from swaps like in the case of a sandwich attack – a popular way of affecting the price in the liquidity pool that results in users getting worse prices on their trades.  

When it comes to speed of swaps, assets on Ethereum can be swapped in 1 Ethereum block which happens every 13 seconds on average. On Thorchain, this is a bit more complicated. The swap time depends on which networks we’re swapping between. In case of a Bitcon to Ether swap, it’d take at least 1 block on the Bitcoin network – 10 minutes on average, plus the internal time for executing a swap on the Thorchain blockchain, plus the outbound Ethereum transaction – around 13 seconds. 

Interestingly, a swap from Ether to Bitcoin would be way faster as the Thorchain network would only have to wait for the Ethereum transaction before sending an outbound Bitcoin transaction that would result in the receiving wallet having the Bitcoin UTXO spendable and available straight after the transaction is broadcast. 

Also, Thorchain as a separate blockchain loses some of the benefits of decentralized applications on Ethereum. One of them is composability. For example, a Uniswap swap can be incorporated into more complicated contracts as a part of one transaction. This is not possible with Thorchain swaps. 

Thorchain network is also, of course, not even remotely as decentralized as the Bitcoin or the Ethereum networks and the system instead relies on strong economic incentives. 

This is not necessarily that bad, considering that Thorchain has a completely different use case than the Bitcoin network that secures an asset worth over $1T or the Ethereum network that secures billions of dollars locked in smart contracts. 

For it’s main use case – swapping assets between different blockchains where most users won’t store their assets on the Thorchain blockchain for a very long period of time – it looks like it could be decentralized enough.

Summary 

After the long-awaited multi-chain chaos network release, the Thorchain team is focusing on growing the Thorchain ecosystem while making sure the system works as expected. 

Users have multiple choices when it comes to interacting with the Thorchain protocol. They can use one of the decentralized exchanges like Thorswap or Asgardex or wallets integrated with Thorchain like ShapeShift. 

We should see more applications and wallets integrating with Thorchain in the future. 

On top of this, it looks like we should see more chains and assets being onboarded, more Thorchain nodes joining the network and hopefully seeing more and more trading volume and total value locked in the liquidity pools. 

Eventually, the extra protective measures will be removed and the chaosnet will become the mainnet.

Thorchain clearly looks like an interesting protocol and a missing piece in the defi ecosystem that would allow people to swap between native assets without using centralized exchanges. 

So what do you think about Thorchain? How big can it grow in the future? 

If you enjoyed reading this article you can also check out Finematics on Youtube and Twitter.

Leave a comment

Your email address will not be published.