Were they hacks? (oracle hacks? DEX hacks?)

Were they attacks? (flash loan attacks? smart contract attacks?)

Or were they arbitrage? (arbitraging… bad DeFi design?)

The 2 incidents involving bZx over Feb 14-18, 2020 caused a bit of existential navel gazing on the new design space for market makers and traders. While the attacks feel novel, if we dissect the different components of front-running, we see that these attacks are just another flavor of front-running.

If in fiat securities/derivatives trading, everything is securities fraud, 
... then in DeFi, everything is front-running.

What is front-running?

Front-running is comprised of 3 parts:

  • A set-up transaction
  • A market manipulation transaction
  • A profit-taking transaction

Below, I’ll show how we can apply this framework to understand market manipulation in fiat markets, break down the bZx exploits, and analyze what makes front-running on the blockchain a new type of attack not seen before in fiat markets. I’ll also explain why the “priceless” design pattern for DeFi contracts as a solution to these problems.

Traditional market manipulation

Let’s say you wanted to do some insider trading for a security, like TSLA. One way you might (naively) do this is as follows:

  • A set-up transaction
    • Buy some short-dated TSLA puts.
  • A market manipulation transaction
    • Find a way to borrow some TSLA to dump in spot markets. Even better if at the end of this trade, you can abscond and never have to pay back the TSLA.
  • A profit-taking transaction
    • Sell/exercise your short-dated TSLA puts.

This is a very naive way of conducting insider trading, and it is a form of front-running (your TSLA puts front-ran the big TSLA dump). People who watch for insider trading will often look for suspiciously large options trades to find set-up transactions. I am not a lawyer, but I would guess that most people are caught because it is very difficult to set up the trap without exposing your identity and leaving fingerprints between trades. We’ll see how this latter weakness turns into a strength in DeFi in a later section.

This framework applies to more traditional front-running as well:

  • A set-up transaction
    • Place some limit orders to sell TSLA (once you have some TSLA, that is; buy it first if you need).
  • A market manipulation transaction
    • There are a few ways to do this:
      • Convince someone to buy lots of TSLA. Maybe you are an investment banker or private wealth advisor and know someone with enough cash to move this market.
      • Buy someone’s TSLA order flow. Maybe you know a broker who sees lots of retail trades in TSLA and he’s willing to route those trades through you to be placed on exchange.
  • A profit-taking transaction
    • Once the TSLA buy orders from your market manipulation transactions lift through your own limit orders, you’ve sold your TSLA at the inflated price.

As we’ll see, in DeFi, you don’t always see these trades happening in a linear way.

Breaking down the bZx exploits

Here’s how to apply this framework to the first bZx exploit, well-covered here.

  • A set-up transaction
    • Flash borrow ETH and use it to borrow wBTC on Compound.
  • A market manipulation transaction
    • Use some borrowed ETH to open a 5x long wBTC/ETH position on bZx.
    • bZx will kick off a large wBTC/ETH buy on KyberSwap (routed to Uniswap) to achieve leverage, causing wBTC/ETH price to spike in an illiquid market.
  • A profit-taking transaction
    • Sell wBTC for ETH at an inflated price on Uniswap.
      • If the market manipulation trade has succeeded, you’ll collect ETH to pay off the loan and collect some excess as profit.
bZx: Attack 1

Here’s how to apply this framework to the second bZx exploit, well-covered here.

  • A set-up transaction
    • Flash borrow ETH and sell some for sUSD.
  • A market manipulation transaction
    • Use some borrowed ETH to buy sUSD on KyberSwap (routed to Uniswap), causing sUSD/ETH price to spike in an illiquid market.
  • A profit-taking transaction
    • Use sUSD to borrow ETH on bZx at an inflated price.
      • If the market manipulation trade has succeeded, you’ll collect ETH to pay off the loan and collect some excess as profit.
bZx: Attack 2

What makes DeFi different?

What did I mean by, “everything is front-running”? If you apply the above framework to analyze other DeFi hacks/exploits/manipulations, we see:

  1. Set-up trades and market manipulation trades can’t be stopped. So long as people can borrow assets on-chain and trade on DEX’s, steps 1 and 2 will always happen.
  2. Profit taking trades are the ones that miners should be able to identify. Seeing that the initiator of that transaction would make a given profit, a miner (executor) of that transaction can charge “miner extractable value” from the initiator. Others have called this “dry front-running”.
  3. While these statements would always be true if the 3 transactions were executed sequentially, they are especially true if front-runners try to execute all 3 in the same transaction. This is when miners should be especially be able to identify profit-taking transactions.

The other big factor that makes DeFi different is flash loans. In this framework, though, they only impact one of the 3 trades: they enable market manipulation trades to be more effective than they usually would. There are a few ways to try to mitigate their impact:

  • Exchanges can fix this by building deep, liquid markets. This is hard and takes time (and a flippening).
  • DeFi projects (e.g. lending/borrowing protocols) can try to use more manipulation-resistant price feeds, such as TWAPs, medianizers, etc. This results in a cat and mouse game until the cost of executing the market manipulation transaction is greater than the results of the profit-taking transaction.
  • DeFi projects can choose to not use on-chain price feeds and instead, choose to operate in a “priceless” or “optimistic” manner.

Of these options, the last one seems most appealing to me. It does require redesigning the incentive structures in DeFi protocols, but I look forward to being a part of that conversation. Take a look here for an example of how you can build a “priceless” version of BitMEX, and keep an eye out for future blog posts that take a stab at redesigning some “priceless” versions of prominent DeFi projects.