Demystifying Blockchain Atomic Swap

charles okaformbah
5 min readApr 17, 2018

--

It’s Importance to the crypto-ecosystem.

image courtesy bit.news

So what is Atomic Swap? Firstly, Atomic in science implies two events occurring simultaneously that they can be referred to as one event. Atomic swap is the trust-less exchange of coin from one blockchain to another without the need of a third party like centralized exchange platforms or escrow and without fear of default from either parties involved in the exchange.

Say you have Litecoin and want to convert it to Bitcoin, instead of going through centralized exchanges that plays as the middle-man between you and someone else that wants to sell Bitcoin, atomic swap helps you send your Litecoin to the Bitcoin holder without you loosing your Litecoin if the Bitcoin holder refuses to send the Bitcoin to you and vice-versa.

It is a trust-less effortless system that only releases the coin to the parties once it certifies that both parties played their required role in the coin exchange.

Why Atomic Swap and what you can do with it?

Good question! 😃 Atomic swap is the next phase adoption for decentralized exchanges that are increasing in number and popularity and it is seen as more secured compared to centralized exchanges. With Atomic swap you have;

  • No trading fees (no withdrawal or deposit or trading fees) except miners fee
  • No fear of centralize exchange hack or preventing you from having access to your crypto cause of government regulation.😐
  • Convenient for swapping large amount of coins without fear of losing it
  • No need being subject to unnecessary KYC request like drivers licence, passport, bank balance, marriage certificate, birth certificate, dog licence, mortgage invoice, utility bill, last vacation destination, the last place you fart 😄 and any other verification.

Note that businesses that implement this technology can charge a listing fee for creating meeting point platform or service fee depending on the atomic swap solution being adopted but some are free to use; e.g decred.

Possible solutions being considered for Atomic Swap

Some atomic swap platforms are being built on-chain like komodo while some are working on off-chain powered solution, e.g Bitcoin Lightning. Bitcoin-based coins like coins like BCH, LTC, DASH, ZCASH, etc are now exchangeable with Bitcoin on BarterDex (by komodo) while that of Ethereum/ERC20 was launched this march. Ethereum already has some decentralized exchanges for trading/swapping to other ERC20 tokens using smart contract or Wrapped Ether(WEth); radarrelay and 0X OTC.

Solution using revealing secrets of contract with nlocktime
The Nlocktime solution also known as hash time-locked contracts (HTLCs) proposes that transaction be completed with a secret puzzle key created and revealed by Party A, to be used by Party B within a specific timeframe and that both parties sign the transaction else the transaction is cancelled and coins sent back to it’s original hodlers. A simple illustration of how this works is below, credit to TierNolan;

A picks a random number x

A creates TX1: “Pay w BTC to <B’s public key> if (x for H(x) known and signed by B) or (signed by A & B)”

A creates TX2: “Pay w BTC from TX1 to <A’s public key>, locked 48 hours in the future, signed by A”

A sends TX2 to B

B signs TX2 and returns to A

1) A submits TX1 to the network

B creates TX3: “Pay v alt-coins to <A-public-key> if (x for H(x) known and signed by A) or (signed by A & B)”

B creates TX4: “Pay v alt-coins from TX3 to <B’s public key>, locked 24 hours in the future, signed by B”

B sends TX4 to A

A signs TX4 and sends back to B

2) B submits TX3 to the network

3) A spends TX3 giving x

4) B spends TX1 using x

This is atomic (with timeout). If the process is halted, it can be reversed no matter when it is stopped.

Before 1: Nothing public has been broadcast, so nothing happens
Between 1 & 2: A can use refund transaction after 48 hours to get his money back
Between 2 & 3: B can get refund after 24 hours. A has 24 more hours to get his refund
After 3: Transaction is completed by 2
- A must spend his new coin within 24 hours or B can claim the refund and keep his coins
- B must spend his new coin within 48 hours or A can claim the refund and keep his coins

For safety, both should complete the process with lots of time until the deadlines.

The downside to this proposed solution is locking up of coins if the transaction does not go through. The holder has to wait for set time-lapse before getting his coin back.

Solution using specialized Altchain
This is the most commonly used solution in Atomic swap technology/platforms. However, most altchain specialized atomic swap platforms’ recent successes are dependent on local coin daemons which is used as a substitute of the original coin; openledger.io. Also, you don’t need to download the blockchain of the other coin you want.

Some atomic swap exchanges/wallet

  • openledger.io
  • komodoplatform.com
  • Decredproject
  • Altcoin.io
  • Lightning Network offchain testing atomic swap
  • https://blocknet.co/

Atomic Swap Limitations

For clarification purpose, you simply can not do atomic swaps between two chains. Some blockchain protocols are already working on update fixes like off-chain solution. The following characteristics need to be met in order for the swap to take place atomically:

  • A hash algorithm must be inherent to both of the participating cryptocurrencies
  • Time lock contract capabilities must be inherent to both cryptos
  • Specialized programming functionalities

Conclusion

As technical advancement in the development and adoption of Atomic swap exchange keeps growing, I envisage a future where the core principle of blockchain which is centered on privacy, security and decentralization for coin exchange will be norm and easy for the average user.

Charles is coFounder of VesselTrust, a blockchain solution architect, full-stack and mobile developer with over a decade experience in the IT world creating applications and running several startups. Passionate about great ideas that have “Proof of concept” and scalability. #Fitfam gym dude and enjoys swimming when he is not in front of his laptop, bar, cooking, playing ping-pong or snooker.
Twitter:
justcharz
LinkedIn:
linkedin.com/in/justcharles

--

--

charles okaformbah
charles okaformbah

Written by charles okaformbah

Blockchain Solutions Architect | Cloud Engineer — CoFounder @ Convexity and VesselTrust

No responses yet