Crypto Quantshots

Be better informed! Get to know the Crypto ecosystem in more detail with reports covering all things Crypto.

Atomic Swaps, Decentralized Exchanges, and The Future of Crypto Exchanges

Jul 27, 2018

What are Atomic Swaps

An atomic swap, also known as atomic cross-chain trading, is a peer-to-peer (P2P) transfer of different cryptocurrencies without the use of a third-party transaction medium.  Third-party intermediaries, such as today’s cryptocurrency exchanges or escrow services require a level of trust in their services. When one stores their cryptocurrencies on a centralized exchange, that person gives the exchange their private keys, and therefore, technically is giving that exchange ownership of their coins.

Atomic swaps utilize Hash Timelock Contracts (HTLCs) to ensure one party doesn’t bail on their side of the trade. HTLCs ensure that both parties fulfill their trade requirements by requiring each recipient to provide a proof of payment, a unique number used for cryptographic hashing, before a specified deadline. After the first party acknowledges payment, the second party must enter their own unique number before the trade is executed.  If either party fails to confirm their sides of the transaction, the entire transaction itself is voided and funds return to their original owners.

There are two different types of atomic swaps: on-chain swaps and off-chain swaps

  • On-chain swaps are transactions that physically take place on the currencies’ blockchains. If two people wanted to exchange coins, both cryptocurrencies would have to be built on the same hash algorithm. For example, since Litecoin (LTC) was built off of Bitcoin’s (BTC) source code, they use the same hash algorithm and are capable of atomic swaps. Along with this minor inconvenience, both cryptocurrencies would have to support HTLCs. Creating on-chain atomic swaps is also not an easy task: a user needs to be well-versed in programming to use on-chain atomic swaps.
  • Off-chain swaps include a platform facilitating the transfer of tokens. Off-chain swap platforms seek to solve the problems associated with on-chain swaps.  With off-chain swaps, a second layer/platform of network nodes is “placed on top” of the transacting blockchains.  This platform is basically a payment channel connecting the parties involved. Instead of every trade being recorded on the blockchain individually, the platform only records on the respective blockchains when the trading channel is initially opened, and when it is closed after all desired trades are completed. This method in and of itself also tackles scalability issues many cryptocurrencies such as Bitcoin have by off-loading back-and-forth transactions from the blockchain. The most well-known example of an off-chain swap platform is the Lightning Network, discussed below.

Examples of Atomic Swap Platforms

  • Lightning Network
    • The Lightning Network (LN) is the leading platform for performing off-chain swaps.  As discussed above, LN is a payment channel allowing parties to transact as many times as wanted, and only touches the blockchain when opened and closed.  The channel is opened by two parties depositing equal quantities of currency in a multi-signature “box” (for this example, both parties deposit 10 Bitcoin (BTC). If one person wants to transfer 2 Bitcoin to the other, and this is the only desired transaction between the pair, the receiver would withdraw 12 BTC, while the sender only withdraws 8 BTC. After the final transaction, the channel is closed and recorded on the blockchain. This is how cryptocurrencies can have their scalability problems fixed by becoming a part of the LN; the coin’s blockchain is only accessed twice, as opposed to several times if the two parties were to transact multiple times. In addition to scalability fixes, the LN is also instantaneous, and lowers transaction fees.  In order for a coin to become a part of the LN, its blockchain must have the software upgrade SegWit installed. Current coins that use the LN include: Bitcoin (BTC), Litecoin (LTC), Decred (DCR), Stellar Lumens (XLM), and several others.
  • Raiden Network
    • The Raiden Network (RN) is another example of an off-chain swap platform. It works very similarly to the Lightning Network, and also provides a scalability solution, has low fees, and transactions are near-instantaneous.  The RN however is only compatible with coins built on Ethereum’s platform, the ERC20 protocol.

What is a Decentralized Exchange (DEX)

A DEX is a trading platform like any other digital asset exchange, except that users maintain ownership of their private keys, and therefore their coins. In common centralized exchanges (i.e. Binance, OKEx, Poloniex, etc.) users give up ownership to their coins when they are deposited. These coins are then kept in large address pools called “honeypots”, which are often subject to attacks. These centralized cryptocurrency exchanges have been subject to many hacks and have had millions of dollars stolen from their platforms. Some notable examples include the security breaches of Mt. Gox in 2014, Bitfinex in 2016, and more recently, Bithumb’s USD$31 million hack in June 2018.

On decentralized exchanges, users’ coins are not kept in these giant “honeypot” addresses. Instead they retain possession of their private keys, and therefore ownership of their coins, which are held in the users’ own individual addresses. This prevents any potential hacks on the DEX from stealing vast amounts of coins from a single “honeypot” account. 

DEXs do come with their own set of limitations however.  One of these issues is illiquidity.  On a DEX, traders individually set and take orders. The problem is that these orders all exist on separate books, so many times traders have to look into multiple books just to place their orders. This illiquidity can be easily resolved by using a process called “Networked Liquidity”. With Networked Liquidity, these individual books are all connected via an API, so the orders can be shared with each other.

Another issue affecting DEXs is called front running, or the fact that traders can outbid already-placed orders on the exchange.  Since most DEXs run on Ethereum smart contracts, anyone comfortable with blockchain technology can check the blockchain to see impending orders. These people can then jump in front of these orders by placing the same exact order but with more GAS, leaving the first order unrealized and erased from the book. There are a number of methods proposed to solve this problem. Two suggested ways to tackle this were to implement a ‘minReturn’ on trades, cancelling them when the user realizes he is being outbid, and to implement a maximum GAS price on trading fees. Both of these are only short-term patches and wouldn’t actually fix the problem though. Another thought on mitigating this front running issue is called a “Commit-Reveal Scheme.” This involves a trader secretly committing his funds in a transaction, but not exposing that information. After the transaction is validated and mined, a second transaction is made containing the actual details. This executes the order on the DEX before anyone can find out about it and try to outbid it. While this sounds like it would work best, this method doesn’t prevent accidental collisions, such as two identical orders being placed at the same time.

Examples of Decetnralized Exchanges

  • IDEX
  • WavesDEX
  • CryptoBridge
  • OpenLedger
  • StellarTerm