MIVORA Start learning free

MEV: The Value Hidden in Ordering

Whoever decides the *order* of transactions in a block can quietly profit from it — an invisible tax on DeFi you should learn to see.

Crypto & Tokenization · Lesson 29 · 10 min read

You send a swap on an AMM (lesson 25), expecting the price the screen quoted — but you get a slightly worse one, every time, as if someone stepped in front of you. They did. There’s a whole hidden economy built on a single fact you already know but may not have connected: the block producer chooses the order of the transactions in a block (lessons 6–7). That ordering power turns out to be worth real money, and it’s extracted from ordinary users. It has a name — MEV — and once you see it, DeFi looks different. Hold the question: how can merely arranging transactions, without changing any of them, be profitable?

Ordering is a power, and power is worth money

When you submit a transaction it doesn’t execute instantly — it waits in a public holding area called the mempool (the queue of pending, not-yet-included transactions) where anyone can see it. The block producer then picks which pending transactions to include and in what order. MEV — Maximal Extractable Value — is the profit that can be captured purely by choosing that ordering: inserting, reordering, or dropping transactions. Nothing about your swap is altered; the sequence around it is arranged to someone else’s advantage. Because block space is auctioned by fees (gas, lesson 9), whoever wants a favorable slot can simply bid more gas to get placed where they want.

The classic move: the sandwich

The signature MEV play against an AMM trade is the sandwich attack, and it works because of price impact (lesson 25 — a big buy pushes the pool’s price up). A searcher watches the mempool, sees your large pending buy, and arranges three transactions in order: (1) their own buy just before yours (front-running — pushing the price up), (2) your buy, now filling at that worse price, (3) their sell just after (back-running — cashing out into the price your trade created). You are the filling; they pocket the difference. It’s not magic or hacking — it’s legal-in-code exploitation of public orders and chooseable ordering.

Worked example
A sandwich, step by step:
• You submit: buy $50k of a token on an AMM.
• Searcher sees it in the mempool, bids high gas to sit right around you.
• Order in the block: searcher buys (price ticks up) → your buy fills at the higher price → searcher sells into that price.
• You got fewer tokens than quoted; the searcher earned the gap. The only thing they controlled was position in line.

Not all MEV is predatory — and how to defend

Be precise: some MEV is harmless or even useful. Arbitrage — buying where a token is cheap and selling where it’s dear — is MEV that actually keeps prices consistent across venues, and it doesn’t pick your pocket. Liquidations (next lesson) are MEV that keeps lending markets solvent. The predatory kind is the front-run/sandwich that targets your trade. Defenses exist and you should know them: set a tight slippage limit (lesson 25 — a cap on how much worse than quoted you’ll accept, which makes a sandwich unprofitable or fails your trade safely), trade smaller sizes, or use private order flow (services that send your trade straight to a builder, skipping the public mempool so no one can see and sandwich it). You can’t abolish ordering power — but you can stop broadcasting the information that makes you a target.

An everyday analogy

Imagine a checkout line where everyone’s cart is visible and the cashier decides the order people are rung up — and will bump you forward for a tip. You spot someone about to buy the last dozen concert tickets at $100. You tip the cashier to ring you up first, buy several tickets (nudging the price to $110), let the person buy theirs at $110, then immediately resell yours to the next buyers at $110. You changed nobody’s purchase — you just controlled who went when, and skimmed the gap. That’s a sandwich: the profit lived entirely in the ordering, and the victim’s only mistake was buying in full view.

Worked example
Telling harmful MEV from harmless, and defending:
1. A bot buys a token on Exchange A at $1.00 and sells on Exchange B at $1.02 → arbitrage; it aligns prices and doesn’t harm your trade. Fine.
2. A bot front-runs and sandwiches your $50k swap → predatory MEV; you eat a worse price.
3. Defense: you set slippage to 0.5%. Now if the sandwich would push your fill past 0.5% worse, your trade simply reverts instead of filling — the attack becomes unprofitable.
4. Better yet, you route through private order flow, so your pending trade never appears in the public mempool for a searcher to see. No visibility, no sandwich.

This is the reading. The interactive version — active-recall quiz, a hands-on experiment you run in your own AI, and an earned mastery check — is free in the app.

Start this lesson free →