SecurityIntermediate

MEV and Sandwich Attacks: How to Protect Your Swaps

How searchers front-run and sandwich swaps in the public mempool, how much they can take, and the settings and routes that keep your trades safe.

ChainBridge ResearchUpdated 5 min read

On this page6 sections

Key takeaways

  • MEV is the profit bots make by ordering transactions around yours; the sandwich attack is the one that costs swappers the most.
  • A sandwich can only take you down to your minimum received, so your slippage tolerance caps the loss.
  • ChainBridge sizes slippage automatically, warns above 2%, and fixes the minimum in every transaction or gasless order you sign.
  • ChainBridge does not send swaps through a private mempool; if you want one on Ethereum, set a private RPC in your wallet.

What is MEV?

MEV, maximal extractable value, is the profit available to whoever decides the order of transactions in a block. On Ethereum, a swap you send through a regular RPC waits in the public mempool before a block builder includes it. Anyone can read it there: the tokens, the amount and the minimum you accept.

Bots called searchers watch the mempool and pay builders to place their own transactions right before or right after yours. Some of that activity is harmless arbitrage. Some of it comes straight out of your trade.

Common types of MEV
TypeWhat the bot doesWho pays
Sandwich attackBuys just before your swap and sells just after it, so you trade at a price the bot pushed up.Direct: you receive less, down to your minimum.
Front-runningCopies or pre-empts a profitable transaction it sees pending, paying more to land first.Direct: you get a worse price, or the opportunity is gone.
Back-runningLands right after your trade to arbitrage the price gap it created between pools.Indirect: it does not change your execution price.
Just-in-time liquidityAdds concentrated liquidity right before a large swap and removes it right after.Mostly to other liquidity providers, who lose the fees.

How a sandwich attack works

A sandwich is three transactions in the same block, with yours in the middle. The bot needs two things: a pool your swap will move, and enough room between the quoted price and your minimum to make a profit after gas.

ETH price in the pool (example)Bot profit = sell price − buy price − gas2,4002,4122,4242,4021. Front-run buyBot buys first,2,400 → 2,4122. Your swapYou buy at the higherprice, 2,412 → 2,4243. Back-run sellBot sells into yourprice, 2,424 → 2,402
Illustrative prices. The bot buys before you and sells after you; you pay the difference.
  1. Front-run

    The bot sees your pending buy and buys the same token first, with a higher priority fee. The pool price rises from 2,400 to 2,412.

  2. Your swap

    Your trade executes on the moved pool, at a worse average price. It still succeeds, because the result is above your minimum received.

  3. Back-run

    The bot sells what it bought into the higher price your trade created, and keeps the gap minus gas and builder tips.

What ChainBridge does about it

No swap interface can make MEV disappear. What it can do is shrink the room a bot has to work with and refuse to send a transaction that would fail.

Sized slippage

Auto mode starts at 0.05% for stablecoin pairs, 0.3% for major pairs and 1% for other tokens, plus half the price impact, capped at 3%. A custom value above 2% shows a front-running warning.

Minimum fixed in what you sign

Every route carries a minimum amount out. If the price is pushed below it, the transaction reverts instead of filling at a worse price.

Gasless orders

On supported networks, a gasless swap is a signed order that 0x's relayer submits for you. The minimum you receive is part of the signed order. See the gasless trading guide.

Market-maker fills

Through 0x, part of a route can be filled by a professional market maker at a fixed, signed price rather than from a pool curve, which a front-run on the pool does not move.

The review screen also simulates the exact transaction before you sign, and blocks the swap if it would revert. Simulation runs on the current state of the chain, so it cannot predict a sandwich that happens later, but it stops you from paying gas for a trade that cannot succeed. Read transaction simulation for details.

MEV risk by network

How exposed you are depends on how the network orders transactions. Chains with a public mempool let bots see and bracket your trade; rollups with a single sequencer mostly do not.

MEV exposure on the networks ChainBridge supports
NetworkOrderingSandwich exposure
EthereumPublic mempool, block builders order transactionsHighest: sandwich bots are active on every liquid pair
BNB Chain, Polygon, AvalanchePublic mempool, validator-orderedReal: sandwiching is common on popular tokens
Arbitrum, Base, Optimism, LineaSingle sequencer, no public mempoolLower: classic sandwiches are hard, but tight slippage still matters

The same trade on a layer 2 is also far cheaper in gas. If your tokens already live there, it is usually the better place to swap. See layer 2 networks.

Checklist: protect your swaps

  1. Keep slippage on auto

    Set a custom tolerance only for the trade that needs it, such as a token with a transfer tax, and switch back afterwards.

  2. Check the minimum received

    Before signing, read the minimum on the review screen. That number, not the expected amount, is your worst case.

  3. Use a private RPC for large trades on Ethereum

    Services such as Flashbots Protect or MEV Blocker send your transaction straight to block builders instead of the public mempool. You add them as a custom network RPC in your wallet; they work with any app, including ChainBridge.

  4. Split very large orders

    A single large swap leaves more value to extract. Several smaller swaps over a few blocks each offer less, at the cost of more gas.

  5. Be careful in fast markets

    During sharp moves, quotes go stale quickly. Refresh the quote rather than raising your tolerance to force a trade through.

Where MEV protection is heading

The wider industry is moving away from broadcasting raw swaps. Intent-based systems such as UniswapX and CoW Protocol let you sign the result you want and leave execution to competing solvers, and batch auctions settle many orders at one price. Encrypted mempools aim to hide transaction contents until they are ordered.

These are general industry developments, not ChainBridge features today. On ChainBridge, the protections that apply now are the ones above: a tight, sized minimum, gasless orders where available, and a simulation before every swap.

Swap with a tight minimum

Auto slippage adapts to the pair and the trade size, and the review screen shows the minimum you will receive.

Open the swap