Backrunning in DeFI

Marius Van Der Wijden
3 min readAug 14, 2020

--

What is backrunning and why should I care?

We recently merged a change into go-ethereum that prevents backrunning spam. This article shall explain why this is a problem that was prevalent on ethereum for the last weeks/months.

Now frontrunning is very well understood concept. If you know someone is going to buy a certain commodity you can buy it right before them and sell it to them for a slightly higher price. This is essentially what high-frequency trading in traditional stocks is all about. In blockchain and Defi frontrunning is prevalent and we cannot do much about it. However since miners order the transactions by gasprice, the highest bidder can always frontrun a transaction. Lower priced transactions are either discarded or executed (often for a loss of the sender) which means there is a limit on how many frontrunning transactions are on the network.

Now backrunning is a different story. In backrunning you try to execute the transaction right after someone bought some coins. But why? It all comes down to the use of bonding curves in Defi. If Bob buys some token on a decentralized exchange A, he move the bonding curve there. Which means the bought currency is more valuable now, while the currency in which Bob sold is less valuable.

Now someone -Alice- who is backrunning this transaction can use this imbalance to do arbitrage with other DEX’s. So Alice buys the sold token from Bob for very little and sells them on another exchange for a premium. This premium (minus transaction fee’s) is her profit.

Now whats the problem with that? In general nothing, Alice even provides a valuable service to the network by keeping prices of tokens stable between exchanges. The only problem that arises is that if a lot of people trade with this strategy the network gets congested by a lot of transactions that try to do this arbitrage. With frontrunning, the users have to spend higher and higher transaction fees for a transaction in order to be executed before the target transaction (and their competitors), with backrunning it is a bit different. The user have an incentive to spam the network with many transactions that have slightly more transaction fee’s attached than the target transaction which congests the network with useless transactions.

Well okay so it is about transaction spam? Yes!
Did this already happen on ethereum? Yes, Dune Analytics estimates in their analysis here that around 500 billion gas was used by backrunning bots. This is ~45.000 full blocks.

Rampant backrunning can be combated by the miners mining transactions with the same transaction costs by arrival date. This discourages users from spamming, as only the transaction that first arrived at the miner will be mined after the target transaction, so it is useless to send subsequent transactions to increase their chance of backrunning.

Now miners should update their nodes to geth-v1.9.19 or higher to enable this fix.

If you want to get in touch, just message me at @vdWijden on twitter or Linkedin.

Ethereum Vectors by Vecteezy

--

--

Marius Van Der Wijden

Ethereum Developer, State Channel Researcher, Student at TU Darmstadt