crypto.bi

Understand how decentralized cryptocurrency exchanges work

Decentralized cryptocurrency exchanges are true P2P systems where investors can trade cryptos directly with their counterparts, without a centralized middleman.

To better understand decentralized exchanges, we’ll first take a look at centralized exchanges and how they contrast to their P2P versions.

A centralized exchange is run by a company or group of people. It’s physically located somewhere, whether it’s Amazon EC2 servers like used by Bittrex and others, or some other professional server hosting solution, the centralized exchange is a big computer system that runs somewhere physically, whether on one machine or several, within a certain infrastructure.

To make a cryptocurrency deposit on such an exchange, the system will generate a unique deposit address just for you. Cryptocurrency backends allow for the creation of infinite addresses for free, so the exchanges can basically create one unique deposit address for each deposit, although most simply create just one for each crypto. Once you receive a unique deposit address, the exchange’s backend will monitor that address for deposits. If you send cryptocurrency to that specific address, the backend will receive a deposit event and will credit your account with that amount of cryptocurrency. Here’s where centralized exchanges become very different from actual cryptocurrency transfers.

Once the deposit is processed, the transactions inside the exchange no longer happen on the blockchain! When you buy and sell one crypto for another inside a centralized exchange, what you’re actually doing is generating transactions inside that particular exchange’s database. Those transactions never reach the blockchain. Therefore there is no guarantee that the cryptos involved in the exchange even exist! As we’ve seen with MtGox, there wasn’t liquidity to honor withdrawals in cryptocurrency and this was only discovered once a massive deficit had already built up. This potential mismatch between cryptocurrency balances and the exchange database balances are a permanent risk at centralized exchanges.

But centralized exchanges offer enormous convenience. Not having to confirm all trades on the blockchain means a very fast centralized database system like MySQL, Cassandra o even commercial solutions like Oracle can be used to maintain balances and trades. So trades happen in real time and you can even build bots to perform several trades per second in high frequency trading, something which is impossible on the most popular blockchains out there. The important thing to keep in mind about centralized exchanges, is that after the deposit is confirmed, you’re no longer operating on the blockchain, but instead of a proprietary system that has a centralized database that is not at all related to the blockchain. The only other time you interact with the blockchain in a centralized exchange is when you actually withdraw funds back to your crypto wallet.

So why are centralized exchanges bad? Well, they’re not actually bad. They’re just not decentralized. Faults on the centralized database can lead to fund losses. Hacking attacks can lead to losses, and so on. The convenience of very fast order execution and instantaneous books comes at at cost. Like all things, it’s a tradeoff between speed, convenience and decentralization.

Enter decentralized exchanges. As we’ve already hinted, the disadvantage of decentralized exchanges is speed and keeping the bid/offer books updated. What happens in most decentralized P2P exchanges is you see a great offer, you bid for it, but that offer has already been taken by another peer in the network. There is usually a significant difference in connection speed between players in a P2P network. For instance a bidder may be using a slow line in Africa while a competitor could be using a fiber optical line in San Francisco, usually the fastest line will win the P2P bid/offer contest. This asymmetry exists in centralized exchanges as well, but since a centralized system will normally update the book in real time, not having to wait for slower lines, the expired/consumed bids and offers are usually updated faster on a centralized exchange. On a distributed P2P exchange, on the other hand, the books are normally lagging behind the actual trading action.

So why do we want decentralized exchanges? Because decentralization is core to the uniqueness of cryptocurrencies. A fully decentralized network of peers is nearly indestructible even under the hardest conditions like war or widespread catastrophe. Another advantage is being able to keep your funds on your wallet  until it is actually traded, not having to send funds to a remote wallet where you do not control the private key. In decentralized exchanges, the private key is stored somewhere in the core of your computer memory, ready to sign trades once they happen.

Like in centralized exchanges, decentralized exchanges require a ledger that will allow cryptos to be traded one for another. This is still a big challenge in cryptocurrency research and development. Cross-chain trades are beginning to be tested but so far there isn’t one de facto solution adopted by the community. So the reality of decentralized exchanges at the time of this writing (May 2018) is that they’re under active development but not ready for mass adoption just yet, at least not cross-chain exchanges.

Exchanges that operate within a single blockchain are widely available. HitBTC, Etherdelta and others already make it possible for you to trade any Ethereum-based asset on their decentralized exchange. All you need is the Ethereum blockchain contract address and the token can be freely traded for other tokens on these P2P exchanges, as long as there is an open order book available.

Decentralized exchanges are often implemented as smart contracts within the Ethereum ecosystem. These self administering smart contracts handle token transfers, Ethereum transfers and between any two parties within the Ethereum blockchain. Thus any new ERC20 tokens registered with the Ethereum blockchain are immediately tradeable on these decentralized exchanges.

Since they’re implemented as smart contracts, P2P Ethereum exchanges are very transparent. Internal and external transactions are visible on the Ethereum blockchain once executed. This has the disadvantage of limiting the transactions per second to the blockchain limit, also requiring fees to guarantee that the contract function calls will be executed by being alloted enough GAS. Every trade also depends on being mined and confirmed, which also makes the process slower than centralized exchanges.

How can these shortcomings of decentralized exchanges be mitigated? By the same methods the Bitcoin shortcomings were: developing 2nd layer applications on top of the blockchain.

Centralized exchanges are, in the end, simply high speed private channels built on top of the blockchain. You register an initial deposit on the blockchain, operate within their fast channel as much as you want, then register an exit operation back on the blockchain. This, in essence, is a lot like what Lightning Network does on the Bitcoin blockchain. The private channel transactions all happen outside the blockchain, only the entry and exit are registered in the blockchain. The same or similar could be implemented on decentralized exchanges. An initial deposit is registered in the blockchain, then the decentralized exchange handles all the private trades, then an exit operation sends the tokens or ETH back to the investor, via the blockchain. This is what some of the decentralized exchanges are doing. HitBTC operates this way and so do others. You send funds to a smart contract, which then manages the private channel within smart contract operations, after you’re done you can “withdraw” your funds back, which is when the final operation goes registered on the blockchain.

We hope this overview of decentralized exchanges has given you a better perspective about how they work and the direction which their development is taking. The tendency is for there to be more and more faster layers built on top of the blockchain, the same tendency to build fast channels on the Bitcoin blockchain, for example, is already being leveraged for the Ethereum and other popular blockchains. Cardano ADA also promises to implement very high protocols on top of the Cardano blockchain, bringing together features which are commonly denominated 3rd generation cryptocurrency features.

About the Author
Published by Crypto Bill - Bill is a writer, geek, crypto-curious polyheurist, a dog's best friend and coffee addict. Information security expert, encryption software with interests in P2P networking, decentralized applications (dApps), smart contracts and crypto based payment solutions. Learn More About Us