MEV Protection
Last updated: August 2025

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

1

Gas Price Bracketing

Two txs with near-identical calldata bounding victim gas price ± small delta Δg.

2

Temporal Clustering

Burst of candidate pairs within sub-second arrival window preceding large swap.

3

Balance Pre-Probing

Microswap probing pool reserves before size decision; signals adaptive attack sizing.

4

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

  1. EIP-1559 Base vs Priority: Maintain priority fee ladder to avoid excessive overbidding patterns exploited by attackers.
  2. Latency vs Cost Curve: Model marginal improvement in inclusion probability vs extra priority wei.
  3. Backrun Awareness: Simulate negative EV after including potential attacker backrun slip impact.
  4. 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

  1. Historical Mempool Replay: Reconstruct order arrival ordering; label sandwich windows; evaluate heuristic recall.
  2. Parameter Sweep: Optimize slippage band scaling coefficients vs missed trade ROI distribution.
  3. Cost Attribution: Separate unavoidable AMM price impact vs attacker induced extra slippage.
  4. Relay Comparison: Measure private vs public inclusion latency & success variance.
  5. Regression Guard: CI test ensures alert precision ≥ baseline after code changes.

Sandwich Defense Execution Checklist

  1. 1. Private Routing Enabled: Fallback to public path only on relay degradation < threshold.
  2. 2. Heuristic Model Healthy: Detection precision / recall charts within accepted band.
  3. 3. Slippage Auto-Scaling: Dynamic band updates reflect current volatility & depth metrics.
  4. 4. Gas Ladder Active: Priority fees align with configured inclusion probability curve.
  5. 5. Alert Noise Controlled: False positive rate under target (e.g. < 15%).
  6. 6. Simulation CI Passed: No regression in backtest sandwich loss delta.
  7. 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.

Share this article

Sources & References

Skip to main content