Decentralized Exchanges Have a Problem

The perils of front-running on the blockchain

Eric Gorski
GnosisDAO
4 min readJan 9, 2019

--

Illustrations by Lea Filipo.

There’s an unsettling contradiction in the cryptocurrency space: Decentralized assets are almost exclusively traded on centralized exchanges.

This isn’t breaking news. A number of projects have already launched alternative decentralized exchanges (or DEXs) — notably IDEX and Ether Delta — to resolve this mismatch.

It’s a noble pursuit. DEXs promise to cut out the middleman and give crypto-holders full custody over their assets. But so far they’ve gained relatively little tractionwhile today’s decentralized exchanges measure daily volume by the thousand, centralized exchanges measure daily volume by the billion.

There are some obvious culprits for this pretty massive gap in use.

Compared to their centralized counterparts, DEXs can have poor liquidity, lousy user interfaces, and lack more advanced trading tools like margin or leverage. While all these shortcomings are undeniably valid, there’s another problem with DEXs that is consistently understated: order front-running.

In what follows, I’ll explain what front-running is, why it flourishes on DEXs, and how we can fix it.

In a Nutshell

Front-running occurs when someone with advanced market information steps in front of a trade for economic gain.

Here’s the basic recipe:

  1. Gain access to market order information that will increase the price of X.
  2. Buy X before the guaranteed price increase.
  3. Sell X after the guaranteed price increase.
  4. Profit.

The practice of market front-running first gained traction in the centralized exchanges of Wall Street, as popularized by Michael Lewis’s Flash Boys.

A decentralized exchange, however, shifts the playing field for front-runners, introducing new parameters that must be accounted for. Two of these new considerations are especially noteworthy.

With DEXs:

  1. Market information is public. Anyone plugged into the blockchain can monitor (and capitalize on) incoming bid orders, sell orders and even cancellations.
  2. Trading is slow. In decentralized exchanges, there is an inevitable time delay between when a blockchain transaction is broadcast and when it is ‘mined’ or validated.

The key takeaway here is that decentralized exchanges make it easier for anyone to exploit temporary market inefficiencies for a profit. In other words, it’s easier to front-run the market.

Mining Profits

The problem of front-running really escalates when you introduce cryptocurrency miners into the equation. Miners can directly affect the order in which transactions on a DEX are executed — an ability which can lead to all kinds of unsavory outcomes.

Picture two actors who star in a short but tragic play: a malicious miner and an absent-minded trader. In the opening scene, the trader — brimming with confidence that he’s detected an opportunity to ‘buy the dip’ — places an order on his favorite DEX. In his haste, the trader mistakenly types an extra zero for the order quantity. Realizing the mistake, the trader cancels the order. But it may be too late.

A malicious miner spots the transactions on the blockchain and willfully sandwiches a sell order between the traders’ mistaken buy order and subsequent cancellation request. The trader’s fate is sealed: the original trade goes through, pumping the price, the miner unloads their unwanted crypto-tokens at an above-market price, and the subsequent cancellation request simply fizzles out.

This is just one (slightly simplified and dramatized) example of how miners can game DEXs for a profit.

By the Numbers

DEX transparency gives front-runners an advantage. But it also gives academics like Cornell Tech’s Philip Daian an inviting research opportunity. (I strongly recommend checking out a recent talk he gave at Devcon iv here.)

Daian and his team conducted a series of tests to measure the potential profits of front-runners on Etherdelta, most recently the third largest decentralized exchange by trading volume.

Top DEXs by transactions, as of January 9, 2019.

Their findings?

In August 2017, a clever front-runner could net ~$4,500 per day or $1.6+ million a year through Etherdelta alone. If you adjust this to today’s ETH price of ~$150, it would be a more modest, but still substantial, $1.5 million a year income (assuming equal trading behavior and volume).

That’s not a bad salary if it’s only split between a few people. But it’s also peanuts relative to the broader market. The real problem arises if DEX adoption and overall trading volume ramp up and a $1 million opportunity becomes a $1 billion opportunity.

There is one way to stop front-runners in their tracks: batch auctions. (Shameless plug: Gnosis is working on two batch auction protocols, dFusion, and the DutchX). The batch auction format eliminates the lag that front-runners need to profit, by settling all trades for a given auction period simultaneously. Critically, this solution does so without conceding full-stack decentralization.

The chief downside of the batch auction format is that exchange requests cannot be executed quickly. Moving in or out of a position on a centralized exchange takes seconds but with a batch auction format, it could take minutes to hours.

While centralization boosts transaction speeds and patches (some) front-running vulnerabilities, it fails to address critical points of failure.

Last year, a string of hacks led to $1.5 billion in losses on centralized exchanges, devastating users and public trust in crypto.

If the major system design hurdles (like front-running) are overcome, and DEXs prevail, these losses could shrink to $0 — and, perhaps, broader public faith in a decentralized future could be restored.

Follow me on Twitter.

Follow Gnosis on Twitter.

Special thanks to Lauren Dunmore, Lea Filipo, Stefan George and Kei Kreutler.

--

--