Trading & Markets

MEV & Trading Dynamics

MEV and Trading Dynamics

Module 3 of Trading & Markets


What Is MEV?

MEV (Maximal Extractable Value) is the value that can be extracted by reordering, inserting, or censoring transactions within a block. Originally called "Miner Extractable Value," now "Maximal" since validators (not just miners) can extract it.

Why Does MEV Exist?

In traditional finance, trade execution order is based on arrival time. In blockchain:

  • Block producers choose transaction order
  • Pending transactions are visible in the mempool
  • Profitable orderings create extraction opportunities
       Mempool (Pending Transactions)
       ┌─────────────────────────────┐
       │  Tx1: Buy 10 ETH @ market   │  ← Visible to everyone!
       │  Tx2: Sell 5 ETH @ 3000     │
       │  Tx3: Swap USDC → DAI       │
       └─────────────────────────────┘
                    │
                    ▼
       Block Producer orders them:
       [Tx_attacker_front] → [Tx1] → [Tx_attacker_back]

Types of MEV

1. Frontrunning

Placing your transaction BEFORE a target transaction:

Example - DEX Trade Frontrunning:

  1. Attacker sees: "Buy 100 ETH on Uniswap"
  2. Attacker submits: Buy ETH (higher gas to go first)
  3. Price increases from attacker's buy
  4. Victim's trade executes at worse price
  5. Attacker sells for profit
Price
   │
   │     ╱── Attacker sells here
   │    ╱
   │   ╱── Victim buys here (slipped)
   │  ╱
   │ ╱── Attacker buys here
   │╱
   └────────────────────► Time
       ↑     ↑      ↑
      Buy  Victim  Sell

2. Backrunning

Placing your transaction AFTER a target transaction:

Example - Liquidation Backrunning:

  1. Large oracle update makes position liquidatable
  2. Bots race to liquidate and claim reward
  3. First transaction after oracle update wins

3. Sandwich Attacks

Combination of front AND back running:

Transaction Order:
1. Attacker BUY  (frontrun) → Price goes up
2. Victim BUY   (target)    → Price goes up more
3. Attacker SELL (backrun)  → Profit from victim's slippage

Victim Impact:

  • Worse execution price (slippage)
  • Paid MEV to attacker unknowingly
  • Same final token balance, fewer dollars

4. Arbitrage

Profiting from price differences across venues:

Uniswap: 1 ETH = 3000 USDC
Sushiswap: 1 ETH = 3010 USDC

Arbitrage:
1. Buy 10 ETH on Uniswap for 30,000 USDC
2. Sell 10 ETH on Sushiswap for 30,100 USDC
3. Profit: 100 USDC (minus gas)

This is generally considered "good MEV" - it aligns prices across venues.

5. Liquidations

DeFi loans become liquidatable when collateral value drops:

// Simplified liquidation
if (collateralValue < debtValue * 1.5) {
    // Position is liquidatable
    // Liquidator repays debt, claims collateral + bonus
}

Liquidation bots compete for the bonus (often 5-10%).


MEV Supply Chain

Pre-Merge (PoW)

Searchers → Flashbots → Miners → Block
   │           │          │
   │      Bundle relay    │
   │                     Select highest bid
   Find MEV

Post-Merge (PoS) - PBS Architecture

Searchers → Builders → Relays → Proposers → Block
    │           │         │          │
 Find MEV   Build      Validate   Propose
          optimal     & relay     to chain
           block

Proposer-Builder Separation (PBS):

  • Searchers: Find MEV opportunities
  • Builders: Construct optimal blocks from bundles
  • Relays: Connect builders to proposers, verify blocks
  • Proposers: Validators who propose blocks

Flashbots and MEV Infrastructure

What Is Flashbots?

Research organization and infrastructure for:

  • Democratizing MEV extraction
  • Reducing negative externalities
  • Enabling private transaction submission

Flashbots Protect

Users can submit transactions privately:

  • Transaction not visible in public mempool
  • Protected from frontrunning/sandwiching
  • Goes directly to Flashbots builders

MEV-Boost

Middleware connecting validators to block builders:

Validator running MEV-Boost:
1. Receives bids from multiple builders
2. Selects highest-paying block
3. Proposes that block
4. Earns MEV share via bid

MEV Impact on Users

Costs to Regular Users

ActivityMEV Risk
Large DEX swapSandwich attack
NFT mintFrontrunning
DeFi positionLiquidation race
Any pending txPotential extraction

Quantifying Impact

Estimated MEV extracted on Ethereum:

  • 2021: ~$600M
  • 2022: ~$300M
  • Cumulative: Billions extracted from users

Hidden Costs

MEV often invisible to users:

  • No explicit fee
  • Just worse execution
  • Hard to measure individually

Protecting Against MEV

For Users

1. Use Private Transaction Services

  • Flashbots Protect
  • MEV Blocker (by CoW Protocol)
  • Private RPCs

2. Set Tight Slippage

Slippage tolerance: 0.5%
- Less profit for sandwichers
- Risk: Transaction may fail

3. Use MEV-Resistant DEXs

  • CoW Swap (batch auctions)
  • 1inch Fusion
  • MEV-aware routing

4. Timing

  • Low activity periods = less MEV competition
  • But also less liquidity

For Developers

1. Use Commit-Reveal Schemes

// Phase 1: Commit
function commit(bytes32 hashedOrder) {
    commitments[msg.sender] = hashedOrder;
}

// Phase 2: Reveal (after commit period)
function reveal(uint256 amount, bytes32 salt) {
    require(hash(amount, salt) == commitments[msg.sender]);
    // Execute trade - no frontrunning possible
}

2. Batch Auctions

  • Collect orders over time
  • Execute at single clearing price
  • No ordering advantage

3. Time-Weighted Average Price (TWAP)

  • Split large orders over time
  • Harder to sandwich
  • Reduces price impact

MEV and Network Health

Negative Effects

  • User harm: Worse prices, extracted value
  • Network congestion: Priority gas auctions
  • Centralization: Sophisticated actors dominate
  • Chain reorganization risk: Large MEV incentivizes reorgs

Positive Effects

  • Price efficiency: Arbitrage aligns prices
  • Liquidation health: Ensures DeFi solvency
  • Validator revenue: MEV increases staking rewards

The Debate

"MEV is a tax on users" vs. "MEV is the cost of decentralization - centralized systems hide these costs"

Reality: MEV is inherent to blockchain design. Goal is minimizing harmful MEV while preserving useful MEV.


Cross-Domain MEV

Multi-Chain MEV

With multiple chains, new opportunities emerge:

  • Cross-chain arbitrage
  • Bridge exploitation
  • Rollup-to-L1 MEV

Example: L2 to L1 Arbitrage

Arbitrum: ETH = $3000
Mainnet: ETH = $3005

Arbitrager:
1. Buy on Arbitrum
2. Bridge to Mainnet
3. Sell at higher price
4. Pocket difference minus fees

Sequencer MEV

L2 sequencers have ultimate ordering power:

  • Can extract MEV from L2 transactions
  • Some protocols share MEV with users
  • Decentralized sequencers reduce this risk

Future of MEV

MEV Minimization

  • Better AMM designs (less predictable)
  • Order flow auctions
  • Encrypted mempools

MEV Redistribution

  • Share MEV back to users
  • Protocol-captured MEV for public goods
  • Token holder MEV distribution

MEV-Resistant Designs

  • Threshold encryption for transactions
  • Trusted execution environments (TEEs)
  • Verifiable delay functions

Key Takeaways

  1. MEV is inherent to transparent blockchains with ordering control
  2. Sandwich attacks extract billions from regular users
  3. Flashbots/PBS institutionalized MEV extraction
  4. Protection exists: Private tx services, tight slippage, MEV-resistant DEXs
  5. Developers can design against MEV (commit-reveal, batch auctions)
  6. Some MEV is good (arbitrage, liquidations maintain system health)
  7. The future is minimization and redistribution, not elimination