Skip to main content

Atomic swaps: life cycle

Introduction

This article explains the whole life cycle of atomic swap transactions, from its inception until its registration into Hathor blockchain. Understanding this life cycle is essential to use such transactions. This is because different from ordinary transactions, making an atomic swap transaction is not straightforward, requiring participants to execute additional off-chain (i.e., out of the blockchain) interactions.

Glossary

These terms are used throughout this article:

  • Transfer is a process by which ownership of assets is reassigned to a new owner.

  • Participant is a person or entity participating in a blockchain transaction.

  • Remitter is a participant of a transfer from which assets are transferred.

  • Recipient is a participant of a transfer to which assets are transferred.

  • Funds is a sum of assets that is allocated in some place, and available to be managed by its owner.

  • Trade is an exchange of predefined and agreed amounts of multiple assets among multiple parties.

    This implies the occurrence of at least two transfers of assets among at least two parties. For example, when you go to a bakery to buy bread, this event is a trade between you and the shop, composed of two transfers of assets, where you transfer cash to it, and it transfers bread to you.

Context: what is an atomic swap transaction?

In Hathor, an atomic swap is a type of transaction with more than one remitter wallet. Such transaction allows trades of multiple tokens among multiple parties in a trustless manner. To know more about the atomic swaps feature, see About atomic swaps.

Overview of atomic swap transactions

Transaction proposal and negotiation

In a broad view, data from all remitter wallets is gathered, and a transaction is assembled. All parties will review if the content of the transaction matches their previous negotiation terms — i.e., tokens being exchanged, their amounts, and recipient addresses. And once an agreement is reached, all parties sign the transaction, and after that, at any time, any participant may submit it to Hathor Network.

Valid and invalid atomic swap transaction

While the transaction is not yet registered on the blockchain, it is considered a transaction proposal. No matter how much time has passed since the definitive form of the transaction proposal is reached — whether one minute or one year — if all funds (namely, UTXOs) allocated as inputs are still available, the transaction proposal is still valid. On the other hand, it also does not matter how long time has passed since the transaction proposal was in a valid state: if once it is submitted (by anyone), at least one of the allocated funds was spent (in another transaction by some of the involved parties), Hathor Network will consider this an invalid transaction proposal and will discard it.

Interactions and communication

The whole process of an atomic swap transaction takes place with two types of interactions:

  • Interactions among participants of the atomic swap.
  • Interactions of each participant with Hathor Network.

Interactions among participants

Regarding the interactions among participants, they always happen off-chain, in a predefined and agreed manner, using their chosen communication medium — e.g., email, Telegram, Discord, etc. This is not a shortcoming of Hathor, but a design decision to provide users the maximum level of privacy and choice concerning how they handle their negotiations.

Interactions of each participant with the Hathor Network

The interaction between each participant and Hathor Network is made through their wallet applications. Each remitter participant uses their wallet to update the transaction, append their partial, check its content and sign it. And finally, one of the participants also uses their wallet to submit to the network the ultimate version of the transaction (once valid and signed among all remitter wallets).

Phases of an atomic swap transaction

To understand how this transaction happens in Hathor, let's imagine the simplest case where we have only two participants, Alice and Bob. They want to make a trade between them, exchanging X amount of token A for Y amount of token B (where, of course, both tokens are assets on Hathor).

For the sake of understanding, we may break the process into three phases:

  1. Negotiation
  2. Signature collection
  3. Transaction registration

Overview of the process

In the following sequence diagram we see the whole process taking place:

Life cycle of an atomic swap transaction

Next, we will detail each phase.

Negotiation phase

They negotiate the terms of the trade

Everything starts with Alice and Bob negotiating the terms of their trade. This conversation takes place in the communication medium of their choice. Let's suppose they are in a private conversation on Telegram.

They start negotiating values, and once they reach a (yet) informal agreement of 'exchanging X amount of token A, for Y amount of token B', one of them says: "Ok, so I will prepare a partial of transaction proposal".

Alice creates a partial transaction

Let's say Alice will start creating her part of the transaction. Alice uses her wallet application to create a partial transaction, stating: "I want to transfer X token A and receive Y token B in address A1". Alice thus sends Bob her partial.

Bob appends his part of the transaction

Once Bob receives Alice's partial, he will review its content. Since the content of the transaction is not human readable, to assure that the data match what they agreed, there is an API in the headless wallet to decode such transaction content. Bob will use it and check if the data match what was agreed with Alice. Let's suppose he found that everything was ok in his review.

He then updates Alice's partial, appending his part — which should states, "I want to transfer Y token B and receive X token A in address B1" —, forming a transaction with all inputs and outputs.

Signature collection phase

He then signs the transaction and sends it to Alice. Alice will also review the content of the transaction. Let's suppose she found that everything was ok in her review.

Once Alice also agrees with the content of the transaction, she will then sign and finally submit the transaction to Hathor Network.

Note that if, during the inspections, any party realizes that the content is not matching their prior informal agreement, the transaction is discarded, and the whole process restarts.

note

What we mean here by signing a transaction, in practice, is using a wallet to generate the signature of the transaction. Signatures are only appended to the transaction right before submitting it to the network. Prior to this, participants exchange the signatures and the transaction as separate pieces of data.

Transaction registration phase

Once submitted, the Hathor Network will register it into the blockchain if the content of the transaction is still valid at that precise moment. To be valid, all funds — i.e., UTXOs — allocated as inputs must still be available, and of course, Alice and Bob must had signed agreeing with the mutual transfer of funds.

Note that the validation process performed by Hathor Network is pretty much the same as in any regular transaction. The only difference here is that, once we deal with funds of more than one participant, between signing and submitting the transaction proposal, one of the participants may spend their funds in another transaction. If that happens, once the network performs validation, the transaction proposal is discarded, which in practice means the trade was canceled (and thus, nobody transfers nothing, nobody loses nothing, etc.).

Key takeaways

This article presented the whole process of performing an atomic swap transaction. We explained that:

  • To perform an atomic swap transaction, participants must first establish a communication channel to negotiate the terms of their trade and put the agreed terms into a transaction.
  • Participants exchange negotiation messages and transaction data through the established communication channel to be read and understood using their wallet applications.
  • Although the definitive content of the transaction was valid by the time you signed the transaction, once the network executes the validation process, it still could be considered invalid if some of the UTXOs allocated as inputs were spent in the meantime.

What's next?