Sandwich Attack
Placing one trade immediately before and another immediately after someone else's swap, so their trade moves the price in your favor.
On an automated market maker, price is a function of the pool's balances, so a trade of known size has a predictable effect. An attacker who sees a pending swap buys first, pushing the price up, lets the victim's swap execute at the worse price, then sells into the pool immediately afterward. The profit comes directly out of the difference between the price the victim expected and the worst price they were willing to accept, which is set by their slippage tolerance. Defenses are setting slippage as tightly as execution allows, routing through private relays that keep the transaction out of the public mempool, splitting large orders, and using venues that batch orders and clear them at a uniform price.
На практике
Raising slippage tolerance to make a stubborn swap succeed enlarges exactly the window a sandwich can capture, which is why failed transactions are sometimes the cheaper outcome.
Распространённое заблуждение
That slippage tolerance only decides whether a trade succeeds or fails, when it also sets the maximum amount a sandwich can extract from that trade.