IndexCrypto
Educational only. Not financial, tax or legal advice, and nothing here is a recommendation to buy anything.

MEV and Sandwich Attacks: Ordering Has Value

A public mempool makes transaction ordering valuable. How a sandwich exploits loose slippage, and what private order flow trades away for protection.

  • Difficultyintermediate

When a transaction is broadcast, it usually sits visible in a public pool before being included in a block. Anyone can read it. Whoever builds the next block decides what goes in and in what order.

Those two facts together mean ordering has value, and the business of capturing that value has a name.

Where the Value Comes From

A block is an ordered list. Execution follows that order, so the state each transaction sees depends on what ran before it.

A large swap moves a price. A transaction placed immediately before it trades at the old price; one placed immediately after trades at the new one. The right to choose those positions is worth something, and it is sold.

The ecosystem that grew around this has specialists who find profitable orderings, builders who assemble blocks from them, and validators who publish the blocks. The value extracted is shared along that chain.

The Sandwich

The sandwich is the form that takes money directly from an ordinary user.

The attacker observes a pending swap large enough to move the price. They insert a buy of the same asset immediately before it, pushing the price up. The victim’s swap then executes against that worse price. The attacker sells immediately after, into the price the victim’s trade created.

The victim receives fewer tokens than they expected. The shortfall is the attacker’s profit, less fees.

Nothing was hacked and no permission was abused. The victim’s transaction did exactly what it said, at a price the victim had already agreed to accept.

Slippage Is the Lever

That last point is the important one. A swap specifies a minimum acceptable output, derived from the slippage tolerance. If the executed price would deliver less than that minimum, the transaction reverts.

So the attacker can only move the price as far as the tolerance allows. A tolerance set generously, to avoid failed transactions, is an explicit statement of how much value may be taken.

Slippage toleranceEffect
Very tightAttack unprofitable; transactions may revert in volatile conditions
ModerateLimits extraction to a small band
LooseDefines a large window an attacker can work within
Very loose, set to stop revertsEffectively an invitation on any trade worth sandwiching

Setting slippage high because transactions kept failing is the most common way users expose themselves. See slippage for how the tolerance interacts with liquidity.

What Reduces Exposure

Tighten slippage. It is the direct control, and reverted transactions are cheaper than sandwiched ones.

Trade in smaller pieces. A swap too small to move the price meaningfully offers nothing worth taking.

Prefer deeper liquidity. The same trade moves the price less where there is more depth, which shrinks the window. See liquidity pools.

Use private order flow where the wallet or interface offers it. The transaction goes to builders directly rather than being broadcast publicly, so searchers watching the public pool never see it.

The trade-off there is real. Privacy from the public pool is bought by giving a specific party advance sight of the transaction, and that party’s incentives and policies are now part of your threat model. It is a change in who can see it, not a removal of visibility.

MEV That Is Not Predatory

Not all of this harms users.

Arbitrage between venues corrects price differences and is the mechanism that keeps prices roughly consistent across the market. Liquidations of undercollateralised positions keep lending protocols solvent and are necessary for those systems to function.

Both are forms of extractable value and both are captured competitively by the same participants. What distinguishes sandwiching is that it depends on inserting transactions around a specific user’s trade in order to worsen their price.

Why It Is Hard to Eliminate

The visibility of pending transactions is a property of an open network. Ordering authority within a block has to sit somewhere. Together they make ordering valuable, and value gets captured.

Approaches exist to reduce it: encrypted mempools that hide contents until ordering is fixed, batch auctions that execute many trades at one price, and application designs that do not expose a price-moving transaction in advance. Each shifts the problem rather than removing it, and each introduces its own assumptions about who is trusted.

For a user, the practical controls remain slippage, size, venue depth, and routing.

What People Get Wrong About This

The first mistake is raising slippage until transactions stop failing. That setting is the attacker’s budget.

The second is believing a sandwich requires something to be broken. It requires only a public pending transaction and a tolerance with room in it.

A third is treating private routing as complete protection. It changes who sees the transaction.

A fourth is assuming small trades are targeted. They are not worth the fee to attack, which is why splitting a large trade helps.

And the last is confusing this with an ordering problem inside your own account. That is the nonce, and it is a different mechanism entirely; see nonce and transaction order.

Common questions

What does MEV mean?

Value that can be extracted by choosing how transactions are ordered, included or excluded within a block. Whoever builds the block decides that order, and some orderings are worth more than others. The term originally referred to miners and now covers validators and the specialist builders who construct blocks for them.

How does a sandwich attack work?

An attacker sees a pending swap that will move a price, places their own buy ahead of it, lets the victim's trade execute at the worse price it creates, then sells immediately after. The victim receives less than they would have, and the difference is the attacker's profit.

Is a sandwich attack possible against any trade?

It needs room to work. The attacker can only move the price as far as the victim's slippage tolerance permits, because beyond that the victim's transaction reverts. A tight tolerance makes the attack unprofitable or impossible; a loose one defines exactly how much can be taken.

What is a private mempool?

A route that sends a transaction directly to block builders rather than broadcasting it publicly, so it is not visible while pending. It removes exposure to searchers watching the public pool, at the cost of trusting the party you route through with advance sight of your transaction.

Is all MEV harmful?

No. Arbitrage between venues brings prices into line and liquidations keep lending protocols solvent, and both are forms of MEV. The extraction that harms users specifically is the kind that depends on being inserted around their transaction, which is what sandwiching does.

Read next