Atomic Swaps Explained: Technology, Projects, P2P Trading – COIN360
SUMMARY
August 15  |  12 min read

Atomic Swaps: Technology and Services

The COIN360 Editorial Team

For the average cryptocurrency trader, the de facto way of obtaining crypto or getting a specific altcoin is resorting to a centralized exchange. However, this method goes against the very essence of cryptocurrencies, since (for the most part) exchanges are centralized entities that act as an intermediary between your funds and the listed currencies on the exchange. The concept of intermediaries is closely related to banks and other centralized institutions, something that motivated the creation of Bitcoin back in 2009. In addition, exchanges are vulnerable to hacks, liquidity issues, poor management, and government regulation. Thankfully, developments within the industry have allowed for more decentralized ways of trading crypto to emerge, ones which have the potential to change the landscape of cryptocurrency services.

In this article, we will be taking a look at atomic swaps, also known as cross-chain swaps, as a decentralized alternative for cryptocurrency trading. We will discuss the meaning of atomic swaps, how they work, and compare some of the services that offer atomic swaps.

What Are Atomic Swaps?

Its name derives from atomicity, and it basically refers to an irreducible set of operations where either all of them take place, or none of them do. If we take this in the context of cryptocurrency trading, it refers to an irreducible set of operations that allow traders to engage in peer-to-peer cryptocurrency swaps while maintaining full control and ownership of their private keys, where either both traders send the agreed-upon amount of crypto, or none of them do.

Commonly, if a trader wants to get hold of a cryptocurrency, the most common course of action is to deposit funds on an exchange so people can trade their way to get the desired cryptocurrency. This, however, often comes with rigorous KYC measures, deposit and withdrawal fees, and handing over custody of your crypto to a third party that is ultimately susceptible to hacks and loss of funds. Through atomic swaps, a trader who, for example, has BTC and wants to get some ETH would only have to find a holder of ETH who is looking for BTC. Once the atomic swap occurs, the traders will successfully exchange previously agreed upon amounts of crypto with no intermediaries.

Atomicity in transfers was first discussed as such in the crypto industry in 2013 by Bitcointalk user Tier Nolan, who is largely credited as the creator of atomic swaps. However, one year prior to that, Sergio Demian Lerner described a P2P altcoin trading protocol with no central intermediary, calling it the “holy grail” of altcoins. Lerner’s proof of concept, called P2PTradeX, didn’t make use of atomicity or other related words to describe the protocol, but the idea is essentially the same, which makes P2PTradeX a precursor or prototype of atomic swaps. The first known instance of the implementation of atomic swaps took place on Sep. 19, 2017, between Decred (the cryptocurrency that implemented the atomic swap trading functionality) and Litecoin. There are reports of the Komodo decentralized exchange implementing atomic swaps a couple of days before, but it was only reportedly available for advanced users.

Decred and LTC perform the first atomic swap in September 2017

First devised and described in 2013, the first actual implementations of atomic swap technology took place in September 2017.


How Do Atomic Swaps Work?

The idea of having a trustless P2P system where two traders can swap cryptocurrencies has the potential to ultimately do away with many third party services, as the only thing needed would be two people who satisfy each other’s trading needs. But how do atomic swaps actually work?

Normal P2P trades between users who want to swap any given currencies have one huge caveat—if I keep up my end of the bargain and send a previously agreed upon amount of crypto to the other user, nothing ensures that they will do the same. The other user could send less than what was agreed, or simply not send anything at all and run off with everything. Atomic swaps tackle this problem thanks to HTLC smart contracts.

HTLC stands for Hash Time Locked Contract. Basically, they are time-dependent conditional payments. It acts as an escrow that makes sure that neither of the two parties involved in a trade can claim both of the cryptos being swapped. These escrows are programmed to communicate with one another and allow parties of a trade to claim their crypto only when certain conditions are met (in this case, when both parties have sent their funds and everything has been checked to be in order).

Hashlocks and Timelocks

In order to successfully provide a trustless system for swapping crypto, HTLC makes use of hashlocks and timelocks, which are essential for the proper execution of atomic swaps.

When a user opens a HTLC, they must think of a key (not much different than a password) and keep it secret from the counterpart of the swap. This key is called the preimage, and it will play an important role in the execution of an atomic swap. In order to claim the transferred funds, the counterpart of an atomic swap needs to have access to the secret preimage. This is the hashlock of an atomic swap.

The timelock is a timeout function of sorts for the contract. If the funds aren’t locked up and claimed by both parties before the contract times out, funds will be refunded to their original owners. This is key to achieve atomicity, the all-or-nothing atomic nature of atomic swaps.

unsuccessful attempt at an atomic swap

An unfinished atomic swap. As things stand right now, Frog cannot claim the BTC that Chrono locked up in the contract. To do so, he needs his preimage. If the atomic swap isn’t finished by the time the timelock elapses, Chrono will get a refund of his BTC.


The hashlock has a twofold function. Following the example above, once Frog locks up the agreed amount of crypto that Chrono will receive (say, ETH) in the contract, Chrono will have to use his preimage to claim it. When that happens, Chrono’s preimage will be revealed to Frog, who will now be able to claim his BTC. In other words, the preimage is needed to claim funds, and once it is used by the person who opens the HTLC, it will be automatically revealed to his or her counterpart as well. If all funds are claimed within the time limit, the atomic swap is considered to have been executed successfully.

a successfully executed atomic swap

When all funds involved in the transaction are locked up in the contract, Chrono will be able to claim his ETH by using his preimage, which will reveal the preimage to Frog as well, enabling both parties to claim their funds and execute the HTLC.


One key aspect of atomic swaps is that users can transparently check if the trade is going in accordance to what was previously agreed upon. If the amount of ETH that Frog locks up is less than what was previously agreed, Chrono can simply not claim the BTC, and the HTLC will eventually time out.

Services That Offer Atomic Swaps

Atomic swaps can be conducted both on-chain and off-chain. The main drawback to on-chain atomic swaps is that transactions are slower, both currencies must support HTLC, and both must also have the same hashing algorithm, such as Bitcoin and Bitcoin Cash’s SHA-256. Off-chain swaps, on the other hand, make use of layer 2 solutions such as the Lightning Network for almost instantaneous swaps.

In this regard, there are several services that offer atomic swaps and allow users to circumvent the aforementioned limitations of swaps.

Komodo

Komodo is a decentralized exchange that is also one of the pioneers in atomic swap technology. In 2014, Komodo’s lead developer wrote the code that would allow for some of the very first peer-to-peer swaps to be made. At first, the swaps could only be made between NXT assets, but the code was eventually extended to fit any SHA-256 cryptocurrency.

In mid-2017, Komodo developed BarterDEX, an open-source protocol and GUI that allows you to trade any coin that developers choose to connect to it. It conducts decentralized order matching (using a low-level pubkey-to-pubkey messaging protocol), trade clearing, and settlements executed through an atomic cross-chain protocol. What’s different about BarterDEX is that they provide different methods to increase asset liquidity by creating Liquidity Provider Nodes (LP nodes) and they also provide a service called Liquidity Multiplication, a protocol that allows the same funds to be used in multiple requests on BarterDEX orderbooks, canceling all outstanding requests once one is completed, creating an exponentially higher amount of liquidity on the DEX.

In October 2017, Komodo developed a method for atomic swap trading with Electrum servers that allowed traders to trade in SPV/Lite mode. Then, in February of the following year, Komodo performed a swap between Ethereum and Doge, allegedly making it the first atomic swap to occur between a Bitcoin-based coin and Ethereum (also known as etomic swaps). By March of that year, Komodo’s atomic swap technology supported trades between 95% of all cryptocurrencies.

In July 2019, Komodo released the public beta test of AtomicDEX, a non-custodial multicurrency wallet that comes with built-in decentralized trading features, and the third generation of Komodo’s decentralized exchange technology. AtomicDEX allows people to swap almost any asset directly. It supports Bitcoin, UTXO-based coins, and ERC-20 tokens. At press time, there are 17 coins enabled in the app, with more coins to be added in upcoming updates.

A difference between Komodo and other services is that in order to perform an off-chain atomic swap on Komodo, the person who posts a trade order must deposit 112% of the amount of the order once the swap process has been initiated (the 12% can be reclaimed after the swap has taken place). The person who accepts the offer must pay a 0.15% fee to make the swap. In both cases, the Unspent Transaction Output (UTXO) must be separate from the ones they intend to trade.

Atomic Wallet

Atomic is a non-custodial wallet with built-in atomic swap technology. It comes with an exchange service where users can place new orders or fulfill a previously placed order in the market. Thanks to partnerships with other exchanges, Atomic currently supports 222 cryptocurrencies. However, atomic swaps are only supported between Bitcoin, Litecoin, and QTUM, with support for Ethereum reportedly coming soon.

Additional features include the ability to purchase crypto with a credit card (powered by payment processor Simplex), an android app, and ERC20 and BEP2 token support. At present, there is no support for hardware wallets.

One of the most enticing features about Atomic Wallet is that it has its own membership rewards, a cashback program that depends on the amount of AWC (Atomic’s native cryptocurrency) that a user is holding in Atomic. There are four membership tiers: Blue, Silver, Gold, and Platinum, which offer 0.25%, 0.5%, 0.75%, and 1% cashback for each exchange respectively. The minimum requirement to be a Blue user is to hold 1,000 AWC, which is equal to $149.53 at press time. A caveat to this is program is that there is a monthly limit: Blue users will be capped at $100 in cashback per month, and Platinum users can get up to $300. Cashback rewards are also distributed on a monthly basis. According to its official website, users can also hold BNB tokens to be eligible for the cashback program.

Liquality

Liquality is a P2P cryptocurrency solutions project that launched their interface for atomic swaps in June 2019. It currently supports atomic swaps between Bitcoin, DAI, and Ethereum. This is Liquality’s first product and it is purported to be in accordance with their vision of a “more open and equitable future where anyone can access the global digital economy in a free, secure, and efficient way.”

Liquality’s only function is to serve as an execution and settlement interface for atomic swaps. This means that Liquality has no matching mechanism available. To conduct atomic swaps, users will have to find a counterparty elsewhere, and then use Liquality’s interface.

The interface supports both MetaMask and Ledger hardware wallets. In addition to this, the Liquality team is working on the integration of additional wallets, with Trezor reportedly being next in line.
Additional features that are in the works include: support for additional coins (Litecoin, Monero, ZCash, Grin, and Ethereum-based tokens like DAI and ERC20 tokens), parameter customization (at present, users will be able to get a refund 12 hours after funds are locked up, this period will reportedly be customizable), the integration of Layer 2 solutions for faster atomic swaps, and a mobile app.

Decred

Decred is a community-driven cryptocurrency most notably known in the context of atomic swaps for being one of the cryptocurrencies involved in the first cross-chain swap. It doesn’t offer a service per se, but the Decred team created prototype tools to manually perform cross-chain atomic swaps. It supports Bitcoin, Bitcoin Cash, Decred, Litecoin, Monacoin, Particl, Qtum, Vertcoin, Viacoin, and Zcoin.

For more information on these prototype tools, read here.

Final Thoughts

Atomic swaps have the potential to solve some of crypto’s biggest challenges. Sadly, the overly aggressive marketing tactics of entrepreneurs and startups has led to the devaluation of words such as revolutionary, but this is a development that has the potential to actually revolutionize the space. If further development and adoption cases flourish, we might enter a new era in crypto where intermediaries and centralized businesses, such as centralized exchanges, might have to adapt or fall out of fashion.

However, atomic swaps still have some hurdles to jump before it fully reaches its potential. As things stand right now, atomic swaps are limited. In most cases, both coins must share the same hashing algorithm and support HTLC. Because of this, many cryptocurrencies are simply not eligible for atomic swaps, and the coin pairs that are available are very limited when compared to the trading pairs available on centralized exchanges. Contrary to centralized exchanges, DEX don’t have dark pools—special order books where certain orders, such as the ones that are equal to millions of USD, are not visible to the public because they could manipulate the market otherwise. In order to implement dark pools in DEX, overly complicated cryptography is required. Some alternatives that offer much better compatibility have emerged (such as Komodo), but they still can’t compare to their centralized counterparts. Adoption is also very low as there simply aren’t enough services that offer atomic swaps. Hopefully, the development of atomic swaps will change this, and it might even help towards making the original definition of Bitcoin a reality: a peer-to-peer electronic cash system, with little to no influence from intermediaries.

Thank you for reading,
The COIN360 Editorial Team