Atomic swaps are often discussed but rarely understood in full. How do atomic swaps work? And what makes them so important?
As the world leader in atomic swap technology, Komodo has all the answers you’re looking for. This post will explain exactly what atomic swaps are, provide a brief history, discuss the benefits of atomic swap trading, and describe how Komodo Platform is pushing this crucial technology to the forefront of the blockchain industry.
What Are Atomic Swaps?
Put simply, a atomic swaps are trades of cryptocurrencies made directly from one user to another. Atomic swaps are sometimes called “peer-to-peer” trades because the trade is made wallet-to-wallet.
Atomic swaps are also referred to as “trustless.” This means it’s not necessary for traders to trust other traders or a centralized middleman, like a cryptocurrency exchange. In fact, atomic swaps do not require proxy tokens, escrow services, or any other type of third-party.
It’s important to emphasize that all traders hold their private keys throughout the entire atomic swap process. As a result, atomic swap trading is magnitudes more secure than trading crypto on a centralized exchange.
Most centralized exchanges do not allow users to retain control of their private keys which, in effect, means that users do not actually own their coins and tokens. As the old crypto mantra goes:
If you do not hold your private keys, then you do not own your coins!
The logical conclusion, then, is that centralized exchanges— not the users— own the coins. Traders are choosing, perhaps unwittingly, to let the centralized exchange seize ownership of their coins and tokens. If the exchange gets hacked and funds are comprised, there is little recourse for the users who had their coins and tokens stolen.
This stands in stark contrast to trading via atomic swap technology for two reasons. First, atomic swap trading allows users to keep control of their private keys. Second, there is no increase in security risk when performing an atomic swap. The risk is exactly the same as storing your coins or tokens in any online wallet (a “hot” wallet).
Of course, the safest way to store crypto is in an offline wallet (a “cold” wallet). However, this method of storage does not allow any form of trading. So if you want to exchange your coins or tokens for other cryptocurrencies, atomic swap trading is indisputably the safest way to do it.
A Brief History Of Atomic Swaps
Before we dive any deeper into how atomic swaps work, let’s take a minute to cover some history.
The idea of trustless, peer-to-peer exchanges of cryptocurrency has been a topic of public discussion since at least 2012. For instance, a developer named Sergio Demian Lerner created a first draft of a trustless exchange protocol in July 2012. While this was a good start, the idea was not yet fully fleshed out.
Later, in May 2013, Tier Nolan provided the first full account of a procedure for atomic swaps. Tier Nolan is widely credited with being the inventor of atomic swaps.
At that point, the idea of an atomic swap was little more than that— an idea. While everyone recognized the benefits such a trading mechanism would bring, no one had written the code to make atomic swaps possible.
Just one year after Tier Nolan presented the idea of an atomic swap protocol, in May 2014, Komodo’s Lead Developer jl777 wrote the code that allowed some of the very first peer-to-peer swaps.
At first, jl777’s code only permitted atomic swaps between NXT assets. Next, jl777 developed a method of atomic swaps that allowed NXT assets to be exchanged with Bitcoin. The code was eventually extended to allow atomic swaps between any Bitcoin-protocol coins.
Many of the first atomic swaps were performed via a command line interface between developers testing out the brand-new technology. As such, most of the evidence of the earliest atomic swap exists only on chat forums.
During the summer of 2017, Komodo developed BarterDEX, the first GUI for a fully atomic-swap-powered crypto trading marketplace. Komodo began integrating dozens of Bitcoin-protocol coins and publicly performing thousands of atomic swaps on BarterDEX.
Atomic swaps didn’t become widely known until several years after the first atomic swaps were made. In September 2017, Litecoin Founder Charlie Lee Tweeted about a successful swap from Litecoin to Bitcoin, bringing a great deal of public attention to the groundbreaking technology.
The next big development came the following month, in October 2017, when Komodo Platform devised a method of atomic swap trading with Electrum servers. This allows traders to execute atomic swaps without needing to download the entire blockchains for the coins they’d like to exchange. This is often called trading in SPV mode or “Lite” mode.
In February 2018, Komodo bridged the gap between Ethereum and Bitcoin-protocol coins with a swap between ETH and DOGE. It appears that Komodo was the first blockchain project to successfully execute an atomic swap between ETH and a BTC-based coin.
Finally, in March 2018, after just one month of bringing atomic swap integration to many more ERC-20 tokens, Komodo’s atomic swap technology supported trades between 95% of all coins and tokens in existence. At the time of writing, over 110,000 atomic swaps have been performed on BarterDEX, Komodo’s decentralized exchange (DEX).
The Benefits of Atomic Swap Trading
Now that the history of atomic swaps is clear, let’s take a closer look at the benefits of atomic swap trading.
First and foremost, users do not have to give up their private keys at any point in time. Period. When trading via atomic swaps, you always own your private keys (and thus your coins and tokens). You never have to give up control of your funds to a third party.
Second, atomic swaps are designed such that the swap takes place and both parties receive the funds they desire, or nothing happens at all and both parties retain the funds they funds they started with (minus a very small transaction fee for the “order-taker”). Atomic swaps make crypto trading as secure as it can possibly be.
Third, atomic swaps are much cheaper than trading on centralized exchanges. Most centralized exchanges charge exorbitant fees, normally 0.2% of every transaction for each party in a trade. Most centralized exchanges also charge a fee to withdraw funds. Imagine that— paying a fee to a centralized exchange just for them to give you back control of your own funds!
Last, but not least, atomic swaps allow you to trade between a wider variety of coins and tokens. Komodo’s decentralized exchange, for example, bridged the gap between Bitcoin-protocol-based coins and Ethereum-based ERC-20 tokens. As such, Komodo’s DEX supports direct trading pairs between 95% of all the coins and tokens in existence.
For instance, a user can trade directly from a BTC-based altcoin to an ERC-20 token (or vice versa). Before Komodo Platform made this possible, a trader would have had to make multiple exchanges to get the same result. The trading process would have been BTC-based altcoin—>Bitcoin—>Ether—>ERC-20 token, with a fee for each of the three transactions.
With all of these enormous benefits, you can see why atomic swaps generate so much excitement in the blockchain industry.
The Atomic Swap Process Explained
Suppose that there are two traders, Bob and Alice. Let’s say that Bob has BTC he would like to exchange for KMD. Meanwhile, Alice has KMD and she is hoping to swap it for BTC. Here’s exactly how the atomic swap would unfold, step-by-step.
Bob posts a trade order on Komodo’s DEX. This is listed as Step 0 because, technically, it’s not part of the atomic swap process. However, it must take place before the atomic swap can begin.
Alice sees Bob’s offer and accepts it. She commits to the trade by paying the atomic swap fee, which is only 0.15% of the total trade amount. The purpose of the atomic swap fee is to make sure Alice, and all other users, don’t spam the network with rapid requests. Note that Bob does not have to pay any transaction fees for the trade.
Also, note that this transaction fee must be a separate UTXO from the one Alice will swap with Bob. If you’d like to learn more, read Komodo’s guide to UTXOs here.
Once Alice has paid the fee, the atomic swap has officially begun.
Bob sends a deposit of funds to a secure address. The decentralized nature of atomic swaps guarantees that no one— neither Bob, nor Alice, nor any third-party administrators— has access to these funds until the trade times out or has been completed.
Bob’s deposit must be 112% of the amount of the order that he originally posted. If Bob is an honest actor, this is not a concern because those funds will be returned to him. Whether the atomic swap fails or whether the atomic swap is complete, Bob’s deposit will be returned. The deposit simply removes any incentives to cheat.
As with Alice’s transaction fee, Bob’s deposit must be a separate UTXO from the one that he intends to swap with Alice.
Alice then sends her KMD to a second secure address. Just as before, nobody— not Bob, not Alice, not even Komodo Platform admin— have the ability to touch these funds until the swap ends.
If, for any reason, the trade fails at this point, then the atomic swap would be timed out and get canceled. At that point, Bob’s BTC deposit would be released back to him and Alice’s KMD would be returned to her, too.
Bob sends his BTC payment to Alice, finishing his part of the deal. Recall that this sum of BTC is a separate from and additional to the deposit of BTC paid in Step 2. Only Alice is able to claim Bob’s BTC payment.
Alice now accepts Bob’s BTC payment. Once Alice has claimed Bob’s BTC payment, Bob gains the ability to claim Alice’s KMD payment.
Bob accepts Alice’s KMD payment. At this point, both parties have obtained the funds they were hoping to trade for. The atomic swap is a success. Hooray!
Now that both parties have exchanged funds, Bob is allowed to reclaim his deposit of BTC. At this point, the atomic swap process is complete.
That’s all there is to it! This process is designed to incentivize each party to continue on to the next step of the trade. It is also an atomic process, which literally means that either: (a) the swap occurs exactly as Bob and Alice agreed, or (b) nothing takes place and both Bob’s and Alice’s funds are returned to them (except the atomic swap fee).
If you’d like to learn even more about atomic swaps, please read Section III, Part 6.5 of the Komodo Platform White Paper.
Komodo Platform’s World-Leading Interoperability Tech
Atomic swaps are the first big step towards blockchain interoperability because they allow users to make exchanges directly between two different blockchains.
Before atomic swap technology was available, each blockchain was like an island with only one bridge off: to either Bitcoin (for BTC-protocol coins) or Ether (for Ethereum-based ERC-20 tokens). Once on the larger islands of BTC and ETH, traders had more bridges to choose from. However, every other bridge just led to another isolated island with only one exit option.
Komodo’s atomic swap technology builds bridges between 95% of all the coins and tokens in existence. As a result, traders will never be stranded on a small blockchain island ever again. This is the first stage of blockchain interoperability.
The second stage of blockchain interoperability is cross-chain transaction proofs and fungibility. With Komodo’s new Cross-Chain Smart Contract technology, exchanges can take place between two chains without a swap or trade occurring.
This is made possible by a series of extensive Merkle tree proofs and a burn protocol that eliminates coins on one chain while allowing the same quantity of coins to appear on an entirely separate chain. This holds the coin supply constant while allowing inter-blockchain exchanges of value.
For the time being, this technology is being tested and will be implemented only for chains on Komodo Platform. As we look further into the future, Komodo hopes to extend this technology to all blockchains in order to achieve our vision of a global, fully interoperable blockchain ecosystem.
If you’d like to get all of the latest updates from Komodo, sign up for a weekly newsletter. You can also join our thriving community on Discord to chat with Komodo’s developers and other core team members.
Join us at the cutting edge of the blockchain industry.