Skip to content

Swap Without Slippage Protection (minAmountOut = 0)

SAFE-0104 MEV / Ordering Checked automatically by the scanner
1

What goes wrong

A router swap is executed with an amountOutMin of 0 (or no minimum at all). Any searcher can sandwich the transaction: buy before it, let it execute at a worse price, and sell after, extracting the difference from the user.

2

The vulnerable pattern

proof of concept — how it is exploited
// Mempool sandwich
// 1. front-run: attacker buys, pushing price up
// 2. victim swap runs with amountOutMin = 0, fills at the inflated price
// 3. back-run: attacker sells, pocketing the spread (victim eats the loss)
3

How to fix it

the pattern that is safe
uint256 minOut = quote * (10000 - slippageBps) / 10000;
router.swapExactTokensForTokens(amountIn, minOut, path, to, deadline);
Never pass 0 as amountOutMin; compute it from an off-chain quote.
Check your own contract for this

The SaferICO scanner runs 201 detectors over your Solidity source, SAFE-0104 among them. Paste an address or the source itself — a small per-scan fee, shown before you sign, or unlimited on any plan.

Run the scanner See how it is attacked Read the docs