Sandwich attack
A sandwich attack is a form of market manipulation in crypto trading on a decentralized exchange. An attacker places two of their own transactions around yours, causing you to get a worse price.
What is a sandwich attack?
A decentralized exchange, or DEX, is a trading platform without a central intermediary. Unprocessed transactions may be visible in its mempool: a digital queue on a blockchain.
A bot can spot a large buy or sell order in that queue. The bot trades in the same direction first, sometimes paying a higher gas fee to get priority. Then the victim’s transaction is processed. After that, the bot trades in the opposite direction.
This changes the price just before your transaction goes through. You experience extra slippage: the difference between the price you expected and the price you actually get.
An example of a sandwich attack
You want to buy a large amount of a token on a DEX. A bot sees your order before it goes through and buys that token first. This pushes the price up.
Your buy order is then processed at the higher price. The bot sells its tokens afterward. The bot tries to profit from the price difference, while you pay more than expected.
Why are sandwich attacks important in crypto?
Sandwich attacks mainly happen in DeFi and on DEXs that set prices using liquidity pools. They can increase your effective trading costs, especially with large orders or pools with little liquidity.
In crypto news, sandwich attacks may come up in stories about MEV bots, DeFi, or issues with trade execution prices. MEV is about extracting extra value from the order in which transactions are processed. A sandwich attack is one type of MEV.
This does not mean that every DEX transaction is attacked. You can reduce the risk by setting a lower slippage tolerance, placing smaller orders, using pools with more liquidity, or using a limit order if one is available. However, a very low slippage tolerance may prevent your transaction from going through.