Whitepaper sneak peek: Architecture comparison of decentralized exchanges
In the upcoming months we'll publish sneak peeks from our new whitepaper. Today we'd like to share a chapter that compares and contrasts software architecture of a number of prominent exchanges: GDAX, EtherDelta, 0xProject and Radex. Keep reading if you want to know more about how these exchanges work under the hood.
As the saying goes, all software projects have an architecture whether you plan for it or not, so you better think about it in advance. Software architecture determines how the project is going to evolve in the future, how it's going to scale, what new features are going to be possible and, most importantly, what features are going to be impossible. All four projects that are featured in this blog post are remarkable in their own right, and their architectures pick different sweet spots on the gradient between centralization and performance vs decentralization and uncensorability.
GDAX is an example of a centralized exchange. While how such exchanges function under-the-hood greatly differs from exchange to exchange, conceptually they all operate under the same business model and thus from a bird’s eye view they all look the same when it comes to handling cryptocurrencies.
Clients interact with the exchange via a web application. They transfer the funds to the exchange by sending them to a one-time-generated address on the corresponding blockchain. This address is owned by the exchange. In return for the crypto the exchange updates a record in their database. This database stores everybody’s balances, trades, withdrawals and the order book. The database is not guaranteed to be in sync with the blockchain. In theory, a hacker could modify the database, draw themselves a thousand BTC and safely withdraw them. The exchange wouldn’t even notice until it’s time to pay someone else and they no longer have the funds. This is the same architecture that the infamous Mt. Gox had, although undeniably Coinbase/GDAX have done a much better job fending off hacker attacks, as far as we know. At least for now.
EtherDelta is a rather popular centralized/decentralized exchange hybrid.
The majority of the operations are being handled directly on the blockchain. Most importantly, a trader never has to let go of the ownership of their tokens, enabling the whole system to deal with money transfers and execute trades in a trustless manner. The main component of this architecture that can be criticized is the centralized order book server.
This server is fairly well protected by design. In case a hacker takes control of the order book server the orders there are always encrypted. This way the hacker will not be able to simply take the money from the people’s orders, they’ll either be able to trade against those orders (which is what market makers want anyway) or simply delete them all. The latter would remove all liquidity from the exchange and will render it unusable, which is a much scarier attack but way less catastrophic than lost funds.
The centralized component does come with a caveat. EtherDelta has the ability to censor the orders in the order book if they are suddenly forced to. They can also frontrun traders on lucrative deals taking unfair advantage of information asymmetry, which is a much more sneaky and scarier attack because, until regulations arrive, it can be performed without being detected.
Overall, EtherDelta requires no less trust than a centralized exchange when it comes to fair trading. On the other hand, you do not have to trust them with not losing your money (you are always in control of your wallet), thus they are much harder to steal money from compared to centralized counterparts.
0x project is EtherDelta’s ideas taken one step further.
0x business model is creating franchises for “decentralized” exchanges. They provide code libraries for making an exchange that can work in 0x network. They also maintain a centralized order book server that works across all the franchises, that’s what they call shared liquidity pool.
Just like McDonald’s lets you own a franchise and sell hamburgers if you agree to lease the land for your restaurant from the parent company, 0x provides you with all the help you need in order to launch an exchange in return for a small favor. They insist that on your new exchange you trade all tokens against ZRX token if you want to take advantage of the shared liquidity pool. You get to own the exchange and take fees from the orders you originate, and they get to use your franchize to create a market for ZRX token that 0x issued and owns a considerable share of.
When it comes to dealing with the centralized parts of the architecture the same problems as with EtherDelta remain but the tradeoffs look slightly different. Ultimately, each exchange maintains their own database of orders, so bringing one down will not make a big impact on the overall liquidity of the network. However, if 0x's servers are ever down this will be the end for the shared liquidity pool as all the orders from it will be destroyed, and all of the exchanges in the network will start operating in an autonomous mode.
Censorship becomes more interesting than a simple denial of service attack. There are two types of censorship attacks that can be performed on the 0x network.
The first is censorship on the individual exchange level. A large enough exchange in the 0x network can benefit from the shared liquidity pool that other exchanges create, while keeping all the orders that it originated to itself and not sharing them with the global liquidity pool. This exchange can then market itself as one that has more liquidity than the whole 0x network and thereby pull the users from other exchanges in the 0x network, thus centralizing it. For now the absence of such parasite exchanges relies on good faith in the actors and an unproven cryptoeconomic model.
The second is censorship that 0x itself can perform on the level of the global order book. Since 0x ultimately controls the shared liquidity pool on their centralized servers, 0x gets to decide if an order created by some particular address should be distributed to the global network or not. 0x will not be able to seize your funds, but they will definitely be able to prevent you from exchanging or transferring your money if a government that regulates the centralized infrastructure demands so.
Ultimately, 0x looks like an interesting continuation of EtherDelta’s ideas. They build on top of EtherDelta's centralized order book model by introducing a second layer of centralized components and an ERC20 token which they force the exchanges in the network to adopt in order to bootstrap the network with enough liquidity. Once 0x will be large enough it will surely attract financial regulators and it will be interesting to see how they protect their “decentralized” platform given that censoring and regulating it is technically possible.
Unlike all other exchanges in this comparison, Radex is the only exchange that has on-chain order book. In fact, all of the data is stored on-chain, without a single centralized component necessary.
This decision was not taken lightly as it has certain downsides compared to more centralized alternatives. However, a fully on-chain exchange has a number of very important qualities that overpower any potential drawbacks. These qualities are:
- Radex cannot be censored without blocking the whole blockchain. So far nobody, not even a powerful government, were able to censor Ethereum blockchain. On the other hand you don’t need to go far for an example of a country blocking entire businesses, even those owned by well-connected and wealthy international corporations. To put it bluntly, if the Chinese government decides to block EtherDelta’s order book server then the exchange will not be able to function on Chinese territory.
- Radex’s trading engine has no maintenance costs. All financial transactions happen on the blockchain that is secured by Ethereum miners. Zero maintenance costs are what enabled us to make Radex entirely free to use. EtherDelta and 0x relayers have to take fees from their customers in order to support their infrastructure by design.
- Radex’s architecture eliminates any potential downtime. Bitcoin has a track record for producing blocks at a regular pace for almost 9 years. Ethereum consistently produces new blocks every 15-20 seconds. While individual servers can crash at any time the blockchain keeps on living. The protocol itself ensures that Radex will not have any downtime or lost orders as long as the blockchain lives. In contrast, when a piece of centralized infrastructure, such as the order book server, fails in another exchange, that exchange will go down and trading will stop, causing massive inconvenience for its former customers and negatively impacting the global markets.
- Radex preserves your anonymity and does not store any data it doesn’t need. Even if you yourself don’t collect any compromising metadata about your users, such as their IP address and time spent on the website, rest assured that your hosting provider already does this for you. That’s why any product that has a centralized component is a potential privacy liability. Radex has one centralized component - the website with the user interface - that is completely optional to use. You can execute trades directly on the blockchain by calling functions on the smart contract, using a blockchain node that you own and control. In the future we plan to provide a standalone app, much like MyEtherWallet, that will let you comfortably trade on Radex while maintaining your full anonymity.
- All traders are equal. While the Wall St. banks and exchanges have tight regulation and supervision that tell them what they can and cannot do, cryptocurrency marketplaces currently do not have any oversight. This means that centralized exchanges can engage in otherwise unlawful practices, such as frontrunning, wash trading and other tricks. You don’t need to go far for a recent example - the way Coinbase has handled adding Bcash has raised questions not only from the community, but also from Coinbase’s board of directors. They know that the next stop is questions from the SEC and a securities fraud lawsuit. The enabler of all these tricks, and the reason why they were made illegal, is the information asymmetry. When the exchange owners have better and faster access to information than other traders it creates a power imbalance. Storing the full order book and trade data on the blockchain is the only way to ensure that everybody plays by the same rules.
One more thing to mention is that since the financial aspect of Radex is an open source fee-less smart contract, it's essentially public property just like the blockchain itself. So if someone else wants to set up a mirror of Radex with a different user interface, or maybe embed Radex into their own website like a widget, they are free to do so, and all of the exchanges that operate on top of Radex smart contract will share balances, orders and liquidity with each other. It's like a shared liquidity pool on the blockchain without double-layer centralized servers.
You can read more about the decision making process that led to current Radex architecture in this article.
All of these exchanges are remarkable in their own right.
GDAX is an example of a trusted centralized exchange with high performance and high throughput.
EtherDelta was the pioneer of decentralized token exchanges and they invented the centralized order book server model that lowers the cost of participation for market makers and shifts the fees (including the Ethereum transaction fees) entirely on the shoulders of takers.
0x took EtherDelta's ideas and turned it into a full fledged franchise empire with built-in reward economics that are supposed to bootstrap the network and make it the largest decentralized exchange network.
Radex focuses on 100% decentralization and removes fees from the equation by moving all of the infrastructure onto the blockchain. The reason why blockchains took the world by storm is that they removed intermediaries and made money transfer cheaper. The reason why Radex will succeed is because market makers will earn rebates for the liquidity they provide, and market takers will get the best prices with minimal fees and maximum comfort and privacy.
2018 will be a formative year for cryptocurrencies and exchanges will be at the forefront of this revolution as they form the backbone of cryptoeconomics. With the imminent upcoming regulations decentralized exchanges are posed to take a much larger market share within the next twelve months. All of the exchanges mentioned above have different architectures and thus different pros and cons, and will compete for different shares of the global trading market. We hope that the choice of the exchanges will be driven by trader's preference and not by CEO profit hoarding desires and that competition will ultimately drive the fees down to zero for everyone.