A new approach to decentralised crypto exchanges

Centralised order-matching but on-chain settlement offers the best of both worlds for the next generation of crypto exchanges.

As the world’s first form of truly decentralised online cash, it is ironic that bitcoin has historically relied on centralised exchanges for trading. The history of bitcoin and cryptocurrency is littered with examples of hacked and failed exchanges, from MtGox to the present day, as trusted intermediaries prove to be among the single points of failure blockchain was created to avoid. Many billions of dollars of crypto has been stolen since the first bitcoin exchange opened, over eight years ago.

Decentralised exchanges have long been seen as the answer to this problem, adopting the same trustless, peer-to-peer approach to trading cryptocurrencies that bitcoin does to transferring value. The first generation of decentralised exchanges (DEXs) has been active for some time, but these have sadly proven unfit for purpose for a number of reasons that we will outline below. However, refinements to the somewhat rudimentary model of these early DEXs can offer both convenience and a user experience that approaches that of popular centralised exchanges — while simultaneously offering users the security of blockchain-settled trading.

DEX 1.0

The first generation of decentralised exchanges — typified by platforms such as the Nxt Asset Exchange (arguably the first ever decentralised crypto exchange) and EtherDelta — aim to replicate on the blockchain alone the approach taken by centralised exchanges. In reality, this understandable goal also necessitates accepting all the shortcomings of a blockchain-only system.

Open orderbooks

The first iteration of DEXs made their orderbooks available in their entirety on the blockchain. Orders are placed by making a transaction, and cancelled if necessary by means of a second transaction. EtherDelta takes this approach, storing the orderbook on the blockchain and settling orders on the blockchain. 0x, meanwhile, store orderbook off-chain as a list of unsettled transactions, but settlement still occurs on the blockchain. On-chain books have the benefit of making the full orderbook transparent for all users, as well as ensuring that order settlement happens transparently and irreversibly on the blockchain. Nevertheless, this transparency comes at a cost — or series of costs — that most traders deem unacceptable:

Fees. Each order or cancellation requires payment of a transaction fee — which, depending on the network and circumstances, may represent a significant proportion of the trade amount. This can render smaller trades, changing orders and repeated order creation and cancellation uneconomical. Additionally, the variable nature of the gas fee in Ethereum can open the way to abuses like front-running (see below).

Speed. Orders are created and cancelled as blocks are mined, meaning they can take seconds or even minutes to propagate. This makes for an extremely poor and unresponsive trading experience, and frequently results in losses if orders cannot be placed or cancelled quickly enough.

Front-running. The full transparency of the orderbook and orders being submitted but not yet lodged on the blockchain means that DEX 1.0 is prone to front-running — when insiders profit from knowledge that is not known to the public. (In the traditional financial world, this is illegal.) For DEXs, this can take place when a trader sees a significant trade waiting in mempool and submits their own trade with a higher transaction fee, ensuring it is accepted first. Miners can abuse the blockchain’s transparent orderbooks even more seriously. ‘A front-running miner can ignore gas prices, place their own transactions into a block wherever they please and censor the transactions of others. Given the opportunity, a rational miner will monitor the mempool for market moving trades and methodically front-run each trade such that they maximize their own profit.’ (See also this post.) This is not simply a theoretical problem, but it happens in practice. It was a significant problem with the Nxt AE and occurs in organised form on Ethereum’s DEXs. This video explores front-running and some of the other security issues that impact DEXs and decentralised systems.

Lack of liquidity. The result of these various practical issues, as well as typically poor user experience, is that relatively few traders use the first generation of DEXs. The advantages are simply not great enough to offset the learning curve or the risk of losing funds through front-running or delays in order confirmations. One of the advantages of DEXs was supposed to be networked liquidity: the idea that liquidity could be pooled across decentralised exchanges that shared the same protocol, giving users access to combined orderbooks across each blockchain. In reality, DEX volumes are low, and the highest volumes are in any case for ‘wrapped’ tokens such as WBTC and WETH, which cannot be pooled. It has also proven difficult to connect to these DEXs via API, due to the extra work required for signing blockchain transactions — further impacting liquidity.

Liquidity is a major and ongoing concern for these exchanges. It doesn’t matter how good the tech is, if they lack liquidity then traders won’t use them and they end up in a vicious circle. This is the major concern for many projects, with order collisions and front-running being significant but secondary problems (in that without the liquidity and userbase, these drawbacks are all but irrelevant anyway). As a result, some exchanges formerly built using the 0x protocol are moving to their own custom solutions. At least one major project, DDEX, is forking/rewriting 0x to address these issues, taking a completely different approach in several key aspects. ‘We plan to ship a new order schema, an engine capable of true matching, robust market orders, and a fundamentally different liquidity sharing model. The ZRX token will be removed as well, because fee-based tokens create unnecessary friction.

Unfortunately, then, the first generation of decentralised exchanges has not been able to deliver on their promises. Full decentralisation is not only inefficient but poses very serious problems to the integrity of the market. The practical implications of such an approach render it counterproductive.

DEX 2.0: Best of both worlds?

Conventional exchanges allow for fast, low-cost order placement and execution, while blockchains do not; conversely, blockchains offer transparency and irreversible and secure settlement, which centralised exchanges do not. (A perennial problem in the crypto world has been exchanges that fake volumes without actually providing the liquidity or depth to back that up for regular traders.) Furthermore, centralised exchanges do offer a degree of privacy to their users and — assuming they are not engaging in illegal activities — all orders are treated the same and dealt with on a first-come, first-served basis. This, of course, cannot be guaranteed and there have been reports of exchanges enabling front-running for insiders.

In the future, it may be possible to create a fully decentralised exchange that does not entail the disadvantages described above; until then, it is clear that neither traditional centralised exchanges nor the first DEXs are fit for purpose. Thus a hybrid solution that combines the speed and privacy of a centralised system with the security and transparency of the blockchain could provide the optimal set-up.

Fast, fair, secure

The obvious first step is to create a solution that combines the strongest features of centralised and decentralised exchanges: centralised orderbooksthat can be accessed in realtime, but blockchain settlement that ensures transparency and unparalleled security after trades have been executed(thereby side-stepping the problem of front-running).

This approach has an analogue in the Plasma network, the scaling solution for Ethereum proposed by Vitalik Buterin and Joseph Poon in 2017, and which has since been implemented. While differing in key details, this functions at a high level like the Lightning Network, the flagship scaling solution for Bitcoin.

In the same way that DEXs are limited by throughput and block times, these scaling solutions seek to use the blockchain for ultimate security but not minute-to-minute or second-to-second operations. ‘Like payment channels in the Bitcoin Lightning Network, Plasma is a technique for conducting off-chain transactions while relying on the underlying Ethereum blockchain to ground its security.’ In Plasma’s case, these off-chain transactions actually occur on child chains, which have their own consensus algorithms and miners/stakers. The Gluon Plasma white paper details a sidechain-based model for a decentralised exchange that offers high-frequency and low-latency trading. The paper details the differences between centralised exchanges (CEX), DEX 1.0 and a hybrid approach. CEXs effective have no (intrinsic) security properties, since customer funds are mingled and depositing to an exchange account entails giving up control. DEX 1.0, or fully on-chain exchanges, do enforce self-custody, but at the expense of speed and cost. ‘Such exchanges are also susceptible to a variety of front-running and DOS attacks.

The ‘off-chain orderbooks, on-chain settlement’ method has successfully been implemented by the Waves Platform, which uses Matchers to pair users’ bids/asks but the blockchain to settle trades. Traffic to Matcher nodes is encrypted, preventing front-running. It is no coincidence that Waves DEX has quickly become one of the most popular DEXs, with millions of dollars in daily volumes. While Ethereum’s market cap is 50x that of Waves, its decentralised exchanges lack meaningful adoption. This gives us a high degree of confidence that there is a gap in the market and a well-designed hybrid exchange for Ethereum would attract substantial trading volumes.

A generic Plasma solution fixes many of the problems of DEX 1.0, though it not perfectly suited to the task. However, Gluon Plasma’s approach does bring significant advantages, offering a third way in a hybrid system in which trustless trades are facilitated by a centralised third party. Orders are not submitted to the exchange contract until they are matched. These centralised parties never take custody of funds, though there is additional complexity involved in ‘proving orders and fills are unique, have not been replayed and there are no race conditions between fills and cancels. This is accomplished by storing filled and cancelled orders or execution in the contract resulting in high costs and low speeds. In addition, price-time priority proofs need to be added to verify that the exchange is not skimming the users.’ As well as being resistant to front-running, a Gluon implementation enables near-instant and practically free transactions, and ChronoBank is actively researching this solution.

ChronoBank’s approach

In designing the TimeX exchange for our ecosystem, we believe that this is the best solution and the best compromise given the range of issues described above. Until such time as blockchain and decentralised technologies advance to a point where all exchange operations can quickly and safely take place on the blockchain, a hybrid model with off-chain orderbooks is the only way to guarantee the integrity of trading — as well as offering a dramatically superior user experience to first-generation DEXs.

While decentralising exchange operations increases security and trust, it is important to strike the right balance in the treatment of user funds. Users’ funds must, of course, remain in their control and not in that of a third party — the history of centralised exchanges provides many examples of why. However, at the same time, the order-matching process must be robust to ensure the market performs as expected and cannot be exploited. Thus there is a compromise to make here: control for users, without compromising the integrity of the market.

We believe that viable DEXs will place greater pressure on centralised exchanges to act more openly and honestly. It is likely that there will always be a place for centralised organisations in this space, not least because interfacing with the fiat banking system requires on- and off-ramps and therefore regulated entities — companies that operate within their own jurisdictions and legal frameworks. However, the crypto sector as a whole will benefit from greater transparency, since centralised exchanges are still opaque in their dealings and can readily fake key statistics such as volumes — as well as facilitating front-running, spoofing, wash trading and other illegal and unethical behaviour. Despite increasing professionalism in the sector, crypto exchanges still badly need to rehabilitate their image after many years of mismanagement and abuse of the customers and community they are supposed to serve.

Leave a Reply

Your email address will not be published. Required fields are marked *