Sandwich attacks are a common form of Maximal Extractable Value (MEV) exploitation in decentralized finance (DeFi), primarily on Ethereum-based decentralized exchanges (DEXs) like Uniswap. They involve a malicious actor (often an automated bot) manipulating the price of a token by placing transactions before and after a victim's pending trade, "sandwiching" it to extract profit at the victim's expense.
These attacks exploit the public nature of Ethereum's mempool (where pending transactions wait to be included in a block) and the price impact of large trades on automated market makers (AMMs).
How Sandwich Attacks Work (Step-by-Step)
• Victim Submits a Trade
A user submits a large swap (e.g., buying Token Y with Token X) to the public mempool. This trade has slippage tolerance (e.g., allowing up to 1-5% price change) to account for volatility.
• Bot Detects the Opportunity
MEV searchers (bots) scan the mempool for large trades that will significantly impact the pool's price.
• Frontrun (Before the Victim)
The bot submits a buy order for Token Y first (paying higher gas fees to prioritize it). This drives up the price of Token Y.
• Victim's Trade Executes
The victim's swap goes through at the now-inflated price, receiving fewer tokens than expected.
• Backrun (After the Victim)
The bot immediately sells Token Y at the higher price created by the victim's trade, profiting from the difference.
The bot profits from the artificial price pump, while the victim suffers worse execution (higher effective cost).
Example
• Pool price
1 ETH = 1000 TOKEN
• Victim wants to buy 1000 TOKEN with 1 ETH (expects ~1 ETH cost).
• Bot frontruns
Buys TOKEN, pushing price to 1 ETH = 900 TOKEN.
• Victim buys at worse rate (gets fewer TOKEN).
• Bot backruns
Sells at inflated price, netting profit (minus gas/swap fees).
Impacts
• On Users
Acts as an "invisible tax"—victims pay more or receive less without realizing.
• On Ecosystem
Increases slippage, reduces trust in DEXs, and contributes to centralization (sophisticated bots dominate).
• Scale
Billions in MEV extracted historically; sandwiching is one of the most common types.
How to Protect Against Sandwich Attacks
While not fully preventable due to blockchain transparency, risks can be minimized
• Low Slippage Tolerance
Set to 0.1-0.5%—limits how much price manipulation the bot can profit from (trade may fail if exceeded).
• Private Transactions/MEV Protection
· Use services like Flashbots Protect, MEV Blocker RPC, or wallets with built-in protection (e.g., Trust Wallet MEV features).
· Routes trades privately, bypassing public mempool.
• DEX Aggregators with Protection
Platforms like Matcha, 1inch, or CoW Swap often include anti-MEV routing.
• Split Large Trades
Break into smaller orders to reduce price impact.
• Avoid Peak Times
Trade during lower congestion to reduce visibility.
Long-term, upgrades like enshrined PBS (in Glamsterdam) aim to reduce harmful MEV. For now, awareness and tools are key defenses.
$BTC $ETH $BNB @Richard Teng @CZ @Yi He @BNB Chain @BNB Nepal @木匠Labs @BNBxyz @币安鹿队长丨官方年度最佳队长 @Binance Blog @Binance Customer Support @Binance Card @Qtum Network @Quant @QuarkChain @Quack AI Official @Quinten Francois @Quentin H @QAZAXLI3535 @Quiiii - Fast News #NasdaqTokenizedTradingProposal #TrumpFamilyCrypto #BTCVSGOLD #bnb #Binance