MEV (maximal extractable value) is the profit that can be made by choosing which transactions go into a block, and in what order. Some MEV, such as arbitrage that keeps DEX prices in line, is broadly neutral for users. The most harmful kind for traders is the sandwich attack, in which a bot buys just before your swap and sells just after it, so you pay a worse price. Understanding how this works, and how slippage settings and private transaction routes affect it, can save DEX traders meaningful amounts.
Key takeaways
- MEV exists because pending transactions can be seen before they are confirmed and block producers can order them.
- A sandwich attack pushes the price up before your swap and sells after it, taking value up to the limit set by your slippage tolerance.
- Keeping slippage tolerance tight, splitting large trades and using private transaction routing are the main defenses.
- On Solana, priority fees and tips to block-building services change transaction ordering and are part of the same landscape.
- Centralized exchanges do not have on-chain MEV, but they carry custody risk instead.
On this page
What MEV is
On most blockchains, a transaction is broadcast to the network and waits in a public pool of pending transactions (the mempool) before a block producer includes it. While it waits, anyone can see what it will do. Block producers, and specialized bots that bid for their attention, can insert their own transactions before or after it.
The term was first described as "miner extractable value" in a 2019 academic paper, "Flash Boys 2.0," by Daian and co-authors. After Ethereum moved to proof of stake in September 2022, "maximal extractable value" became the usual term, because validators, not miners, now produce blocks.
Today, on Ethereum, most blocks are assembled by specialized builders who compete to create the most profitable block and pay validators for inclusion. Bots called searchers find MEV opportunities and send bundles of transactions to builders. The structure is similar in spirit to the speed competition in high-frequency trading, but played out in block ordering.
Types of MEV
| Type | What happens | Effect on regular users |
|---|---|---|
| DEX arbitrage | A bot trades away price differences between pools or venues | Mostly neutral; keeps prices aligned |
| Liquidations | Bots race to liquidate undercollateralized DeFi loans | Necessary for lending protocols; harsh for the borrower |
| Front-running | A bot copies a profitable pending transaction and gets ahead of it | Takes the opportunity from the original sender |
| Sandwich attack | A bot trades just before and after a user's swap | Direct cost to the user through a worse price |
| Back-running | A bot trades right after a large transaction to capture the price move | Usually neutral for the original user |
How a sandwich attack works
The steps, described from the victim's side:
- You submit a swap on an AMM to buy a token, with a slippage tolerance of, say, 5 percent.
- A bot sees the pending swap and calculates how far it can push the price without exceeding your tolerance.
- The bot's buy is placed ahead of yours, pushing the price up.
- Your swap executes at the worse price, still within your tolerance, so it does not fail.
- The bot's sell is placed right after yours, at the higher price your purchase created.
The bot profits from the price movement it created, and you receive fewer tokens than you would have. The attack works because of how AMM pricing responds to each trade.
Worked example: what your tolerance exposes
You swap 10,000 USDC for ETH in a pool where the quote, after fees, is about 4.748 ETH.
- With 5 percent slippage tolerance, the minimum you accept is 4.748 × 0.95 = 4.511 ETH. A sandwich can take you close to that floor, costing up to about 0.237 ETH, roughly $475 at a $2,000 ETH price.
- With 0.5 percent tolerance, the minimum is 4.748 × 0.995 = 4.724 ETH. The most you can lose to the sandwich is about 0.024 ETH, roughly $47.
In practice, attackers need their own profit to exceed gas or tips and pool fees, so small swaps with tight tolerances are often not worth attacking. Large swaps with wide tolerances in thin pools are the most attractive targets.
How to protect yourself
Set slippage tolerance deliberately
Use the tightest tolerance that lets the trade go through. For liquid major pairs, a fraction of a percent is often enough. Volatile or thinly traded tokens may need more, which is exactly when sandwich risk is highest. Some interfaces offer an "auto" slippage setting; check what it actually chooses.
Use private transaction routing
Several services offer private RPC endpoints (the network address your wallet uses to send transactions) that send your transaction directly to builders instead of the public mempool, so bots cannot see it before it lands. On Ethereum, examples include Flashbots Protect and MEV Blocker. Some also return part of any back-running value to the user. Many wallets now offer MEV protection as a setting.
Use intent-based or batch-auction venues
Some aggregators, such as CoW Swap, collect orders and settle them in batches at a uniform price, or let professional solvers compete to fill your order. This design removes the ordering advantage a sandwich bot needs. See CEX vs DEX for more on aggregators.
Reduce trade size per transaction
Price impact grows faster than trade size in an AMM, so splitting a large order into smaller pieces, or using a limit-order feature, reduces both impact and sandwich profitability.
Check the result
After a swap, compare the tokens received with the quote. A block explorer will show transactions immediately before and after yours. Repeated large shortfalls are a sign to change your settings or routing.
Solana: priority fees and Jito tips
Solana has no traditional public mempool, but ordering still matters. Transactions can include a priority fee, paid per unit of compute, that makes validators more likely to process them first. A large share of Solana validators also run software from Jito, which lets users send bundles of transactions with a tip to the validator for guaranteed ordering.
For ordinary traders this means:
- In busy periods, swaps without a priority fee may be delayed or fail.
- Trading bots and launchpad tools often add priority fees and tips automatically, sometimes large ones. Check what you are paying. See meme coin trading bots.
- Sandwich attacks have occurred on Solana, especially on meme coin swaps with high slippage settings. In March 2024 Jito suspended its public mempool feature, citing its use for harmful MEV, but sandwiching continued through other routes. Tight slippage and MEV-protected routing remain the main defenses.
MEV and centralized exchanges
On a centralized exchange, orders are matched on the exchange's private servers, so on-chain MEV does not apply. Other issues, such as exchange custody and conflicts of interest, take its place. On fast-moving tokens, traders sometimes accept the trade-off of counterparty risk to avoid on-chain front-running.
Common mistakes
- Leaving slippage tolerance at a high value after one volatile trade.
- Making large swaps in shallow pools through the public mempool.
- Paying very high priority fees set by a bot's default without noticing.
- Assuming a failed transaction cost nothing. On many chains, failed transactions still pay fees.
- Trusting unknown "MEV protection" services that ask for private keys. Real protection never needs your keys. See wallet security.
FAQ
What is a sandwich attack in crypto?
It is an attack where a bot places a buy just before your DEX swap and a sell just after it. Your trade executes at a worse price, and the bot keeps the difference.
How do I avoid sandwich attacks?
Use a tight slippage tolerance, send transactions through an MEV-protected private RPC or batch-auction aggregator, and avoid large swaps in thin pools. Splitting trades also helps.
Is MEV illegal?
MEV extraction on public blockchains operates in a legal gray area that differs by country, and regulators have not settled how market abuse rules apply. Some forms, such as exploiting protocol bugs, have led to criminal charges in the US.
What slippage tolerance should I use?
Use the lowest setting that lets your trade execute, often well under 1 percent for liquid pairs. Higher settings may be needed for volatile tokens, but every extra percent is value a sandwich bot can take.