The Mechanics of Atomic Sandwich Trading: Mempool Slippage Sizing, Dual-Bundles and Searcher Relays
Sandwich trading represents one of the most mathematically formalized strategies in decentralized finance. Operating primarily on automated market maker (AMM) decentralized exchanges such as Uniswap v2/v3 and PancakeSwap, a sandwich attack captures the price impact generated by large unconfirmed trader swaps.
While controversial in public discussions, understanding the underlying mathematical mechanics and execution architecture is essential for quantitative developers and searchers.
1. Anatomy of a Three-Transaction Sandwich
A sandwich execution consists of three sequential transactions submitted within the exact same block:
[Tx 1: Front-run Buy] ---> [Tx 2: Target Victim Swap] ---> [Tx 3: Back-run Sell]
-
Transaction 1 (Front-run): The searcher buys asset $X$ immediately ahead of a large pending transaction detected in the mempool, pushing the marginal price of $X$ upward along the AMM bonding curve.
-
Transaction 2 (Victim): The victim swap executes at a higher price, absorbing the maximum slippage tolerance configured in their trade parameters.
-
Transaction 3 (Back-run): The searcher immediately sells asset $X$ back to the liquidity pool at the inflated price, capturing the spread in ETH or native currency and returning the pool to balance.
2. Dynamic Slippage Sizing Formula
Executing a sandwich without triggering reverts requires precise calculation of the victim trade size $Delta x$, current pool reserves $(R_x, R_y)$, and allowable slippage tolerance $S_{max}$:
The optimal searcher input $Delta x_1$ satisfies:
Sizing errors cause the victim transaction to exceed its slippage limit and revert. If the victim reverts, the back-run transaction collapses into a loss.
Production engines employ automated solver routines like the dedicated Sandwich Bot and the flagship Ethereum MEV Bot to compute optimal size limits in under 2 milliseconds.
3. The Necessity of Flashbots Builder Bundles
Submitting sandwich legs via public mempools is non-viable in production:
-
Competing searchers will intercept and front-run the front-run leg.
-
Block reorderings will separate Transaction 1 from Transaction 3, leaving the searcher holding unwanted token inventory.
To ensure safety, searchers submit the three transactions as an atomic Flashbots bundle. If any single transaction reverts, the entire bundle is dropped off-chain. Zero gas is lost.
Review the complete architectural breakdown and commercial licensing at MEVBOT.TOP.