Atomic Swaps

The process of exchanging cryptocurrencies on exchanges and other specialized platforms can still be quite time-consuming and often involves high commissions. In addition, not all exchanges support the necessary coins or the necessary trading pairs. As a result, a trader who wants to exchange one cryptocurrency for another is faced with the need for additional conversions.

Atomic Swaps solve the above problems and eliminates the need for trusting a third-party as well, and enables the exchanging of cryptocurrencies across different blockchains.

A number of problems can arise in the process of exchanging cryptocurrencies.

  1. Trust. To exchange cryptocurrencies, for example, LTC to BTC, you will need to either send your coins to the exchange or conduct an OTC transaction. In the first case, you need to trust the platform which will accommodate the trade, otherwise, you will have to rely on the guarantor that ensures the security of the transaction.
  2. Additional fees. When executing a trade on the exchange, you pay a commission for the trade itself, you also pay for the withdrawal of coins, and sometimes even for depositing the funds. In the case of an over-the-counter exchange, you pay a fixed percentage to the guarantor.
  3. Convenience. To trade cryptocurrencies on the exchange, you need to deposit funds and withdraw them afterward, but the exchange may temporarily close for maintenance, or indefinitely suspend deposit/withdrawal option for the cryptocurrencies you use. 

To solve these problems, Atomic Swaps were developed. The technology was first described by Tier Nolan back in 2013, but it wasn’t put into practice until recently.

Working principle

The Atomic Swap protocols are designed to eliminate any fraud opportunity for the participants. To understand how this works, let’s use an example where Alice wants to exchange her LTC for Bob’s BTC.

First of all, Alice must deposit LTC to the address of the contract, which plays the role of a safe box. When this “safe box” is created, Alice generates a key to access it. She then shares the cryptographic hash of this key with Bob. Bob cannot access LTC because he only has the hash of the key, but not the key itself.

Bob uses the hash provided by Alice to create another secure contract address where he then stores his BTC. To receive BTC, Alice must use the same key, thereby providing her currency to Bob (utilizing the hashlock function). This means that as soon as Alice requests BTC, Bob, in turn, will request LTC, and the currency exchange will be completed.

The term “atomic” is used because these transactions are either carried out in full or don’t occur at all. If one of the parties does not fulfill its obligations, the contract is canceled, and the funds are automatically returned to the respective owners.

Atomic Swaps can occur in two different ways: on the blockchain and off the blockchain:

  • On-chain swaps occur on any of the networks involved in the exchange process (in this case, it is either bitcoin or litecoin blockchain).
  • Off-chain swaps occur on the second layer, for example, on the Lightning Network.

From a technical point of view, most of these trading systems are based on smart contracts that use Multisig and Hash Timelock Contracts (HTLC).

Multisig

Multisig is a special type of digital signature that allows two or more users to sign documents together as a group. Therefore, a multi-signature is created through a combination of several unique signatures.

As a simple analogy, you can think of a safety deposit box with two locks and two keys. With Alice having one key and Bob having the other. The only way they can open the box is by using both keys at the same time. Therefore, none of the participants will be able to open the box independently.

Hash Timelock Contracts (HTLC)

Hash Timelock Contracts are based on two functions: hashlock and timelock.

The goal of Hashlock is to prevent spending if any part of the data remains inaccessible (like Alice’s key in the example above). Timelock is a function that ensures that a contract can only be executed within a previously defined time period. Consequently, the use of HTLC eliminates the need for trust because the contract creates a specific set of rules that prevent partial execution of an Atomic Swap.

Benefits of Atomic Swaps

The main advantage of Atomic Swaps is the elimination of the need of a third party as all transactions are P2P, directly between two users. Atomic swaps also enhance security, since users do not need to transfer their funds to a centralized exchange or a third party. Instead, transactions can occur directly from the users’ wallets. In addition, this also helps users save on commissions. When using swaps, you only need to pay a transaction fee, while when using exchanges, apart from paying a transaction fee, a trading commission and a withdrawal commission apply. Atomic swaps are much faster as well — theoretically, they only take the time equal to the transaction processing speed.

Disadvantages

To execute the exchange, two cryptocurrencies must be based on blockchains using the same hashing algorithm (for example, SHA-256, as with the bitcoin network). In addition, they must be compatible with HTLC and other programmable functions.

Also, some researchers are concerned with the privacy issues, since atomic swaps can be tracked on the blockchain, which makes it possible to link the addresses involved in the swap with the other funds of the user.

Conclusion

Atomic Swaps are still complicated to execute for most, but this technology leads to significant changes in the interoperability of blockchains and decentralized trading. Thus, this method exchange has great potential, opening up new opportunities for decentralization and peer-to-peer money transfers.

Cryptocurrency

Comment