Missing Deadline Remediation
Overview
Related Detector: Missing Deadline
A transaction can sit in the mempool for a long time before a validator includes it. For price-sensitive operations — swaps, liquidity provision, mints priced off a curve — a stale execution can settle at a price the user would never have accepted. A deadline lets the user cap how long their signed intent remains valid. Omitting it, or hard-coding block.timestamp or type(uint256).max, removes that protection.
Recommended Fix
Before (Vulnerable)
function swap(uint256 amountIn, uint256 minOut) external {
// No deadline: this can be mined hours later at a much worse price,
// still passing the (now stale) minOut chosen when the tx was signed.
_swap(amountIn, minOut);
}
After (Fixed — enforce a real, caller-supplied deadline)
error DeadlinePassed();
function swap(uint256 amountIn, uint256 minOut, uint256 deadline) external {
if (block.timestamp > deadline) revert DeadlinePassed();
_swap(amountIn, minOut);
}
The caller (or the front end) sets deadline to a short window — often a few minutes. Combined with a meaningful minOut slippage bound, this ensures the trade either executes near the intended price or reverts.
Common Mistakes
- Accepting a
deadlineparameter but passingblock.timestampfrom within the contract, which makes the check always pass. - Setting the front-end default to
type(uint256).max, which disables the protection while appearing to support it. - Relying on the deadline alone without a
minAmountOut; the deadline bounds time, not price.