Skip to content

More News Guides Info

LIVE
Loading prices...
Sandwich Attack: How Traders Stop MEV Extraction

Close-up of hand holding smartphone near crypto device

Sandwich Attack: How Traders Stop MEV Extraction

A sandwich attack is a three-transaction exploit where a bot buys ahead of your trade, lets your swap execute at a worse price, then sells immediately after, pocketing the difference your slippage tolerance allowed. It works because pending transactions sit visible in a public queue before confirmation, giving bots a window to react before your trade lands.

You can shrink that window right now, before reading another paragraph, with three moves:

  • Tighten your slippage tolerance to the minimum your trade can accept, typically 0.1% to 0.3% for stable pairs and 0.5% to 1% for major pairs, per guidance from Nomos Labs.
  • Route your swap through a private RPC endpoint or protected order flow such as Flashbots Protect or MEV Blocker, so bots never see the pending transaction.
  • Split large orders into smaller chunks or use an MEV-aware aggregator like 1inch’s flashbot transaction option, which sends swaps directly to block builders instead of the public queue.

None of these require you to change your trading strategy. They change how your transaction travels from your wallet to the chain, which is exactly where the vulnerability lives.

Key Takeaways

Sandwich attacks profit from public mempool visibility, and closing that visibility through private routing is the single most effective defense available to traders today.

Point Details
Mempool visibility is the root cause Public pending transactions let bots see and react to your swap before it confirms.
Slippage sets the profit ceiling Tightening slippage to 0.1% to 1% directly limits how much an attacker can extract.
Private routing suits large trades Flashbots Protect or MEV Blocker works best for sizable swaps where visibility risk is highest.
Verification catches missed protection Check your wallet’s actual RPC endpoint, not just a toggle, to confirm private routing is active.
Detection is possible after the fact A buy-then-sell pattern from one address around your trade on a block explorer confirms a sandwich.

Table of Contents

What Is a Sandwich Attack and Why Mempools Make It Possible

A sandwich attack isn’t a bug in a smart contract or a hack of your wallet. It’s a market-manipulation tactic that exploits how automated market makers price trades and how blockchains handle pending transactions, according to Coinbase’s glossary on the topic. Understanding why requires knowing three pieces of plumbing most traders never think about.

  • Mempool: the public waiting room where transactions sit after you submit them and before a validator includes them in a block.
  • MEV (maximal extractable value): profit that block producers or bots can extract by choosing, delaying, or reordering transactions within a block.
  • Front-run / back-run: placing a transaction immediately before (front-run) or after (back-run) a target transaction to profit from the price movement it causes.

AMM pricing is what turns visibility into a paycheck. On a constant-product exchange like Uniswap, every trade shifts the pool’s price along a curve, and the size of that shift is calculable in advance from the pool’s reserves. A bot watching the mempool can see your swap, calculate exactly how much your trade will move the price, and insert its own trades around yours to capture that movement before you do.

The flow looks like this: you submit a swap, it becomes visible in the mempool, a searcher bot or MEV-aware script spots it, and that bot pays a higher priority fee to get its front-run transaction ordered immediately before yours, with a matching sell ordered right after. Research using EigenPhi’s on-chain data has tracked this pattern closely enough to show how much of it happens automatically, with bots scanning thousands of pending transactions per block for exactly this setup.

How a Sandwich Attack Actually Executes, Step by Step

The mechanics come down to three transactions landing in a specific order inside one block, as Uniswap’s own support documentation lays out.

  1. Front-run buy. The attacker sees your pending swap in the mempool, calculates your slippage tolerance, and submits a buy order for the same asset with a higher gas fee so it lands first.
  2. Victim swap. Your transaction executes next, but the price has already moved against you because of the attacker’s buy. You still get filled, just at a worse rate.
  3. Back-run sell. The attacker immediately sells the position from step one, capturing the price difference your trade created.

Here’s how that plays out with real numbers. Say you’re swapping $10,000 into a token with a 1% slippage tolerance, meaning you’ll accept execution up to 1% worse than the quoted price. A bot detects this, buys $8,000 worth of the same token ahead of you, pushing the price up close to your 1% ceiling. Your trade fills at the worse rate, and the bot immediately sells its $8,000 position into the price bump your trade caused. After gas costs, priority fees, and any relay costs, the bot might net $60 to $150 on that single sandwich, depending on pool depth and gas conditions.

Attackers refine this with a few consistent tactics: bumping gas fees aggressively to guarantee ordering priority, submitting transactions through private relay bundles so their own front-run doesn’t get sandwiched by a competing bot, and running fully automated scripts that scan the mempool around the clock rather than manually watching individual trades.

Hands pressing cold wallet button to confirm transaction

Which Trades Attract Sandwich Bots

Not every swap is a target. Bots are economically rational, they go after setups where extraction is easy and profitable, which means certain trades carry far more risk than others.

  • Large single swaps in thin liquidity pools move price the most, creating the biggest extractable gap.
  • Newly minted tokens and memecoins, especially in the first hours after launch when liquidity is shallow and volatility is high.
  • Trades submitted during peak gas congestion, when bots have more competing transactions to hide among and victims are less likely to notice a fee spike.
  • Small retail trades on chains with near-zero gas costs, where even thin margins are worth extracting because the attacker’s cost floor is so low.

Ethereum’s gas costs impose a natural floor: an attack has to clear priority fees plus base gas before it’s worth executing, which filters out a lot of small trades. Solana’s fee structure works differently. Transaction costs are low enough that bots can profitably sandwich much smaller trades, which is part of why extraction volume on that chain has run so high relative to Ethereum despite Solana’s younger DeFi ecosystem. AMM-based DEXs with shallow pools are the common thread across both environments.

The Real Cost of Sandwich Attacks to Traders and Markets

The scale here isn’t a rounding error. Estimates compiled by Arbitrage Scanner put Solana sandwich extraction at a very large sum over a period exceeding one year, with Ethereum extraction activity also high during peak periods.

For an individual trader, the damage usually shows up as a single bad fill rather than a headline number. A trade that should have executed within a few basis points of the quoted price instead lands 0.5% to 1% worse, and unless you go looking, it just looks like normal slippage. Multiply that across thousands of trades a day and you get worse effective execution across the entire market, not just for the traders who get directly sandwiched, since bots widen effective spreads and fragment liquidity as they compete for the same extraction opportunities.

Sandwich attacks are not a software exploit or a smart contract bug. They are a deliberate manipulation of transaction ordering that takes advantage of public visibility and predictable AMM pricing, which is why the fix lives in transaction routing rather than in the protocol’s code.

Regulatory bodies have started paying closer attention to manipulative on-chain trading behavior generally, and jurisdictions tightening scrutiny of crypto market conduct, as seen in China’s recent rule changes, suggest sandwich-style extraction won’t stay purely a technical problem for much longer.

Practical Defenses That Actually Cut Your Risk

Fixing this problem is mostly about where your transaction goes before it’s confirmed, not how you trade. DEXTools’ MEV protection guidance converges on the same short list nearly every serious defense guide recommends.

  1. Switch your wallet’s RPC endpoint to a private or protected route, such as Flashbots Protect or MEV Blocker, so your transaction skips the public mempool entirely.
  2. Set slippage tolerance as tight as your trade allows, since slippage tolerance is literally the ceiling on how much an attacker can extract.
  3. Split large trades into smaller sequential swaps rather than one big order that creates an obvious, sizable price-impact target.
  4. Use an MEV-aware aggregator or protected routing option, like 1inch’s flashbot transaction feature, which sends your swap directly to a builder instead of broadcasting it publicly.

Configuring these takes minutes, not hours. Changing your RPC means going into your wallet’s network settings and swapping the default endpoint for a protected one, most wallets support this natively now. Protected aggregators usually just require toggling a setting in the swap interface. Slippage adjustment is a field you already see on every trade. Order splitting just means executing two or three smaller swaps instead of one large one, spaced a block or two apart.

Defense Removes mempool visibility Extra cost Ease of use Chain/DEX coverage Best for
Private RPC (Flashbots Protect, MEV Blocker) High None to minimal Moderate (one-time setup) Ethereum, growing L2 support Medium to large trades
Tight slippage tolerance None None Easy Universal (Uniswap, SushiSwap, PancakeSwap) All trade sizes
Order splitting Partial Slightly higher gas Easy Universal Large trades in thin pools
MEV-aware aggregator (1inch flashbot routing) High Minimal Easy Ethereum, multi-chain Medium to large trades

Pro Tip: Don’t trust a wallet’s “MEV protection” toggle blindly. Some interfaces show it as enabled by default without actually pointing your RPC at a private relay. Open your network settings and check the RPC URL itself, if it doesn’t reference Flashbots, MEV Blocker, or a similar protected endpoint by name, you’re still broadcasting publicly.

Why Some Trades Are Worth Attacking and Others Aren’t

Sandwich bots run on the same math any trader would run: expected profit minus cost. A rough version of that calculation looks like trade value multiplied by the slippage cap, minus gas and priority fees, minus relay or builder fees where applicable.

  • Gas and priority fees: the attacker has to outbid the network’s going rate to guarantee front-run placement, which erodes margin fast on Ethereum during congestion.
  • Capital required to front-run: the bot needs enough liquidity on hand to move the price meaningfully, tying up capital for the duration of one block.
  • Revert risk: if ordering doesn’t land the way the bot expects, the front-run transaction can fail or land unprofitably.
  • Relay and builder fees: routing through private bundles to protect the attack itself from being sandwiched by a rival bot adds another cost layer.

The practical rule-of-thumb: trades under a few hundred dollars on Ethereum rarely attract attention because gas costs eat the margin, while on Solana, where transaction costs are a fraction of a cent, much smaller trades can still be worth targeting. Tightening your slippage cap doesn’t just protect you, it directly shrinks the bot’s maximum possible payout, which can make your specific trade uneconomic to attack even if a similar trade elsewhere isn’t.

What DEXs and Protocol Designers Are Doing About It

Traders aren’t the only ones with skin in this game. Protocol teams have been building structural defenses because sandwich attacks degrade the trading experience across their entire user base, not just for the individuals who get hit.

  • Protected order flow and private relays, like Flashbots Protect, give any trader on Ethereum a way to bypass the public mempool without needing custom infrastructure.
  • Minimum-output checks built into swap contracts force a transaction to revert rather than execute at a worse price than the trader specified, a baseline protection most major DEXs already implement.
  • Batch auctions, which group multiple trades and settle them at a single clearing price instead of processing them sequentially, remove the ordering advantage that makes sandwiching possible in the first place, though they’re still uncommon outside a handful of specialized protocols.
  • Oracle-based price checks help contracts detect and reject trades that deviate suspiciously far from an external reference price, catching some manipulation attempts before they settle.

Uniswap, SushiSwap, and PancakeSwap all rely primarily on minimum-output checks and slippage settings as their built-in defense, leaving the mempool-visibility problem largely up to the trader’s own routing choices. That’s exactly why private RPC adoption and aggregator-level protection have become the more meaningful lever for individual traders in the near term.

A Checklist for Every Swap You Make

Treat this as a habit, not a one-time setup. The strongest protection comes from applying the same checks every time, especially on trades that feel routine.

Before you swap:

  • Check the pool’s liquidity depth, thin pools mean bigger price impact and bigger sandwich targets.
  • Set slippage to the tightest level your trade type supports.
  • Decide if the trade size warrants a private route or protected aggregator.

During the swap:

  • Confirm your wallet’s RPC endpoint is actually pointed at a protected relay, not just showing a toggle labeled “on.”
  • Watch for unusual gas spikes right before you submit, which can signal a congested mempool where bots are more active.
  • Prefer aggregator routing when it’s available instead of a direct DEX call.

After the swap:

  • Pull up the transaction on a block explorer and check the two or three transactions immediately before and after yours.
  • Look for a buy from the same address right before your trade and a sell from that same address right after, that pairing is the signature of a sandwich attack.
  • If you spot the pattern, note the pool and time of day, since recurring exposure on the same pair often points to a specific gap in your routing setup worth fixing.

The Gap Between Convenience and Protection

Most traders know sandwich attacks exist and keep using default wallet settings anyway, and that gap is the real story here, not the mechanics of the attack itself. Private RPC endpoints and protected aggregators aren’t hard to set up, they take less time than reading this article, yet default public mempool routing remains the norm across most retail wallet configurations.

Part of that comes down to friction that isn’t really there anymore but still feels like it is. Flashbots Protect and MEV Blocker have matured to the point where switching your RPC is a five-minute change, not an engineering project. The bigger issue is that most traders never see the cost directly. A sandwich attack doesn’t produce a failed transaction or an error message, it just produces a slightly worse fill that gets written off as ordinary slippage. That invisibility is exactly why the defense has to be proactive rather than reactive.

TechGaged has covered enough on-chain security incidents, from Harmony’s repeated security shocks to emerging regulatory responses to on-chain theft, to say confidently that the traders who avoid the worst outcomes are the ones who treat routing hygiene as part of trading, not as optional overhead. Tight slippage and protected routing cost you a few minutes of setup. Skipping them costs you a little on every trade, indefinitely, without ever showing up as a line item you’d notice.

For deeper coverage on DeFi security trends and market-moving developments, TechGaged’s full posts archive tracks these issues as they evolve, and readers looking for the latest on crypto markets more broadly can check TechGaged’s homepage for ongoing coverage.

The Gap Between Convenience and Protection — overview diagram

Frequently Asked Questions

What is a sandwich attack in simple terms?
It’s when a bot places a trade right before yours and another right after, using the price movement your trade causes to turn a profit at your expense.

How do I know if I got sandwiched?
Pull up your transaction on a block explorer and check the transactions immediately before and after it. A buy and sell from the same address surrounding your trade is the signature pattern.

Does using a private RPC guarantee I won’t get sandwiched?
It removes the main enabler, public mempool visibility, but no single defense is absolute. Pairing private routing with tight slippage gives you layered protection.

Are sandwich attacks illegal?
Regulatory treatment varies by jurisdiction and is still evolving. This is general information, not legal advice, so confirm current rules for your market with a qualified professional or primary regulatory source.

Do sandwich attacks happen on centralized exchanges?
Rarely in the same form, since centralized exchanges don’t broadcast pending orders to a public mempool the way on-chain DEXs do. The risk is largely specific to decentralized, blockchain-based trading.

This article is general information, not a substitute for advice from a qualified financial advisor. Consult a qualified financial professional about your own circumstances before acting on anything here.

Sources

Start with the Uniswap support article on sandwich attacks if you want the clearest technical breakdown of the three-transaction mechanic straight from a major DEX’s own documentation. KuCoin’s explainer covers historical examples and risk framing well for readers who want more real-world context.

For hands-on defense setup, 1inch’s documentation on flashbot transactions walks through exactly how protected routing works on their aggregator, and Trust Wallet’s security blog explains what to look for in wallet-level MEV protection settings. DEXTools’ protection guide and Nomos Labs’ full defense breakdown both go deeper into slippage math and detection steps than fits in a single article. Before your next large swap, use these pages to confirm your wallet’s RPC and aggregator settings actually match what you think they’re doing.

Made with BabyLoveGrowth to reach people using AI search

How do you rate this article?

Join our Socials

Briefly, clearly and without noise – get the most important crypto news and market insights first.