Breaking Down the “Flash Boys” DEX Trading Bots Bloomberg Article

Scott Winges
Hydro Protocol
Published in
7 min readApr 17, 2019

The recent bloomberg article “Flash Boys Trading Bots Are Running Wild on Crypto Exchanges” provides a broad overview of the much more detailed Cornell Tech Paper.

It’s great to see this type of thing picked up by larger media outlets, but while it highlights a lot of interesting points, some of the concepts in the bloomberg article are pretty vague and oversimplified. For example, the main front running problem with DEX’s discussed only applies to a specific type of DEX — others have already solved this.

Quick Summary

The paper boils down to 4 main points:

  • Due to price discrepancies, there is sometimes “free money” in crypto markets
  • Lots of people notice that this free money opportunity exists and try to get it
  • In a traditional market, whoever gets there first gets the money
  • In DEX’s, it’s actually whoever PAYS the most who gets the money. This leads to massive problems.

The first three statements are absolute truths. However, the last point is misleading. I would revise that point to:

  • In a subset of DEX’s, it’s actually whoever PAYS the most who gets the money. This leads to massive problems.

Only on-chain matching DEX’s suffer from the problems highlighted in the paper. Hybrid DEX’s have already completely solved this.

This distinction is quite important. To understand it further, continue on!

Two Types of Front Running

The firms that deploy the autonomous trading programs manage to get priority ordering by paying higher fees, and use that advantage for practices such as front running, in which traders can see orders from others and manage to place their own first. (source: Flash Boys Trading Bots Are Running Wild on Crypto Exchanges)

First let’s examine the term “Front Running” that is often casually thrown around, but can mean drastically different things in different contexts. There’ are two distinct types of front running that can occur on exchanges:

  • Trader vs Trader
  • Broker/exchange vs Trader

The type of front running discussed in the article, and that is rampant on these on-chain matching DEX’s, is the former: Trader vs Trader.

In the “Trader vs Trader” front running, two or more traders are trying to take an order (the free money!). In a traditional market, whichever trader acts first would take the order. Just like in the grocery store with the last box of cereal: whoever grabs that box first is the winner. However, in the case of many on-chain DEX models, it’s actually not who acts first: whoever PAYS more (sets a higher gas fee) gets the order.

The article analyzes arbitrage bots which make instant calculations to determine the proper gas prices — such that they can duck in and grab orders before others take it, even if they place their request much later. They could snatch that box of cereal right out of your hands. Trading in a market with Trader vs Trader front running is like competing with an athlete on steroids: these bots have technological advantages for making these high frequency trades over a traditional user.

“Flash Boys” is a reference to the Michael Lewis book — it loosely ties into this, with the example of Spread Networks’ famous Chicago to NYC fiber-optic pipeline. The extra speed from this network connection theoretically allowed them to trade on Wall Street milliseconds before others could.

Except in blockchain, it’s about 1000x slower — less of a flash and more of a jog really.

Broker/exchange vs Trader front running is a bit different. In this type of front running, the trade organizer (broker or exchange) receives an incoming order from a user, and uses this input to snipe the order out from under them. It’s the equivalent of the house rigging a poker game. This is not what is happening with these on-chain matching DEXs currently. But this type of front running could be happening all the time on centralized exchanges, and none would be the wiser.

On-Chain Matching DEX Front Running Is Fundamentally Different

What’s more, similar practices are likely rampant on centralized crypto exchanges as well, Ari Juels, a professor at Cornell Tech, said. (source: Flash Boys Trading Bots Are Running Wild on Crypto Exchanges)

This is where things start to get a bit vague and might lead to wrong conclusions. It’s not actually that similar. Centralized exchanges are not performing trades on-chain: their order settlement process is more akin to Wall Street — it is done by a centralized server. There is no gas price setting for these bots to manipulate.

  • The concept of extrapolating the on-chain matching DEX front running to centralized exchanges does not work.

The type of potential front running on centralized exchanges is fundamentally different than the type that is discussed in the paper which occurs with on-chain matching DEXs.

Arbitrage: who should get the order?

With front running better understood, how are people determining which orders are so heavily desired?

Sometimes an asset will trade at one price on one trading venue, and another price on another venue. If you notice this discrepancy, you can buy the asset at the lower price in one place, sell it at the higher price in the other place, and make an instant guaranteed profit. (source: Crypto Bots Feast on Your Typos)

This buying and selling for instant profit across two exchanges is referred to as “cross-exchange arbitrage”. While it may sound scary, it’s actually a perfectly healthy aspect of any financial market (discussed in greater detail by the hummingbot team). Quick acting arbitrage helps to reduce market fragmentation and makes price discovery easier: two features that commonly plague many cryptocurrencies.

These price opportunities are the equivalent of seeing free money on the ground. But rather than you being the only person to see it, hundreds of other people spot this at the exact same time — and a hunger-games-esque digital brawl ensues. This price information is easily visible to tons of traders — and there are plenty of services that perform these price checks instantly using exchange API’s. So even if only a few people are running a fancy arbitrage bot, when a price discrepancy occurs between two different exchanges: lots of people notice.

In a traditional stock market, whoever places their counteroffer to the exchange first gets the order. This seems like the logical answer, and is actually performed daily on both centralized and decentralized exchanges. However, as discussed above, these on-chain matching DEX’s have a different solution with a plethora of downsides: whoever pays the most in gas.

DEX Design Flaws

The crypto bots’ use can be so lucrative, it would pay for a miner to execute a so-called 51-percent attack, in which computers take over the network of a particular coin, Juels said in a later phone interview.

“We explain that DEX design flaws threaten underlying blockchain security,” the eight authors said in the paper. (source: Flash Boys Trading Bots Are Running Wild on Crypto Exchanges)

One of the things that the article briefly touches on is the “design flaws” of these DEX systems. Specifically, these are flaws associated with on-chain matching DEX systems.

While they don’t exactly spell them out, there’s a bunch of issues with these fully on-chain systems. To name a few:

  • Trader vs Trader front running creates a horrible user experience — results is frustrating failed transactions, which still cost the user gas but yield them nothing
  • Gas auctions become a thing — trading benefits go from the traders to the miners
  • 51% attack concerns
  • Cancelling orders costs money
  • Makes providing liquidity harder and more risky

Many of these issues stem from the article’s main point: these orders don’t have proper time-price priority because they match on-chain. It’s pretty critical to note that not all DEX’s match on-chain.

Hybrid DEX’s

“This should incentivize the community to consider new exchange designs,” Juels said. (source: Flash Boys Trading Bots Are Running Wild on Crypto Exchanges)

While I completely agree that new exchange designs are exciting and have great potential, the issues that the article brings up are actually already solved. Hybrid DEX’s suffer from none of these issues. They do this by placing the orderbook and order matching off-chain, while still making the actual trades on-chain.

Exchanges have three core components: Orderbook, Matching, and Storage.

Decentralized exchanges such as IDEX, Paradex, DDEX, etc. all use this type of hybrid structure. This solves a bunch of the problems from the article:

  • Traders front-running one another by paying more gas is no longer a thing — it’s back to first come first serve
  • The exchange determines the gas price for the settlement. No gas price auction.
  • 51% attacks become less of a concern

Arbitrage is still occurring here on these exchanges, and certainly some by arbitrage bots — but they don’t suffer from the front running challenges highlighted in the article. It’s once again the first to place the order is the first to take it.

Building Better DEX Systems

As the bloomberg piece asked the community to consider new exchange designs, it seems relevant to discuss why these different forms of DEX’s exist.

There are definitely pros and cons to each method of exchange. While the article highlights several cons with on-chain matching DEX’s, there are some advantages. These orders can be used for certain DeFi applications that cannot use off-chain orders, and they arguably offer a higher level of trustlessness. Additionally, they have historically been much easier to build than hybrid DEX’s.

As Juels called for the community to consider new exchange designs, Hydro is open sourcing modern DEX design. We believe that the hybrid style DEX system elegantly solves the front-running issue, and provides a much better user experience for a variety of different use cases.

Have any questions or want more clarifications on any of this? Let us know!

--

--