We have already written about decentralized exchanges and how they are slowly but steadily making their way on the crypto markets. It is a big deal after all. Centralised exchanges have their vulnerabilities as any other software, but the deal here is that they operate with large sums of actual money being exchanged by numerous traders. They are, in itself, a SPOF or a Single Point of Failure in the blockchain network. Therefore, concepts like atomic swaps come to the rescue.
However, I do not think centralized exchanges will vanish completely. In my opinion, they will still be around, but disguised in another form. What do I mean by that, you may ask? Let’s take institutional investors for example. Regulating cryptocurrency exchanges is a difficult task, and I’m not so sure that the big guys like hedge and mutual funds will enter into a playground where everyone makes their own rules. Custodians, escrows, security audits need to be bulletproof or at least implemented on a very high level if large sums of cash are in the game. Because once the shit hits the fan, someone needs to take the blame, and if you are a multi-billion mutual fund, you are not willing to enter a game where everyone and no one is the judge. This is why I think, that centralized exchanges will take the role of some kind of facilitator of decentralized exchanges, at least until we reach an evolutionary stage where the current financial system is completely engulfed by decentralization and blockchains. But this is definitely for another story.
Today we will talk about one component of decentralized exchanges. The Atomic Swaps. And why they are an extremely important R&D area in this tidal wave of decentralized exchanges.
So, what is this atomic swap?
Atomic Swap is essentially a smart contract allowing two interested parties to make a “swap” of their cryptocurrencies without the need of a particular middleman because everything is handled on the blockchain. Well, you could argue that the Smart Contract itself is the middleman but it basically lives on the blockchain so this is more of a philosophical question.
The main thing is that the smart contract will do just for what is coded, and that is to ensure that a trustless transaction between two coins of different blockchains is executed. If something fails, the transaction will not be processed and the coins are returned to its rightful owners.
Here is an algorithm that tries to explain details how this should work:
A picks a random number xA 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 BB signs TX2 and returns to A1) A submits TX1 to the networkB 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 AA signs TX4 and sends back to B2) B submits TX3 to the network3) A spends TX3, revealing x4) B spends TX1 using xThis 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 72 hours to get his money backBetween 2 & 3: B can get refund after 24 hours. A has 24 more hours to get his refundAfter 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 72 hours or A can claim the refund and keep his coinsFor safety, both should complete the process with lots of time until the deadlines.
In more laic terms, an exchange between these two parties can happen in a trustless manner and no party has the opportunity to “mess” with the transaction as everything is secured cryptographically by the smart contract.
The parties make a secret (random number x) and let it run through a hash function. Hashing is a mathematical function that will take a certain input (our random number) and create a specific output that can’t be “reversed” and therefore cracked.
Once the transactions are broadcasted into network they have an open time slot in which any of the parties can refund the coins and get back the same values they inputted (minus the transaction fees of each related blockchain)
When the secret is revealed, the transactions are matched and spent on the corresponding blockchains, making the “swap” successful.
Atomic means that the exchange of coins is happening with a full enclosure of the coins. The coins are essentially swapped between the parties and there are no other transactions happening outside the swap. The term is derived from Atomicity which in computer science represents an operation that appears to occur in a single moment when it is called and the response is immediately recorded.
Already executed atomic swaps
Contrary to the mainstream belief that the first successful atomic swap has happened amongst Decred & Litecoin, there were several projects and teams that were pushing this technology long time ago. Nobody can actually know who was the first to successfully conduct an atomic swap but the origins of the idea date all the way back to mid-2013. However, Komodo’s lead developer, JL777, took things into his own hand and completed his first atomic swap in mid-2014 making Komodo Project definitely one of the first candidates in the atomic field. This has set a motion wave for Komodo team as they pushed this technology onward with many other coins and blockchains since then. More in a detailed timeline that can also be found on their blog.
Another atomic swap implementation that caught most of the public eye in the blockchain space was between Litecoin and Decreed. Both teams have inputted a lot of work, with even Charlie Lee pulling of the test run.
A continuous effort is also being pushed on the Litecoin and Vertcoin frontier. In september of 2017 an attempt was again tried by Charlie to undergo this transaction. It seem as it was successful although I couldn’t find a detailed explanation of the whole thing happening except this tweet.
— Charlie Lee [LTC⚡] (@SatoshiLite) September 21, 2017
Most recent Cross-Blockchain atomic swap happened between Bitcoin and Litecoin in November of 2017 and it was conducted and implemented by a company named Lightning Labs.
You can see in the video how “raw” the process still is. This surely says that the technology is still in early phases but hey, this is crypto and things are moving at an astronomical pace here.
There are some hurdles
Not every cryptocurrency and underlying blockchain can facilitate atomic swaps. Some key characteristics of the blockchains that are executing it have to be inherent to them. For example, all current implementation happened using SCRIPT smart contract language. Likewise, the hash algorithm has to be the same for the “swapping” cryptocurrencies. Furthermore, timelock capabilities have to be possible due to nature of refunding if one of the parties decides to bail out on the transaction.
After all, these are just the first try-outs of the atomic swap concept. Komodo is currently leading the charge in this area but there is no doubt that other dev teams are working on their chains to support atomic swaps.
Altcoin.io decentralised exchange
A promising new exchange that is due to hit the market is Altcoin.io. The reason why it fits into our narrative is that they have made an extensive selling position around their implementation of atomic swaps as one of the core mechanisms running in the background of the exchange. Their github repo is specifically aimed at Atomic Swaps and can be reviewed by other developers as the code is open source.
We will definitely keep an eye on the development and update the progress accordingly.
One thing that I noticed in the blockchain domain when people are talking about atomic swaps is that they don’t really understand the implications that atomic swaps are going to have. What I mean by this is that usually when you hear someone talk about atomic swaps, the few coins that get brought up are litecoin, decred and vertcoin because they have done unchained atomic swaps and the development teams are really putting quite a lot of effort into this concept to get it flawlessly working on their chains. However, one thing might have very big implications here. And those are privacy coins.
When you do an atomic swap, you gain properties of both chains. In this way, we might see a merger between privacy features of a certain anonymous coins and our classical ones. This opens a whole new domain of interchangeability and added value for any coin that supports the atomic swap concept.
It is still early to make prophecies but the tech looks promising and continues the foray towards a completely decentralised ecosystem of exchange and operations. Exciting times are ahead!