Front-Running

Security Updated Apr 2026

What is Front-Running?

Front-running is the act of exploiting advance knowledge of a pending transaction to profit before that transaction executes. In crypto, a bot monitors the public mempool, sees your incoming trade, and submits its own trade first with a higher gas price to get executed before yours.

The concept comes from traditional finance, where brokers who knew a large institutional order was coming would trade ahead of it. In DeFi, there are no brokers — anyone can front-run anyone through the public mempool.

How Front-Running Works

The Mempool is Public

When you submit a transaction to Ethereum (or any EVM chain), it enters the mempool — a public waiting room for pending transactions. Anyone can see:

  • What operation you’re performing (swap, mint, transfer)
  • Which tokens are involved
  • How much you’re trading
  • Your gas price

Bots scan the mempool 24/7 looking for profitable opportunities.

The Race

1. You submit: "Buy TOKEN A with 5 ETH" (gas: 20 gwei)
2. Bot sees your tx in mempool
3. Bot submits: "Buy TOKEN A with 5 ETH" (gas: 50 gwei)
4. Validator includes bot's tx first (higher gas = higher priority)
5. Bot buys at lower price, your tx buys at higher price
6. Bot has cheaper tokens → can sell for instant profit

Types of Front-Running

TypeMechanismVictim Impact
DisplacementBot outbids you for the same opportunity (e.g., NFT mint spot)You miss the opportunity entirely
InsertionBot places trade before yours to profit from your price impactYou pay a worse price
SuppressionBot prevents your transaction from executing (censoring)Your tx fails or is delayed

Front-Running Beyond Trading

Front-running isn’t limited to DEX swaps:

  • NFT mints: Bots front-run to mint rare tokens before regular users
  • Liquidation races: Bots compete to liquidate undercollateralized DeFi positions first (the liquidation bonus goes to whoever is first)
  • Arbitrage: Bots front-run arbitrage opportunities between DEXs
  • Airdrop farming: Sybil operators front-run to claim more airdrop allocation

How to Protect Yourself

Use Private Mempools

Services like Flashbots Protect, MEV Blocker, and MEV-Share route your transaction privately — it never appears in the public mempool, so bots can’t see it coming.

Use RPC-Level Protection

Some wallets and dApps offer “MEV-protected RPC endpoints” that automatically route transactions through private pools. Examples: MetaMask’s “Advanced Gas” with Flashbots, CoW Swap’s solver-based execution.

Set Appropriate Slippage

Low slippage (0.5–1%) makes insertion front-running unprofitable. If the attacker can’t extract enough profit to cover gas, they won’t bother.

Avoid Predictable Behavior

  • Don’t always trade at the same time
  • Split large orders into smaller ones
  • Use TWAP (time-weighted average price) orders when available

The MEV Connection

Front-running is a subset of MEV (Maximal Extractable Value). The broader MEV ecosystem includes:

  • Arbitrage (beneficial — keeps prices consistent)
  • Liquidation (neutral — necessary for protocol health)
  • Front-running / Sandwich attacks (harmful — extracts value from users)

Ethereum’s Flashbots infrastructure was designed to make MEV extraction more transparent and less harmful, but front-running remains a persistent issue.

Frequently Asked Questions

Q: Is front-running the same as a sandwich attack? A: No. A sandwich attack is a specific type of front-running that adds a back-run (selling after the victim’s trade). Regular front-running is just buying before.

Q: Can front-running happen on centralized exchanges? A: It can, but CEXes have strict internal controls and regulatory oversight. Front-running by CEX insiders is illegal in most jurisdictions.

Q: Do L2s have front-running? A: Much less than Ethereum mainnet. Most L2s use a single sequencer that orders transactions without a public mempool, making front-running far harder.