Skip to main content
Important: We do not provide financial advice or custody funds. All transactions occur on third-party platforms.

Sandwich Attack

In simple terms

A sandwich attack surrounds your trade with two others. The attacker buys just before you, your purchase pushes the price up, and they sell just after — the extra you paid is their profit.

Definition

Placing one trade immediately before and another immediately after a victim's trade to profit from the price it moves.

In depth

A sandwich exploits the deterministic price impact of a constant-function market maker together with a visible mempool. The attacker front-runs with a buy that moves the price along the curve, the victim executes at the worsened price within their stated slippage tolerance, and the attacker back-runs with a sell into the elevated reserve ratio. Profitability is bounded by the victim's tolerance and by the pool's depth, which is why the defence is a tight tolerance, a smaller order relative to liquidity, or private submission that keeps the transaction out of the public mempool.

How does Sandwich Attack work?

A bot detects a large pending swap in the mempool and estimates how far it will move the pool. It submits a buy with a higher priority fee so it is ordered first, lets the victim's trade execute at the worse price, and submits a sell ordered immediately after. All three land in the same block, and the profit is the price impact the victim absorbed minus fees.

An example

A user swaps an illustrative $20,000 in a shallow pool with a 5 percent slippage tolerance. A sandwich can take close to that 5 percent — roughly $1,000 — while the transaction still succeeds and shows nothing obviously wrong to the user.

Figures are illustrative only.

What beginners get wrong

  • Raising slippage tolerance until the trade succeeds, which directly increases the amount extractable.
  • Trading a large size in a thin pool, where price impact is what makes the attack worth running.
  • Assuming a successful transaction means a fair price. Sandwiched trades succeed by design.

Related terms

Part of

How do crypto scams work, and how do you avoid them? — the subject page for security and scams, with all 17 of its definitions in one place.

Educational only — not financial advice.