sandwich attack
A sandwich attack is a form of maximal extractable value in which a searcher wraps a victim's pending swap between two of their own trades to skim profit from the price movement the victim causes. Because most transactions sit visibly in the public mempool before they are mined, an attacker can see a large buy order coming. They front-run it by buying the same asset first, which pushes the price up; the victim's swap then executes at that inflated price; finally the attacker back-runs by selling the asset they just bought, now at the higher price the victim left behind. The victim is the meat in the sandwich, and the spread is the attacker's profit.
The attack works precisely against trades with loose slippage tolerance. The victim authorized a maximum acceptable price by setting that tolerance, and a rational attacker pushes the price exactly to that limit — no further, or the victim's swap would revert. So the victim still fills, but at the worst price they signed off on, and the difference between the fair price and that worst price flows to the searcher. Larger trades in thinner pools are juicier targets because they move the price more and leave a wider band to exploit.
Defenses attack the attack's prerequisites. Setting a tight slippage tolerance shrinks the band, though it risks ordinary reverts. Splitting a big order into pieces reduces each piece's exploitable impact. The most robust defense is to keep the transaction out of the public mempool entirely by submitting through a private order-flow channel or an MEV-protected relay (such as Flashbots Protect), so no searcher ever sees the pending swap to sandwich it. At the protocol level, batch auctions, encrypted mempools, and fair-ordering schemes aim to remove the informational and ordering advantage that makes sandwiching possible.
A sandwich is profitable for the attacker only up to the victim's slippage tolerance — which means an overly generous tolerance is, in effect, the user inviting and signing off on exactly how much they can be sandwiched for. Tolerance is the single most important knob a trader controls.