November 18, 2021

By SW van Heerden

Atomic swaps

Tari Atomic swaps

With the release of version 0.21.2, the Tari Console wallet now supports atomic swaps with multiple coins. TariScript allows us to implement several advanced payment ideas that are difficult or impossible in vanilla MimbleWimble, including One-sided payments and Atomic swaps.

Most of these advanced features were possible the moment TariScript launched on testnet, but let’s be honest: Handcrafting transactions is a complex process.

With this release, we added support via CLI and GRPC commands to initiate, claim and refund atomic swaps with all crypto coins that support HTLCs with a SHA256 pre-image. Any crypto coin that can unlock a payment using a SHA256 pre-image can carry out atomic swaps with Tari, including Bitcoin, Litecoin, and many more.

So what does all this mean? Well, with this new release, all your atomic swaps are just a command away. We have written a handy guide taking you through a BTC-tXTR atomic swap step by step. The process for other coins is entirely analogous.

Let us dig a bit deeper into how this all functions and what the process is. We can divide this whole process into the following steps:

  • The Tari initiation.
  • The Other coin initiation.
  • The other coin finalization.
  • The Tari finalization.
  • And if something goes wrong somewhere: Refunds.

One crucial step that is always hinted at but not always directly mentioned is that the two persons doing the atomic swaps need to communicate out of band with each other to exchange information.

Tari initiation

The first step consists of broadcasting a Tari HTLC transaction. Your wallet provides the information required to move forward, such as the pre-image, pre-image hash, and the hash of the output created on the blockchain. The pre-image needs must be kept secret as this is your key to claiming your coins on the other blockchain, and revealing it to the other person will break the security of the atomic swap. The hashed pre-image and the hash of the output need to be provided to the counterparty.

The newly created output will be saved in your local wallet as a potential time-locked input. More on that later.

Other coin initiation

Here is where the other person needs to commit to their funds on the other blockchain. This transaction creates an HTLC that has the same pre-image as the Tari one. This can be a complicated step as this is where they will need to craft custom transactions on the other blockchain, but luckily we have tools that will create all of this.

Other coin finalization

This is where you claim your coins from the other blockchain. Remember that secret pre-image created in the first step? Again, this step could be complex, but luckily, we have tools to simplify this by following the easy steps.

Tari finalization

Finally, the other person uses the secret pre-image that you just revealed in claiming your coins on the other blockchain. They can use this to claim the Tari you put up for the exchange. This is also just a signal step they have to call on their wallet using the pre-image and hash of the output. The wallet will search the blockchain for the output and transfer it to a wholly-owned UTXO.

Refunds

The refunds ensure that everyone can reclaim all their funds if something goes wrong. On the Tari side, the refunds are handled in one of two ways:

  • Automatic: This is where the wallet will automatically reclaim the funds for you. The wallet will store when this UTXO becomes spendable, and when possible, it will try to spend this UTXO before spending any other UTXO.
  • Manual: This is where you can yourself issue the wallet with the instruction to reclaim the refunds immediately and respond to a new UTXO given that the timelock has expired for them UTXO.