Rules › Anchor (Rust)

Unchecked arithmetic on amounts

lowAnchor (Rust)Rule anchor-unchecked-math

+, - and * on balances or amounts can overflow; prefer checked_add/checked_sub and return an error.

Why it matters

Even with overflow checks on, a panic is a poor failure mode, and with them off the math wraps. Using checked_add, checked_sub and checked_mul makes every amount calculation either succeed or return a clear error, and documents that the edge case was considered.

Vulnerable

vault.balance -= amount;

Fixed

vault.balance = vault.balance.checked_sub(amount).ok_or(VaultError::InsufficientFunds)?;

What other tools call it

ToolDetector or reference
Clippyarithmetic_side_effects

Check your code

Paste a contract into the in-browser checker, or let the Claude Code plugin scan before every deploy. The quick check for this rule is a pattern match: treat a hit as "look here", and a miss as no guarantee.

Static analysis finds known bug classes; it can't prove code is safe and isn't an audit. Get a professional audit before deploying code that will hold value.