contracts-mev-sandwich
What it does
This skill describes sandwich attacks, where someone places trades around a victim's swap to profit from the price movement. It is for DeFi developers and traders who want to protect their swaps.
When to use it
- βWhen you build an exchange front end and want to reduce slippage risk for users.
- βWhen a trader wants to understand why a swap received a worse price.
- βWhen a protocol team reviews transaction routing and private submission options.
Skill link
https://github.com/BitterSecurity/Decepticon/blob/main/packages/decepticon/decepticon/skills/standard/contracts/mev-sandwich/SKILL.mdCopy it and paste it into your AI (Claude, ChatGPT or Cursor), asking it to follow the instructions.
How to use
The easiest way: copy the message and paste it into your AI. It reads the skill and follows the instructions.
Ready-to-paste message
For Claude Code, Codex or Cursor: run it in your project folder and the skill gets installed.
Download the SKILL.md and drop it into your agentβs skills folder.
Example of what to ask your AI
βWhy did my swap on the exchange get a worse price than expected, and how can I protect future swaps?β
5 new skills a week. 1 minute to read.
How it works
The agent explains how a sandwich works in plain terms, checks the slippage setting, and suggests settings and routing choices that reduce exposure.
Technical content (original SKILL.md)
Original text by the author, straight from GitHub.
MEV Sandwich Attack
You observe a victim's DEX swap in the mempool. Sandwich it: buy the same token before the victim (pushing price up), let the victim swap at a worse price, then sell after them.
Detect a sandwichable swap
# Stream pending transactions
from web3 import Web3
w3 = Web3(Web3.HTTPProvider("https://eth.merkle.io"))
# Or: subscribe to alchemy/blocknative streams
# Filter for Uniswap V2 swapExactTokensForTokens or V3 exactInputSingle
# Look at the swap amount + slippage tolerance (deadline + minAmountOut)
# Sandwichable when: swap_amount * slippage > sandwich_gas_cost * 2
Math: profitable when victim's slippage tolerance exceeds your gas cost. Typical threshold for ETH/USDC swaps: victim swap >$10k with >1% slippage.
Construct the sandwich bundle
// Bundle: 3 tx in same block, in order
// 1. attacker_tx_1: swap baseToken -> token (push price UP)
// 2. victim_tx: swap baseToken -> token (worse price now)
// 3. attacker_tx_2: swap token -> baseToken (sell back at higher price)
// Flashbots bundle (Ethereum mainnet β others have similar private RPCs)
const ethers = require("ethers");
const { FlashbotsBundleProvider } = require("@flashbots/ethers-provider-bundle");
const provider = new ethers.providers.JsonRpcProvider(process.env.RPC);
const wallet = new ethers.Wallet(process.env.PK, provider);
const fb = await FlashbotsBundleProvider.create(provider, wallet, "https://relay.flashbots.net");
const blockNumber = await provider.getBlockNumber();
const bundle = [
{ signer: wallet, transaction: attackerTx1 }, // front-run
{ signedTransaction: rawVictimTx }, // victim from mempool
{ signer: wallet, transaction: attackerTx2 }, // back-run
];
const signedBundle = await fb.signBundle(bundle);
await fb.sendRawBundle(signedBundle, blockNumber + 1);
JIT (Just-In-Time) liquidity sandwich
Uniswap V3 concentrated liquidity lets you provide liquidity in a tight range for one block:
// 1. Just before victim's swap: mint a position concentrated at victim's price
// 2. Victim swaps β your liquidity earns 100% of the fee
// 3. Just after: burn the position
// No price-impact risk; pure fee capture.
Works when victim's swap is large enough that the fee exceeds gas + capital cost.
Multi-block MEV
Cross-block sandwiches when validator is also the searcher (or in collusion):
Block N: attacker front-run TX
Block N+1: victim's TX (separate user, expects same price)
Block N+2: attacker back-run TX
Requires builder/searcher cooperation. PBS (proposer-builder separation) on Ethereum makes this harder; still works on chains with single-block validators.
Defenses that break sandwiches (what to look for as "harder targets")
- Victim uses private mempool (Flashbots Protect, MEV-Blocker, bloXroute Private Tx)
- Victim contract has tight
minAmountOut(low slippage like 0.1%) - DEX uses commit-reveal (rare)
- Threshold encryption mempools (Shutter, etc.)
Common pitfalls (sandwich-of-sandwich = your sandwich gets sandwiched)
- Don't broadcast your sandwich publicly β always use Flashbots / private relay
- Other searchers also see the victim β outbid them via gas price + priority fee
- Don't sandwich your own user's swap from same Address β easy attribution
Tooling
mev-inspect-py(Flashbots) β historical sandwich detection (defender + reverse research)mev-shareβ partial-order-flow ecosystemsearcher-sageβ open-source sandwich bot patternsEigenphiβ MEV analytics dashboard (for reconning known searcher patterns)
OPSEC / ethics / legal
- Sandwich attacks are public mempool predation, generally legal but ethically grey. In bounty context: only ever test on test networks or on a target you own.
- For research / detection: use mev-inspect-py against historical blocks; no harm.
- Some chains (e.g., Solana / Jito) have different MEV architectures β adapt accordingly.
References
- "Flash Boys 2.0" (Daian et al., 2019) β original MEV academic paper
- Flashbots docs β docs.flashbots.net
- "MEV Wiki" β github.com/flashbots/mev-research
- EthCC / Devcon talks: search "MEV" on YouTube
FAQ
Who is harmed by a sandwich?
The victim trader receives a worse price because of the extra trades placed around theirs.
Which setting helps?
A tight slippage tolerance limits how far the price can move before the swap fails.
What is a private transaction route?
It sends a trade without exposing it to the public pending pool, which the skill mentions as one option.
Details
Original description by the author
MEV sandwich attacks β front-run + back-run a victim swap on Uniswap V2/V3, Curve, Balancer; mempool monitoring via Flashbots / private RPC, slippage tolerance exploitation, JIT liquidity sandwich, multi-block MEV.
Popularity
- GitHub stars
- 6.5k
- Ranking position
- #14009
- License
- Apache-2.0
- Updated
- 11/1/2026
Comments
- β¦
More skills from this repository
detector-overview
6.5kHelps your agent read code that a scanner flagged and decide which flagged spots are real security bugs and which are false alarms.
exploiter-overview
6.5kHelps your agent join several confirmed security weaknesses into one test chain and check how far that chain could reach.
llm-redteam-overview
6.5kHelps your agent find the right AI red-team guide for a test, covering 15 tactic groups from prompt injection to model abuse.
aatmf-t01-prompt-injection
6.5kExplains prompt injection, where hidden instructions try to override an AI system, so security testers can check for it.
Similar skills
reverse-engineer-anything
422kHelps your agent look inside shipped apps and packages to explain features, compare versions, or guide a rebuild, using the REA tool.
1password
394kHelps your agent set up the 1Password CLI, sign in, and read or inject secrets without printing their values into chat.
healthcheck
394kHelps your agent audit the computer or server that runs OpenClaw for security risks, such as SSH, firewall, updates, and backups, then suggest safe fixes.