---
title: "The sandwich"
url: "https://www.mikefluff.com/en/experiments/nom-ch22a-sandwich"
locale: "en"
author: "Mikhail Savchenko (Mike Fluff)"
updated: "2026-11-24"
description: "The MEV sandwich attack"
book: "https://www.mikefluff.com/en/books/nobody-owns-money"
alternates:
  - locale: "en"
    url: "https://www.mikefluff.com/en/experiments/nom-ch22a-sandwich"
    markdown: "https://www.mikefluff.com/en/experiments/nom-ch22a-sandwich.md"
  - locale: "ru"
    url: "https://www.mikefluff.com/ru/experiments/nom-ch22a-sandwich"
    markdown: "https://www.mikefluff.com/ru/experiments/nom-ch22a-sandwich.md"
  - locale: "pt"
    url: "https://www.mikefluff.com/pt/experiments/nom-ch22a-sandwich"
    markdown: "https://www.mikefluff.com/pt/experiments/nom-ch22a-sandwich.md"
  - locale: "es"
    url: "https://www.mikefluff.com/es/experiments/nom-ch22a-sandwich"
    markdown: "https://www.mikefluff.com/es/experiments/nom-ch22a-sandwich.md"
---

# The sandwich

*The MEV sandwich attack*

A Uniswap pool has no order book. It holds two coins, and the product of the two balances never changes. Buy ether, and the pool ends up with less ether and more dollars, so the next ether costs more. Every trade moves the price, and every trade can be seen before it happens, because a transaction waits in a public queue, the mempool, until it gets into a block.

That queue is what the bot reads. It sees your purchase, buys just ahead of you, lets you buy at the higher price it has caused, and sells right after you into the price you pushed up. Its only limit is the slippage you allowed. Had it bought any more, your trade would have come out below your minimum and been cancelled, so it buys exactly up to that line.

The pool here is a toy: a thousand ether against two million dollars, so ether starts at $2,000, with the pool’s 0.3% fee and gas left out. Set the size of your purchase and the slippage, then switch the bot on and off. The curve marks the pool after each step, and the table shows who paid what. The difference between the quote without the bot and what you actually received is the bot’s profit.

The book starts from a record that anyone can read. This experiment shows the same openness from the other side, where somebody reads it faster than you and is paid for that.

_The page has an interactive experiment that runs in a browser: https://www.mikefluff.com/en/experiments/nom-ch22a-sandwich_

## From the book

Beside it in the book:

> Katsuyama was fighting a few dozen high-frequency firms. The decentralized exchange spawned thousands of bots, and instead of a 350-microsecond delay it had only the rules of an auction. In 2020 a company called Flashbots appeared and proposed bringing this market out of the shadows and making the auction for a place in the block open, so that bots would at least stop clogging the network with fee wars. The auction became an industry. The ordering of transactions was now sold according to rules, and the money for it went to a few big block builders, run by the same smart guys with math degrees.

- Read the chapter: [Chapter 28. The Dark Forest](https://www.mikefluff.com/en/read/nobody-owns-money/ch22a) (opening free, rest in the full book; Markdown: https://www.mikefluff.com/en/read/nobody-owns-money/ch22a.md)

- Book: [Nobody Owns Money](https://www.mikefluff.com/en/books/nobody-owns-money) — $15
