The future of decentralised exchanges and off-chain atomic swaps.

Whilst the cryptocurrency economy champions itself as being decentralised in nature, ironically it has usually relied on centralised platforms of exchange. This provides problems as these exchanges will often hold funds in large “honeypot” addresses that are prime pickings for sophisticated hackers. This has resulted in no less than two hacks in the last three months along. On the 12th of February, Bitgrail reported that over $170 in XRB was stolen from their wallets, and Coincheck suffered their largest losses ever with over $400 in NEM being taken.

DEXs

There are however alternative solutions to centralised exchanges and these are called decentralised exchanges (DEXs). These platforms are structured in such a way that users are able to retain the ownership of their coins and their private keys. This solution is much needed and it will prevent cryptocurrencies from being kept in one centralised place, making large-scale hacks a lot less likely.

The demand for these DEXs is increasing and as exchanges trade volume grows, so will their susceptibility to being hacked.

The way that these exchanges work is by individuals setting and taking orders. These orders exist on separate order books that are hosted independently of each other. This means that new orders placed on one book, will not place on another creating an issue around a lack of liquidity and users having to look up several different books to place their orders.

There is, however, a solution. A process called “Network Liquidity” means that different order books can be gathered together in an API to share their orders. This way, orders can flow freely between relayers as well as providing the required liquidity in the network.

Front Running

A particular concept known as Front Running is one where an individual can outbid an order that has been placed on DEX. Many decentralised exchanges that run on Ethereum rely on smart contracts but as the network is public, it means anyone can check the memory pool to see who is planning an order.

Once someone identifies that an order has been placed on DEX, they can easily jump in front of them by placing the same order, but with more gas. This means that the first order that was placed never gets realised and is removed from the book.

One suggested solution from Ivan Bogarty, a former Google software engineer, is to implement a minReturn on trades, which means that the trade is cancelled once the user realises someone is trying to cut in front of them. Another suggested solution is to set a max gas price so that people are unable to bid higher than the limit.

These are just short-term fixes. Adding a minReturn doesn’t stop front running, it just reduces the users losses. Additionally, adding a gas limit isn’t ideal on an already congested network.

Another way of mitigating this issue is through the use of a Commit-Reveal Scheme. This solution was presented by Will Warren, the co-founder of Ox project, an open protocol for decentralised exchanges. This means that the user can secretly commit his funds without executing a transaction and revealing it. Once the transaction has been mined, a second transaction is sent with all the relevant details- therefore placing the order on the DEX. Unfortunately, this method is not perfect either as it doesn’t allow for accidental collisions when two individuals may place the same order at the same time.

Atomic Swaps

Back in March, Lightning Labs announced the release of the first Lightning beta for mainnet on Bitcoin and Litecoin. One of the most anticipated applications on the Lightning Network is Atomic Swaps.

An Atomic Swap pertains to the “all or nothing” exchange of one currency for another e.g. Bitcoin for Litecoin. The use of the Lightning Network makes this process instant, private, and free when it comes to mining. So how does the Lightning Network handle issues of liquidity and front running?

Liquidity

There are two different paths that can be followed to perform an Atomic Swap on the Lightning Network. These are directly from one node to another node, or routing your swap through a third party intermediary.

When it comes to liquidity, one issue the Lightning Network faces is fund and channel availability. The nature of the network means that users have to create their payment channels through multisigs which means you can only get on the Lightning Network if you have funds to spend. The other option is that intermediaries can route your payments if they have access to a sufficient amount of funds.

This issue can be solved in a similar way to DEXs. Just as a DEX order book is able to share information amongst other order books, so too can transactions be shared and routed between nodes that have the funds and channels to do the swap. All that is needed is the ability to extend the number of hops that your swap goes through. This is a challenge as the Lightning Network is still in the early development stage, but as the network grows, it is hoped that this will be less of an issue.

Hash Time Locked Contracts

Atomic Swaps use a type of technique called Hash Time Locked Contracts which submit both currencies into the contracts simultaneously. These HTLCs mean that the amount you are exchanging is ensured and cannot be outbid by another user. There is also no risk of an accidental collision.

If for example, you want to exchange your Bitcoin for Litecoin, you would need to find another user on the Lightning Network who also wants to exchange. You would then commit respective coins to the swap and route them through the other nodes. This way there are no fees and the exchange is guaranteed.

The Lightning Network does face other problems though. Bad actors may try to steal another person’s funds however severe punishing contracts have been created in such a way as to put off anyone who may consider this.

At the moment, DEXs pay an important role in allowing the cryptocurrency ecosystem to trade without relying on centralised exchanges. At the same time, they are pretty much only suited to Ethereum based tokens. Atomic Swaps, however, are yet to be widely implemented as the Lightning Network is still in its infancy but it will also be limited in terms of compatible currencies.

If we consider these facts, it appears that the two forms of exchange will develop independently of each other as they apply to different ecosystems, but this isn’t necessarily the case. There is a chance that these two ecosystems may one day become compatible with each other. A Lightning Network Developer, Alex Bosworth recently stated that one of his aims is to make Atomic Swaps compatible with as many other coins as possible. This would include the exchange of ERC20 tokens and Lightning Network compatible currencies.

E&S Group is a leading law firm offering various services with regards to ICOs. Feel free to contact us directly on +356 20103020 or by email at [email protected] to find out how E&S can help you in ‘making things happen’.

For more information click the link.