How a Sandwich Attack Changes a Swap Fill A Sandwich Attack places one trade before a pending swap and another right after it. The first trade pushes the pool price against the trader. The vi
How a Sandwich Attack Changes a Swap Fill
A Sandwich Attack places one trade before a pending swap and another right after it. The first trade pushes the pool price against the trader.
The victim's swap then fills at that worst price, and the attacker sells back to capture the difference. The swap can still succeed, which is the key point: the trader receives tokens, but fewer than the quote promised.
Not every poor fill is a Sandwich Attack, because normal price movement, pool fees and routing also change results.
What Is a Sandwich Attack in Crypto Trading?
A Sandwich Attack is a form of MEV, short for maximal extractable value, which means profit taken by influencing how transactions are included, ordered or executed.
It targets swaps on decentralised exchanges that use automated market makers. Bots watch pending transactions, spot a-swap that will move a pool, and wrap it with their own trades.
It differs from a wallet hack. The attacker does not need a recovery phrase, a private key or an approval.
The weakness lies in public ordering and in how much price movement the swap-allows. A short entry onsmart contracts explains why the pool code simply follows its inputs.
How Does a Sandwich Attack Change a Swap Fill?
A fill is what a trader actually receives. The quote shown before signing is only an estimate based on the pool at that moment. A Sandwich Attack changes the pool before the swap-runs, so the final fill falls below the quote.
Take a simple case, A trader swaps ETH for a token and the screen shows an expected output. A bot buys that token first, lifting its pool price.
The trader's swap then executes and receives noticeably fewer tokens than expected, yet still above the minimum the trader allowed. The bot then sells the tokens it bought at the raised price.
The shortfall is the visible harm, though it is not automatically the bot's profit, since fees, gas and market movement also count.
Step
Who acts
Effect on the pool
Spot
Bot reads the public queue of pending swaps
None yet
Front-run
Bot buys the token before the victim
Pool price moves against the victim
Victim fill
The trader's swap-executes
Output falls below the quote
Back-run
Bot sells after the victim
Price moves back toward its start
How Do Front-Running and Back-Running Transactions Work?
Front-running means placing a transaction ahead of a pending one. Back-running means placing one right after it. Together they form the two slices of bread around the victim's swap.
Order matters because blocks have a fixed sequence. Transactions waiting in the public mempool can be seen before inclusion, and searcher bots pay to be placed before or after a target.
Block builders then arrange the final order. Theofficial explanation of maximal extractable value describes how this ordering produces sandwich trades and why it can worsen slippage for traders.
Why Can a DEX Swap Succeed at a Worse Price?
A swap-fails only when the output drops below the minimum the trader set. Until that line is crossed, the pool is happy to fill the order at any price the market offers at that moment. A Sandwich Attack works inside that allowance. The attacker pushes the price as far as the tolerance lets the swap survive, and no further, because a failed-swap earns nothing.
Support material from a major exchange protocol states that a sandwich does not necessarily cancel a swap or touch wallet credentials.
Itshelp article on sandwich attacks explains that the trader receives the tokens at a worse execution price. A successful transaction message therefore proves nothing about the quality of the fill.
How Do Slippage Tolerance and Liquidity Affect Sandwich Attacks?
Two settings and one pool property shape the risk.
Slippage tolerance: The maximum price movement the trader accepts. A loose setting gives a bot more room, and a tight one leaves less, though a very tight setting can make honest swaps fail.
Minimum amount out: The least number of tokens the trader agrees to receive. It turns the tolerance into a hard floor.
Liquidity depth: A deep pool absorbs a trade with little price impact, so the bot's first trade moves it less. A thin pool moves easily, which is why small or new tokens attract more attacks. The guide onwhy memecoins pump and crash fast shows how shallow markets behave.
Price impact, the change in pool price caused by a trade's size, is the lever the bot pulls. Large swaps against thin pools hand it the most room.
How Much Can a Sandwich Attack Cost a Trader?
There is no single figure, and none is quoted here. The loss depends on trade size, pool depth, the slippage setting, gas costs and how many bots compete. Competition cuts both ways: more bots can shrink each attacker's margin, yet a trader's worse fill remains.
A regulator's analysis ofmaximal extractable value in crypto markets treats sandwich trading as a recognised market-integrity issue and a hidden cost of trading on-chain.
The loss is often invisible, because a trader sees a completed swap and may never compare it with the original quote.
How Can Traders Reduce Sandwich Attack Risk?
Lower the slippage tolerance to a sensible level, without making it so strict that swaps keep failing.
Choose deeper pools so each trade has less price impact.
Use private transaction routing, which keeps a pending swap out of the public mempool and away from public bots.
Turn on swap protectionwhere a wallet or exchange interface offers it.
Check the minimum output before signing.
Split very large trades when the extra fees and risks are worth it.
The decentralised exchange's ownguide to securing swaps covers private routing, lower slippage and deeper liquidity, and a protection service's page on sandwich attacks explains slippage, price impact and ordering.
A newer draft standard on reference-relative slippage bounds proposes execution-time protection, though it is still a draft and not a universal tool. Wider scam habits are in the guide oncrypto phishing protection.
What Does the Evidence Show About a Sandwich Attack?
Official/Confirmed
Sandwich trading can increase slippage and worsen the execution price for traders.
A sandwiched swap can still succeed and deliver tokens at a worse price.
Private routing, lower slippage and deeper liquidity are recommended ways to reduce exposure.
Reported
Bots watch the public mempool for pending swaps worth targeting.
A regulator analysis treats MEV and sandwich trading as a market-integrity concern.
A draft standard proposes execution-time slippage bounds.
Final Thoughts
The lesson of a Sandwich Attack is that the quote and the fill are different things. A swap that succeeds can still cost more than it should, and the gap comes from ordering, liquidity and how much slippage the trader allowed.
Readers who check the minimum output, favour deep pools and use protection tools shrink that gap, though no step removes it. For market context, thelatest crypto news page tracks daily moves.
Disclaimer: This article is for educational purposes only and is not financial or investment advice. DEX trading carries slippage, smart contract and MEV risk. Always check swap settings and current protocol guidance before trading.