Bible Network Crypto DeFi Onchain RWA AI Agent Stablecoin CryptoTax DeFAI Chain SAFU AGI Claude Me Claude Skill Claude Cowork
Independent Media
Not affiliated with any project
DeFi × AI Convergence: Strategies, Projects & Risks, Decoded
defai-bible.com
LATEST
Three Risks to Understand Before You Try Your First DeFAI Product  ·  Is Your Session Key Over-Permissioned? Three One-Minute Checks  ·  Where DeFAI Agent Execution Actually Breaks: Delay Across Perceive, Decide, Act  ·  Anatomy of a DeFAI Project: The Three Things to Check, From Wallet Permissions to Execution Records
Glossary · MEV & Arbitrage

Sandwich Attack

MEV & Arbitrage intermediate

30-Second Version · For the impatient
An attack where the attacker inserts one transaction before and one after the victim's transaction, pushing the buy price up and the sell price down to profit — leaving the victim with a worse execution price than expected. One of the most common forms of MEV extraction.
Full Explanation +
01 · What is this?

What is a sandwich attack, and how does it differ from ordinary front-running?

A sandwich attack is a specific form of MEV (Miner/Maximal Extractable Value) extraction: the attacker spots a large decentralized exchange (DEX) transaction sitting in the mempool awaiting confirmation, predicts it will push the price in a particular direction, and front-runs it by submitting a same-direction transaction first (pushing the price up ahead of time). Once the victim's transaction executes at a worse price, the attacker immediately submits a reverse transaction to close the position and lock in profit. The victim's transaction ends up sandwiched between the attacker's two transactions — hence the name.

Ordinary front-running just means the attacker completes a same-direction trade ahead of the victim. A sandwich attack combines front-running with a follow-up close, requiring the attacker to execute two transactions within the same block (or an extremely short window) — a more well-defined technique with a more explicit profit mechanism.

02 · Why does it exist?

Why does the sandwich attack exist, and what mechanism makes it profitable?

The fundamental reason a sandwich attack is possible is that transactions on chains like Ethereum sit briefly in a public mempool before being packed into a block — anyone can see the contents of these unconfirmed transactions. This transparency (originally meant to let network nodes verify transactions) inadvertently lets attackers "see in advance" what someone is about to execute, and exploit the fact that block builders (miners or validators) prioritize transactions offering higher gas fees, cutting in line before and after the victim's transaction.

AMM (automated market maker) style DEX pricing also amplifies the problem — the larger the trade, the greater its slippage impact on price, meaning larger trades offer attackers more "juice" to extract. This is exactly why sandwich attacks tend to concentrate on large swap transactions.

03 · How does it affect your decisions?

How is a sandwich attack actually carried out, and what does an attacker need?

Attackers typically run an automated agent system that continuously monitors pending transactions in the mempool, using algorithms to determine in real time which transactions are worth attacking based on size and slippage tolerance (the more loosely a transaction's slippage tolerance is set, the more room there is to exploit). Once a suitable target is identified, the agent assembles two transactions simultaneously — the front-run and the back-run — and pays a higher gas fee than the victim's transaction to ensure its front-run gets prioritized by the block builder.

In recent years, as pure gas-fee-bidding front-running has become more expensive and easily outcompeted by other MEV bots, many attackers have shifted to using private transaction pool services (such as Flashbots-style infrastructure), negotiating transaction ordering directly with block builders instead of competing in the public mempool — making the attack stealthier and more reliably successful.

04 · What should you do?

What's the practical impact for everyday users, and how can they reduce their chances of being attacked?

If you get hit by a sandwich attack while executing a swap on a DEX, the practical impact is that your execution price ends up worse than expected — that difference becomes the attacker's profit directly, and the trading interface usually gives no indication that "this loss happened because of an attack," so it's easily mistaken for ordinary market slippage.

Practical ways to lower attack risk include: setting slippage tolerance as close to a reasonable range as possible (not setting it too wide just to avoid failed transactions), using a trading route with built-in MEV protection (such as routing through a private transaction pool to avoid exposure in the public mempool), and avoiding large swaps on thinly liquid trading pairs (the larger the slippage room, the easier it is to target). Most mainstream wallets and DEX front-ends now have some built-in MEV protection options — worth checking whether they're enabled before trading.

Real-World Example +

In 2023, a well-known sandwich-attack MEV bot was traced by on-chain analysts to a single-day exploit in which it sandwiched a whale user's large swap transaction, netting over $200,000 in profit from that one trade. The incident sparked extensive community discussion around mempool transparency and the need for wider adoption of private transaction pools.

Common Misconceptions +
✕ Misconception 1
× Misconception: sandwich attacks only happen on large trades, so small trades are safe, when actually: as long as slippage tolerance is set loosely enough, even small or mid-sized trades can be targeted — the attack threshold depends on the slippage room available, not simply the trade size
✕ Misconception 2
× Misconception: setting a gas fee higher than the market average will prevent a sandwich attack, when actually: attacker bots typically detect the mempool in real time and dynamically bid even higher gas prices to front-run — simply raising gas fees doesn't fundamentally stop the attack; what actually works is lowering slippage tolerance or using a private transaction pool
The Missing Link +
Direct Impact

From the attacker's perspective, the advantage is being able to profit consistently from transaction information asymmetry without needing large capital; from an ordinary user's perspective, the drawback is that the actual execution price can be significantly worse than expected, and the loss is often mistaken for plain market slippage and goes unnoticed unless additional precautions (tighter slippage, private transaction pools) are taken.

Ask a Question
Please enter at least 10 characters
More Related Topics