In this track: Smart contract security foundations
advanced · 4 MIN READ

Slippage and sandwich attacks

Transaction ordering can worsen an execution price.

LET’S PICTURE IT

A buyer’s order can be surrounded by other trades that move the quoted price.

SEE IT FOR YOURSELF
A transaction moves from Maya’s wallet through signing, node verification, peer sharing, a mempool, block inclusion and finality. Maya’s instructionTOLeo’s public addressAMOUNT0.01 ETHPretend transactionFirst, the wallet prepares a request. Maya’s walletSignature added ✓Private key stays in wallet 🔒Signed request WalletSigned requestNode AChecks ✓Node BChecks ✓Node CChecks ✓Node DChecks ✓NODE C’S LOCAL MEMPOOLVerify.Then share. Pending requestsProposed blockMaya → Leo · 0.01A proposer includes it. Nodes check the result. BlockIncludedCheckpointAgreementFinalizedValidator checkpoint votes support finality.Simplified model · not one vote per transaction
Illustration · no network calls
Prepare
→
Sign
→
Share
→
Include
→
Finalize

Maya prepares an instruction: send 0.01 pretend ETH to Leo.

A local simulation. Nothing is signed or sent to a network.

Distinguish quote and execution

A displayed quote reflects particular state. Trades included before the user’s transaction can change the actual execution result.

Enforce an acceptable bound

A minimum output or maximum input constrains what the contract may accept. The bound must be part of the on-chain action rather than only a UI preference.

Understand the ordering risk

A sandwich places trades around a user’s swap to exploit price movement and the user’s allowed tolerance. Conditions and profitability depend on the market and execution environment.

Avoid false guarantees

Tighter limits and execution strategies involve tradeoffs such as more failed transactions. No simple UI setting guarantees fair ordering or removes every form of MEV.

Reason about the scenario

quoted output: 100 toy units
minimum accepted output: 98
execution below 98 → reject under the intended swap rule

Pseudocode or a simplified scenario for local reasoning. This is not a production contract or a completed security review.

QUICK CHECK · NO PRESSURE

Must a minimum-output constraint be enforced on-chain to bind execution?

Your progress stays in this browser.
Keep exploring the original referenceSolidity documentation ↗

Original explanations by EtherTools. Examples are educational and source-linked; this site is independent of the Ethereum Foundation. Our approach.