Crypto Guide

MEV and Sandwich Attacks: How to Protect Large Swaps

MEV and Sandwich Attacks: How to Protect Large Swaps

MEV, Maximal Extractable Value, is the profit that validators, block builders, or bots can extract by reordering, inserting, or excluding transactions within a block before it’s confirmed. A large swap is a more attractive MEV target than a small one because the potential profit from exploiting it scales with size, and because a large order is easier to spot and more costly to execute if the price moves against it during the brief window between submission and confirmation. Reducing exposure means limiting what a bot can see and act on before your trade settles, mainly through private transaction routing, intent-based execution, sensible slippage limits, and order splitting. None of these eliminate MEV entirely; they reduce your realistic exposure to it.

How MEV Works

Every transaction submitted to a public blockchain like Ethereum sits in a mempool, a public queue of pending transactions waiting to be included in a block, before it’s confirmed. That visibility is fundamental to how these networks operate, but it also means anyone running the right infrastructure can see your trade before it settles.

Validators and block builders control the order in which transactions within a block get processed, and that ordering power has real value. Specialized participants called searchers monitor the mempool looking for transactions they can profit from by inserting their own transactions before, after, or around them. They pay for priority, either through gas fees or through direct arrangements with block builders, to get their transactions sequenced favorably. This reordering and insertion activity, in aggregate, is what MEV refers to: value extracted from the mechanics of transaction ordering rather than from genuine trading insight or market-making.

Most Ethereum blocks today are produced through a builder auction process, where builders compete to construct the most valuable block and pay validators for the right to have their block included. This has formalized what was once a more chaotic, purely bot-driven process into a more structured (though still largely opaque to end users) marketplace for transaction ordering.

Sandwich Attacks Explained

The sandwich attack is the most common form of MEV that directly costs ordinary traders. The mechanics: a searcher spots your pending swap in the mempool and calculates how much your slippage tolerance allows the price to move against you. The searcher then submits two transactions around yours. The front-run transaction executes just before your trade, buying the same asset and pushing the price up. Your trade then executes at that now-worse price, still technically within your stated tolerance. The back-run transaction executes immediately after, selling back into the price movement your trade caused, capturing the difference as profit. You end up with fewer tokens than you would have without the attack; the searcher captures the gap.

The conditions that make a trade an attractive sandwich target: wide slippage tolerance (which gives the attacker more room to move the price while staying within your accepted range), thin liquidity in the pool being traded (which makes the price easier to move with a smaller capital outlay from the attacker), and large order size relative to the pool’s depth (which increases the absolute profit available from the attack).

Why Large Orders Are Targets

Size cuts both ways for MEV exposure. A large order moves the price more as it executes, which is exactly the mechanism a sandwich attack exploits, more size means more potential profit for the searcher executing the attack. A large order is also, in a sense, more visible: it stands out in the mempool relative to routine smaller trades, and the potential payoff justifies more sophisticated searcher infrastructure and higher gas bids to guarantee favorable positioning around it.

This creates a specific dynamic for treasuries, whales, and any trader executing meaningful size: the same order size that creates market impact risk (covered in how to execute large swaps with minimal market impact) also creates elevated MEV exposure, and the two risks compound. A large order routed naively through public infrastructure with a loose slippage tolerance is exposed to both simultaneously.

Protection Methods

Sensible slippage limits. Setting tolerance to the minimum level that still allows your trade to succeed under normal conditions limits how much room a sandwich attacker has to work with, even if it doesn’t eliminate the risk entirely. A very wide tolerance set purely to guarantee execution is one of the most common, avoidable ways traders expose themselves to unnecessary sandwich risk.

Private transaction routing. Tools like Flashbots Protect route your transaction through a private relay directly to block builders, bypassing the public mempool where searchers watch for opportunities. Because your trade’s details aren’t broadcast publicly before confirmation, front-running and sandwiching become substantially harder to execute against it. Some of these services also return a share of any MEV your transaction does generate back to you, rather than letting a searcher capture it entirely. Independent sources report meaningful reductions in sandwich exposure from these tools, though figures vary by provider and shouldn’t be read as a universal guarantee across all conditions and chains.

Intent-based and batch-auction protocols. Rather than submitting a raw transaction that reveals your exact trade to the public mempool, intent-based protocols let you sign an intent to trade at a specific price, which professional solvers then compete to fulfill. Because the solver bears the execution risk and handles the actual on-chain routing, the end user’s exposure to mempool-based exploitation is substantially reduced. Batch auction models, where multiple orders settle together at a single clearing price, remove the sequential ordering that sandwich attacks depend on entirely for the orders settled within that batch.

Order splitting. Breaking a large trade into smaller pieces, in addition to reducing market impact (covered in depth in the market impact guide linked above), also reduces the payoff available to a sandwich attacker on any single piece, since each individual transaction is smaller and less profitable to target.

Routing across liquidity sources. An aggregator that splits a large order across multiple pools or chains, rather than sending it all to one venue, reduces both the market impact and the single-point visibility that make a large order an efficient sandwich target.

Our YiFi private rail (XMR/stable-hop) and the CEX rail move large orders outside the public mempool, so execution does not occur on-chain via a pool, but rather through a deposit on an exchange. As a safeguard against sandwich attacks, this approach is more radical than Flashbots: there’s nothing to front-run if the transaction doesn’t go through an AMM.

How Routing Reduces Exposure

For a swap routed through an aggregator that can split across multiple liquidity sources and, where available, submit through private transaction paths rather than the public mempool, the combined effect is meaningfully reduced MEV exposure compared to a single large trade broadcast publicly with a loose slippage setting. This is a genuine, measurable improvement, not a marginal one, for large orders specifically.

It’s not completely eliminated, and it shouldn’t be sold as such. Even private relay submission depends on the specific relay and builder infrastructure being used, and coverage varies by chain; some networks have mature private-routing infrastructure; others don’t yet. A portion of any given trade may still be visible or inferable to sophisticated market participants regardless of the routing path. The honest framing: better routing and private settlement reduce your realistic MEV exposure substantially; they don’t guarantee zero extraction on every trade, on every chain, under every condition.

When a Dedicated Private RPC or Specialized Tool Is Better

Routing through an aggregator with built-in protection isn’t always the most complete solution:

You need chain-specific, purpose-built infrastructure. For very active Ethereum trading specifically, a dedicated tool like Flashbots Protect, configured and used directly, may offer more granular control (custom builder preferences, specific hint-sharing settings, MEV refund configuration) than a general-purpose aggregator’s built-in protection provides.

You’re running automated or algorithmic trading at high frequency. Trading bots and arbitrage strategies executing many transactions benefit from direct integration with private relay infrastructure and bundle submission, rather than routing each transaction through a general swap interface.

You need bundle-level atomicity across multiple transactions. Some private routing tools support submitting multiple transactions as an atomic, all-or-nothing bundle, useful for complex multi-step strategies where partial execution would be worse than no execution at all. This level of control typically requires direct integration rather than a standard swap flow.

Limitations

MEV protection reduces exposure; it doesn’t eliminate it. No combination of private routing, intent-based execution, and careful slippage settings guarantees zero value extraction on every trade. Sophisticated searchers continue to adapt to defensive measures, and coverage of private routing infrastructure varies by chain and isn’t universal.

Private routing can affect execution speed or certainty. Depending on the specific relay and builder configuration, private transaction paths may take longer to confirm than a standard public mempool transaction, a trade-off worth understanding for time-sensitive trades.

Protection tools are chain-specific. Infrastructure like Flashbots Protect is primarily built for Ethereum and expanding gradually to other chains; coverage on newer or smaller networks is less mature. Confirm what protection is actually available on the specific chain you’re trading on before assuming a given tool covers it.

The YiFi private rail (XMR/stable-hop) and the CEX rail move large orders outside the public mempool, so execution does not occur on-chain via a pool, but rather through a deposit on an exchange. As a safeguard against sandwich attacks, this approach is more radical than Flashbots: there’s nothing to front-run if the transaction doesn’t go through an AMM.

Builder centralization is an ongoing structural concern. A relatively small number of builders currently produce the large majority of blocks on networks like Ethereum, which introduces its own centralization and trust considerations into what “private” routing actually means in practice.

FAQ

What is MEV in crypto? 

MEV, Maximal Extractable Value, is the profit validators, block builders, or automated bots called searchers can extract by reordering, inserting, or excluding transactions within a block before confirmation. It arises from the ordering power inherent in how public blockchains process transactions, and includes both harmful forms like sandwich attacks and more benign forms like arbitrage that helps keep markets efficient.

What is a sandwich attack? 

A sandwich attack is a specific MEV exploit where a searcher spots your pending trade in the public mempool, places a transaction immediately before yours to push the price against you, lets your trade execute at that worse price (still within your slippage tolerance), then immediately trades back to capture the price movement your trade caused. You get a worse fill than you would have otherwise; the searcher captures the difference.

Why are large swaps targeted by MEV bots? 

Larger orders move the price more as they execute, which directly increases the potential profit available from a sandwich attack. They’re also more visible and easier for searchers to identify as worth the gas cost and infrastructure investment to target, compared to routine smaller trades that offer a less attractive payoff relative to the effort.

How do I protect a large swap from MEV? 

Set slippage tolerance to the minimum level that still allows normal execution, route through private transaction infrastructure or intent-based protocols where available rather than the public mempool, split large orders into smaller pieces, and use an aggregator that routes across multiple liquidity sources rather than concentrating a large order in a single visible transaction.

Does routing eliminate MEV? 

No. Routing through private infrastructure and splitting large orders substantially reduces MEV exposure, but doesn’t eliminate it entirely. Private routing coverage varies by chain, sophisticated searchers continue to adapt to defensive measures, and no available protection method guarantees zero value extraction on every trade under every condition. Treat protection tools as meaningfully reducing risk, not as a complete guarantee.

What slippage setting protects against sandwiches? 

There’s no single tolerance that eliminates sandwich risk, since a bot can extract value up to whatever your tolerance allows, however small. A tight tolerance, typically in the range of 0.1%–0.5% for major liquid pairs, limits the maximum room available to an attacker and reduces the profit that makes attacking your trade worthwhile, but genuine protection against sandwiching comes primarily from where and how you submit the transaction, not the tolerance setting alone.

Get Started

For programmatic access to liquidity routing designed to reduce both market impact and MEV exposure on large swaps, see the YiFi Swap API documentation.

For the complete method on minimizing market impact specifically, see How to Execute Large Crypto Swaps With Minimal Market Impact. For the fundamentals of slippage and how it relates to MEV risk, see What Is Slippage in Crypto?

Subscribe:

📱 Yifi Platform

📱 Our Twitter/X

📱 Our Telegram