# Sandwich Attack Checker: Was My Swap Front-Run?

> Sandwich attack checker for DEX swaps: see if an MEV bot front-ran and back-ran a swap, what the trader lost, the attacker's profit and sandwiches by day.

Markdown copy of https://voltfincrypto.com/apps/sandwich-attack-checker

**Question:** Was this swap sandwiched by a bot, and how much did the trader lose to it?

- Kind: Dashboard in Voltfin Vantage
- Topic: [DeFi](https://voltfincrypto.com/topics/defi)
- Chains: Ethereum, BNB Chain, Base, Arbitrum
- Status: Planned. The data is not published yet, so this page states no figure; each figure will open its receipt when it is.

A sandwich attack wraps a victim's swap between two trades by the same bot: one just before it that moves the price against the victim, and one just after that trades back at the better price. The victim still gets a fill within their slippage limit, but a worse one, and the difference becomes the bot's profit. This checker takes a swap transaction and shows whether that happened and what it cost.

Everything it needs is in the block: the order of transactions, the pools they touched and each pool's state before the first trade. The loss is the output the swap would have received without the front-run, minus what it received. The page also counts sandwiches by day on each covered chain, each one linked to its transactions.

## Blueprint

### Check a swap

Whether one swap was sandwiched, by whom and what it cost.

- **Sandwiched**: Whether the swap sat between a front-run and a back-run by the same actor in the same pool and block.
- **Loss to the sandwich** (USD): The output the swap would have received at the pool state before the front-run, minus what it received.
- **Slippage limit used** (%): How much of the swap's allowed slippage, from amountOutMin in its calldata, the sandwich consumed.
- **Attacker profit** (USD): The attacker's gain from the front-run and back-run, after the gas and tips they paid.
- **The three transactions**: The front-run, the swap and the back-run in block order, with amounts, prices, gas and tips.
- **Pool price through the block**: The pool's price before the front-run, after it, after the swap and after the back-run.

### Sandwiches by day

Detected sandwiches and the value taken on each covered chain.

- **Sandwiches, last 24 hours** (count): Sandwiches detected on the selected chain in the last 24 hours.
- **Value taken, 30 days** (USD): Value taken from sandwiched traders over the last thirty days, by the same loss rule.
- **Most sandwiched pools**: The pools with the most detected sandwiches in the period, with the value taken in each.
- **Sandwiches by day** (count): Detected sandwiches and the value taken from traders on each day of the period.

Filters: Transaction (Any swap transaction hash on a covered chain); Chain (Ethereum, BNB Chain, Base, Arbitrum or all); Period (Last 7, 30 or 90 days).

## How it will be measured

- A sandwich is three swaps in one block and pool: a front-run and a back-run by the same sender or contract, in opposite directions, with the victim's swap between them in the same direction as the front-run.
- The victim's loss is its output at the pool state before the front-run, computed from sqrtPriceX96 and liquidity or from reserves, minus its actual output, valued at the day's oracle price.
- The attacker's profit is what the back-run returned beyond the front-run's cost, less the gas and the tip to the block builder or validator they paid.
- The victim's slippage limit, amountOutMinimum or amountOutMin, comes from its decoded calldata, which shows how much of the allowed slippage the sandwich used.
- Swaps are read from Uniswap v2, v3 and v4 Swap logs and their forks, with each transaction's index in the block, so the order is the chain's own.

## Data it needs

- `mev_daily` (to build): Blocks by builder, MEV-Boost relay share, and detected sandwich attacks with the value taken from users, per day.
- `dex_swaps_daily` (to build): Swap counts and volume per DEX, pool and chain per day, decoded from Swap events, valued with stablecoin legs and oracle prices.
- `native_prices_daily` (to build): Reference prices of major assets read from on-chain oracle feeds (Chainlink latestRoundData) at each day's last block, with each round's update time.
- Source: DEX Swap logs (Uniswap v2, v3 and v4 and their forks) with each transaction's index in the block
- Source: Front-run and back-run legs by the same sender or contract in the same pool around the victim
- Source: Pool state (sqrtPriceX96 or reserves) before the front-run to price the counterfactual
- Source: Victim amountOutMin from decoded calldata

## Questions

### What is a sandwich attack?

A form of MEV where a bot sees a pending swap, trades just before it to move the price, lets the swap execute at the worse price and then trades back. The bot profits from the price move it caused, at the swapper's expense.

### How can I tell if my swap was sandwiched?

Look at the transactions just before and after yours in the same block and pool. If the same address or contract traded in your direction just before you and the opposite way just after, your swap was sandwiched. This checker makes that comparison for you.

### How much does a sandwich cost?

The cost is the difference between what the swap would have returned without the front-run and what it returned. It is bounded by the swap's slippage tolerance: a wide tolerance leaves a bot more to take.

### What makes a swap harder to sandwich?

A sandwich needs the swap to be visible before it is included and room within its slippage limit. A tight limit leaves less to take, and private submission hides a swap until it lands in a block. Rollups whose sequencer keeps no public mempool see fewer sandwiches for the same reason.

### Which chains does the checker cover?

Ethereum, BNB Chain, Base and Arbitrum to start, for swaps on Uniswap and its forks. Each detected sandwich links to the three transactions behind it.

## Glossary

- **MEV**: Maximal extractable value: profit taken by choosing, ordering or inserting transactions within a block.
- **Front-run**: A trade placed just before a known pending trade to profit from the price move it will cause.
- **Back-run**: A trade placed just after another trade, here to trade back at the price the victim's swap moved to.
- **Slippage tolerance**: The worst price a swap will accept, set as a minimum output; a sandwich can take up to that limit.

## Related apps

- [Ethereum Block Builders: Market Share of Blocks](https://voltfincrypto.com/apps/ethereum-block-builders)
- [DEX Volume by Chain and Protocol](https://voltfincrypto.com/apps/dex-volume-by-chain)
- [Trending Crypto Tokens on DEXs Today](https://voltfincrypto.com/apps/trending-crypto-tokens)
- [Token Approval Checker: Open Allowances by Wallet](https://voltfincrypto.com/apps/token-approval-checker)
- [Crypto Address Checker: Flagged, Sanctioned or Hacked](https://voltfincrypto.com/apps/crypto-address-checker)
- [DeFi TVL by Chain: Total Value Locked Rankings](https://voltfincrypto.com/apps/defi-tvl-by-chain)

Build it in Voltfin Studio: https://app.voltfincrypto.com/signup?next=%2F
