Most traders calculate profit on a DEX swap by subtracting what they paid from what they sold for. That works when the trade executes at the expected price. When a sandwich attack hits your swap, though, the real profit can be quietly smaller than it looks on screen.
A sandwich attack happens when a bot spots your pending swap in the public mempool, buys the same token just before you (the frontrun), and sells it right after you (the backrun). You buy at a worse price, and the attacker pockets the difference. The loss never appears as a line item in your wallet, so many traders never notice it.
What a Sandwich Attack Does to Your Execution Price
Your swap does not execute at the price shown when you click confirm. It executes at the price available when your transaction is included in a block, and anyone watching the mempool can act on your order first.
The attacker's frontrun pushes the price up before your swap lands. You buy fewer tokens for the same money, and when the attacker sells immediately after you, the price falls back. The attacker profits from the round trip; you are left with fewer tokens and a worse cost basis.
Key takeaway: A sandwich attack does not steal tokens from your wallet, it quietly worsens the price you pay, so the loss shows up as fewer tokens received rather than a visible deduction.
The Worked Example: A $10,000 Swap, Clean vs. Sandwiched
We run the same trade twice, clean and sandwiched. The input is $10,000 in both cases, and the token is later sold at $2.50.
On the clean route, the token trades at $2.00, so $10,000 buys exactly 5,000 tokens. Gas costs $12, for a total of $10,012. On the sandwiched route, the frontrun pushes the price to $2.04, so the same $10,000 buys only 4,901.96 tokens. Gas is higher at $27, for a total of $10,027.
| Clean Swap | Sandwiched Swap | |
|---|---|---|
| Execution price | $2.00 | $2.04 |
| Tokens received | 5,000 | 4,901.96 |
| Gas cost | $12 | $27 |
| Total cost | $10,012 | $10,027 |
| Sale proceeds at $2.50 (after $12 sell fee) | $12,488 | $12,242.90 |
| Net profit | $2,476 | $2,215.90 |
Now sell both positions at $2.50. After a $12 sell fee, the clean position brings in $12,488 (net profit $2,476) and the sandwiched position brings in $12,242.90 (net profit $2,215.90). The profit gap is $260.10.
Breaking Down the $260.10 Profit Gap
The gap comes from two places. The larger part is the lost tokens: 98.04 fewer tokens, worth $245.10 at the $2.50 sale price. This is the core MEV loss, value that would have been yours at the quoted price.
The second part is the extra gas: $27 versus $12, an extra $15. Together, $245.10 plus $15 gives the full $260.10 gap. Recording your execution price and gas on every trade makes this loss visible immediately.
Why the Loss Looks Small but Compounds
A $260.10 loss on a $10,000 trade is about 2.6 percent, easy to dismiss as a bad day in a volatile market. But bots target wallets that trade sizeable amounts through public mempools, so the same traders get hit repeatedly, and over a year that drag adds up. Execution quality matters just as much as picking the right token, as our guide on how slippage affects your actual crypto profit on large trades explains.
Key takeaway: The $260.10 gap splits into $245.10 of lost tokens and $15 of extra gas, so always compare tokens received and gas paid against the clean quote, not just the final sale price.
Practical Ways to Reduce Sandwich Risk
No method eliminates sandwich risk entirely. But several practical steps reduce how often you get targeted and how much an attack costs.
First, use an MEV-protected RPC endpoint or a private transaction relay, which keeps your swap out of the public mempool. Second, set a sensible slippage limit: a tight limit can make your transaction fail rather than execute at a badly worsened price, though it can also cause failures during genuine volatility. Third, break large trades into smaller pieces, since smaller swaps are less profitable to sandwich. Fourth, avoid trading during extreme congestion, when gas spikes and frontrunning are both at their worst.
For a deeper explanation of how these attacks work at the protocol level, the Ethereum documentation on maximal extractable value (MEV) is the most reliable starting point. For running the numbers on your own trades, including token-to-token swaps, see our guide on how to calculate profit on token-to-token swaps.
Conclusion
A sandwich attack rarely announces itself. It shows up as a slightly worse fill, a few fewer tokens, and a gas fee a little higher than expected. On a $10,000 swap, that quiet damage was $260.10 in lost profit, most of it from 98.04 tokens you never received. Once you can split the loss into lost tokens and extra gas, you can measure every suspicious trade instead of guessing.
For a quick check, try the Crypto Profit Calculator on our homepage: enter your buy cost, tokens received, and sale price, and compare it against the clean quote you expected. If the two keep diverging on large swaps, your execution route is where the profit is leaking.
Disclaimer: This article is for educational purposes only and is not financial advice. Crypto trading involves significant risk of loss. Always do your own research (DYOR) before making trading decisions.
Comments
No comments yet. Be the first to share your thoughts.
Leave a comment