What are atomic swaps?
1
What are atomic swaps?
An atomic swap is an exchange of one cryptocurrency for another that can be executed instantly without relying on a trusted third party such as an exchange or swapping platform. Control over the trade rests solely with the counterparties.
Atomic swaps can occur on-chain, meaning directly between the blockchains of different cryptocurrencies, or off-chain — outside the blockchain. The first such exchange was carried out on 19 September 2017 between Decred and Litecoin.
2
Why are atomic swaps needed?
Exchanging cryptocurrencies on exchanges and other specialised platforms can still be time-consuming and is often associated with hefty fees. Moreover, not all exchanges support every coin or the required trading pairs, forcing traders who want to swap one asset for another into additional conversions.
Atomic swaps were designed to address these problems, including the risks of relying on a third party. The idea was first described in 2013, but only recently began to be implemented in practice.
3
How does it work technically?
Atomic swaps use a hashed timelock contract (HTLC). As the name suggests, an HTLC is a time-bound smart contract that involves generating a cryptographic hash that can be verified by the parties to the exchange.
In other words, an HTLC requires the recipient to confirm receipt of funds before a set deadline by producing cryptographic proof of payment. Otherwise, the transaction is void and the funds return to the sender.
4
How does it work in practice?
Alice has 100 LTC she wants to exchange for the equivalent amount of BTC. Traditionally, Alice would go to an exchange, fund her account and place a sell order for her LTC. With an atomic swap, Alice can exchange her LTC directly for Bob’s BTC.
As the initiator, Alice creates a contract address akin to a safe-deposit box. It holds Alice’s LTC during the swap. Opening it requires Bob’s signature and a number generated by Alice. It is crucial that Alice not share this number at this stage, as Bob could otherwise open the box and take the funds before the swap completes.
Next, Alice chooses a secret number and creates its hash. The hash acts as a lock, while the secret number is the key. Bob reviews the contract address from Alice, ensures everything is in order, then creates his own box with the same key. To do this, Alice sends Bob the previously created hash; to open the box, he needs Alice’s signature.
From that moment, Alice holds the key and can sign Bob’s box and thus redeem the funds tied to the address. Bob then receives the secret number, which he did not know until that point. He can use it to open Alice’s box and take the funds due to him.
As is clear, HTLCs structure the transaction so that each side depends on the other for successful completion. The transactions are crafted so that, if for any reason the deal is halted, all funds are returned to their owners after a period specified by each party.
5
Is the Lightning Network required for atomic swaps?
Contrary to a common misconception, the Lightning Network is not a prerequisite for atomic swaps, though it can make the process simpler, faster and more efficient.
Like atomic swaps, the Lightning Network uses hashed timelock contracts; the difference is that atomic swaps connect blockchains, whereas Lightning connects payment channels. In this method, Alice and Bob open payment channels with Carol and carry out the exchange through Carol without needing to trust her.
The shared underlying mechanism means integrating the Lightning Network with atomic swaps is straightforward, allowing different Lightning networks on separate blockchains to interconnect. A participant who opens payment channels on both blockchains can act as a payment processor or, for example, a decentralised altcoin exchange.
6
What is the difference between on-chain and off-chain swaps?
On-chain atomic swaps occur directly on the blockchains of the cryptocurrencies being exchanged; for a successful swap, besides supporting HTLCs, they must also use the same hashing algorithm.
Off-chain atomic swaps allow coins to be exchanged outside the blockchain and are an extension of the Lightning Network.
7
Which cryptocurrencies support atomic swaps?
The first successful exchanges using atomic swaps were conducted between Litecoin and Decred, and between Vertcoin and Bitcoin. These drew attention, but the approach is not limited to those assets.
Note that, in the initial implementation, users had to download the blockchains of both currencies to perform atomic swaps. For the average user, this is impractical from both a practical and technical standpoint.
However, a solution has been found and may soon be available to a broader audience. The Komodo project is developing its decentralised exchange, BarterDEX. Its developers have successfully executed an atomic swap via an Electrum server, which enables interaction with a cryptocurrency without downloading the entire blockchain.
Moreover, the Komodo team claims that, after linking the Bitcoin and Ethereum blockchains and implementing support for ERC-20 tokens, BarterDEX now supports p2p swaps between 95% of all existing coins and tokens.
Other notable projects actively working on practical implementations include Blocknet, which aims to create an internet of blockchains based on the Xbridge technology; Altcoin.io, which is developing a decentralised exchange using Plasma and a wallet with built-in atomic swap functions; and Atomic Wallet.
To track how close a given cryptocurrency is to supporting atomic swaps with another asset, a resource such as swapready.net. can help.
Рассылки ForkLog: держите руку на пульсе биткоин-индустрии!
