Back to Glossary

Sandwich Attack

A trading exploit where attackers manipulate trade order timing to profit at the expense of others.

A Sandwich Attack is a malicious trading strategy where an attacker places one transaction before and one after a user’s trade to exploit price movement and extract profit. This form of MEV (Maximal Extractable Value) is most common on decentralized exchanges.

How a Sandwich Attack Works

A user submits a large swap on a DEX

The attacker sees it in the mempool

Attacker front-runs with a buy order, pushing the price up

User’s trade executes at a worse price due to slippage

Attacker back-runs by selling the tokens at the inflated price

The attacker profits; the user suffers increased slippage

Why Sandwich Attacks Happen

Public mempools reveal pending transactions

AMM pricing formulas are predictable

Attackers use bots with higher gas fees to jump ahead

How to Prevent Sandwich Attacks

Use private transaction relays

Set strict slippage limits

Trade on MEV-protected DEXs

Use limit orders instead of swaps during volatility

Summary

A sandwich attack is an MEV exploit where an attacker places trades around a user’s order to manipulate prices and profit at the user’s expense.

See also