How does a sandwich attack work, and why does it succeed?
Sandwich attacks exploit two key mechanisms: (1) mempool transparency, and (2) gas bids determining transaction order.
Attack flow: ① Victim submits a transaction — "buy ETH with 10,000 USDC on Uniswap" — to the mempool, with 1% slippage tolerance ② The attacker's bot instantly spots this transaction and assesses sufficient profit margin ③ Attacker submits a "buy ETH" transaction with higher gas than the victim, ensuring it's prioritized — this is the frontrun ④ The attacker's buy pushes ETH's price higher in the pool ⑤ The victim's buy executes, but ETH is now more expensive — the victim gets less ETH for their USDC (within tolerance) ⑥ Attacker immediately submits a sell ETH transaction (backrun) at the price elevated by the victim's trade, locking in profit
Throughout this, the attacker's profit = the victim's overpayment, minus gas fees.
Which situations are most likely to be targeted by sandwich attacks?
Three factors determine whether you're an attractive target:
(1) Large trade size: small trades ($50) have little extractable margin — gas fees may exceed profit, making attacks unattractive. Large trades ($1,000+) offer enough margin to cover gas costs and remain the primary targets.
(2) Wide slippage tolerance: if you set 3% tolerance, the attacker knows up to 3% can be extracted. Setting strict 0.1% tolerance dramatically reduces attack risk (too little room for the attacker).
(3) Shallow liquidity pairs: pools with low liquidity already have large natural slippage; a small push makes it easier for the victim's trade to still execute within tolerance, while also generating higher attacker profit.
Popular stablecoin pairs (USDC/USDT) are virtually immune to sandwich attacks — prices barely move, leaving almost no attack window.
What measures can users take to protect themselves from sandwich attacks?
(1) Strict slippage settings: setting tolerance to 0.1–0.5% greatly reduces the attacker's operating window. The tradeoff: transactions may fail during high-volatility periods.
(2) Private mempool services: Flashbots Protect, MEV Blocker, and similar services keep your transaction out of the public mempool — attackers simply can't see it. One of the most effective defenses currently available.
(3) Split large orders: break one large trade into multiple smaller ones executed in batches, reducing each transaction's size and diminishing attack profit margins.
(4) Choose deep-liquidity pools: deep pools have less price impact per transaction, leaving attackers less profit to extract.
(5) Use MEV-resistant DEXs: some DEXs designed to reduce MEV (like CoW Protocol's batch auction mechanism) prevent user transactions from being front-run.
How does a sandwich attack differ from a general front-running attack?
Front-running is the broader concept: an attacker inserts their own transaction before a target transaction to profit.
A sandwich attack is a specific front-running pattern defined by its key characteristic: "both a pre-trade and a post-trade" — the attacker inserts a trade on both sides, sandwiching the victim.
Other front-running forms: (1) Pure front-run: only inserts before the victim's trade, completing the action first and leaving the victim without the opportunity (e.g., sniping NFT mints, racing for arbitrage) (2) Back-run: only inserts after the victim's trade, profiting from the price movement caused by the victim (e.g., post-liquidation arbitrage)
Sandwich attack = front-run + back-run combined — the most complex pattern, but also the most reliable for continuously extracting from ordinary users.
According to EigenPhi on-chain analysis, Ethereum averaged over 4,400 sandwich attacks per day between October 2022 and September 2024. The most thoroughly documented operator is the bot jaredfromsubway.eth: since launching in March 2023, it accumulated over $22 million in profit through sandwich attacks, verifiable on EigenPhi's public Dune Dashboard. A specific verifiable case: on March 12, 2025, a user submitted a $220,764 USDC swap on Uniswap v3's USDC-USDT pool and received only $5,271 USDT after a sandwich attack — a loss of over $215,000. (Transaction hash 0xee9fcd2b9996e96b642cb4cda47fc140f98fdaf07ee02657743d4bfcc4670106 is verifiable on Etherscan.)
Private mempool solves the sandwich attack problem but introduces new trust assumptions — you must trust services like Flashbots not to exploit your transaction information themselves. Strict slippage tolerance defends against attacks but raises transaction failure rates. There is no perfect solution currently; MEV is an inherent property of public blockchain architecture, and sandwich attacks are merely its most visible negative manifestation.