In simple terms — A bot sees a pending swap, buys first to move the price, lets the user buy at a worse price, and sells immediately afterward. The victim's transaction stays in the middle, like the filling in a sandwich.
A sandwich attack is a form of value extraction based on transaction order. It is associated with MEV and mainly affects trades that are visible before confirmation on automated market makers. The attacker does not need to steal the user's keys; they exploit the conditions the user authorized.
The three transactions in a sandwich
First, the attacker identifies a sufficiently large swap with enough slippage tolerance. They place a buy before the victim, pushing up the price in the pool. The victim's swap executes at the less favorable price, provided it remains within the minimum amount received. Finally, the attacker sells after the victim and tries to keep the difference after fees, gas, and competition with other bots.
Not every movement before and after a swap proves a sandwich. Analysis must check the order within the same block, assets, addresses, reserve changes, and net profit. A deep pool or a small swap generally reduces the available price impact; a shallow pool and very wide tolerance increase it.
Reducing exposure
Before confirming, compare the expected output with the minimum amount to be received. Tighter tolerance limits the acceptable price, but it can make the swap fail in volatile markets and is not absolute protection. Splitting an order changes costs and visibility; it is not automatically better. Deeper pools tend to reduce impact, while complex routes add more points to inspect.
Some wallets and protocols offer private submission, auctions, or specific MEV-protection mechanisms. You need to understand who receives the order and what guarantees they provide. Moving a transaction out of the public mempool reduces one channel of observation, but may introduce trust in a relay or solver. Practical defense starts with a current quote, deliberate slippage, and verification of the on-chain result.
Sources
- Ethereum.org — MEV — Describes sandwich trading step by step and explains the role of transaction order.
- Flash Boys 2.0 — Examines front-running and competition for priority on decentralized exchanges.