Atomic swaps are a peer-to-peer, trustless methodology of exchanging cash on completely different blockchains. In essence, atomic swaps assist you to trade, for instance, bitcoin with litecoin, whereas avoiding the necessity to belief an trade or every other third occasion.
Atomic swaps could be carried out in certainly one of two methods: Firstly, atomic cross-chain buying and selling could be completed straight between two blockchains with completely different native cash — often called an on-chain atomic swap. Secondly, you should utilize off-chain channels which can be offshoots of the primary blockchains concerned — often called off-chain atomic swaps.
On-chain atomic swaps present extra safety for the reason that mechanism is embedded into the blockchain itself and the transaction will both finalize or be cancelled. Then again, off-chain atomic swaps are quicker and supply extra throughput than on-chain atomic swaps however are extra complicated to carry out and nonetheless a number of years away from sensible implementation.
A Temporary Historical past of Atomic Swaps
Often known as atomic cross-chain buying and selling, the thought of atomic swaps has been round since July 2012, with Sergio Demian Lerner’s preliminary try at making a trustless trade protocol referred to as P2PTradeX. The thought was additional refined and formalized by Tier Nolan in Could 2013.
Nolan’s algorithm was refined even additional by former Bitcoin developer Mike Hearn and others. Their improved strategy allowed the direct trade of cash on Bitcoin-derived blockchains, with out particular help from the protocol.
A profitable mechanism to hold out Nolan’s formal description of an atomic swap didn’t happen till 2014, when the developer jl777 carried out a take a look at for swapping litecoin with dogecoin. Decred later simplified the code to make atomic swaps extra extensively obtainable, successfully executing an atomic swap with litecoin in September 2017.
The primary bitcoin-to-litecoin off-chain atomic swap utilizing the Lightning Community was performed in November 2017. These off-chain atomic swaps are largely simply demonstrations for the time being and have solely been exhibited with two cash that help the identical Lightning specification, particularly BOLT.
How Do Atomic Swaps Work?
Let’s say Alice and Bob need to trade one bitcoin for 100 litecoin. Alice has one bitcoin and prefers 100 litecoin; Bob has 100 litecoin and prefers one bitcoin.
To make the trade, Bob first creates a secret quantity, a “worth.” He then additionally generates a hash from this worth, and he shares this hash with Alice. (However he doesn’t share the worth itself!)
Now Bob creates a bitcoin transaction, “locking up” one bitcoin. This bitcoin could be claimed in a follow-up transaction in two methods. Both, it may be claimed by Alice, together with her signature, together with the key worth. The Bitcoin community will acknowledge the key worth if it matches the hash, which is included on this transaction. Or, it may be claimed by Bob, along with his signature, however solely after two weeks have handed.
Proper now, Alice can’t declare the bitcoin, as a result of she doesn’t know the key worth, and Bob can’t declare the bitcoin, as a result of two weeks haven’t handed.
Subsequent, Alice creates a litecoin transaction, “locking up” 100 litecoin. The 100 litecoin locked up on this transaction could be unlocked in a follow-up transaction in two methods as nicely:
Both, it may be claimed by Bob, along with his signature, together with the key worth. Or, it may be claimed by Alice, together with her signature, however solely after per week has handed.
Which means that Bob can now declare the 100 litecoin: He does know the key worth. He simply must do it inside per week, as a result of after that week Alice can declare her 100 litecoin again.
Now, if Bob does declare the 100 litecoin with a follow-up transaction, he broadcasts the key worth: it’s now included within the Litecoin blockchain. So, if Alice retains an eye fixed on the Litecoin blockchain, she will simply take the key worth, and, in flip, use it to assert the bitcoin on the Bitcoin blockchain. (She simply must do it inside two weeks, earlier than Bob can declare his bitcoin again.)
Certainly, Bob can solely declare the 100 litecoin if he lets Alice declare her bitcoin: a trustless commerce.
The Way forward for Atomic Swaps
Because the know-how of atomic swaps matures, we must always see elevated adoption amongst decentralized exchanges and wallets. At this level, we’re already beginning to see some uptake of atomic swaps, similar to with Altcoin.io, Atomic wallet and Liquid wallet.
If atomic swaps turn into extensively used, they might play an element in finally making centralized cryptocurrency exchanges out of date.
However first, atomic swaps must be built-in throughout present wallets and companies. There additionally must be an enchancment within the consumer expertise to make cross-chain buying and selling straightforward for the common individual.