Cryptocurrency these days is almost automatically associated with exchanges. Coinbase, Binance, Bitfinex - Platforms that seamlessly facilitate trading one cryptocurrency for another, and even convert it to fiat. A user creates an account, opens a wallet, and sends his or her cryptocurrency to any place around the globe. Unbeknownst to the common user is the fact that by doing so, he or she is giving full control of their assets to the exchange.
End-users are under constant risk of hacks, the sort that happened to Mt.Gox, Coincheck, Binance, or Bitgrail. Users are also constrained by the requirements and regulations of the country of the exchange, and are subject to price manipulations, as well as high fees.
The same ethos that created cryptocurrencies should be taken further into their mode of exchange. That is why the concept of peer-to-peer, or wallet-to-wallet, exchange across blockchains has been sometimes dubbed the “holy grail” of the altcoin ecosystem.
Because of the constraints of computer code, and the blockchain ledger, a simultaneous swap cannot be made. One side must commit their side of the deal first, which leaves them vulnerable to counterparty risk. An escrow can be used -- this is a third-party which both sides agree on, and which functions as the middleman. However doing so merely transfers the trust to somewhere else.
A swap protocol, built with smart contracts, can allow for an “atomic” transaction, which means that either the entirety of the process takes place, or the entirety of it reverts. Such protocols aim to remove the need for trust completely, protecting both sides from vulnerability by making both sides of the trade interdependent. In this case the trust is placed on a smart-contract with automatic execution. The code is open and readable, but no one can tamper with it.
On-chain atomic swaps still rely on blockchain transactions where mining is required, as such, there are transaction fees and latency. Speed is vital for a successful exchange, and at this stage blockchains simply cannot compete with centralized exchanges. Also, all transactions are recorded on both blockchains, so this can be a privacy issue if the data is de-anonymized. The alternative is off-chain swaps in the form of payment channels such as the Lightning Network. As James Lopp tweeted in January: “Nearly instant atomic swaps via Lightning Network are coming sooner than everyone thinks.”
From a recent conversation I had with someone who is building it: "Nearly instant atomic swaps via Lightning Network are coming sooner than everyone thinks. Definitely not a year away, but mere months."— Jameson Lopp (@lopp) January 4, 2018
For a comparison, exchanges don’t need to broadcast blockchain transactions. They can just represent cryptocurrency amounts with “vouchers.” These vouchers can be transmitted instantaneously inside their system, and only be redeemed in crypto when withdrawn, similarly to how banks operate. Usually all the exchange’s cryptocurrency supply is stored in one giant multi- signature address. These are usually the largest wallets, some holding over a billion USD in one cryptocurrency. This means that for all intents and purposes, the amount displayed under one’s exchange wallet is virtual, an IOU. As such exchanges are massive honeypots for hackers.
The first draft of a trust-less swap was published in bitcointalk forums by Sergio Demian Lerner in July 2012. He named it P2PTradeX and explained it as follows:
1. John commits transaction 1 to a holding wallet. This is the address of a contract which will unlock to Marsha if a “proof” of step 2 is published, with a time limit.
2. Marsha sends transaction 2 in a standard way.
To unlock the holding wallet and be able to “spend” the value, a proof of the transaction must be submitted, confirming that the transaction has taken place. The contract also specifies the amount of confirmations required, from which block to count the confirmations, and the expiration date.
This type of contract is called a Hash Time-lock Contract. However, this model left an imbalance and a vulnerability for Marsha, as her transaction is irreversible, while Bob’s commitment depends on a future proof, and the burden of proof lies with Marsha.
A year later, Tier Nolan provided the first account for atomic transactions, with the required code to verify the hash. This process included a holding wallet for both sides and was completely atomic. If the process is halted, it can be reversed no matter when it is stopped. Because it is implemented with the native code provided in Bitcoin, called SCRIPT, this approach can be used directly to trade between bitcoin-derived chains without specialized support from the protocol, such as Bitcoin, Litecoin, Decred, Viacoin, and Vertcoin, which have all successfully completed on-chain atomic swaps.
In 2014, a year after Nolan’s post, the developer jl777 carried tests for swapping Litecoin with Dogecoin, two Bitcoin-derived coins. jl777 later became the lead developer for Komodo, who developed BarterDEX , a platform which included order matching, trade clearing, and liquidity provision.
Komodo introduced additional steps to create incentives to proceed at each stage of the swap, such as the addition of a fee to avoid spam, and a security deposit consisting of 112.5% of the traded amount. BarterDEX also records a merchant’s reputation score for both sides.
Decred successfully achieved an atomic swap with Litecoin in 2017, and so did Litecoin. These made headlines at the time, and popularized the term. The website swapready.net provides a table of how close each network is to supporting atomic swap.
On March 2018, Lightning Labs announced the first Lightning beta release for mainnet on both Bitcoin and Litecoin, which allows off-chain atomic swaps. This would make make Atomic Swaps instantaneous, private, and fee-less. As Charlie Lee said, “Lightning with atomic swap makes Litecoin effectively Bitcoin’s sidechain, but with much better security.”
BarterDEX also achieved swaps with the Ethereum network, which bridged the gap between Bitcoin-protocol coins and Ethereum-based ERC-20 tokens, as well as ERC-721 collectibles. This was achieved by supporting coins that use SPV (Simplified Payment Verification ), which also 6 removes the need to download blockchain data. Following the success of Decred, and using their codebase, altcoin.io achieved swaps with an ERC-20 as well.
Atomic swaps have the potential to disrupt the current exchange mechanisms. Both on-chain swaps, as well as their faster and cheaper counterparts through payment channels. As the ecosystem matures, it will find ways to interlock and play together well with clever technological solutions.