contracts-mev-sandwich
できること
このスキルは、被害者のスワップの前後に取引を置いて価格の動きから利益を得る、サンドイッチ攻撃を説明します。スワップを守りたいDeFiの開発者とトレーダー向けです。
使う場面
- ✓取引所のフロントエンドを作り、利用者のスリッページのリスクを減らしたいとき。
- ✓スワップの価格が予想より悪かった理由をトレーダーが理解したいとき。
- ✓取引のルーティングと非公開の送信の選択肢をプロトコルのチームが見直すとき。
スキルのリンク
https://github.com/BitterSecurity/Decepticon/blob/main/packages/decepticon/decepticon/skills/standard/contracts/mev-sandwich/SKILL.mdコピーしてAI(Claude、ChatGPT、Cursor)に貼り付け、指示に従うよう頼んでください。
使い方
いちばん簡単な方法:メッセージをコピーしてAIに貼り付けるだけ。AIがスキルを読んで指示に従います。
貼り付け用メッセージ
Claude Code、Codex、Cursorの場合:プロジェクトのフォルダで実行するとスキルがインストールされます。
SKILL.mdをダウンロードして、エージェントのスキル用フォルダに入れてください。
AIへの頼み方の例
“取引所のスワップの価格が予想より悪くなりました。なぜかを説明し、今後のスワップを守る方法を教えてください。”
毎週5つの新しいスキル。1分で読めます。
仕組み
エージェントは、サンドイッチの仕組みを平易な言葉で説明し、スリッページの設定を確認して、露出を減らす設定やルーティングの選択を提案します。
技術的な内容(元のSKILL.md)
作者による元のテキスト(英語)を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
よくある質問
サンドイッチ攻撃で誰が損をしますか?
被害を受けるトレーダーは、取引の前後に置かれた余分な取引のせいで、より悪い価格を受け取ります。
どの設定が役立ちますか?
厳しいスリッページの許容範囲は、スワップが失敗する前に価格が動ける幅を制限します。
非公開の取引ルートとは何ですか?
公開の保留プールにさらさずに取引を送る方法で、一つの選択肢として挙げられています。
詳細
作者による元の説明
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.
人気
- GitHubのスター
- 6.5k
- ランキング
- #14009
- ライセンス
- Apache-2.0
- 更新日
- 2026/11/1
コメント
- …
このリポジトリの他のスキル
detector-overview
6.5kエージェントが、スキャナーが指摘したコードを読み、本物のセキュリティバグと誤検知を見分けられるよう支援します。
exploiter-overview
6.5kエージェントが、確認済みの複数のセキュリティ上の弱点を一つのテストの連鎖にまとめ、その影響がどこまで及ぶかを確認できるよう支援します。
llm-redteam-overview
6.5kエージェントが、プロンプトインジェクションからモデルの悪用まで、15の戦術グループの中から適切なAIレッドチーム用ガイドを見つけられるよう支援します。
aatmf-t01-prompt-injection
6.5kプロンプトインジェクションを説明します。隠された指示でAIシステムを乗っ取ろうとする手口を、セキュリティテスターが確認できるようにします。
似ているスキル
reverse-engineer-anything
422kREAツールを使って、出荷済みのアプリやパッケージの中身を調べ、機能の説明、版の比較、再構築の手順をエージェントが支援します。
1password
394k1Password CLIをセットアップし、サインインして、秘密情報の値を会話に表示せずに読み取ったり注入したりするようエージェントを支援します。
healthcheck
394kOpenClawを動かすコンピューターやサーバーを、SSH、ファイアウォール、更新、バックアップなどのセキュリティリスクについて監査し、安全な修正案を提案するようエージェントを支援します。