trades do not execute in a vacuum. Before a token swap reaches the blockchain, it sits in a public queue — the mempool — where anyone running the right infrastructure can see the pending transaction…
trades do not execute in a vacuum. Before a token swap reaches the blockchain, it sits in a public queue — the mempool — where anyone running the right infrastructure can see the pending transaction, its size, its token pair, and the slippage tolerance the user has authorized. That visibility is the prerequisite for a specific category of value extraction known as maximal extractable value, or MEV. On AMM-based decentralized exchanges, this public mempool exposure has produced a recurring, well-documented attack pattern: the sandwich attack, in which an automated bot inserts a buy immediately before a victim's swap and a sell immediately after, capturing the difference while the victim receives fewer tokens than the quoted output suggested.
This is not exotic risk. It is architectural. Public visibility combined with a non-zero slippage tolerance is the condition that makes a sandwich attack possible — a swap submitted to a public-mempool AMM advertises the input size, the token pair, and the price band within which a sandwich bot could bracket a profitable trade. Whether that opportunity is actually profitable to attack is a separate question, and one that depends on the trade's size relative to pool depth, the bot's gas costs, the volatility of the pair, and the competition among searchers for the same block. Small swaps against deep pools, or any trade where the gas required to win priority ordering would exceed the extractable value, are routinely passed over by automated searchers. The question is not whether such bots exist — they do, and the infrastructure to find them has been industrialized since at least the 2019 publication of "Flash Boys 2.0: Frontrunning, Transaction Reordering, and Consensus Instability" on arXiv — but how the underlying mechanism works, what fraction of observed slippage actually comes from predatory extraction versus ordinary market impact, and which architectural mitigations meaningfully reduce exposure.
The Mechanics of MEV: How Block Production Impacts Your Trade
Maximal extractable value refers to the value that block producers — Ethereum validators in the proof-of-stake model, or miners historically — can capture beyond standard block rewards and gas fees by deciding which transactions to include, exclude, or reorder. Independent actors, commonly called searchers, detect profitable reordering opportunities in the mempool and submit automated bundles to validators or block builders, sometimes paying the bulk of the extracted profit in gas fees to win priority ordering.
On Ethereum's proof-of-stake network, validators control the block-production roles, but the searcher ecosystem is competitive. According to Ethereum's own documentation, in highly competitive cases, searchers may pay 90% or more of total MEV revenue in gas fees to validators to obtain priority ordering. That figure is not specific to sandwich attacks — it describes the broader economics of MEV competition, including the DEX arbitrage that keeps cross-venue prices aligned — but it illustrates a structural fact: priority is auctioned, and the value of priority rises with the size and visibility of the opportunity.
Block production is not a neutral ordering of pending transactions. It is an auction, and the auction price is paid in gas.
For the retail swapper, this means the transaction they submit is competing for inclusion against automated bundles whose economics are precomputed before the swap is even mined. The validator does not need to be malicious; the market structure alone produces the extraction.
Anatomy of a Sandwich Attack: Front-running and Back-running Explained
The sandwich attack is the clearest user-harmful MEV pattern on AMM DEXs. It has three components.
First, the victim's pending swap appears in the public mempool with a defined slippage tolerance — between 0.1% and 5% in many web interfaces, including Uniswap's, though that range is a UI convention rather than a protocol-wide standard. The bot reads the transaction, identifies the token pair, the input amount, the minimum acceptable output, and the slippage cap.
Second, the bot executes a front-run buy: it submits the same token purchase with higher gas, so it lands in the same block immediately before the victim. This moves the AMM's internal price upward, depending on the pool's depth relative to the trade size.
Third, the victim's swap executes at a worse price than the quoted mid-market rate. Because the user set a slippage tolerance, the transaction does not revert — it simply fills at the now-elevated price. The bot then submits a back-run sell immediately after the victim, unwinding its position into the price impact it has just amplified and capturing the difference.
The user receives fewer output tokens than they would have if their transaction had been ordered differently. The bot walks away with the spread. The pool's reserves are redistributed. Ethereum's educational materials use a visible trade of 10,000 UNI as an illustrative example: a swap of that size against a thin pool produces enough price movement within the allowed slippage band for both legs of the sandwich to execute profitably.
The attack is not a hack in the conventional sense. No private key is compromised, no smart-contract exploit is triggered. It is a deterministic consequence of public visibility plus permitted price movement — and it is the predictable outcome only when the resulting bracket produces a profit that exceeds the bot's gas cost.
Slippage vs. Predatory Bots: Distinguishing Market Impact from Manipulation
Not every worse-than-quoted DEX execution is a sandwich attack. The distinction matters, because conflating the two leads to misdiagnosed risk and unhelpful mitigations.
AMMs price through a constant-function invariant. A swap of size X against a pool of depth Y moves the spot price by an amount that is a mathematical function of X relative to Y. Larger swaps against thinner pools produce larger price impact. That is ordinary market microstructure, not extraction. If a user submits a 6% slippage tolerance and the trade moves by exactly 6% due to its own size, the execution is technically at the floor of the accepted range, but no bot was required.
The MEV layer is added on top. When a searcher front-runs the victim's swap, the price impact the victim experiences is the sum of the bot's front-run, the victim's own size, and the bot's back-run. The victim's executed price can therefore be substantially worse than what a same-sized trade against the same pool would produce if executed in isolation.
| Indicator | Likely ordinary price impact | Likely sandwich attack |
|---|---|---|
| Slippage matches AMM calculator for trade size | Yes | No — observed worse |
| Trade is on a low-liquidity pair | Yes | Possible |
| Multiple sandwich-bot transactions appear in same block, immediately bracketing the user's swap | No | Yes |
| Quote aggregator shows better price on an alternative venue at the same block height | No | Strong signal |
| User-set slippage tolerance is wide (e.g., 5% or higher) | Possible | More exploitable |
The table is heuristic, not deterministic. But it captures the core analytical distinction: ordinary price impact is endogenous to the trade; sandwich extraction is exogenous, inserted by a third party reading the mempool. A swap that experiences more slippage than the AMM's price-impact calculator predicts for its size, on a venue with no unusual pre-block market movement, is more likely to have been sandwiched. A swap that experiences the predicted impact is more likely to have been priced correctly, however frustrating the result.
The Evolution of Execution: Private Pools and Intent-Based Routing
Architectural responses to sandwich attacks have evolved along two tracks.
The first is private transaction flow. Uniswap and other venues have introduced private pools — also referred to as private order flow — that hide pending trades from public mempool sandwich bots. If a transaction never appears in the public queue, the standard front-run opportunity does not exist. The trade still executes on-chain; the difference is that the searcher cannot see it in time to insert a bracket bundle.
The second is intent-based execution, exemplified by UniswapX. Rather than submitting a direct swap, the user expresses an intent — "I want at least X output tokens for Y input" — and competing fillers bid to fill that intent from their own inventory or via on-chain routing. According to Uniswap's protocol description, when a filler executes from its own inventory, the resulting fill cannot be sandwiched in the same way as a public-mempool swap, because there is no public pending transaction to bracket.
Per Uniswap's developer changelog, UniswapX became available through its Trading API on Avalanche, Base, BNB Smart Chain, and Tempo on June 9, 2026, and from July 9, 2026, API requests without an explicit protocols field receive UniswapX quotes on chains where it is available. That routing default is a meaningful structural change: for integrators relying on the default, sandwich exposure is no longer the assumed baseline.
But neither mitigation is universal. Private pools hide trades from public-mempool sandwich bots; they do not eliminate the possibility of extraction by the private pool's own operator or by parties with visibility into the private route. Intent-based systems do not guarantee optimal execution on every chain, wallet, or transaction type. No reviewed source establishes that these designs eliminate every MEV risk — they reduce specific user-harmful patterns, primarily sandwich attacks on public-mempool AMM swaps. For those studying how automated systems detect and exploit timing opportunities, research on machine learning–driven execution algorithms offers a useful cross-domain reference, since the same optimization problems — predicting short-horizon price movement and allocating priority — arise in both financial execution and algorithmic search.
Private routing and intent-based execution are mitigation designs, not guarantees. The architecture changes; the adversarial ecosystem adapts.
A separate note on costs: intent-based systems are often described as "gasless" from the user's perspective, but that framing is incomplete. Per UniswapX documentation, fillers price gas into the swap price, meaning the economic cost of execution is embedded in the quoted output rather than appearing as a separate transaction fee. Certain operations — token approvals, native-token wrapping for gas — may still require gas. "Gasless" describes a billing model, not an absence of cost.
Balancing Slippage Tolerance: Why Restrictive Limits Aren't Always the Answer
The instinctive response to sandwich attacks is to tighten slippage tolerance — set it to the minimum, refuse any price movement, force exact output. This is partially correct: a tight tolerance makes sandwiching less profitable or unprofitable, because the bot has less room to move the execution price while still allowing the victim's transaction to execute within the accepted band.
But a slippage limit that is too restrictive causes a different failure mode: the swap does not execute. If the AMM's price impact plus ordinary market movement exceeds the user's tolerance, the transaction reverts. The user pays gas for nothing.
The appropriate slippage is therefore a function of several variables: token volatility, liquidity depth for the pair, route complexity, trade size relative to pool reserves, and whether the token transfers cleanly — some tokens impose transfer fees that themselves consume slippage budget. A 0.1% tolerance is reasonable for a stablecoin pair on a deep pool. The same tolerance on a thin altcoin pair may revert frequently.
There is no universal safe slippage percentage. Anyone presenting one — including this article — is generalizing. Uniswap's 0.1% to 5% interface range is a UI convention, not personalized advice and not an industry standard. The defensible practice is to understand the pool's depth, understand the trade's size, and set the tolerance to the minimum that historically allows the trade to execute under normal conditions. DEX aggregators partially automate this calculation by routing across multiple pools and venues, selecting the path that minimizes expected slippage; they do not, however, eliminate sandwich exposure on the underlying venues if the user's transaction still appears in a public mempool.
Security Posture and Required Mitigations
For the specific architecture analyzed here — public-mempool AMM swap with non-zero slippage tolerance — the baseline risk profile is medium. It is reducible to low with private routing and intent-based fillers where supported, but it is not eliminable through interface settings alone.
The required mitigation stack, in order of impact:
1. Route through a venue that supports private order flow or intent-based execution on the target chain; verify that the routing default actually delivers a non-public-mempool fill rather than merely advertising the option.
2. Size slippage tolerance to the pool and trade, not to a remembered percentage — 0.1% for deep stablecoin pools, higher for thin altcoin pairs where the trade's own price impact would otherwise cause revert loops.
3. Split large swaps across blocks or venues if the trade size relative to pool depth would otherwise produce enough price movement to fill the entire slippage band; size, not slippage tolerance, is the dominant variable when the trade itself is large.
4. Treat "gasless" execution as gas-priced-into-the-quote, not as cost-free; measure execution quality against the all-in output, not the headline network fee.
5. Accept that sandwich mitigation is architectural, not behavioral — no wallet setting or browser extension retroactively undoes a public-mempool submission.
Sandwich attacks are a predictable consequence of three architectural features: public mempool visibility, AMM pricing curves that allow trade-size-dependent price impact, and user-set slippage tolerances that permit execution across a band of prices. Remove any one of those features and the attack becomes uneconomic. The cleanest way to remove public visibility is to route through private order flow or intent-based systems where pending transactions are not visible to sandwich bots. The cleanest way to reduce the exploitability of permitted price movement is to size slippage tolerance to the pool and the trade, not to a percentage remembered from a previous transaction. What remains is the harder problem: MEV is not a single attack but a category, and mitigations that address sandwich attacks do not address every form of value extraction at the block-production layer. Liquidation MEV, cross-domain MEV, and long-tail back-running opportunities persist regardless of how a retail swapper configures their tolerance. For non-custodial execution on public-mempool AMMs, the practical posture is layered: tight, context-appropriate slippage; routing through venues that offer private pools or intent-based fillers where supported; awareness that "gasless" describes billing rather than cost; and recognition that execution quality is an architectural property, not a UI setting.