Atomic swaps are a peer-to-peer, trustless technique of exchanging cash on completely different blockchains. In essence, atomic swaps mean you can trade, for instance, bitcoin with litecoin, whereas avoiding the necessity to belief an trade or some other third celebration.
Atomic swaps may be carried out in certainly one of two methods: Firstly, atomic cross-chain buying and selling may be executed instantly between two blockchains with completely different native cash — referred to as an on-chain atomic swap. Secondly, you should utilize off-chain channels which are offshoots of the principle blockchains concerned — referred to as 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. Alternatively, off-chain atomic swaps are quicker and supply extra throughput than on-chain atomic swaps however are extra advanced to carry out and nonetheless a couple of years away from sensible implementation.
A Temporary Historical past of Atomic Swaps
Also called 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 Might 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 assist 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 check 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 assist the identical Lightning specification, specifically BOLT.
How Do Atomic Swaps Work?
Let’s say Alice and Bob wish 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 may be claimed in a follow-up transaction in two methods. Both, it may be claimed by Alice, along 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, together 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 may be unlocked in a follow-up transaction in two methods as effectively:
Both, it may be claimed by Bob, together with his signature, together with the key worth. Or, it may be claimed by Alice, along 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 a watch on the Litecoin blockchain, she will be able to 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 should always see elevated adoption amongst decentralized exchanges and wallets. At this level, we’re already beginning to see some uptake of atomic swaps, reminiscent of with Altcoin.io, Atomic wallet and Liquid wallet.
If atomic swaps grow to be 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 particular person.