launchkit

YOU'RE IN 🚀

What is a Sandwich Attack? The Most Profitable MEV Strategy
Web3 Glossary - Key Terms & Concepts
What is a Sandwich Attack? The Most Profitable MEV Strategy
Sandwich attacks trap your trade between two bot transactions to extract maximum value—costing DeFi users over $900 million annually

Picture this: you're swapping $50,000 worth of ETH for some token on Uniswap. You hit confirm, your transaction enters the mempool, and in that brief moment before it gets mined, a bot sees it, calculates your exact price impact, and makes its move.

The bot buys the token right before you, pushing the price up. Your transaction executes at this inflated price. Then the bot immediately sells at the peak you created, pocketing the difference. You're transaction number 47,892 in the block—sandwiched between 47,891 and 47,893. Both placed by the same bot.

This is a sandwich attack, and it's probably the most profitable MEV strategy out there. According to EigenPhi research, these attacks extracted over $900 million from DeFi users in 2023 alone—that's $2.5 million per day.

Here's what makes this particularly nasty: most victims don't even know it happened. They see slightly higher slippage and think "that's just how DEXs work." They don't realize a bot intercepted their transaction mid-flight and engineered the slippage to extract maximum value.

What exactly is a sandwich attack?

A sandwich attack happens when a bot places one transaction immediately before yours and another immediately after, trapping your transaction in the middle to profit from your trade's price impact.

It's a three-step process. First, the bot front-runs by buying the same token you're buying, pushing the price up. Second, your transaction executes at this inflated price. Third, the bot back-runs by selling at the elevated price your purchase created.

Unlike simple front-running where a bot just jumps ahead of you, sandwich attacks control both sides of the price movement. This makes them more profitable and more damaging.

How it actually works

Let's say you want to buy $50,000 worth of LINK on Uniswap. You submit your transaction with 2% slippage tolerance at 30 gwei gas. Your transaction enters the mempool and becomes visible.

Sandwich bots are always watching. When they spot your $50,000 order, they calculate that your trade will move the price by about 1.5% given the pool's liquidity. Perfect target.

The bot submits its own $100,000 LINK buy order at 31 gwei—slightly higher than your gas price, ensuring it mines first. The bot's purchase pushes LINK from 0.005 ETH to 0.00515 ETH.

Now your transaction executes at this inflated price. Your 10 ETH buys only 1,942 LINK instead of the 2,000 you expected. Your purchase pushes the price to 0.00525 ETH.

Finally, the bot sells all the LINK it bought at 0.00523 ETH. The bot bought at 0.00515 and sold at 0.00523, netting around $1,450 after gas. You paid 3% more than you should have, losing about 58 LINK tokens worth roughly $1,400.

Twelve seconds. Almost zero risk. Completely legal.

Why these attacks work so well

Sandwich attacks exploit three fundamentals of DEX design. First, price impact—large trades move prices in liquidity pools. Second, transaction ordering is determined by gas fees, so bots can always outbid you. Third, your slippage tolerance tells the DEX "I accept prices up to X% worse." Bots use this as their profit ceiling.

If you set 2% slippage, sophisticated bots extract up to 1.9%, leaving just enough room for your transaction to succeed. Research by Flashbots shows experienced sandwich bots achieve 95%+ success rates—they've mastered maximizing extraction while staying within your tolerance.

Who's running these bots?

Remember jaredfromsubway.eth? This MEV bot became notorious in 2023. In April alone, it extracted $6.3 million across 120,000+ sandwiches. The largest single sandwich netted $500,000. The bot paid $1.2 million in gas that month and still came out massively profitable.

The operators remain anonymous. The bot continues running today.

Then there's the whale who swapped $50 million USDC for ETH on Uniswap in one transaction with 3% slippage. A sandwich bot front-ran with a $20 million purchase, let the whale's trade execute, then back-ran. Bot profit: $1.8 million. The whale could have avoided this by splitting the trade or using a private mempool.

These bots are run by independent operators, MEV firms like Wintermute and Jump Crypto, and increasingly by validators who can execute sandwiches without touching the public mempool.

How to protect yourself

Lower your slippage tolerance. Most sandwiches exploit high slippage. Use 0.5% instead of 3% to give bots less room. The downside is your transaction might fail with legitimate price movement, so test with small amounts first.

Split large trades. Instead of one $100,000 swap, do five $20,000 swaps over time. Smaller trades have less price impact. Bots might ignore trades with only $50-100 potential profit. You'll pay more in gas but save more by avoiding extraction.

Use private mempools. Services like Flashbots Protect send transactions directly to block builders, bypassing the public mempool. If bots can't see your pending transaction, they can't sandwich it. Validators could still sandwich you, but third-party bots can't.

Use MEV-resistant protocols. CoW Swap uses batch auctions where trades within a batch can't sandwich each other. Solvers compete for best price, protecting billions in trading volume. 1inch Fusion works similarly with intent-based swapping and built-in MEV protection.

Use limit orders. Many DEXs now support them through protocols like Uniswap X. Set your price, and the trade only executes at that price or better. Bots can't inflate beyond your limit.

Layer 2 solutions like Arbitrum and Optimism help too. Many L2s use centralized sequencers that order transactions first-come-first-served rather than highest bidder, reducing sandwich risk.

The ethics question

Is this theft or market efficiency? The DeFi community is split.

Some see it as predatory extraction—you didn't consent to interception. It undermines DeFi's promise of fairness. Others argue mempool visibility is public, transaction ordering is blockchain design, and bots optimize market efficiency. If you don't want sandwiching, use protective measures.

There's a middle view: sandwiches exist from design flaws in public mempools and AMMs. It's not theft, but not desirable. The solution is better infrastructure—encrypted mempools, batch auctions, fair ordering—not blaming users or bots.

In traditional finance, front-running is illegal. Should sandwich attacks face regulation? Regulators are exploring this, but blockchain transparency that enables these attacks makes "illegal information access" logically messy.

What's next

The future might look different. Projects like Shutter Network are implementing encrypted mempools where transactions stay hidden until execution, eliminating mempool-based sandwiches.

Some Layer 2s experiment with provably fair transaction ordering—by submission time, random ordering, or threshold encryption that decrypts everything simultaneously.

Account abstraction through ERC-4337 and intent-based protocols might shift trading away from public transactions. Instead of broadcasting "swap A for B," you broadcast an intent. Solvers compete to fill it, only the final settlement hits the chain. No sandwichable mempool transaction.

There's movement toward MEV redistribution too. What if sandwich profits went to liquidity providers or traders? Projects like Eden Network explore validators sharing MEV profits with users.

Bottom line

Sandwich attacks are real, profitable, and constant. But you're not powerless. Use private mempools when possible, keep slippage tight, split large trades, and consider MEV-resistant protocols. The infrastructure exists—you just need to use it.

Now you know why your trades cost more than expected. More importantly, you know how to fight back.


References:

  1. EigenPhi MEV Data - Real-time sandwich attack tracking and analytics
  2. Flashbots Research - Technical deep dives on MEV and sandwich attacks
  3. CoW Protocol - Batch auction design for MEV protection
  4. Flashbots Protect - Private transaction submission service
  5. Uniswap V3 Whitepaper - Price impact and liquidity mechanics
  6. Blocknative Mempool Explorer - Live sandwich detection tools
  7. MEV-Boost Documentation - Validator MEV infrastructure
  8. 1inch Fusion Mode - Intent-based MEV protection
  9. Sandwich Attack Research Paper - Academic taxonomy of MEV attacks
  10. Dune Analytics MEV Dashboard - Real-time MEV bot tracking and analysis

Disclaimer: This article is for educational purposes only, not financial or investment advice. Always protect yourself with appropriate tools and strategies when trading in DeFi.

Related Terms