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
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?
A website display alone cannot constrain contract execution.