Why You Should Care about Decentralized Exchanges
The four core functions of any exchange are capital deposits, order books, order matching, and asset exchange. In order to create a fully decentralized exchange (DEX), each of these functions must be decentralized. In most exchanges, only the asset exchange is decentralized, as the assets are cryptocurrencies deployed on the blockchain that no central entity controls. However, the other three functions, and especially capital deposits, are usually centralized. Due to KYC (know your customer) and AML (Anti-Money Laundering) regulations, exchanges are often required to seek users’ identities for capital deposits, creating centralized record-collection and data-storage of personal information. Effectively, centralized exchanges give users permission to transact currencies, rather than creating a permissionless ecosystem.
On an architectural level, decentralization means that there is no centrally-controlled server(s), and the networks’ nodes are distributed. Currently, perhaps the only truly decentralized exchange is the Blocknet “BlockDX”, as other attempts do not decentralize all four functions.
The Two Types of Decentralized Exchanges
As exchanges revolve around transacting currencies, there are two fundamental exchange models: currency-centric and currency-neutral. Either of these models can be centralized or decentralized, depending on how the four key functions of the exchange are handled.
Currency-centric exchanges are built on top of singular blockchain platforms, such as Ethereum. A currency-centric exchange is limited to escrowing only the currency of the platform it is built on, such as ERC20 assets and other contracts if the exchange is built on top of Ethereum. This is the way traditional exchanges are built.
The newer model is currency-neutral, which is architected to connect different native cryptocurrencies, meaning that users do not have to adhere to any specific currency ecosystem. These systems allow users to trade cryptocurrencies without a coin underlying that exchange, which acts as a sort of additional “middleman” to go through since it is no longer fully peer-to-peer. Examples of these models include Bisq, altcoin.io, and flyp.me.
These newer projects allow for securely matching and handling order books, and not just asset exchange, in a decentralized manner, which is done using the blockchain. Because an exchange is a community of users, there has to be a way to broadcast and match orders. One way of trustless trading is through “atomic swaps” for order matching, but atomic swaps alone cannot create a trustless marketplace, as it is done from one specific peer to another, rather than as a broadcast to anyone on the network. An atomic swap is when a trade is done in a single, or atomic, operation, as opposed to two separate transactions (such as first sending one coin, then waiting for the receiver to send their coin). This is facilitated through smart contracts that act as a trustless escrow holding onto one currency until the other user sends their currency as well when both currencies can be released.
The Pros and Cons of Decentralized Exchanges
The most obvious benefit of a DEX is the same as with any decentralized application, which revolves around the philosophy of cutting out the middlemen and returning interactions to peer-to-peer, permissionless models without central authorities. More specifically, decentralization creates censorship-resistance, which in the case of decentralized exchanges means that no central authority could forcefully impose regulations, or even ban currencies and/or the exchange itself. This is especially important considering that many countries are clamping down on cryptocurrency trading. For example, the two most populous countries on earth, China, and India, have banned cryptocurrency exchanges, while countries including Mexico, Russia, Saudi Arabia, and Brazil have restricted cryptocurrencies.
Without Decentralized Exchanges, the peoples’ ability to invest in crypto is subject to governments, so cryptocurrency becomes hardly more democratic than traditional asset markets. Governments can exert control over centralized exchanges, and users are subject to authorities who may at any moment track and tax users, or ban currencies.
Other merits of a DEX include heightened security. Massive security attacks, such as the roughly $470 million that was stolen from Mt. Gox, were only possible because the centralized hot wallets of the exchange were targeted, which presented a single point of failure. In a DEX, each user is in private control of their own funds, so there is no central point of attack. However, as we’ll get to later, many exchanges claim to be decentralized, such as Bancor, but are truly hybrid, and their centralized aspects present vulnerabilities. For instance, around $23 million was recently stolen from Bancor, and Bancor responded with a freeze attempt built into their protocol, which is only possible with at least a partially-centralized architecture.
As we’ll see, DEXs use Smart Contracts to facilitate transactions, such as using contracts as an escrow for peer-to-peer transactions. If the contracts themselves are highly secure, then the exchange benefits from the cryptographic security of the underlying blockchain. However, this is often not the case, and Smart Contracts can contain many vulnerabilities, including underflows, overflows, reentrancy attacks, and many more. In fact, studies have found over 34,000 contracts with known vulnerabilities. These facts, alongside recent hacks such as the Bancor attack, reflect the need for Smart Contract Auditing to validate the security of the contract code and find any back-door vulnerabilities.
Further, a DEX could facilitate faster and cheaper transactions than a centralized exchange, since there is no third party authenticator. Currently, this is just theoretical and has yet to be proven by exchanges on a large scale, as DEXs have not achieved the “network effect” of reaching enough users for critical mass.
The largest drawback of current DEXs is the lack of functionality, relative to centralized exchanges. Most DEXs only support basic market functions, and not even features such as margin trading and stop loss. The technology has simply not yet caught up with the ambitions of most decentralized exchanges, though DEXs like BlockDX are planning to support additional functionality.
Lastly, because of the KYC and AML regulations mentioned earlier, Decentralized Exchanges do not support fiat conversions, as this would introduce a point of centralization. Instead, users must use cryptocurrency deposits.
Comparing Decentralized Exchanges
Currently, Decentralized Exchanges are still far off from achieving the liquidity, scalability, and functionality needed for mass adoption. However, current attempts built for Ethereum-based tokens include 0x Protocol, Kyber Network, EtherDelta, BlockDX by Blocknet, and Radex. One unique DAO-based platform is IDEX. Decentralized Exchanges in early development include the Waves Platform, Binance Chain, and OasisDEX, which is built by MakerDAO.
0x Protocol and Kyber Network are considered serious contenders for the future of Decentralized Exchanges. Both use their own internal tokens (KNC for Kyber and ZRX for 0x). The largest difference between the two is in how order matching is done:
- 0x solves this problem with a hybrid method where order matching is done off-chain with an intermediate party and then using the blockchain for the actual trade.
- Anyone can be an off-chain matchmaker by maintaining an order book
- Programmable Smart Contracts allow market makers to set fees for managing the transaction (accepting an order and posting it in the order books)
- Kyber solves this problem by using Smart Contracts and reserves.
- Unlike 0x, Kyber does not use off-chain matchmakers, and instead, all reserve transactions are managed by Smart Contracts.
- Reserves provide liquidity, and a singular reserve is held by Kyber.
- Additional reserves can be public or private.
- Private reserves are private coin holders who choose to act as a source of crypto for the exchange and set their own rates
- Public reserves can receive contributions from the public, and the public benefits by sharing in the profits
Looking at the above two (very strong) platforms, EtherDelta is very weak in comparison:
- EtherDelta was initially breached and the exchange never fully recovered to work properly
- Their ICO was launched before the exchange was working properly
- Cancellation orders are mined on-chain, and waiting for the next mined block means that real-time trading becomes impossible
- Order processing is not done on-chain, yet EtherDelta does not experience the speed benefits of off-chain order processing, and users report very slow functionality
With EtherDelta, the order book matching (one of the four key functions) is handled by centralized EtherDelta servers. Due to this centralization, orders in the order book can be censored, meaning that the censorship-resistance philosophy is made moot, but the security benefit of controlling your own funds remains. The 0x project is similar to EtherDelta, with the key difference being that 0x provides a multi-national chain, where many exchanges can collaborate to build a larger order book taking advantage of a shared liquidity pool. 0x has the same centralization concern of EtherDelta, whereby the centralized servers of an individual exchange handle order matching.
The IDEX platform lies in a category of its own, as it runs on top of the Aurora DAO (Decentralized Autonomous Organization), which is inspired by free banking:
- They’ve developed a multi-token structure through the DAO, with IDXM, AURA, and Boreal tokens
- IDXM is used as a membership fee token
- AURA is the Snowglobe staking token that supports the multi-exchange protocol
- Market makers are rewarded with AURA while takers pay gas fees
- Boreal is the stablecoin, also enabling decentralized P2P lending
- The Decentralized Capital aspect of IDEX provides users with free banking and loans through Boreals
- Snowglobe, which uses the AURA token above, is the protocol that creates a secondary network of child-chains that link exchanges to improve liquidity
- IDEX is not fully decentralized, as IDEX itself is the only authority that may submit signed trades to Ethereum
- This provides the speed and UX of centralized exchanges, forming a hybrid model
OasisDEX is a competitor to IDEX, as it is built by MakerDAO and aims for similar levels of decentralized interactions alongside decentralized governance. However, OasisDEX is only in alpha stage and their GitHub is not seeing any recent developments.
- Oasis does not aim to have the same token support as IDEX, and is meant for assets in the Maker registry (currently MKR, DAI, and ETH)
Radex is similar to IDEX in the fashion that market makers earn rebates for the liquidity they provide. This is the unique value proposition that Radex provided until IDEX came along, and now IDEX is a more developed and decentralized platform:
- The use of Radex requires you to use the centralized Saturn Wallet plugin in your web browser
- The handling of the order book is not ideal in Radex, as it is not stored in a decentralized fashion, but is instead dynamically recreated by reading the events that Radex creates
Soon, the “Binance Chain” will be released, which claims to provide a DEX. Once Binance Chain is live, Binance Coin (BNB) will be swapped with a new coin based on the Binance blockchain at a 1:1 ratio. Since the plans were announced in March 2018, there have been no updates, though Binance Chain is unlikely to be fully decentralized, since capital deposits will be made to Binance, and Binance itself will not convert to a decentralized model. Further, as Binance practices freezing funds to comply with regulations and prevent theft, this means that there is centralized control over funds.
To our knowledge, BlockDX is the most decentralized platform, as all four functions of the exchange are decentralized. Further benefits include a partnership with 0x that enable interoperability with Ethereum tokens. For peer-to-peer trades without a central escrow, Blocknet uses atomic swaps, discussed earlier, in a technology called XChat. Blocknet also creates an inter-chain overlay using XBridge, which provides a DHT-based peer-to-peer network. Importantly, BlockDX comes with a decentralized API that you can connect to over localhost without permission, allowing for truly decentralized trading.
Hurdles Toward DEX Adoption
Without central processing of the exchange functions, authorities such as taxation and regulation bodies have no power over a DEX. If DEX’s were to be massively adopted and replace centralized exchanges, that would mean hundreds of billions of dollars escaping the purview of taxation and regulation bodies. In effect, this would mean that the platform users, rather than rent-seeking authorities, would control the funds.
These rent-seeking authorities have already exerted massive efforts to stop the blockchain revolution and maintain their control, such as India and China banning crypto. Other attempts of maintaining control include government-run cryptocurrencies without much transparency, such as the asset-backed petro cryptocurrency of Venezuela. Further, traditional mega-corporations are creating permission blockchain ecosystems, such as IBM.
Many exchanges claim to be moving towards a decentralized model, defending their current centralization by saying that centralization speeds up development. Whether or not this is true is up for debate, as entire protocols will now have to be re-written to shift to decentralization.
Creating a DEX
The ideal model for a DEX would be a Decentralized Autonomous Organization (a transparent, shareholder controlled, computer-represented organization that is a more complex version of a ÐApp). This would ensure full decentralization of all aspects of the exchange, and users would have the decision-making power instead of any central body.
Proof-of-identity becomes a non-trivial problem with a DEX, and especially a DAO exchange. One solution is with Decentralized Identities (DIDs), which make identifiers and names self-sovereign to their owning entity. Existing DIDs include NuID, Identity.foundation, and Sovrin. The current identity handling that many supposed DEXs are using is through email sign-ups – the same as most sites (i.e. sign up with your Gmail). However, any service that requires your email, or any asset running on centralized servers, is not fully decentralized.
First off, creating a crypto exchange requires that the four fundamental functions discussed earlier are built: capital deposits, order books, order matching, and asset exchange. These include allowing users to control their own funds, running the network on multiple nodes, not revealing a user’s identity, and integration with existing wallets. Then, a front-end is built that matches user input, such as clicking a “buy” button, to the Smart Contract functionality in the back-end.
The above is fundamentally how any DEX is built, though even a single point of centralization introduces new vulnerabilities. Besides the technical creation of the DEX, it requires a governance model, which can be up to the creators, or up to the users, as in a DAO. Further, the exchange has to achieve “network effect” to become scalable and maintain high enough liquidity for serious use.
BlockDX describes their order system as a “decentralized state machine”, where the first step is placing an order, which will be canceled or accepted depending on service node polls, market makers, whether the broadcast was received, and whether the recipient accepts or cancels the order.
As an example of a how a DEX may operate, let’s look at the BlockDX algorithm summary, inspired by the Blocknet GitHub, which describes order matching via atomic swap:
- Initiator creates secret X and hashes it to create H(X).
The initiator also creates public/private key pair (pubkey i1, i2 / privkey i2, i2).
Responder creates public/private key pair (pubkey r1, r2 / privkey r1, r2).
- Initiator shares H(X) and pubkey i2 with responder.
Responder shares pubkey r1 with initiator.
- Initiator creates TxAb.
TxAb can be redeemed after time T2 with privkey i1. At any time TxAb can be redeemed with signature from privkey r1 and reveal of secret X.
Initiator broadcasts TxAb onto the network.
- Responder confirms TxAb. Responder creates TxBb. TxBb can be redeemed after T1 time with privkey r2. At any time TxBb can be redeemed with signature from privkey i2 and reveal of secret X.
Responder broadcasts TxBb onto the network.
- Initiator creates TxBp which spends TxBb using privkey i2 and secret X. With the revealed secret, responder can create TxAp which spends TxAb with privkey r1.
To simplify the above: Users are in control of their own funds and broadcast orders to the network from their end. The security and encryption aspects of this process are handled on the user-end, as there is no centralized server.
With the framework and definitions presented in this guide, you’ll be able to make the distinctions between a true DEX and a centralized exchange for more informed decision-making.
- Guide to Atomic Swaps and Trustless Cross-Chain Trading
- Blocknet White Paper
- “The Trouble With Centralized Exchanges” by Blocknet
- “Decentralized Cryptocurrency Exchanges” on Hackernoon
- “Decentralized Exchanges: Three Types That Will Be Essential For The Crypto Economy” by Totle
- “Analyzing Activities on Decentralized Exchanges” by ConsenSys
- “70% of Value in Tech is Driven by Network Effects” by NFX