Atomic Swaps has the potential of completely revolutionizing the money transfer system in the crypto world. To put it in simple terms, atomic swaps will enable people to directly trade with one another wallet-to-wallet.
Since 2012, the concept of a trustless, peer-to-peer cryptocurrency has been a pretty hot topic. In July 2012, a developer by the name of Sergio Demian Lerner created the first draft of a trustless exchange protocol. The idea was pretty appealing, however, it wasn’t really fleshed out.
The breakthrough in atomic swap research happened around May 2013, when TIer Nolan provided the first full account of a procedure for atomic swaps. Tier Nolan is widely credited as the inventor of atomic swaps.
In this guide, we are going to look into how atomic swaps work and the advantages that they are going to bring into the ecosystem.
Problems With Centralized Exchanges
Suppose Alice has Bitcoin and wants to sell them for Litecoin. Similarly, we have Bob who has Litecoin but wants some Bitcoin instead. Normally what would have happened is that both of them would have had to go a centralized exchange, sell their cryptos and buy newer cryptos. However, there are a lot of problems with these exchanges.
#1 Hack Vulnerability
Centralized exchanges always have the risk of getting hacked. Probably the most infamous example of this is Coincheck which got hacked for $550 million worth of NEM. The worst part is that this hack greatly reduced crypto sentiment in Japan, a country that was traditionally known to be very crypto friendly.
#2 Subject to Mismanagement
The infamous Mt. Gox hack where bitcoins worth $500 million were robbed happened directly as a result of CEO Max Karpeles’s inept management. As Andreas Anatopoulos put it:
“Magic The Gathering Online Exchange (Mt. Gox) is a systemic risk to bitcoin, a death trap for traders and a business run by the clueless.”
#3 Volume Demands
Exchanges can’t deal with changes in demand, especially when there is a sudden increase in demand. Do know why BCH’s value nearly went down by half on 12th November?
Turns out, there was a sudden rise in demand and most exchanges couldn’t cope. Bithumb, in particular, suffered 90 mins of downtime and lost 60,000 BTC in volume.
#4 Subject to Government Regulation
Because the centralized exchanges are registered in particular countries, they are subject to the whims of the government,
Because of the reasons stated above, centralized exchanges are not the ideal way to go forward for mainstream adoption.
What Are Atomic Swaps?
Atomic swap is a peer-to-peer exchange of cryptocurrencies from one party to another, without going through a third party service like a crypto exchange. During this entire process, the users have full control and ownership of their private keys.
On September 20, 2017, Decred and Litecoin did the first known successful implementation of the atomic swap.
Another interesting thing to note about atomic swaps:
They can either be directly executed between separate blockchains with different native coins
Or, they can also be executed via off-chain channels that are offshoots of the main blockchain.
Atomic swap is also known as cross-chain trading.
How Does Atomic Swaps Work?
To give a very simplistic explanation. Two parties who are going to engage in atomic swaps decide on a shared secret. The two parties will share their cryptos if and only if their secrets match. So, this way, if somebody else barges into this exchange, they won’t be able to get their hands on any of the coins because they will not know this secret.
Ok, so now you know the concept, but how does it actually work?
In order to execute this, something known as Hashed Timelock Contracts or HTLCs are used. If you are familiar with the lightning network then you should know how hashed timelock contracts work. Right now we will just give you a brief description of what hashed timelock contracts are.
What are Hashed Time Contracts?
Hashed timelock contracts are a special form of payment channels. Payment channels are basically off-chain state channels which deal with payments.
A state channel is a two-way communication channel between participants which enable them to conduct interactions, which would normally occur on the blockchain, off the blockchain. What this will do is that it will decrease transaction time exponentially since you are no longer dependent on a third party like a miner to valid your transaction.
So what are the requirements to do an off-chain state channel?
A segment of the blockchain state is locked via multi-signature or some sort of smart contract, which is agreed upon by a set of participants.
The participants interact with each other by signing transactions among each other without submitting anything to the miners.
The entire transaction set is then added to the blockchain.
The state channels can be closed at a point which is predetermined by the participants. Closing can happen because of one of the following reasons:
Time lapsed eg. the participants can agree to open a state channel and close it after 2 hours.
It could be based on the total amount of transactions done eg. close the chain after $100 worth of transactions have taken place.
Hashed timelock contracts or “HTLCs” are one of the most convenient applications of the payment channels.
So, what is an HTLC?
Earlier iterations of payment channels which use “timelocks”. An HTLC “extends” that by introducing “Hashlocks” along with the timelocks.
The HTLC enables opening up of payment channels where funds can get transferred between parties prior to a pre-agreed deadline. These payments get acknowledged via the submission of cryptographic proofs. Along with that, another brilliant feature of the HTLCs is that it allows a party to forfeit the payment given to them and return it to the payer. The idea is to use a multisignature transaction system that holds both traders accountable for a swap to be successful.