Skip to main content

THORChain: Decentralized Bitcoin Swaps

While many in Bitcoin circles are clamoring for a “winner takes all” environment to lead to a world where only Bitcoin is used, most people who see the value in cryptocurrency as a tool for freedom realize that different cryptocurrencies fit different user’s needs.

In this world where different assets and ecosystems bring unique benefits, a way to seamlessly swap between them without disclosing your identity to a third party is something of a holy grail, as it would enable users to freely choose the asset or network they want to use for storing value, spending, decentralized finance, and much more.

THORChain, launched in April 2021, is seeking to solve this problem in the cryptocurrency space. But how does it work, how are assets secured, and how does the protocol manage to perform no-KYC cross-chain swaps with native assets like Bitcoin and Ethereum?

How did we get to THORChain? #

Since the first cryptocurrencies other than Bitcoin were created, there has been a driving need for users to be able to swap between assets in a seamless manner that does not require giving up custody, preserves user privacy, and does not require the immense regulatory and privacy burden of current “know your customer” (KYC) laws.

While there have been many proposed solutions and attempts at decentralized exchange, most have failed to solve the problem of swapping across chains. Early attempts relied on atomic swaps, an extremely powerful (but also very tedious) way to perform trustless swaps.

The Ethereum community went a different route, however, and the rise of “automated market maker” (AMM) exchanges began with Uniswap. Uniswap enables users to deposit funds into liquidity “pools” that are then leveraged by other users to swap between assets within the Ethereum ecosystem.

This limitation of only being able to interface with assets within the Ethereum ecosystem is the biggest drawback, as users are not able to trade other assets like Bitcoin without giving up custody to get a “wrapped” asset from a third-party – an IOU, essentially.

The concept of the AMM has immense promise, however, as it allows for extremely deep liquidity to be built up in a decentralized way via strong financial incentives, granting liquidity and UX similar to centralized exchanges without the same custody and regulatory risks.

Decentralizing cross-currency swaps #

Enter THORChain. Multi-party computation combined with a unique financial model enabled THORChain to build a protocol that strikes a middle-ground between centralized exchanges and atomic swaps.

A large threshold multi-signature scheme allows large numbers of THORChain node operators with staked funds to custody assets deposited into liquidity “pools” (the AMM concept mentioned earlier that is used by Uniswap), enabling cross-chain swaps in a more decentralized manner than centralized exchanges. Validators run full nodes for every network connected to THORChain to ensure proper validation and completion of swaps.

THORChain currently supports no-KYC Layer 1 swaps between BTC, ETH, BCH, LTC, BNB, DOGE, ATOM, and their native asset RUNE. It does not yet support any privacy coins, ignoring Litecoin’s new opt-in MWEB privacy feature.

How does THORChain prevent theft or “rug-pulls”? #

THORChain takes a bonded approach to incentivizing node operators to act in the best interest of the network, requiring that each node operator put up RUNE (the native asset of the THORChain network) as collateral in order to become a node operator. The amount necessary to become a node is variable, but is currently set at 300,000 RUNE - a hefty sum. Nodes cannot singlehandedly hold user assets greater than the amount of this bonded “security deposit”. They earn rewards in RUNE in exchange for securing the network.

If a node acts maliciously, they risk their bonded RUNE being “slashed”, or taken by the network, in order to counter-act their malicious actions taken. For instance - if a node operator tried to run away with the funds that they are helping to custody or sign fraudulent outbound transactions, they would risk a part (or all!) of their bonded funds. In the event of theft of assets, the bonded RUNE from the malicious node would be taken and used to make the victims whole.

These incentives also play a key role in ensuring that swaps performed by users are properly executed, as ultimately there is trust placed in the node operators that they don’t refuse a swap, send the funds to themselves, or try to siphon off part of the funds owed the swap user. As there are many more nodes on the network than are currently active, this competition incentivizes nodes to properly perform swaps or risk being slashed, replaced, and even kicked from the network entirely. This alleviates most of the risk inherent for a user who is merely swapping funds.

How do cross-chain swaps work on THORChain? #

So how do these swaps actually function at a basic level? THORChain uses an interesting approach, requiring the swap user to insert memo data into their native on-chain swap transaction in order to signal to the THORChain network that a swap is being performed, and which assets are involved. For this example we will assume you’re swapping Bitcoin for Ethereum, and take a quick look at how it works under the hood.

(This is a deep dive for a technical audience. Most people swapping on THORChain are using friendly user interfaces like Shapeshift or THORSwap.)

To swap Bitcoin for Ethereum “the hard way” on the THORChain DEX, the swap user uses a tool like THORSwap or THORChain’s Midgard API to see the prices currently available and the current deposit addresess, then then initiates a swap. When they send the Bitcoin transaction for the swap, their wallet will insert the relevant swap information into the “OP_RETURN” field of the Bitcoin transaction, ensuring that the network knows which assets are being swapped, what the destination address is, and the maximum price for the trade to hedge against market volatility during confirmation. In this case, the OP_RETURN field would use the format SWAP:ASSET:DESTADDR:LIM, like the following:

  • SWAP:ETH.ETH:0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045:100000000

This signals to the THORChain network that the user intends to swap, wants native Ethereum in return, wants the swapped funds sent to the address 0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045, and only wants the swap to execute if the Ethereum out is 1 ETH or more. Once the transaction with this information is confirmed, the current THORChain validators vote on the transaction (as they all run a Bitcoin full-node) and then initiate the swap. The swap transaction is also logged in THORChain’s independent blockchain which acts as a state machine tracking the honesty of all participants in the network.

While the swap uses RUNE as a go-between asset (all native assets provided as liquidity are “pooled” alongside RUNE), the swap user never needs to hold or interact with RUNE directly. When the swap is performed, the THORChain protocol creates a transaction with BTC.BTC, their representation of Bitcoin, swaps it for RUNE, swaps RUNE for ETH.ETH, their representation of Ethereum, and then the next node in line is selected to send funds from its personal hot wallet out to the destination address, on the Ethereum network, with the resulting tokens (with the current price dictated by the formula provided here).

If any aspect of the swap was unsuccessful, funds are refunded to the initiator (in this case the Bitcoin is returned, minus a RUNE penalty and 3x outbound network fees), and the swap may be tried again. On the other hand, if a node refuses to perform a valid swap, they are penalized as discussed in the previous section. If the incentives function properly, swaps are either completed successfully or are refunded in an autonomous way.

This complex protocol allows users to swap native assets through THORChain with a similar UX to using a tool like Uniswap - all with minimized loss of custody, no KYC, and no invasive anti-privacy practices.

Conclusion #

THORChain is certainly not without flaws - they have suffered multiple severe vulnerabilities, both exploited and unexploited, which were quickly patched by their team (users took no loss). Regardless, the concept of a decentralized cross-chain swap platform is an immensely important one and has so far been championed by the THORChain project in a unique way.

The promise of being able to reduce trust, increase decentralization, and minimize risk when swapping between cryptocurrencies is a much-needed one, and one that THORChain is aiming to solve.

NOTE: Please be aware that this article is in no way a recommendation to buy/use/hold RUNE, the native currency of THORChain, and is purely looking at how people are using THORChain as a tool to swap assets across different chains.