Skip to content

MEV and transaction ordering

Expert4 min readLesson 8 of 8

170 XP

In short

Pending transactions are often visible before they are included in a block, and whoever orders the block decides the sequence. A 2019 paper, Flash Boys 2.0, documented bots paying higher fees to place their trades ahead of other users' trades on decentralized exchanges, and named the value available from ordering "miner extractable value" (MEV); the term is now usually expanded as maximal extractable value, since validators as well as miners order blocks. In this example, a user buying 1 VRX from the Larkspur pool pays 40,404.04 MDT; if another party buys 0.5 VRX just before and sells it just after, the user pays 40,813.20 MDT instead. The extra 409.16 MDT the user pays is exactly what the other party earns, before fees. The user's slippage tolerance sets the maximum price the trade accepts: the wider it is, the more value is available to take.

Scope. This article explains how the order of transactions in a block can be used to extract value from other users, what the research that named this called it, and what the arithmetic of a sandwich trade looks like. It is educational and informational only and describes the mechanism at the level needed to understand its cost to ordinary users; it is not a guide to performing it. It contains no price forecast, level, target or signal, names no protocol, exchange or platform, and does not evaluate any token. Research findings are dated and attributed. Worked figures use the fictional Larkspur pool from DeFi Mechanics: Automated Market Makers and Lending Pools. Tax rules vary by country and are not covered here.

Why order matters

On a public blockchain, a submitted transaction usually waits in a public pool before it is included in a block. The miner or validator who builds the block (see Miner and Validator Metrics) chooses which transactions to include and in what order, usually favoring higher fees. On an AMM (see DeFi Mechanics: Automated Market Makers and Lending Pools), the price each trade gets depends on the trades before it. Seeing a large pending trade, and being able to place trades around it, is therefore worth money.

PracticeWhat happensCost to ordinary users
Front-runningA trade placed just ahead of a known pending tradeThe user gets a worse price
SandwichA trade just before and an opposite trade just afterThe user pays the difference
Back-runningA trade placed just after, for example to arbitrage the price the user movedUsually no direct cost to the user
Liquidation racesCompetition to be first to liquidate a loan (see DeFi Mechanics: Automated Market Makers and Lending Pools)The borrower can be liquidated as soon as the threshold is crossed

What research found

Philip Daian and seven co-authors published Flash Boys 2.0 in 2019. They documented bots on decentralized exchanges bidding up transaction fees to obtain priority ordering, which they called priority gas auctions, in order to front-run ordinary users' trades. They introduced the term miner extractable value, now usually called maximal extractable value, for the profit available from including, excluding and reordering transactions, and argued that it posed risks to the security of the network itself, not only to users.

A sandwich: worked example (illustrative figures)

The Larkspur pool holds 100 VRX and 4,000,000 MDT. A user submits a buy of 1 VRX with a 3% slippage tolerance.

SequenceWithout the sandwichWith the sandwich
Other party buys 0.5 VRX first—Pays 20,100.50 MDT
User buys 1 VRXPays 40,404.04 MDT (1.01% above 40,000 MDT)Pays 40,813.20 MDT (2.03% above 40,000 MDT)
Other party sells 0.5 VRX after—Receives 20,509.67 MDT
Result—User pays 409.16 more; other party earns 409.16

The user's price stays within the 3% tolerance, so the trade goes through. With a tighter tolerance the room for the other party shrinks; with a looser one it grows. Pool fees and the fee paid for ordering reduce the other party's profit; pool fees also shift the user's price slightly, which the figures here ignore.

Teaching value, not a forecast: Larkspur figures are fictional and ignore pool fees.

What has changed since

Networks and applications have introduced private transaction channels that hide pending trades, auctions that separate who builds blocks from who proposes them, and trading designs that batch orders. These change who captures the value and how much reaches users; none has removed ordering power from block producers entirely.

Try it with your numbers

What does a trade cost in a constant-product pool?

Try it · AMM constant product.

Inputs

No lesson works an example for this tool, so it opens on round starting values. The tool suggests no number: enter your own.

0 by default, as in the lessons.

The size you enter; it is never solved for.

Cost of buying 1.00 tokens40,404.04 MDTConstant-product pool, x × y = k, on the entered reserves; a pool fee is charged on the quote paid in and kept outside k; impermanent loss is versus holding, excludes pool fees earned, and the model assumes no fees
  • k = x × y · Constant-product pool, x × y = k, on the entered reserves; a pool fee is charged on the quote paid in and kept outside k; impermanent loss is versus holding, excludes pool fees earned, and the model assumes no fees400,000,000
  • Spot price, y ÷ x · Constant-product pool, x × y = k, on the entered reserves; a pool fee is charged on the quote paid in and kept outside k; impermanent loss is versus holding, excludes pool fees earned, and the model assumes no fees40,000.00 MDT
  • Average price paid · Constant-product pool, x × y = k, on the entered reserves; a pool fee is charged on the quote paid in and kept outside k; impermanent loss is versus holding, excludes pool fees earned, and the model assumes no fees40,404.04 MDT
  • Average over spot · Constant-product pool, x × y = k, on the entered reserves; a pool fee is charged on the quote paid in and kept outside k; impermanent loss is versus holding, excludes pool fees earned, and the model assumes no fees1.01%
  • Cost of buying 10.00 tokens · Constant-product pool, x × y = k, on the entered reserves; a pool fee is charged on the quote paid in and kept outside k; impermanent loss is versus holding, excludes pool fees earned, and the model assumes no fees444,444.44 MDT
  • Average price paid for 10.00 tokens · Constant-product pool, x × y = k, on the entered reserves; a pool fee is charged on the quote paid in and kept outside k; impermanent loss is versus holding, excludes pool fees earned, and the model assumes no fees44,444.44 MDT
  • Average over spot for 10.00 tokens · Constant-product pool, x × y = k, on the entered reserves; a pool fee is charged on the quote paid in and kept outside k; impermanent loss is versus holding, excludes pool fees earned, and the model assumes no fees11.11%
  • LP value ÷ hold value, 2√r ÷ (1 + r) · versus holding; excludes pool fees earned; model assumes no fees0.9428
  • Impermanent loss · versus holding; excludes pool fees earned; model assumes no fees−5.72%
  • LP position value · versus holding; excludes pool fees earned; model assumes no fees$14,142
  • Shortfall against holding · versus holding; excludes pool fees earned; model assumes no fees$858
  • Cost to the user, sandwiched · cost to the user only, at the entered front-run size, which is not solved for40,813.20 MDT
  • Extra cost to the user from the sandwich · cost to the user only, at the entered front-run size, which is not solved for; the same fee treatment on both costs409.16 MDT
  • User's average price over spot, sandwiched · cost to the user only, at the entered front-run size, which is not solved for2.03%

A pool of 100.00 tokens and 4,000,000.00 MDT has k = 400,000,000 and a spot price of 40,000.00 MDT. Buying 1.00 costs 40,404.04 MDT (1.01% over spot); buying 10.00 averages 44,444.44 MDT (11.11%), with a 0.00% pool fee: constant-product arithmetic on the entered reserves. At a price ratio of 2.00 the LP position is worth 0.9428 of holding: $14,142 against $15,000, a shortfall of $858 (−5.72%), versus holding; excludes pool fees earned; model assumes no fees. Cost to the user of a sandwiched trade: with 0.50 tokens bought ahead (the entered size, not solved for), the user pays 40,813.20 MDT against 40,404.04 MDT unsandwiched (the same fee treatment on both), an extra 409.16 MDT, 2.03% over spot, within the entered 3.00% tolerance. Framed only as cost to the user. Protocol risk and the total-loss row: a pool can lose its reserves to a contract failure, or a token can go to zero, and an LP position falls with it. No protocol is named or evaluated, and no fee-APR or yield figure is shown.

Educational and informational only — not investment advice, a recommendation, or an offer to buy or sell any security. Investing involves risk, including the possible loss of principal. Worked examples use fictional companies and figures.

Calculators earn no XP.

Open this calculator on its own page

Check understanding

1 of 5

What did Flash Boys 2.0 (2019) originally call the value available from ordering transactions?

Frequently askedCommon questions

4 questions

What is MEV?

Maximal extractable value, originally miner extractable value: the value available to whoever orders a block from including, excluding and reordering transactions; the term was introduced in Flash Boys 2.0 (2019).

How much more does the user pay in the example?

409.16 MDT: 40,813.20 instead of 40,404.04.

Where does the other party's profit come from?

From the user, one for one, before fees.

What caps it?

The user's slippage tolerance sets the maximum price the trade accepts.

ReferencesWhere this comes from

Finished reading?

Mark it complete once the answer holds without scrolling back up.

Ask MarketClue AI about this lesson

The question carries this lesson as its context. MarketClue AI needs an account.

MarketClue does not provide financial advice.

Next on your list

Topic 52 · Crypto in the EUMiCA: the architectureLesson 1 of 6
Next lesson

After that

Educational and informational only — not investment advice, a recommendation, or an offer to buy or sell any security. Investing involves risk, including the possible loss of principal. Worked examples use fictional companies and figures.