What is a sandwich attack in crypto?
A sandwich attack is when a bot trades just before and just after your swap on a DEX, pushing up your price and keeping the difference as profit.
A sandwich attack is a way for a trading bot to profit from your swap on a decentralized exchange (DEX). The sandwich bot places one trade just before yours and another just after it, so your order is squeezed in the middle like the filling in a sandwich. You end up paying more, or receiving less, than you would have otherwise.
How does a sandwich attack work in crypto?
Most DEXs price tokens with liquidity pools, so a large purchase pushes the price up. A sandwich bot watches pending transactions, picks out a swap big enough to move the price, and then:
- Front-runs it by buying the same token first, which raises the price.
- Lets your swap execute at that higher price.
- Back-runs it by selling straight after, capturing the price gap.
Your swap still succeeds as long as the final price stays inside your slippage tolerance. Uniswap Labs notes that bots target wide tolerances because they can nudge the price right up to your limit. Sandwiching is one type of MEV, or maximal extractable value.
How do sandwich attacks happen on Ethereum?
On Ethereum, transactions usually wait in a public mempool before going into a block, which gives bots time to see them. Ethereum.org describes sandwich trading as a common MEV strategy that gives users higher slippage and worse execution, calling the result a clearly worse experience for users. It is riskier for the attacker than simple arbitrage, because the steps are not guaranteed to land together.
Ethereum's block-building system now lets some apps send trades privately to block builders, which ethereum.org says helps traders avoid front-running and sandwiching.
Do sandwich attacks happen on Solana?
Yes. Solana has no built-in mempool, but Jito Labs ran one through its validator software until it shut the feature down in March 2024 over sandwiching concerns. Reports then emerged of private mempools used for the same purpose. In June 2024 the Solana Foundation removed more than 30 validator operators suspected of involvement from its delegation program. Blockworks later reported that Anza economist Max Resnick said sandwiching had dropped sharply, which he credited mainly to software changes that limit how many validators see each transaction.
How do you avoid sandwich attacks?
You cannot remove the risk entirely, but these steps reduce it:
- Keep slippage tight. Uniswap Labs says a lower tolerance makes attacks less profitable, though too tight a setting can cause failed swaps.
- Use private routing. Services such as Flashbots Protect send Ethereum transactions to a private mempool where sandwich bots cannot see them, and some wallets offer similar swap protection.
- Consider intent-based or limit orders. UniswapX sends your order to a private network of fillers who compete on price, and limit orders fix your price in advance. CoW Swap is another intent-based design.
- Trade in deep pools. Larger pools move less per trade, leaving less room for profit.
This guide explains how things work. It is not financial, legal or tax advice. Last updated .