Try โ€‚โ€‰HackMD

Flashbots for MEV protection

This document is outdated - see Flashbots Protect documentation for up to date information.

This document aims to provide a simple guide which highlights how flashbots can be used by ethereum dapps and wallets to provide frontrunning protection for their users.

context

The Flashbots Auction is a private communication between ethereum users and miners. It provides a way for users to get an array of transactions included on chain atomically with conditional payments. Approximately 85% of ethereum miners are currently connected. You can find out more in the Flashbots documentation.

use cases

  1. Frontrunning protection
  2. Free transaction cancellation
  3. No reverts on chain
  4. Atomic multi-transaction
  5. Backrunning kickback

built on Flashbots

tornado cash mistX backrun me archerswap 1inch zeneth
Frontrunning protection โŒ โœ… โœ… โœ… โœ… โŒ
Free transaction cancellation โŒ โœ… โŒ โŒ โŒ โŒ
No reverts on chain โœ… โœ… โœ… โœ… โœ… โœ…
Atomic multi-transaction โœ… โœ… โœ… โŒ โŒ โœ…
Backrunning kickback โŒ โŒ โœ… โŒ โŒ โŒ

tornado.cash

Tornado Cash uses Flashbots to improve upon the use of meta-transactions for user withdrawl UX. Currently, users need to chose one of the available relayers to submit anonymous withdraw transactions. These relayers are expensive because they must get transactions included quickly to avoid bottlenecks, but users are not always time sensitive and may prefer to have transactions included when gas prices are at their lowest.

mistx.io

mistX is a DEX aggregator which uses the full scope of Flashbots capabilities to offer users a novel UX. Users looking to swap on mistX effectively create limit orders which benefit from free cancellations, frontrunning protection, and no reverts on chain. Furthermore, mistX provides a "gasless" experience to users by paying for inclusion with the tokens being swapped. mistX makes use of bundles to include "approve" and "transfer" transactions atomically.

backrunme.com

Backrun Me is a DEX aggregator which uses Flashbots for frontrunning protection and inclusion of transactions atomically. The aggregator inserts an atomic transaction after the swap which brings the market prices back into equilibrium and provides a gas fee discount to the users.

archerswap.com & 1inch.io

ArcherSwap and 1inch are DEX aggregators which use Flashbots for frontrunning protection. By routing transactions through Flashbots, they are hidden until included on chain which prevents bot operators from sandwiching the trades.

zeneth.app

Zeneth is a dapp which provides the ability to perform token transfers with a "gasless" experience by paying transaction fees with other tokens. Every token transfer includes a uniswap transaction to atomically convert tokens to eth and pay miners for inclusion.

tooling providers

The following projects have built tooling which aims to simplify the work of integrating Flashbots capabilities into your apps. Please refer to their website and documentation for more information on their offering.

known challenges

uncle bandits

Transactions using Flashbots for frontrunning protection in theory never reach the public mempool and therefore should not be visible to bot operators until successfully mined in the chain. However, if the block in which the transaction is included is uncled (honestly or maliciously), the transactions are revealed and can be targeted. This type of exploit is dubbed an "uncle bandit". On average, 1 in 20 blocks are uncled.

In order to protect against uncle bandits, users looking for frontrunning protection should include a check on the parent hash in their transaction:

require(blockhash(block.number - 1) == expectedParentHash, "block was uncled");

eth_signTransaction support by wallets

To avoid broadcasting transactions to the public, wallets must allow users to sign transactions without broadcasting them to the txpool. Unfortunately, many wallets refuse to provide the standard eth_signTransaction rpc method which allows developers to obtain these signed transactions. Sometimes, the wallets allow the use of the eth_sign rpc method, but it is generally dangerous and scary for users.

Metamask is currently considering if they should implement a solution which allows apps to protect their users from frontrunning. You can show your support on the github issue.

multi-block submission

The Flashbots relay requires users to specify the block in which they wish their transactions to be included. The means users need to re-submit transactions every block if they do not successfully get included in the first block.

bundle signing and relay reputation

The Flashbots relay requires bundles submitted to the eth_sendBundle endpoint to be signed with a key which is used for identifying and building a reputation for the signer. Signers with high reputation obtain more reliable access to the relay in periods of heavy load. This makes it is difficult to do a purely serverless integration as the signing key must remain private.

EIP-1559 basefee payment

"Gasless" transactions become more difficult after the london fork as transactions with 0 gas price are no longer considered valid by consensus. There exists alternatives which involve lending eth to the user atomically as a part of the transaction execution, but no one has used this approach yet. Alternatively, it may be possible to introduce a change to the EIP-1559 spec which allows for the evaluation of basefee burn post evm execution, but this change would require going through the EIP process.