Atomic Swap – Revolutionising Exchange of Crypto Assets
Atomic Swap or Atomic Cross Chain Trading refers to the exchange of one cryptocurrency with another cryptocurrency without the need to trust a third party. The process is entirely trustless and works by ensuring that both parties fulfill the requirements of the trade as per the contract. In case, one fails to meet the requirements, the time-locked contract will refund the other user.
An Atomic Swap functions using a hash-time locked contract. The contract establishes a payment channel between two blockchains. However, not all blockchains support payment channels. In order to let the payment channels function, a blockchain needs to implement Lightning Network or its alike.
This allows for opening and closing the payment channels which execute off-chain transactions. The channels will be closed after a certain period and end balances will be submitted to both blockchains. Moreover, since these transactions are hash-time locked contracts, both blockchains need to support the same cryptographic hash function, such as SHA-256.
The person who makes the initial payment sets up the hash time locked contract. He provides a specific hash which represents the amount of money paid. Thus, to receive the payment, the recipient needs to create a cryptographic proof of payment within a specific time. The swap is executed only when the recipient meets the deadline else the contract is refunded.
On March 15, 2018, Lightning Labs announced the first Lightning beta release for mainnet on both Bitcoin and Litecoin. One of the most anticipated applications of the Lightning Network (LN) is atomic swaps.
Need for Atomic Swap Technology
The crypto asset holders presently use exchanges to trade their coins. However, the exchanges are vulnerable to attacks such as hacks, inefficiencies, manipulation and even human error. There is no way to recover lost coins as the owners cannot prove the amount they held.An atomic swap eliminates completely the need for an exchange. Additionally, the transaction fee reduces to zero.
Atomic swap also takes in place the failure of decentralized exchanges. A DEX is not capable of handling large amount of trades, some of the exchanges have also incorporated blockchain technology. However, it is not an ideal solution. The blockchain-based exchanges can only facilitate trading within their own blockchain. A trader then requires to use a proxy token such as BTC and ETH and double transaction fees needs to be paid. On the other hand, Atomic swaps can be executed quickly. It is due to the cryptographic proof of payment which makes the validation faster.
Shortcomings of the Atomic Cross Chain Swap
Let us take an example of Alice and Bob who wish to execute an atomic swap. With the atomic swap technology a time-locked contract will act as escrow between Alice and Bob . If Alice wants to trade say one Dash coin for a Dogecoin, she would send her Dash coin to the contract. Similarly, Bob would also send it, after the swap Alice would own a Dogecoin and Bob a Dash coin.
However, there are several ways in which Alice can cheat Bob.
In the one-way exchange, neither Alice or Bob can withdraw funds without depositing funds.
First, Alice deposits funds on the chain A with a hashed pre-image. Second, Bob sees the hashed image and uses it as reference for his deposit on chain B. However, Bob is unaware of the preimage used to create the hash. Third, Alice withdraws Bob’s deposit using the secret, which is now visible to Bob as well. Lastly Bob can now withdraw on chain A.
However, this works only if both parties are honest. It breaks if Bob never deposits, then Alice cannot withdraw. If both deposit and Alice do not withdraw, it further prevents Bob from withdrawing. Thus, one- way exchange does not work.
Ion Forged Proof
Image Courtesy- Medium
Ion stage 1 allows for a transaction to be performed across two chains, but only if the happy path is followed which is-
First, Alice and Bob make a deposit. Second, Bob sends a signed proof of deposit to Escrow Contract on Chain A, blocking Alice from refunding. Third, Alice sends a signed proof of deposit Escrow Contract on Chain B, blocking Bob from refunding. Lastly, both withdraw their amounts. However, this function is not fool-proof as both Alice and Bob can create a false proof without depositing.
An immediate solution to this is to make the other party submit a proof of trade. However, this solution also fails as there is no incentive for a party to allow others to withdraw, once they have withdrawn funds. Once Alice submits Bob’s proof of deposit, allowing Bob to withdraw, there isn’t any reason forcing Bob to allow Alice to withdraw.
Alice and Bob can also refund themselves, even if the other chain is locked. Thus, a party can withdraw after the other chain is locked for refunding.
Can all cryptocurrencies do Atomic Swapping?
All cryptocurrencies cannot carry out atomic swaps. Many cryptocurrencies have hashing algorithms and time locked contracts, but lack the specialized programming functions required to interact with other blockchains. However, the development of Raiden on Ethereum which is similar to Lightning Network for Bitcoin, may meet the required conditions for successful atomic swaps. It is very likely that many more popular cryptocurrencies will be able to do atomic swaps in the future as they develop specialized programming functions.
For example, Stellar Lumens plans to implement Lightning Network channels in 2018, Ethereum has Raiden and IOTA has a similar system called Flash.
Associated Risks with Atomic Cross Chain Swapping
- Atomic swaps could further fuel growth in illicit markets. The DEXs built around atomic swaps are useful for merchants and consumers alike. Lightning Network and decentralized exchanges will make regulating the cryptocurrency space more difficult.
- It’s possible that the future of atomic swaps might be impacted by changing cryptocurrency regulations around the world.
The current evolution of the cryptocurrency market is developing a larger demand for decentralized exchanges and atomic swaps might be a faster and cost-effective way to exchange cryptocurrencies. Decentralized exchanges such as Altcoin.io aim to take full advantage of atomic swaps to maintain high liquidity, cut exchange costs and perform quick transactions. While it is difficult to predict the signs of progression, looking ahead atomic swaps might come handy, if not already so in their initial stages.