Research/Education/Ethereum/Sandwich attacks explained: how MEV bots profit from your DEX swap
# Ethereum

Sandwich attacks explained: how MEV bots profit from your DEX swap

BloFin Academy07/06/2026

A sandwich attack is a trick where a bot places one trade just before your decentralized-exchange swap and one just after, squeezing your trade in the middle to profit from the price it pushes around. It works because pending trades are public and your slippage setting leaves the bot room to exploit.


What is a sandwich attack?

A sandwich attack is a type of MEV, or Maximal Extractable Value, where an attacker surrounds your swap with two of their own trades to profit at your expense. They buy just before you to push the price up, let your trade fill at that worse price, then sell just after. Your loss is their gain (source: what are sandwich attacks, Coinbase).

The name is literal. Your transaction is the filling, and the attacker's two trades are the slices of bread on either side. It only works on public, on-chain trades, because the attacker needs to see your swap coming before it settles. That visibility is the same openness that makes decentralized exchanges permissionless, and it is also the opening a sandwich bot exploits.

It helps to place this in the bigger picture. Sandwiching is one of several ways bots extract value from transaction ordering on Ethereum, a topic our guide on MEV covers in full. Most forms of this ordering game are harmless or even useful, like arbitrage that keeps prices aligned. The sandwich is the predatory one, because it does not provide any service. It simply inserts itself around your trade and takes a slice of your money through a worse execution price.

A quick distinction before the mechanics. A sandwich is not the same as ordinary slippage. Slippage is the natural price movement between when you submit a trade and when it settles, and it can go either way. A sandwich deliberately engineers that movement against you, on purpose, for profit. The next sections show how, and the good news is that the same setting that lets it happen is one you control.


How does a sandwich attack actually work, step by step?

It happens in three quick steps around your single swap, all usually within one block. First the bot spots your pending trade in the public waiting area. Then it buys the same token just before you, pushing the price up. Your trade fills at that raised price, and finally the bot sells right after, pocketing the difference.

Here is the sequence laid out:

  1. Detect. Your swap sits in the mempool, the public holding area for pending Ethereum transactions, before it confirms. A bot scanning the mempool sees it, including the token, the size, and your slippage setting.

  2. Front-run. The bot submits its own buy of the same token, paying a higher fee so its trade lands just before yours. This buying pressure pushes the token's price up.

  3. You fill high. Your swap now executes at the elevated price, so you receive fewer tokens than you would have, or pay more, up to the limit your slippage tolerance allows.

  4. Back-run. Immediately after your trade, the bot sells the token it just bought, now at the higher price your trade helped create. The gap between its buy and sell, minus fees, is its profit.

This front-run-then-back-run pattern around a victim's swap is the defining shape of the attack (source: sandwich attacks explained, Cointelegraph). The whole move is low-risk for the attacker, which is why bots do it at scale. Because all four steps can sit in a single block, the bot is not exposed to the market moving against it. It is not predicting anything. It is using the certainty of seeing your trade and the power to order transactions around it, the ordering power our guide on MEV explains. The one ingredient it cannot supply itself is the room to move the price, and that room comes from your slippage setting, which is where we go next.


Where does the attacker's profit come from?

From your slippage tolerance, the maximum price change you tell the exchange you will accept. A sandwich bot can only push the price as far as your slippage limit allows, then your trade still goes through. If you set a wide tolerance, you hand the bot a large window to work in. A tight tolerance shrinks that window.

Walk through a worked example with round numbers. Suppose you want to buy a token on a decentralized exchange, and the fair price means your trade should cost about 1,000 dollars worth of ETH. You set a slippage tolerance of 10 percent, meaning you will accept paying up to 1,100. A bot sees your order. It buys first, pushing the price up until your trade would cost right around that 1,100 ceiling. Your swap fills at the worse price. The bot then sells into the bump, and the roughly 100 dollars of extra cost you paid becomes most of its profit. Set the tolerance to 1 percent instead, and the bot can only nudge the price to about 1,010, so there is far less to steal, often not enough to bother. This direct link between your slippage setting and your exposure is why protection guides treat it as the first dial to turn (source: what is a sandwich attack, CoW).

That is the core insight: slippage tolerance is the attacker's room. It exists for a good reason, because prices really do move while a trade is pending, and a tolerance that is too tight makes trades fail. But the wider you set it, the bigger the sandwich a bot can build. This is why the depth of a pool's liquidity and depth matters too. In a deep pool, even a large trade moves the price little, so there is little to extract. In a thin pool, a modest trade can swing the price a lot, which is exactly where sandwiches thrive.


Who is most at risk, and who is usually safe?

Large trades in shallow pools are the prime targets, while small everyday swaps are usually safe. A sandwich only pays if the profit beats the attacker's own gas and fees, so tiny trades are simply not worth it. The risk rises with your trade size, a wide slippage setting, and a low-liquidity token.

Think of it as a break-even calculation the bot runs on every pending trade it sees. Attacking your swap costs the bot gas for two transactions and a competitive fee to win the ordering. If the slice it can take from you is smaller than those costs, it moves on. A ten-dollar token swap almost never clears that bar. A five-figure swap on a thinly traded token, with a generous slippage setting, can be very much worth it. So the people who actually need to worry are those making larger trades, trading low-liquidity tokens, or leaving slippage wide by default.

From Blofin's operational perspective, the sandwich is a hazard of trading directly on-chain, which is why a user swapping on a decentralized exchange faces it while the same trade on a centralized order book, matched internally, never enters the public mempool a sandwich needs. That is one of the quieter differences between centralized and decentralized exchanges. It does not make one strictly better than the other, but it does mean the sandwich risk is specific to acting on-chain, and it is the kind of thing worth knowing before a first large DEX swap rather than after.


How common are sandwich attacks?

Common enough to take seriously, but trending down as protection spreads. Through 2025, Ethereum saw an estimated tens of thousands of sandwich attacks per month, yet the dollars extracted per month fell sharply over the same period as more traders adopted protection tools. The pattern is a lot of attempts chasing a shrinking pool of unprotected, profitable trades.

A little history shows both the scale and the direction. Sandwiching has been a recognized form of MEV since decentralized exchanges grew popular, and large cumulative sums have been extracted over the years (source: maximal extractable value, ethereum.org). More recently, research drawing on on-chain data found the monthly value taken by sandwiches has fallen sharply, even as the raw number of attempts stayed high, because protected trading routes have pulled many of the most valuable trades out of reach (source: EigenPhi data on Ethereum sandwich attacks, Cointelegraph). Always treat any specific figure as a snapshot, since these numbers move constantly and are best checked on a live dashboard rather than trusted from any single article, including this one.

The takeaway from the numbers is not panic. It is that sandwiching is an industrialized, automated activity, not a rare event, and the trades that still get caught are largely the unprotected ones. That is an encouraging message, because it means the defenses work. The same data that shows tens of thousands of monthly attempts also shows the money drying up where users took simple precautions. Those precautions are the final section.


How do you avoid getting sandwiched?

You lower your risk with a few simple habits: tighten your slippage, use a protected transaction route for larger trades, and break very large orders into smaller pieces. None of these require special tools or skills, and together they remove most of the danger for an ordinary user. The single most powerful lever is the slippage setting you already control.

Three principles cover the basics. Tighten your slippage, because a lower tolerance directly shrinks the attacker's room; start low and raise it only if the trade fails. Keep meaningful trades out of the public mempool by sending them through a private, protected route, which removes the visibility a sandwich needs, and which major wallets now offer as a setting. And favor deep liquidity, limit orders on a DEX, and smaller order sizes, since each makes your trade a less attractive target.

That is the starter set, and it is deliberately brief here. For the full defensive playbook, including how private RPC endpoints and services such as Flashbots Protect and MEV Blocker work in detail (source: Flashbots Protect documentation), and the dollar thresholds at which protection becomes essential, see our dedicated guide on how to protect your trades from MEV. That guide is the trader-grade companion to this explainer: this article shows you the attack, and that one shows you the full defense. Between the two, a careful user can keep swapping on-chain while making themselves a poor target.


Frequently asked questions

Did I get sandwiched, or was that just normal slippage?

It can be hard to tell from the outcome alone, since both leave you with a worse price than quoted. A clue is the pattern: if a block explorer shows a buy of your token immediately before your trade and a sell immediately after, both from the same address, that is the signature of a sandwich. Ordinary slippage has no such matching pair around your trade. Tools and dashboards exist that flag suspected sandwiches on a given transaction, which can confirm it after the fact.

Can a sandwich attack happen on a centralized exchange?

No, not in the same way. A sandwich needs to see your pending trade in a public mempool and reorder transactions around it. On a centralized exchange, trades match on the platform's internal order book, so there is no public mempool of pending swaps for a bot to watch and no transaction ordering to exploit. The sandwich is specific to trading directly on-chain through a decentralized exchange. This is one reason the risk surprises people moving from an exchange to a DEX for the first time.

Does setting slippage to zero protect me completely?

No, and it usually backfires. With zero tolerance, almost any natural price movement between submitting and settling your trade will cause it to fail, so your trades rarely go through. The goal is a tolerance that is tight enough to give a sandwich little room but loose enough that legitimate trades still settle. A small tolerance plus a protected transaction route is far more effective than chasing zero, which mostly just wastes gas on failed attempts.

Are stablecoin swaps sandwiched too?

Less often, but it is possible. Swaps between two stablecoins usually happen in very deep, tightly priced pools, so there is little room to move the price and little to extract, which makes them poor targets. The risk rises if you swap a stablecoin for a thinly traded token, or use a small or low-liquidity pool. The deciding factors are the same as always: how much your trade moves the price, and how wide your slippage setting is.

Is a sandwich attack illegal?

It is predatory, but it is not against any protocol rule, and it occupies a legal gray area that varies by jurisdiction. Like other forms of MEV, a sandwich exploits the open, permissionless design of public blockchains rather than breaking into anything. There is active debate about whether it should be treated as market manipulation, and some protection efforts aim to make it structurally harder. For now, the practical stance for a user is defensive: assume it can happen and trade in a way that makes you an unattractive target.

Do sandwich attacks happen on Layer-2 networks?

In a different form. Many Layer-2 networks order transactions through a single operator called a sequencer, rather than a public mempool open to everyone, which changes the exposure. That can make classic public-mempool sandwiches harder on some Layer-2s, though it concentrates ordering power in the sequencer instead. As Layer-2s move toward more open and decentralized sequencing, the sandwich question follows them, so the same precautions remain worth keeping.

 


Researched and written by the Blofin Academy editorial team with AI-assisted drafting. Primary sources include the Ethereum.org documentation on maximal extractable value and the Flashbots protection documentation, with attack mechanics and scale figures cross-checked against EigenPhi on-chain data reported by Cointelegraph and current 2026 coverage. All facts independently verified against cited sources current as of June 2026.

 

This article is for informational purposes only and does not constitute financial advice, investment guidance, or a recommendation to buy, sell, or hold any digital asset. Sandwich-attack frequency and extracted-value figures are fast-moving, on-chain measures presented as approximate ranges as of 2026, not as quotes or forecasts. Cryptocurrency markets involve significant risk and you should conduct your own research and consult qualified professionals before making decisions. Blofin Academy content reflects the state of public information at time of publication; protocol parameters, fees, and ecosystem data change frequently.