Cryptocurrencies were first created to solve a problem regarding governance and centralization; they were made to ensure that the money system wasn't controlled or inflated by a single entity. Cryptocurrencies returned financial power democratically back to the users.

However, many parts of the system are still centralized, mainly surrounding exchanges and trading. Though a few decentralized exchanges (DEXs) exist, they either only work selectively on some coins, or rely on derivatives such as OPEN.btc
that track the value of a coin.
Most of them don't actually swap blockchain coin ownership during trades, and this is quite an important problem to solve. Thankfully, a system exists to solve this conundrum, and is key to the rise of decentralized exchanges. This article will cover cross-chain atomic swaps, and why this technology will allow DEXs to take over.

The Decentralized Exchange (DEX) vs Centralized Exchange (CX)
Decentralized exchanges (often referred to as "DEXs") are exchanges that aren't governed by a single company, person, or entity. This is very similar to how decentralized cryptocurrencies like Bitcoin aren't governed by a single entity. Rather, both of these decentralized systems are governed freely; by the people and the users who use the system.

Centralized exchanges (CXs) are exchanges that we normally use today, from Coinbase to Bittrex to Poloniex. CXs are governed by a single company, and this is why it's risky to trust them with funds.
Some of them get shut down or hacked, such as the infamous Mt. Gox exchange. Others have large downtimes due to being targeted by hackers. All of these exchanges have trading fees and some even have withdrawal fees, taking cuts of your money and your profits.
These are all problems that DEXs do not cope with. DEXs, to reiterate, aren't owned or operated by single entities, servers, companies, or people. This means, with a DEX, you (theoretically) get:
- 100% uptime (0% downtime)
- no need for trust
- no possibility of shutdown or fund loss
- no exchange/trading fees
- no withdrawal fees (except for network transaction fees)
- complete control over trading/exchange terms
and many other features. DEXs already exist today, with one of the most popular being the OpenLedger or BitShares DEX. However, the problem is that these DEXs can only perform decentralized trades of specific coins. OpenLedger is incompatible with trading Bitcoin directly, so it trades a cryptocurrency called OPEN.btc
, which is different from Bitcoin but is worth 1 BTC.
This is a problem if we want to perform fully-trustless secure decentralized trades directly on the blockchain. Trading with derivatives or "mock cryptocurrencies" like OPEN.btc
introduces new variables and more complicated steps to the system.
Cross-Chain Atomic Swap
The solution to this is called an "atomic swap." Atomic is a word used in cryptography and science to imply that two events occurred simultaneously, such that they can be referred to as just one event.
A handshake is atomic, because "A
shaking B
's hand" occurred simultaneously with "B
shaking A
's hand"; it's not possible for them not to occur simultaneously.
Let's say Alice and Bob want to perform a cryptocurrency trade; namely, Alice wants to sell 1 BTC for 20 ETH, and Bob wants to sell 20 ETH for 1 BTC. They find each others' requests, and pair with each other.

How do they perform the trade without relying on an escrow or third party? A terrible solution would be:
- Alice sends 1 BTC to Bob
- Bob sends 20 ETH to Alice
The above "solution" requires an insane amount of trust from Alice, because after Step 1, Bob could easily just keep the Bitcoins and the Ethereum. Therefore, the above solution doesn't work.
Solution: Hashed Time-Locked Contracts (HTLC)
However, in recent years cryptocurrency enthusiasts and developers have found solutions using something called a "Hashed Time-Locked Contract", or HTLC.

An HTLC basically allows the recipient of a pending payment to acknowledge or verify that the payment occurred, before a set deadline. The recipient would acknowledge the payment using a cryptographic proof.
The secondary component is what happens if the recipient does not acknowledge the payment. If they fail to acknowledge the transfer before the set deadline, they forfeit their ability to claim the pending payment.
This HTLC technology can be used in tandem with Bitcoin transactions to perform cross-chain atomic swaps. This has actually already been done on testnets multiple times; most recently, Altcoin.io performed a BTC/ETH testnet atomic swap, and the creators of Litecoin and Decred performed a LTC/Decred atomic swap.
HTLC Drawbacks
There are drawbacks to using an HTLC. In exchange for solid and complete security/accountabilty, the user forfeits some convenience. If the recipient were to stop the process in the middle, everyone would still have access to their respective cryptocurrencies.
However, they would only be able to transact with them after a certain amount of time (generally a day or two in tests). This deadline is decided by the set deadline the two parties use for their HTLC contracts.
Technical Atomic Swap Details
In the last section, we covered HTLCs and how they help support atomic swaps. But what is the technical "system" or method that allows this to occur? Below, we'll take a look at the Tier Nolan
model or example for atomic swaps. Specifically, Alice is selling 1 BTC to Bob, for 20 ETH.
- Alice chooses a random number, say
x
. She hashes the number and givesH(x)
to Bob. - Alice creates a transaction that sends her BTC to a multi-sig address (2-of-2). This address is such that B can only redeem the coins if he reveals the value of the number
x
. Let's call this transactionTx-1
. - Bob creates a transaction that sends his ETH to a multi-sig address with the same configuration as A's transaction. Let's call this
Tx-3
. - Alice and Bob do not broadcast
Tx-1
andTx-3
yet. Instead, they each create time-locked refund transactions that allows each of them to take back their original coins if the trade was unsuccessful. A's locktime isP
and B's isQ
. It's recommended thatP
is much larger thanQ
. - Alice reveals the value of the number
x
, and redeems her 20 ETH from Bob. - Bob receives the value of
x
from Alice's reveal. He reveals it as well, and redeems his 1 BTC from Alice.
Above is the complete description of the model. Note that if at any point in these steps, Alice or Bob fails to complete their side of the deal, the other can easily use a refund transaction to cancel the trade.
Conclusions

If you've read this far, it's clear you're knowledgeable about cryptocurrencies; you now know what a cross-chain atomic swap is, and how this technology can greatly benefit the DEX (decentralized exchange).
As the Lightning Network for Bitcoin is developed and released, cross-chain atomic swaps on Bitcoin are expected to ramp up, beginning a possible reign for decentralized exchange, and ridding us of the problems with centralized ones.
Thanks for reading,
ā @mooncryption
image sources: 1, 2 -
modified, 3,4, 5, 6
references: