agentleFS
iktok90-designiktok90-design/ai-smart-contract-auditor/skills/integer-issues/SKILL.md

integer-issues

Skill36 starsChanged 5 months agoMITView on GitHub

Detect integer over/underflow in `unchecked` blocks, downcasting losses, fixed-point precision errors, division-before-multiplication, signed/unsigned mixing. Activate on any arithmetic in `unchecked { }`, `SafeCast`, `uintN(uintM(x))` casts, division and modulo, percentage/basis-points math, AMM share/asset math.

The file

We split this skill into the rules it gives an agent

1 rule. About 0 are common, 1 is distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Always scale to a common decimal base before doing math.

    line 88

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Integer issues detection

When this applies

  • unchecked { … } blocks (Solidity ≥0.8)
  • Downcasts: uint128(x), int256(uint256(x)), uint8(...)
  • Division and modulo
  • Fixed-point math with custom decimal scales
  • Share/asset math in vaults, lending, AMMs
  • Pre-0.8 Solidity code (no built-in overflow checks)
  • Vyper code with unbounded loops
  • Inline assembly arithmetic

Detection patterns

Unchecked overflow on user input (HIGH)

unchecked {
    balance[to] += amount;        // ← if amount controlled, can overflow back to 0
}

unchecked is fine for proven-safe accumulators (e.g. ++i in bounded loops), not for value math.

Division before multiplication (HIGH)

uint256 fee = (amount / 100) * feeBps;   // ← truncation; do (amount * feeBps) / 100

Decimal mismatch (HIGH)

USDC = 6 decimals, WETH = 18, WBTC = 8. Mixing without scaling produces silent 1e10–1e12 errors.

uint256 wethValue = amountUsdc * price;   // ← USDC 6dp × price 8dp = 14dp, need 18dp

Downcast loss (HIGH)

uint128 sharesU128 = uint128(shares);   // ← silently truncates if shares > 2^128

Use OZ SafeCast.

Fixed-point precision loss (HIGH)

Compounding interest done as principal * (1 + rate)^t with too-few-decimal rate. Use ray (1e27) or wad (1e18) math via PRBMath / Solady.

Round-direction asymmetry (HIGH for vaults)

ERC-4626 must round shares down on deposit (favor vault) and up on withdraw (favor vault). Reversed direction = donations-style drain. Use OZ Math.mulDiv(_, _, _, Rounding.Down/Up).

Signed/unsigned mixing (HIGH)

int256 delta = int256(a) - int256(b);   // a or b might be > 2^255, becomes negative silently

Modulo zero (revert, but…) (MEDIUM-HIGH if attacker can set divisor=0)

Block-time math on L2 (MEDIUM)

block.timestamp granularity differs (2s on Optimism, 250ms on Arbitrum). Slot-based deadlines can be off.

Sqrt / log integer approximations (MEDIUM)

Custom sqrt implementations are notorious. Use Solady/PRBMath.

Percentage in basis points without bounds (LOW)

fee_bps should be capped (fee_bps <= 10_000).

Severity rubric

PatternSeverity
Unchecked overflow on user inputHigh
ERC-4626 round-direction wrongHigh
Decimal-mismatch in price/balance mathHigh
Downcast losing high bits silentlyHigh
Division before multiplication on financial-critical pathHigh
Custom sqrt/log without overflow proofMedium
Bps fee with no capLow
Loop index underflow in pre-0.8 codeHigh
Modulo-zero on attacker-controlled divisorHigh

Remediation patterns

  • Solidity 0.8.x default checks; only unchecked proven-safe (e.g. ++i in for loops bounded by array length).
  • OZ SafeCast for downcasts.
  • Math.mulDiv (OZ) for multiply-then-divide without intermediate overflow.
  • PRBMath or Solady for fixed-point exp/log/pow.
  • Always scale to a common decimal base before doing math; document the scale.
  • ERC-4626: always use Math.mulDiv(..., Rounding.Down) on deposits, Rounding.Up on withdrawals; or use OZ's ERC4626Upgradeable which handles this.

False-positive notes

  • unchecked { ++i; } in for loops with i < arr.length is the canonical safe use — not a finding.
  • Pre-0.8 SafeMath is fine; the issue is mixed-version dependencies.

Related

  • [[token-compatibility]] — decimals confusion
  • [[oracle-manipulation]] — price scaling
  • [[yield-aggregator-specialist]] — ERC-4626 round direction

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.