Glossary

Sandwich Attack

A sandwich attack is a form of front-running in which a bot places one trade immediately before a victim's pending swap and another immediately after it, profiting from the price movement the victim's own trade causes. The victim's transaction is 'sandwiched' between the attacker's buy and sell, and the cost appears to the victim as unusually bad execution — they receive fewer tokens than the price they saw when submitting.

A concrete example: a user submits a large swap of USDC for ETH on Uniswap with a generous slippage tolerance. A bot watching the public mempool spots it and pays for priority ordering: first the bot buys ETH, pushing the pool price up; then the victim's swap executes at that worse price; then the bot sells its ETH back into the pool at the elevated level. The bot pockets the difference, and the victim's loss is bounded only by the slippage tolerance they allowed.

Sandwich attacks are among the most common forms of MEV extraction on public chains, executed automatically by competing bots. A common misconception is that they exploit a bug — they exploit the ordinary transparency of the mempool and the miner or validator's freedom to order transactions. Practical defenses exist: set tight slippage tolerances, break large trades into smaller ones, and submit transactions through private relays or MEV-protected RPC endpoints that keep them out of the public mempool until execution.