Tautological Compare Remediation
Overview
Related Detector: Tautological Compare
A condition whose result is fixed by type — uint >= 0 (always true), uint < 0 (always false) — provides no protection. It usually means the author intended a meaningful bound (> 0, >= minAmount) but wrote something the compiler can constant-fold. The remediation is to replace the tautology with the check that was actually intended.
Recommended Fix
Before (Vulnerable)
function deposit(uint256 amount) external {
require(amount >= 0, "Invalid amount"); // always true — zero-value deposits slip through
_credit(msg.sender, amount);
}
After (Fixed — the intended bound)
function deposit(uint256 amount) external {
require(amount > 0, "Amount must be positive"); // real check
_credit(msg.sender, amount);
}
Trace what the guard was protecting: a minimum size, a non-zero requirement, or a real upper bound — then encode that.
Common Mistakes
- “Fixing”
amount >= 0toamount != 0when the intent was actually a minimum threshold (>= minAmount). - Leaving a signed/unsigned confusion in place, where the impossible branch hides a real edge case.
- Removing the check entirely instead of replacing it, dropping validation the function needs.