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 시스템을 덮어쓰려 하는 프롬프트 인젝션을 설명해, 보안 테스터가 이를 점검할 수 있게 합니다.