What Are Decentralized Exchanges?

--

This post explains and contrasts centralized and decentralized crypto-asset exchanges and looks at reasons for preferring decentralized exchanges. Helpful diagrams are included.

Introduction

When cryptocurrencies were first released with the creation of Bitcoin in early 2009, the creator of Bitcoin, under the pseudonym Satoshi Nakamoto, claimed that “[a] purely peer-to-peer version of electronic cash would allow online payments to be sent directly from one party to another without going through a financial institution.”¹ Despite the inherent decentralized, peer-to-peer nature of cryptocurrencies, however, the majority of cryptocurrency trading happens through centralized exchanges. Before delving into the reasons why you should be using a decentralized exchange that supports the intent and meaning behind cryptocurrencies, it is important to define some key terms.

Centralized Exchanges

In a centralized exchange, also known as a “CEX”, the exchange operates through central infrastructure usually controlled by a single party. Examples of a centralized exchange include Coinbase and Binance. Centralized exchanges match two willing participants in a transaction through the exchange’s central orderbook and settle that trade on top of the exchange’s privately managed cryptocurrency wallets.²

The act of trading on a centralized exchange essentially amounts to manipulating credits and debits to balances inside of a centralized database. Each user has a claim over their portion of the crypto-assets managed and held by the exchange, but user balances are managed off-chain.³ The blockchain is only involved when a user deposits or withdraws their assets. In other words, the exchange receives and sends out crypto-assets over the blockchain (and fiat via banks), but otherwise trades are tracked in the exchange’s internal systems.

With centralized exchanges, users must send their crypto-assets to the exchange before they can execute trades. This means that, as far as the blockchain is concerned, the centralized exchange is the owner of the crypto-assets once a deposit has been made. This exposes users to two major risks:

  1. Loss of Access to Funds. Users are susceptible to losing access to their funds if the centralized exchange goes offline for maintenance or experiences downtime. This prevents them from being able to withdraw or trade on their assets for unknown periods of time that are out of their control.
  2. Theft. Users could potentially lose all of their funds if the exchange is hacked and the hacker is able to withdraw those tokens before being detected and quarantined. Centralized exchanges have been viewed as targets for hackers because the money deposited by users is concentrated in the exchange wallets. There are plenty of examples of high profile thefts such as the implosion of Mt. Gox. For a more complete list, see the Blockchain Graveyard.

Despite these downsides, the inherently off-chain processes of centralized exchanges makes it easier for them to handle much higher trade throughput and perform automated order matching. However, decentralized exchanges are on the path to catch up to centralized exchanges in these areas.

Here is a picture which demonstrates a typical deposit, trade, and withdraw cycle for a centralized exchange (more explanation after the picture):

In this diagram, Alice is a user interacting with a centralized exchange.

Step 1: Alice sends her cryptocurrency to the exchange through the blockchain. That cryptocurrency is now owned by the exchange as far as the blockchain is concerned. The cryptocurrency sits inside the exchange’s wallet(s).

Step 2: Alice places orders with the exchange, buying and selling crypto-assets. Alice can place orders directly with the centralized exchange through the exchange’s user interface (“UI”) on the web or via an app. She can also place orders programmatically using code and calling an Application Programming Interface (API) provided by the exchange. The exchange maintains wallets containing the aggregate cryptocurrency deposited by all users. The exchange tracks how much is owned by each user. When users trade with other users, balance changes are only reflected inside the exchange’s databases. We can see here that two other users, Bob and Charlie, deposited Ethereum (ETH) and that the exchange holds the aggregate ETH from Alice, Bob, and Charlie inside of the exchange wallet.

Step 3: Alice initiates a withdrawal by requesting it through the exchange UI or API. At this point, the exchange is suppose to send cryptocurrency to Alice by initiating a blockchain transaction. However, any number of reasons can delay the actual transmission of the cryptocurrency, including downtime or solvency issues with the exchange (e.g., if internal wallets were mismanaged such as in the case of Mt. Gox).

Step 4: Eventually, the centralized exchange initiates a transaction on the blockchain to send Alice the cryptocurrency she requested in Step 3.

This is a simplified picture, but it largely matches the flow of centralized exchanges. There are many more details, especially around managing the exchange wallet securely (e.g., hot and cold storage), but that’s for another time.

Decentralized Exchanges

A decentralized exchange, also known as a “DEX”, settles trades using blockchains and smart contracts instead of relying on a centralized party. In other words, trades settle peer-to-peer through the blockchain. Decentralized exchanges are also referred to as non-custodial exchanges to reflect the fact that a centralized party does not take custodianship of the assets. The Everbloom Exchange is a decentralized / non-custodial exchange.

Decentralized exchanges never have direct control over users’ funds. With a DEX, your private keys and your crypto-assets remain in your control.

In addition, by settling through the blockchain, a DEX has a very compelling extra benefit. If a DEX experiences downtime, users still have access to their funds by placing transactions directly on the blockchain with software provided by other vendors. This means users can always access their funds with zero dependency on the condition of the exchange interface.

Since trade settlement happens peer-to-peer, decentralized exchanges essentially act like matchmakers, helping users find each other for whatever trades they wish to place.

This diagram will help us look at the process of trading on decentralized exchanges (explanation follows the picture):

Step 1: Alice first “deposits” assets into a smart contract. This process can work differently for different DEXs and in some cases has varying terminology, but it’s fine to think of this step as a deposit in the traditional sense. However, unlike a CEX, the DEX has no control over the deposit. At this point, only the user is allowed to touch the assets via either a withdrawal or a trade submitted to the contract.

Step 2: Alice signs an order to buy a crypto-asset. For example, she would like to buy some Basic Attention Tokens (BAT). She sends the order to the DEX’s off-chain orderbook servers to store and share with other users. The signed order effectively amounts to a message that reads “Alice authorizes a trade of 1 ETH (owned by her) for 1000 BAT (from someone else)”. She signs the message with her private key to prove that it came from her.

Step 3: Bob comes along and takes Alice’s order from the DEX’s off-chain orderbook. Some DEXs require Bob to find the order himself by browsing the orderbook (similar to how one would browse listings on eBay). Other DEXs provide automated matching.

Step 4: Bob deposits enough BAT to the smart contract to cover the opposite side of Alice’s order. He does so using the same process Alice used in Step 1. After completing his deposit, Bob signs a blockchain transaction that includes Alice’s signed order and his authorization to be a counter-party to that order. He submits this transaction to the trade function of the smart contract. The funds get swapped in the smart contract. Alice is credited BAT and debited ETH, and vice versa for Bob.

Step 5: Alice is now free to withdraw her BAT by sending a transaction to the blockchain. The DEX interface can help her construct and submit this withdrawal transaction, but she has the option of doing it with zero assistance from the DEX. That means she can withdraw regardless of the state of the DEX, a hugely powerful advantage. Ideally, the DEX or her wallet app would have offline functionality to construct blockchain transactions and queue them for delivery.

That’s a complete trade!

DEXs are evolving, and we are seeing the emergence of some hybrid exchanges which are not as black and white as the examples here, but this accurately approximates many DEXs today.

For a more thorough explanation of how decentralized exchanges work, check out the following content from around the web:

Benefits of Using a Decentralized Exchange

1. Control of Funds

One of the most compelling aspects of a decentralized exchange is that it gives customers complete control over their assets. Customers on centralized exchanges must deposit their funds onto the exchange in order to conduct transactions. This means that funds on centralized exchanges are held by the central party’s wallet. The customer’s access to their funds is dependent on that central party. If a centralized exchange goes offline, the customer cannot access their funds.

In addition to availability concerns, centralized exchanges are a large target for hackers because all funds are stored by one entity. The reward-to-work ratio of hacking a centralized exchange is much more attractive than hacking each individual user in a decentralized exchange.

On decentralized exchanges, customers have the ability to transact directly between wallets through the exchange’s orderbook (or even directly). The users have full control of their funds at every step.

2. Security

Thanks to the advent of blockchain technology, decentralized exchanges essentially operate on a distributed ledger where security is greatly enhanced. Users interact on a trustless and a non-custodial platform. As long as users are not careless with their private keys, they have a greater degree of control over their accounts and transactions on a decentralized exchange.

Even if a decentralized exchange frontend were to be compromised, the user’s wallet software provides another line of defense. In this scenario, the compromised frontend might request a transaction that sends funds to a fraudulent address instead of the real DEX smart contract. The user would have to approve the requested transaction with their wallet software. If the wallet clearly presents the approval request with a well-designed UI, it would be possible for a user to spot an improper transaction destination and decline the approval. It is even possible for wallet software to detect sudden, suspicious changes in destination addresses in a similar fashion to how browser vendors collect and push malware and phishing URLs to browsers to warn their users when they click known malicious links.

Thanks!

Thanks for reading. Have questions? Something we should explain further? Ask by tweeting EverbloomHQ on Twitter or chatting in our Telegram group. The Everbloom DEX is live! See our announcement post.

About the Authors

Andrew Rollins (Twitter): CEO and co-founder of Everbloom | Former developer at Microsoft and VC at Sigma Prime | Previously Chief Software Architect and co-founder of Localytics | Blog at Andrew Rollins on Medium.

Andrew Hall (LinkedIn): Business Development Associate at Everbloom | Studying Finance and C.S. at Wake Forest University | Investor / Trader in Traditional and Crypto Markets.

Eric Nemeth (LinkedIn): Business Development Associate at Everbloom | Studied Economics at Boston College | Interested in tokenizing real assets | International traveler | Futbol loving Chelsea fan.

Footnotes

[1] Bitcoin: A Peer-to-Peer Electronic Cash System; https://bitcoin.org/bitcoin.pdf

[2] What is a wallet? Learn more: https://en.wikipedia.org/wiki/Cryptocurrency_wallet and https://cryptocurrencyfacts.com/what-is-a-cryptocurrency-wallet/

[3] The term “off-chain” means “outside of any blockchain.” The term is used to specify that an action happens outside of the purview of any blockchain (the action has no effect on the blockchain and the blockchain is not aware of the action). The term is also used to specify that a piece of data does not reside on the blockchain.

--

--