Solidity theorytheory 0/50 · 0%
Security · hard

44. MEV, front-running and slippage

Public mempools change how you design.

Pending transactions are visible, so a searcher can insert their own before or after yours. Swaps get sandwiched, liquidations get raced, and naive commit-then-act flows get stolen.

require(amountOut >= minOut, "slippage");
require(block.timestamp <= deadline, "expired");

Defend with user-supplied minimum outputs, deadlines, commit-reveal for sensitive ordering, and private transaction relays where appropriate.

Check your understanding

  1. 1. What is a sandwich attack?

  2. 2. Which parameter protects a swap?

  3. 3. Why add a deadline?