The 0x Protocol in a Nutshell
The blockchain is often heralded as a technology that removes the need for trust. Yet hundreds of thousands, if not the majority of cryptocurrency traders today still need to place so much trust in exchanges to operate in a responsible, secure manner. Hackers are targeting these honeypots of digital assets and under-informed speculators are being tricked into giving away their private keys. Trades are halted when servers are down, and large orders aren't being filled due to low liquidity...
In comes decentralized exchanges, which leverage the blockchain technology to enable safer and more transparent trading. They enable users to remain in control of their funds by performing their critical operations on the blockchain. This article will be an overview of 0x, a decentralised exchange protocol that will serve as the public infrastructure for these dexs.
Motivation & Background
In late 2016, Amir Bandeali and Will Warren had been working on a tokenised derivatives project on the Ethereum blockchain when they realised that these tokenised derivatives would not be useful if there was nowhere to exchange them (this was before the days of Etherdelta) - they soon switched gears and begun building their own for-profit decentralised exchange.
As the co-founders became more immersed in the Ethereum community, they found that a lot of project teams required exchange functionality for their tokens. Various teams had plans and proposals to build one-off implementations for their exchanges.
It soon became clear that instead of a general dex which attempted to meet everybody's needs, what the community really needed was a truly free and public decentralised exchange infrastructure that anyone can plug into and use. And so, the 0x team shifted towards repurposing their system towards a public dex infrastructure.
AN OPEN PROTOCOL
By having 0x serve as an open protocol on which anyone can create their own for-profit decentralised exchange, we open up a single piece of infrastructure to a wide variety of different use cases. This saves teams the time and effort needed to build their one-off dex implementations from scratch, as well as create a global liquidity pool that builds on network effects.
When trading on an exchange that runs on the 0x protocol, users begin by broadcasting their intent to enter into a trade in a message format. This "message" is a chunk of data with parameters such as: tokens they'd like to exchange, buy/sell price, expiration time, and whether or not they'd like to trade with a specific counter-party (point-to-point order) or leave it open to anyone (broadcast order).
They then package this data, cryptographically sign it and either send it to the counter-party as a message (P2P) or broadcast it to the network. 0x itself is a system of smart contracts on the Ethereum blockchain, broken into the:
💼 Core Business module which...
- Accepts packets of cryptographically signed data, processes them, and allows trades to be settled on the blockchain and
- Authenticates cryptographic signatures, ensures that senders have sufficient funds to settle the trade and that the order hasn't already expired or filled
☑️ Governance module which
- Allows the trade settlement module to be upgraded over time without requiring users to migrate to the new version or disrupt ongoing trades.
- It's extremely important that the system of smart contracts that businesses are plugging into can be updated without bringing the market to a halt (more on this later)
Etherdelta has had to upgrade their smart contract 4 times. It's important to upgrade smart contracts as the blockchain technology stack is rapidly evolving. This process has to be as non-disruptive as possible
When using 0x in its simplest form (point-to-point trade), a user can package, sign the data and send it to a specified person via SMS, email, Facebook message, or whatever means they want. The order can only be filled by the specified taker address. The counter-party just has to then take that piece of data and inject it into the 0x smart contract, which will move the tokens between the sender and their counter-party at the exchange rate that was specified without the need for trust.
However, people typically conduct large over-the-counter deals through an open exchange, where many buyers and sellers aggregate their liquidity, making it easy to find a counter-party that is offering the asset of interest at a specified price . The first dexs were using on-chain orderbooks, which meant that people were paying transaction fees to even initiate the order - this wasn't sustainable in the long term because you are losing value in the transaction process.
THE ROLE OF RELAYERS
Relayers aggregate these cryptographically signed 0x trade orders and present them to the world in the form of an orderbook, hosted off-chain. Off-chain orderbooks decrease trading costs but require a mechanism to match orders to their counter-parties, and this is where relayers come in. Since 0x orders are just chunks of cryptographically signed data, a relayer's job is to host a database of orders and sort them according to price, expiry time etc., and serve them to anyone that comes to the site looking for a counter-party. Once the parties have been matched, the trades are then settled on-chain.
A relayer is therefore really a decentralized exchange that looks like a centralized one. However since they are not responsible for the custody of assets nor trade execution, they aren’t really acting as exchange but are instead relaying messages back and forth between people - hence the name 'relayers'. Generally, relayers are for-profit entities that build their decentralized exchange as a product running on the 0x protocol.
BUSINESS MODELS OF RELAYERS
We'll see competition between the different relayers which will be healthy for dex ecosystem as a whole. Etherdelta has been incredibly successful, but since dex protocols like 0x have lowered the barrier to entry, we'll see competition around:
User experience - if there are multiple teams competing for market share, one of the first challenges is providing great UX, everyone will benefit from the competitive approaches taken to achieve this.
Transaction fees, which will move towards economic equilibrium.
One of the big assumptions is that relayers will trade the same set of tokens. There is not a finite number of tokens people are interested in trading. This explosion of tokens that come into existence is going to continue and will trend towards infinity over the years [4]. Relayers will find a market niche and carve it out, there will probably be a few dominant relayers in a specific niche but hundreds of niches e.g. relayers that focus on real estate tokens, on prediction markets (elections, politics, sports, science etc.) Each can tailor their product and the UX for specific markets.
CURRENT ISSUES AND MODELS FOR TRADING
When you create, sign a transaction, and broadcast it to the P2P network, that transaction isn’t necessarily mined into a block straight away. The message has to propagate through the network and typically sits in a pending transaction pool (mempool) — waiting to be mined into a block.
The transparent nature of the blockchain means that anyone can examine the unconfirmed transactions in the mempool. In the context of an exchange, this can be a drawback as other traders can use this public information to their own advantage. They can rebroadcast a similar or same transaction message but set a higher gas price so that their trade will get mined into a block before yours -- this is called front running.
Front running is an issue that isn’t specific to decentralised exchanges, it is just something that people associate with dexs a lot today because it is one of the use cases of smart contracts in production right now.
0x doesn't define the way that people can enter into a trade or the way that these orders are transported off-chain, there are currently two trading models in place, each with their trade-offs:
OPEN ORDERBOOK MODEL
This model is the way relayers can facilitate exchange and host an orderbook, as presented in the 0x whitepaper in February 2017
- Anyone can generate signed orders and post it on a relayer’s orderbook, which is like a post-it board on which anyone can see pending transactions, take it off and inject it into the 0x smart contracts
- This model is subject to front running because the way the orders are specified allows anyone to fill them. Miners can arbitrarily arrange transactions into any order they want. Since miners can run their nodes however they want, they can also front run orders
- If someone can see that you’re attempting to fill the order, that the txn is in the pool, they can attempt to fill it by setting a higher gas price and jump in front of you.[5]
MATCHING MODEL
- Every order that is sent to the relayer specifies that that relayer as the only entity as being able to fill the order and execute that trade
- When this relayer gets orders on opposite sides of the market at the same price, they package these two orders together and inject them into the 0x smart contracts -- filling them synchronously and autonomously in a single transaction
- This relayer is not only aggregating liquidity but also taking on the responsibility of trade execution. In this model, miners and other traders cannot front run an existing order in a pending transaction pool — only the relayer is able to execute these trades
- But the relayer can front run as have full control over the trade execution process — some trust involved there
Generally, these relayers are for-profit businesses who have reputations to uphold. Front running will be a bad idea for them if they want to continue to operate their business
There are various strategies relayers could use with varying degrees of trust. These models are not custodial, which is what matters the most. The 0x system is designed to be modular and extendable, there are models being explored that combines the of the openness of the open orderbook model with the strong trade execution fidelity of the matching model.
In the long run, the end solution might be something like zero-knowledge mining, where you can't see transactions and their properties in the mempool, but can only prove that it will pay the miner's fees.
REGULATORY ISSUES
Relayers are typically people who are running for-profit businesses. While cryptocurrency trading is still in a regulatory gray area, the pioneers are cognizant of this and employ good legal counsel to make sure they’re operating in a legally compliant way.
WHAT WOULD PREVENT UNREGISTERED PEOPLE FROM TRADING SECURITIES?
0x can be used to trade all sorts of ERC20 assets and there are currently no models in place to regulate private OTC trades. There are other projects exploring approaches to incorporate KYC (Know Your Customer) and AML (Anti Money Laundering) processes for the assessment of security tokens.
Polymath and Harbor are examples of projects creating new token standards for trading securities tokens. These protocols implement proof of process by whitelisting Ethereum addresses of people who have gone through an off-chain KYC/AML procedure. Only people with those addresses are able to receive the token (that might be a security) and transfers to non-whitelisted addresses will fail. These protocols will be a layer underneath 0x that would prevent people from obtaining securities tokens if they hadn’t gone through the KYC/AML process.
VULNERABILITIES WHEN USING A DEX?
There aren't many vulnerabilities that would be a systemic risk to everyone. It is hard for hackers to attack a dex for large catastrophic failures in the same way that they do centralized ones. Some users may get tricked into doing something with their private key, but that’s more of a UX/UI issue that needs resolving. [4]
Ideally, you’ll be using a hardware wallet to trade on a dex, with your private key is very far removed from anyone on the internet. Every single action has to go through your wallet in a way where you can examine exactly what's happening.
GOVERNANCE AND ROLE OF THE ZRX TOKEN
The ZRX token plays two roles:
Primarily as a governance token that allows the 0x team to upgrade the smart contracts over time without needing to migrate thousands of users over to a brand new pipeline, as this would bring the market of exchanges to a halt
Since Ethereum smart contracts are immutable, to update a protocol developers must deploy a completely new smart contract that either forks the network or disrupts the protocol until users “opt-in” to the newest version
A disruptive protocol update could invalidate all open orders on an exchange, and require each market participant to approve a new smart contract to access their balances
Protocol tokens may be used to drive a decentralised update mechanism that allows for continuous integration of updates into the protocol while also protecting the protocol’s users and stakeholders
Paid as trading fees to relayers who are hosting and presenting the orderbooks
The rationale behind using a token to pay fees (as opposed to just using Ethereum), is so that all stakeholders in the 0x ecosystem can participate in governance and voting. If only relayers hold tokens and vote, it will be unsustainable because their incentives do not necessarily align to the end users. It's important to distribute governance across the ecosystem as a whole.
Voting is weighted on the amount of tokens you own. There needs to be a way to soft fork on-chain to keep everyone on the same shared protocol. If the team pushes out changes in a centralized way, where some people decide to stay on the old version, we'll end up with the same problem of fragmented, silo'd exchanges.
There is a placeholder governance module that prevents the 0x team from doing malicious activities. This will eventually be replaced with a decentralised governance system that uses the ZRX token as the primary lever over which these protocol upgrades are approved/denied.
While the trading functionality is already in place, the 0x team is taking their time to build out a robust governance model as the long term success of the ecosystem depends on it.
ARE ALL STAKEHOLDERS EQUALLY QUALIFIED TO ANALYZE AN UPGRADE AND DRIVE THE GOVERNANCE PROCESS?
Real world governance is a very challenging problem. Right now, the 0x team are collaborating with Aragon team for research into liquid democracy: the way that stakeholders in the ecosystem to delegate their voting power to someone that they deem capable to vote on their behalf. This will allow the people with expertise to voice their opinions and have sufficient voting power even without the monetary resources at their disposal.
To be continued...
When it comes to dexs, one of the things I'm looking forward to the most is the emergence of these niche marketplaces for token exchange. The exchanges widely used today differ mainly in aesthetics and market prices, but there isn't really a clear boundary for what types of tokens Bittrex and Poloniex and Liqui offer, for example, and what specific communities they serve.
In an answer to why there probably won't just be one dominant dex where you can trade everything, the 0x founders made an interesting anecdote to Reddit and its subreddits. Subreddits are communities within Reddit where people can talk about whatever subject it is they are interested in. The UX of each subreddit is customized to that community to some extent, yet you still can't fully tailor the experience for it to be unique from the other subreddits. You still need a platform that is fully customized for your needs. For example, vinyl collectors have a vibrant community on /r/vinyl but they still need Discogs to find and obtain records.
In the future, there will be exchanges that specialize in energy tokens, non-fungible tokens, prediction market tokens (and even within this there will be those tailored to sports, politics, gaming etc.)... and these exchanges will customize their UX to best serve that specific use case. Therefore while there will be few dominant relayers in each niche, there will be many niches for token exchange - it's exciting to see what these marketplaces will look like.
Decentralised exchanges and the protocols they're built on will not only require programmatic robusticity but also a well-thought out user interface design and sustainable governance models. I believe that within the next few decades, our interaction with dexs will be as commonplace as purchasing goods via PayPal today. For now, it is important to educate ourselves and others about the technology to avoid being taken advantage of when we do explore and adopt these applications ourselves.
This post is a shorter version of an article I posted a while back on my blog. I look forward to using Steem more often for content. Feedback appreciated!
You can also find me on Twitter and Instagram
Cheers
RESOURCES & FURTHER READING
- Why Decentralized Exchange Protocols Matter - Fred Ehrsam
- State of Decentralized Exchanges - Nathan Sexer
- 0x whitepaper
- Epicenter episode with Will Warren & Amir Bandeali, co-founders of 0x
- Unchained episode with Will Warren
- 0x guide from Blockonomi
- Liquid Democracy - Dominik Schiener
- TechCrunch article about voting on liquid democracy
Coins mentioned in post:
Congratulations @nichanank! You received a personal award!
You can view your badges on your Steem Board and compare to others on the Steem Ranking
Vote for @Steemitboard as a witness to get one more award and increased upvotes!