What Is a Sandwich Attack?

A sandwich attack wraps a victim's DEX trade between two bot transactions — one before, one after — to profit from the predictable price impact. This post explains the mechanism, the slippage variable, and what's changing structurally.
Lewis Jackson
CEO and Founder

The term "front-running" gets used in crypto to describe two related but different things. One is simply placing a transaction ahead of another. The other — the sandwich attack — is more surgical: a bot inserts itself both before and after a victim's trade, extracting value from both ends of the price movement. The name is accurate.

Understanding why sandwiches work requires understanding why large DEX trades are predictable.

Price Impact and the AMM

On a traditional order book, your trade doesn't necessarily move the price unless there aren't enough matching orders. On an automated market maker like Uniswap, price is determined by a formula — typically x × y = k — and every trade moves the price in the direction of the trade. Buy token A, and each successive unit costs slightly more. The bigger your buy, the more expensive the later units get.

This means price impact is calculable before a trade executes. A searcher bot monitoring the mempool can look at a pending swap, run the math against the pool's reserves, and know exactly how much the price will move if that transaction goes through. If the price movement is large enough to cover two additional gas fees with profit left over, the sandwich is worth running.

The Attack, Step by Step

The bot constructs three transactions in a specific sequence and submits them as a bundle:

First, it buys the same token the victim is buying — using a higher gas fee to ensure it lands before the victim's transaction. This nudges the price up.

The victim's swap then executes at this slightly elevated price and pushes the price further in the same direction. This is the price impact the victim was always going to pay. The sandwich just front-loads some of it.

Then the bot sells its position immediately after, at the price the victim's trade helped create.

The extracted value is the price difference between the bot's two execution prices, minus gas. The victim received fewer tokens than they would have without the bot's intervention.

The Slippage Variable

Here's where it gets a bit nuanced. The victim's trade executes successfully only if the final price stays within their slippage tolerance — the maximum price deviation they're willing to accept. If the sandwich pushes the price beyond that limit, the victim's transaction reverts. Both of the bot's transactions also revert, since they were bundled with the expectation the victim's trade would succeed. Everyone eats gas.

Very tight slippage is a defense of sorts. But it's a double-edged one. In volatile markets, legitimate trades revert constantly even without a sandwich attempt. Setting 0.1% slippage might protect you from MEV bots and also guarantee that any meaningful price movement reverts your transaction entirely.

What's Changed

Two things are worth knowing here.

Private transaction channels — Flashbots Protect, MEV Blocker, and the private RPC options now baked into most major wallets — route transactions without broadcasting them to the public mempool. No public visibility, no target. These are practical today, not experimental, and the right call for anyone doing a large swap they'd prefer not to have sandwiched.

But the more structurally interesting development is batch auction design. CoW Protocol collects batches of trades, matches willing counterparties directly where possible, and clears the rest through a pool at a single uniform price. Because every trade in the batch settles at the same clearing price, there's no positional advantage to exploit. The sandwich requires a "before" and an "after." A batch has neither. The attack vector isn't suppressed — it doesn't exist within that mechanism.

That's a meaningful distinction. Slippage settings and private channels reduce exposure. Batch auction design removes the structural prerequisite.

Confirmation Signals

Sandwich attack volume declining as a share of total DEX activity. Wider batch auction adoption in routing infrastructure. Wallets defaulting to private mempools as a standard rather than an opt-in.

What Would Invalidate the Concern

An encrypted mempool deployed at production scale would change this entirely. Several research projects are working on it, but none have deployed on a major chain in a way that affects real trading volumes. Until then, the prerequisite conditions — public mempool visibility and discretionary transaction ordering — remain in place on all major EVM-compatible networks.

At the individual level: the attack can't complete if slippage is set tight enough, or if the transaction doesn't touch the public mempool.

Timing Perspective

Now: Active risk on any large public mempool DEX swap. Private RPC options exist and work today.

Next: Batch auction adoption is growing; whether it reaches the scale to meaningfully shift the overall MEV landscape is an open question.

Later: Encrypted mempools remain a research-stage development, not a deployed reality.

Scope and Limits

This is a mechanism explanation. It doesn't recommend any specific wallet, protocol, or routing configuration — those decisions depend on chain, trade size, and acceptable friction. What's tracked at the signal level lives elsewhere.

The mechanism is understood. The structural solution — batch auctions — is live but not dominant. That gap is where the sandwich attack remains a real cost of doing business on public AMMs.

Related Posts

See All
Crypto Research
New XRP-Focused Research Defining the “Velocity Threshold” for Global Settlement and Liquidity
A lot of people looking at my recent research have asked the same question: “Surely Ripple already understands all of this. So what does that mean for XRP?” That question is completely valid — and it turns out it’s the right question to ask. This research breaks down why XRP is unlikely to be the internal settlement asset of CBDC shared ledgers or unified bank platforms, and why that doesn’t mean XRP is irrelevant. Instead, it explains where XRP realistically fits in the system banks are actually building: at the seams, where different rulebooks, platforms, and networks still need to connect. Using liquidity math, system design, and real-world settlement mechanics, this piece explains: why most value settles inside venues, not through bridges why XRP’s role is narrower but more precise than most narratives suggest how velocity (refresh interval) determines whether XRP creates scarcity or just throughput and why Ripple’s strategy makes more sense once you stop assuming XRP must be “the core of everything” This isn’t a bullish or bearish take — it’s a structural one. If you want to understand XRP beyond hype and price targets, this is the question you need to grapple with.
Read Now
Crypto Research
The Jackson Liquidity Framework - Announcement
Lewis Jackson Ventures announces the release of the Jackson Liquidity Framework — the first quantitative, regulator-aligned model for liquidity sizing in AMM-based settlement systems, CBDC corridors, and tokenised financial infrastructures. Developed using advanced stochastic simulations and grounded in Basel III and PFMI principles, the framework provides a missing methodology for determining how much liquidity prefunded AMM pools actually require under real-world flow conditions.
Read Now
Crypto Research
Banks, Stablecoins, and Tokenized Assets
In Episode 011 of The Macro, crypto analyst Lewis Jackson unpacks a pivotal week in global finance — one marked by record growth in tokenized assets, expanding stablecoin adoption across emerging markets, and major institutions deepening their blockchain commitments. This research brief summarises Jackson’s key findings, from tokenized deposits to institutional RWA chains and AI-driven compliance, and explains how these developments signal a maturing, multi-rail settlement architecture spanning Ethereum, XRPL, stablecoin networks, and new interoperability layers.Taken together, this episode marks a structural shift toward programmable finance, instant settlement, and tokenized real-world assets at global scale.
Read Now

Related Posts

See All
No items found.
Lewsletter

Weekly notes on what I’m seeing

A personal letter I send straight to your inbox —reflections on crypto, wealth, time and life.
Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.