Sandwich Attack Simulator

Experience getting sandwiched on a DEX trade

Your Swap

FromYour Wallet
ToUniswap V3
ActionDAI → ETH
1K10,000 DAI50K

Pool Status

ETH Price$2500.00
ETH in Pool1000.00 ETH
DAI in Pool2,500,000 DAI
StatusProtected

Public Mempool

Your transaction will appear here after you click "Send Transaction"

B
Block #Pending...

Transactions by gas priceEmpty

Block is empty

Transactions will be ordered here

How It Works

A sandwich attack exploits DEX price slippage. The attacker "sandwiches" your trade between two of their own:

  1. 1.Attacker buys ETH first, pushing the price up
  2. 2.You buy ETH at the inflated price (paying more)
  3. 3.Attacker sells ETH at the pumped price (profit!)

How to Protect Yourself

  • Flashbots: Flashbots: Send privately, skip public mempool
  • Advanced gas: Higher gas: Outbid attackers to go first
  • Low slippage: Reject if price moves too much

Deep Dive

AMM Math: x * y = k

Uniswap V2 uses a constant product formula. The attacker exploits this:

Uniswap V2 AMM Formula
JavaScript
1// Constant Product AMM: x * y = k
2// x = ETH reserve, y = DAI reserve
3
4k = ethReserve * daiReserve; // k is constant
5newDaiReserve = daiReserve + daiInput;
6newEthReserve = k / newDaiReserve;
7ethReceived = ethReserve - newEthReserve;
8
9// Price impact calculation
10oldPrice = daiReserve / ethReserve;
11newPrice = newDaiReserve / newEthReserve;
12priceImpact = (newPrice - oldPrice) / oldPrice * 100;
13
14// Example: 1000 ETH, 2,500,000 DAI pool
15// k = 2,500,000,000
16// Buy 10,000 DAI → get 3.984 ETH (price: $2,510/ETH)
17// Without attack: 4.000 ETH (price: $2,500/ETH)
18// Loss: 0.016 ETH ($40) from slippage manipulation

Real Attacks

Cream Finance$130M

Multiple sandwich attacks on large swaps during liquidity crisis

Sushiswap$100M+ (cumulative)

Ongoing MEV extraction through sandwich bots

Use arrow keys to navigate