Skip to main content
Menu

⚠️ Risk Warning: Trading forex, CFDs, and cryptocurrencies involves substantial risk of loss and may not be suitable for all investors. This platform provides educational content only and does not constitute financial advice.

⚡ Level 4 · Advanced Institutional & Advanced Crypto Markets Emerging Market Structure

Sandwich Attacks

Advanced guide to sandwich attacks, front-run/victim/back-run ordering, slippage, AMM price impact, evidence and mitigation.

Progress 0%

Reading progress — saved on this device

INSTITUTIONAL & ADVANCED CRYPTO MARKETS · EMERGING MARKET STRUCTURE

A sandwich attack places an attacker transaction before a victim’s market-moving swap and another after it, extracting value from the victim’s predictable price impact and permitted slippage.

Risk-first note. A poor DEX fill is not automatically a sandwich. Detection requires transaction-level evidence showing strategic ordering around the victim and pool-state changes consistent with extraction.

Learning objectives

  • Describe the front-run, victim and back-run structure.
  • Understand how trade size, pool depth and slippage tolerance affect profitability.
  • Evaluate evidence and mitigation without overclaiming.

How a sandwich works

In an AMM, a sufficiently large swap moves the pool’s marginal price. When a pending user transaction is visible before inclusion, an attacker can estimate the price movement and the user’s minimum-received or maximum-input constraint.

For a large buy, the attacker may buy first, pushing the pool price higher. The victim then executes at a worse price but still within its slippage tolerance. The attacker sells after the victim’s buy has pushed the pool further, attempting to capture the difference net of gas, fees and competition.

The attack depends on economics. Deep liquidity reduces price impact for a given order size. Tight slippage reduces how much adverse state change the user will accept. High gas and competition between searchers also reduce attacker profit. Thin pools and oversized swaps create more room.

Slippage tolerance should therefore be treated as a risk limit, not a convenience setting. Setting it far wider than expected market volatility and route impact can transfer unnecessary execution discretion to adversarial actors. Setting it too tight, however, can cause repeated reverts and wasted gas.

Detection should reconstruct the pool state and transaction order. The analyst looks for an attacker buy before the victim, a victim swap in the same direction, and an attacker unwind after it, often within the same block or bundle. Similar addresses, token amounts, profits and gas bidding can support attribution.

Ordinary arbitrage should not be mislabeled. A trader can independently buy before a user or arbitrage the post-trade pool price without deliberately manipulating the user’s execution. The sandwich label requires evidence that the surrounding trades were strategically constructed around the victim.

Mitigation includes routing to deeper pools, splitting size when economically sensible, explicit limit-style constraints, protected/private submission, batch auctions and intent-based execution. Each method has trade-offs. Private submission changes who sees the transaction; batch systems change price discovery; splitting can increase fees and signalling.

Worked example

A user submits a swap expected to move an AMM from £100.00 to £100.80 and allows up to 2% slippage. A searcher sees the public transaction and buys first, moving the price to £100.40. The victim then executes at a worse effective price but still inside the 2% tolerance. The searcher sells after the victim has pushed the pool further.

If the user instead routes through a pool with four times the active liquidity, the same notional generally causes materially less price impact. Lower impact reduces the amount of value available to a sandwich, although gas, route fees and other liquidity sources still need comparison.

Practical mitigation workflow

  1. Estimate expected price impact before signing the swap.
  2. Set slippage only wide enough for legitimate execution uncertainty.
  3. Compare deeper routes, aggregators and protected execution.
  4. For material trades, inspect surrounding transactions after execution.
  5. Track realised execution against the pre-trade quote and route alternatives.

Common mistakes

  • Using extremely loose slippage simply to avoid reverts.
  • Calling every bad DEX fill a sandwich.
  • Assuming private routing has no trust or inclusion trade-offs.
  • Ignoring pool depth when executing large size.
  • Looking only at token price rather than reconstructing transaction order and pool state.

Knowledge checkpoint

  1. What are the three transactions in a classic sandwich?
  2. Why does pool depth affect attacker economics?
  3. How does slippage tolerance create room for extraction?
  4. What evidence distinguishes a sandwich from ordinary arbitrage?

FAQs

❓ Why does slippage tolerance matter?

It defines how much adverse price movement the user is willing to accept before the swap reverts.

❓ Can sandwiches occur in deep pools?

Yes, but deeper liquidity generally reduces price impact and available extraction for the same trade size.

❓ How can a sandwich be detected?

Reconstruct surrounding transactions and pool-state changes rather than relying only on a bad fill or heuristic label.

❓ Do limit constraints remove all MEV?

No, but clear price constraints can reduce the room for adverse execution.

Summary

Sandwich attacks exploit visible, market-moving intent. The practical defence is not mythology about “MEV bots”, but disciplined control of size, pool depth, slippage and order-flow exposure, followed by transaction-level analysis when outcomes are suspicious.

BUILD YOUR OWN PATH

Want this in a personalised order?

Take the crypto assessment and get a custom path of 10 modules matched to what you already know. Free, no card required.

Build my path →