# W06 Lab Guide: MEV in Practice

## Workshop Overview

**Duration:** 90 minutes (40 lecture + 25 notebook + 20 simulation + 5 buffer)
**Difficulty:** Intermediate, accessible cold-read for non-specialists
**Tools:** Browser, Excel or Google Sheets, optional Jupyter notebook
**Network:** Not required for the workshop activities

## Prerequisites Checklist

- [ ] You completed W05 (stablecoins) or you have read the W05 primer
- [ ] You can open and run a Jupyter notebook
- [ ] You can type a value into a spreadsheet cell
- [ ] No prior MEV knowledge required (the lecture builds it from zero)
- [ ] Optional: read the trimmed primer (`handouts/w06_mev_primer.pdf`) before class

## Learning Objectives

By the end of W06 you will be able to:

1. Define mempool, MEV, searcher, builder, and validator in plain English and place them in the correct step of the MEV pipeline.
2. Trace the three transactions of a sandwich attack (front-run, victim trade, back-run) and calculate the bot's maximum profit given a trade size and slippage tolerance.
3. Explain why a private RPC (Flashbots Protect) breaks the sandwich for individual users, and why a batch auction (CoW Swap) breaks it structurally.
4. Describe proposer-builder separation (PBS) and explain how it changes the incentive structure for validators.
5. Argue both sides of the MEV ethics debate (tax vs. auction) with at least two supporting points per side.

---

## Part 1: Lecture (40 minutes)

You will be in your seat with a printed deck or your laptop showing the slides. Your job:
- Listen for the four polls. Vote with show-of-hands or Mentimeter.
- Take note of any term you do not recognize on the glossary slide.
- Predict before the reveal on the predict-beat slides.
- Stay through the mitigation slides. The attack case is always followed by the mitigation beat; do not leave at the attack.

> **Discovery question (write your guess before the lecture):** What happens to your Uniswap swap between the moment you click confirm and the moment it confirms on-chain? Where does it go, and who can see it? Write your guess: ___________

### Checkpoint after the lecture
- Can you trace the three transactions of a sandwich in the right order?
- Which mitigation did you find more convincing: private RPC or batch auction?
- What surprised you about the MEV pipeline (searcher to builder to validator)?

---

## Part 2: Workshop W-A, Notebook Analytics (25 minutes)

### Step 1: Open the notebook

Find `notebooks/W06_mev_sandwich.ipynb` in your course folder. Open it in Jupyter (or VS Code with the Jupyter extension, or Google Colab if you upload the folder).

If you cannot run the notebook, raise your hand. The facilitator will give you a printed paper fallback (`paper_fallback/w_a_paper_fallback_handout.pdf`) that runs the same exercise on paper.

### Step 2: Run cells C0 to C6 with the facilitator

The facilitator will pace the room through the cells on the projector. Each cell takes roughly 2.5 minutes. Your job:
- Run the cell on your own laptop after the facilitator runs it on the projector
- Read the output
- Be ready to answer the checkpoint question

> **Discovery question:** Cell C5 shows a histogram of bot profits from the sample dataset. Before you look, predict: what is the median profit per sandwich? More than $100? Less? What does the distribution shape tell you?

### Step 3: Reflection cells C7 and C8 (5 minutes)

Cell C7 asks you two questions. Type your answers in cell C8.

You have 5 minutes. Be brief. One sentence per answer is enough.

### Step 4: Summary cell C9 (1 minute)

Run cell C9 with the facilitator. The output is your one-line takeaway. Write it down (on paper or in the notebook) before closing your laptop for Part 3.

### W-A success criteria
- [ ] You ran cell C9 and saw the summary table
- [ ] You answered both reflection questions in cell C8
- [ ] You can state, in one sentence, the median profit per sandwich and the most common trade size range in the dataset

---

## Part 3: Workshop W-B, MEV Roles Simulation (20 minutes)

### Step 5: Get your role card

The facilitator will hand out 4 role cards. You will be in a group of 2-8 students assigned one of:
- Searcher (bot operator)
- Victim (retail user)
- Validator / Builder
- Regulator / Press

Each card explains your mission, tools, and constraints. You also have a quiet-participation opt-out: if you prefer not to speak in front of the group, write your decisions on a card and hand them to your team lead.

### Step 6: 30-second explainer

The facilitator reads the explainer slide aloud. The bot profit and victim loss are computed each round from the slippage setting, trade size, gas price, and any mitigation the victim role chooses to activate.

### Step 7: Three simulation rounds (5 min each)

Each round runs:
- 3 minutes caucus (your group decides what to do)
- 1 minute enter actions (your team lead types in the simulation sheet)
- 1 minute compute and announce (facilitator reads the round outcome)

The rounds (in order):
1. Round 1: Baseline (no mitigations, 2% slippage, standard gas)
2. Round 2: Victim activates private RPC (Flashbots Protect); searcher must adapt
3. Round 3: Victim switches to batch auction (CoW Swap); searcher must adapt

> **Discovery question:** Before Round 1, predict: which round do you think the Victim role will break even or come out ahead? Why?

### Step 8: Debrief (3 minutes)

The facilitator asks 5 questions. Be ready to answer one of them in front of the group. The closing line is the takeaway: "MEV is not a bug in the system. It is a consequence of the system's most important property: openness. Every mitigation trades some openness for some protection."

### W-B success criteria
- [ ] Your group submitted an action in all 3 rounds
- [ ] You can state the round-end outcome (Searcher profit / Victim loss) for each of the 3 rounds
- [ ] You can connect at least one round to the mitigation arc from the lecture

---

## Evaluation

W06 is not graded. The evaluation below is for self-assessment and for the facilitator's pedagogy-quality check.

### Self-assessment
- I can define mempool and explain why it is public by default. (LO1)
- I can trace the three transactions of a sandwich attack and calculate the maximum extraction. (LO2)
- I can explain how a private RPC and a batch auction each break the sandwich, and how they differ. (LO3)
- I can describe proposer-builder separation and its effect on validator incentives. (LO4)
- I can argue both the tax view and the auction view of MEV without using value-loaded language. (LO5)

### Pedagogy-quality items (for facilitator review, mirroring W05 Patch 12)

These items go beyond compliance with the prompt. They test whether the workshop actually worked as intended.

- [ ] **Analogy persuasiveness.** Did the auction analogy and the assembly-line pipeline land for the room, or did they feel abstract? If abstract, where? (Track via show-of-hands at the end: "raise hand if the searcher-builder-validator pipeline was clear to you".)
- [ ] **Mitigation honesty.** Was the batch auction explanation strong enough that a student who started favoring the private RPC was momentarily persuaded to consider structural fixes? (Track via Poll 3 results and any spontaneous questions.)
- [ ] **Glossary completeness from cold-read.** Did any student flag a term they did not understand after the glossary slide? (Mark unflagged terms as effective; mark flagged terms for revision in the next iteration.)

The pedagogy-quality items are recorded by the facilitator in a post-class note in `claude-logs/`.

---

## Troubleshooting

- **Notebook will not open.** Use the W-A paper fallback handout. The facilitator has copies. The exercise is the same.
- **Simulation sheet will not load.** Use the W-B paper fallback packet. A lookup table replaces the formula.
- **You missed the lecture portion.** The trimmed primer in `handouts/w06_mev_primer.pdf` covers the same material at study pace. The deck is the visual companion to the primer.
- **You disagree with the "MEV as auction" framing.** Good. The framing is designed to be challengeable. The W-B simulation gives you a way to test which side you find more defensible after living both roles.
- **You feel rushed.** The 5-minute buffer is yours. Tell the facilitator. We will use it.

---

## Optional extensions (for advanced students)

- **ADV1 (sandwich data deep dive):** Pull live sandwich data from Eigenphi.io (eigenphi.io). What is the largest single sandwich in the past 30 days? What slippage setting did the victim use?
- **ADV2 (Flashbots Protect mechanics):** Read the Flashbots documentation on how bundles are submitted and how the relay works. What trust assumptions does the user make when using Flashbots Protect?
- **ADV3 (CoW Swap batch auction design):** Read the CoW Protocol whitepaper section on the uniform clearing price mechanism. How does the solver role compare to the searcher role in the traditional MEV pipeline?
- **ADV4 (encrypted mempool research):** Find one academic paper or EIP (Ethereum Improvement Proposal) on encrypted mempools or commit-reveal schemes. What is the main unsolved problem?

These are not graded. They feed forward into the rest of Module H (advanced DeFi topics).
