contracts-mev-sandwich
Skill này làm gì
Skill này mô tả tấn công sandwich, khi ai đó đặt giao dịch quanh một lệnh hoán đổi của nạn nhân để kiếm lợi từ biến động giá. Skill dành cho nhà phát triển DeFi và người giao dịch muốn bảo vệ các lệnh hoán đổi của mình.
Khi nào nên dùng
- ✓Khi bạn xây giao diện sàn và muốn giảm rủi ro trượt giá cho người dùng.
- ✓Khi một người giao dịch muốn hiểu vì sao một lệnh hoán đổi nhận được giá tệ hơn.
- ✓Khi một đội giao thức rà soát định tuyến giao dịch và các lựa chọn gửi riêng tư.
Liên kết skill
https://github.com/BitterSecurity/Decepticon/blob/main/packages/decepticon/decepticon/skills/standard/contracts/mev-sandwich/SKILL.mdSao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.
Cách dùng
Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.
Tin nhắn có sẵn để dán
Dành cho Claude Code, Codex hoặc Cursor: chạy lệnh trong thư mục dự án của bạn và skill sẽ được cài đặt.
Tải tệp SKILL.md về và thả vào thư mục skill của agent.
Ví dụ cách nhờ AI
“Vì sao lệnh hoán đổi của tôi trên sàn nhận được giá tệ hơn mong đợi, và làm sao bảo vệ các lệnh sau này?”
5 skill mới mỗi tuần. Đọc chỉ 1 phút.
Cách hoạt động
Agent giải thích sandwich hoạt động ra sao bằng ngôn ngữ đơn giản, kiểm tra cài đặt trượt giá (slippage), rồi gợi ý các cài đặt và lựa chọn định tuyến giúp giảm rủi ro.
Nội dung kỹ thuật (SKILL.md gốc)
Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.
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
Câu hỏi thường gặp
Ai bị thiệt bởi sandwich?
Người giao dịch nạn nhân nhận giá tệ hơn vì các giao dịch thêm được đặt quanh lệnh của họ.
Cài đặt nào giúp ích?
Dung sai trượt giá chặt hạn chế mức giá có thể di chuyển trước khi lệnh hoán đổi thất bại.
Tuyến giao dịch riêng tư là gì?
Đó là cách gửi giao dịch mà không để lộ nó trong pool chờ xử lý công khai, skill nêu đây là một lựa chọn.
Chi tiết
Mô tả gốc của tác giả
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.
Độ phổ biến
- Sao GitHub
- 6.5k
- Vị trí xếp hạng
- #14009
- Giấy phép
- Apache-2.0
- Cập nhật
- 1/11/2026
Bình luận
- …
Thêm skill từ kho mã này
detector-overview
6.5kGiúp agent của bạn đọc code mà một công cụ quét đã đánh dấu, rồi quyết định điểm nào là lỗ hổng bảo mật thật và điểm nào là báo động giả.
exploiter-overview
6.5kGiúp agent của bạn ghép nhiều lỗ hổng bảo mật đã xác nhận thành một chuỗi kiểm thử và kiểm tra chuỗi đó có thể gây hậu quả đến đâu.
llm-redteam-overview
6.5kGiúp agent của bạn tìm đúng hướng dẫn red-team AI cho một bài kiểm thử, bao quát 15 nhóm chiến thuật từ prompt injection đến lạm dụng mô hình.
aatmf-t01-prompt-injection
6.5kGiải thích prompt injection, khi các chỉ dẫn ẩn cố ghi đè một hệ thống AI, để chuyên gia bảo mật có thể kiểm tra lỗi này.
Skill tương tự
reverse-engineer-anything
422kGiúp agent của bạn xem bên trong các app và package đã phát hành để giải thích tính năng, so sánh phiên bản hoặc hướng dẫn dựng lại bằng công cụ REA.
1password
394kGiúp agent của bạn cài đặt CLI của 1Password, đăng nhập, và đọc hoặc đưa thông tin bí mật vào mà không in giá trị ra cuộc trò chuyện.
healthcheck
394kGiúp agent của bạn rà soát bảo mật máy tính hoặc máy chủ đang chạy OpenClaw, như SSH, tường lửa, cập nhật và sao lưu, rồi đề xuất cách sửa an toàn.