Sandwich Attack Detection & Prevention Framework
Sandwich attacks extract value by frontrunning and backrunning a victim trade, amplifying slippage and siphoning edge from DEX / AMM arbitrage strategies. Detection requires mempool pattern analytics, gas price intent inference, dynamic slippage guardrails, and order flow privacy. This 2025 framework details taxonomy, detection heuristics, prevention architecture, monitoring KPIs, simulation, and an execution checklist to materially reduce extractable value leakage while preserving arbitrage fill probability.
Sandwich Attack Taxonomy & Lifecycle
Classic Two-Leg Sandwich
Attacker buy before victim, sell after; profits from induced price impact and victim slippage.
Multi-Hop Sandwich
Sequential hops through correlated pools to amplify impact / reduce detection signal noise.
Backrun Skimming
Only the back leg executed when front-run risk too high; opportunistic tail extraction.
Bundle-Based Sandwich
MEV searcher submits atomic bundle (front + victim + back) via private relay for guaranteed capture.
Mempool Detection Signals & Heuristics
Gas Price Bracketing
Two txs with near-identical calldata bounding victim gas price ± small delta Δg.
Temporal Clustering
Burst of candidate pairs within sub-second arrival window preceding large swap.
Balance Pre-Probing
Microswap probing pool reserves before size decision; signals adaptive attack sizing.
Repeating Calldata Hashes
Identical function routes with adjusted gas premium & nonce sequence scanning ordering edge.
Core Prevention Techniques & Architecture
Private Order Flow
Route via Flashbots / MEV-Share / other relays to skip public mempool exposure.
Adaptive Slippage Bounds
Slippage % a function of real-time pool depth, volatility & gas congestion score.
Transaction Slicing
Split size into micro-batches across blocks to reduce exploitable impact footprint.
Sequenced Bundling
Combine multi-pool legs atomically preventing intermediate state arbitration by attackers.
Gas Price Strategy & Ordering Control
- EIP-1559 Base vs Priority: Maintain priority fee ladder to avoid excessive overbidding patterns exploited by attackers.
- Latency vs Cost Curve: Model marginal improvement in inclusion probability vs extra priority wei.
- Backrun Awareness: Simulate negative EV after including potential attacker backrun slip impact.
- Gas Spike Circuit: Freeze automation during mempool surge percentile > 95th with high variance.
Monitoring KPIs & Alert Thresholds
Sandwich Loss Rate
% of swaps with adverse pre+post slippage pattern signature.
Private Flow Coverage
Share of notional routed via private relays vs public mempool.
Slippage Utilization
Actual price impact / allowed slippage band; indicates tightness calibration.
Alert Precision
True positive ratio of sandwich detection alerts; manages analyst fatigue.
Simulation & Backtesting Framework
- Historical Mempool Replay: Reconstruct order arrival ordering; label sandwich windows; evaluate heuristic recall.
- Parameter Sweep: Optimize slippage band scaling coefficients vs missed trade ROI distribution.
- Cost Attribution: Separate unavoidable AMM price impact vs attacker induced extra slippage.
- Relay Comparison: Measure private vs public inclusion latency & success variance.
- Regression Guard: CI test ensures alert precision ≥ baseline after code changes.
Sandwich Defense Execution Checklist
- 1. Private Routing Enabled: Fallback to public path only on relay degradation < threshold.
- 2. Heuristic Model Healthy: Detection precision / recall charts within accepted band.
- 3. Slippage Auto-Scaling: Dynamic band updates reflect current volatility & depth metrics.
- 4. Gas Ladder Active: Priority fees align with configured inclusion probability curve.
- 5. Alert Noise Controlled: False positive rate under target (e.g. < 15%).
- 6. Simulation CI Passed: No regression in backtest sandwich loss delta.
- 7. Incident Runbook Current: Relay outage & mempool surge procedures verified.
Tools, Data Sources & APIs
- Flashbots / MEV-Share (private submission)
- Blocknative (mempool telemetry)
- MEV Inspect (historical labeling)
- OpenSearch / Elastic (pattern indexing)
- Prometheus (KPI metrics)
- Spark / DuckDB (replay analytics)
- Great Expectations (data quality)
- Slack / PagerDuty (alert routing)
Deploy Strong MEV Defense
Pair sandwich detection with private transaction pool strategies, optimize execution using AMM pricing mechanics, and reinforce overall risk posture via finality monitoring.
Conclusion
Effective sandwich prevention is a systems engineering problem: integrate mempool analytics, adaptive controls, private routing, simulation feedback and measurable KPIs. Avoid binary solutions (always private, always tight slippage) in favor of dynamic policies tuned by real data. Continuous replay and precision tracking transform MEV defense from reactive patching into a competitive execution moat.
Tags
Categories
Sources & References
-
1Flashbots DocsPrivate transaction relay & MEV research
-
2Flashbots Research PostsIn-depth MEV attack & defense analyses
-
3MEV BlockerOrder flow protection initiative
-
4Blocknative BlogMempool latency & gas market insights
-
5Uniswap DocsCore AMM swap & pool mechanics
-
6Etherscan Gas TrackerGas volatility context for dynamic policies