Skip to content
GetProfitable
Search
Dictionary

Sandwich attack

A bot buying just before your swap and selling just after it, pushing your fill to the worst price your slippage setting allows and pocketing the difference.

The bot watches the mempool, sees your pending buy, and submits its own buy with a higher priority-fee so it lands first. Your trade then executes at the elevated price, and the bot's sell lands immediately after, capturing the move you created.

Your slippage-tolerance is the bot's budget. Setting 15% on a thin pool tells it that anything up to 15% of your order is available to take, and it will take close to all of it. Small swaps are often ignored because gas costs exceed the prize; large swaps on shallow pools are the profitable targets.

Defences that work: tight tolerance, splitting large orders over time, routing through a private-mempool so the trade never sits in public view, and trading pairs deep enough that the attack is not worth the gas. On chains with a single sequencer and no public queue, the attack surface differs but does not vanish.

Related: mev, slippage-tolerance, private-mempool, front-running-onchain

See it drawn

Original diagrams for the ideas on this page. Illustrative, not real market data.

Slippage on a market orderA buy order clears four price levels, so the average price paid is worse than the price first quoted.Buy 1,000 shares at marketpricesell orders resting (bar length = size)20.04300 shares20.03200 shares20.01200 shares20.00300 sharesnothing resting at 20.02order sweeps up the bookaverage fill 20.02SLIPPAGE0.02 a share$20.00 in totalintended 20.00Each level fills at its own price; the average is what you really paid.
Slippage on a market order. You click at 20.00, but only 300 shares are resting there, so the rest of the order fills at 20.01, 20.03 and 20.04. The average price paid is 20.02, and that two-cent gap is slippage.

Educational only, not advice. Spotted an error? Post in Site Feedback.