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.
In this repository44 other files it gives its agents.
- access-controlSkill
- approval-issuesSkill
- caching-and-incrementalSkill
- centralization-riskSkill
- confidence-scoringSkill
- cosmwasmSkill
- cross-chain-messagingSkill
- cross-contract-stateSkill
- delegatecall-risksSkill
- diamond-eip2535Skill
- dos-vectorsSkill
- erc1271-contract-signaturesSkill
- erc4337-account-abstractionSkill
- erc4626-inflationSkill
- false-positive-feedback-loopSkill
- fee-on-transferSkill
- flash-loan-attacksSkill
- initializationSkill
- inline-assemblySkill
- intents-erc7683Skill
- known-good-comparisonSkill
- liquidation-cascadeSkill
- mev-frontrunningSkill
- mev-pbsSkill
- multi-pass-self-critiqueSkill
- oracle-manipulationSkill
- oracle-redundancySkill
- permit2-patternsSkill
- pragma-and-addressesSkill
- progress-and-streamingSkill
- reentrancySkill
- restaking-eigenlayerSkill
- selfdestruct-eip6780Skill
- signature-malleabilitySkill
- signature-replaySkill
- solana-anchorSkill
- storage-layoutSkill
- stylus-rustSkill
- token-compatibilitySkill
- tx-context-misuseSkill
- unchecked-callsSkill
- ve-lock-governanceSkill
- vyper-specificSkill
- zk-verifier-bugsSkill
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
- Distinctive: line 88
Always scale to a common decimal base before doing math.
≈ “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.
Files
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) / 100Decimal 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 18dpDowncast loss (HIGH)
uint128 sharesU128 = uint128(shares); // ← silently truncates if shares > 2^128Use 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 silentlyModulo 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
| Pattern | Severity |
| Unchecked overflow on user input | High |
| ERC-4626 round-direction wrong | High |
| Decimal-mismatch in price/balance math | High |
| Downcast losing high bits silently | High |
| Division before multiplication on financial-critical path | High |
| Custom sqrt/log without overflow proof | Medium |
| Bps fee with no cap | Low |
| Loop index underflow in pre-0.8 code | High |
| Modulo-zero on attacker-controlled divisor | High |
Remediation patterns
- Solidity 0.8.x default checks; only
uncheckedproven-safe (e.g.++iinforloops bounded by array length). - OZ
SafeCastfor 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.Upon withdrawals; or use OZ'sERC4626Upgradeablewhich handles this.
False-positive notes
unchecked { ++i; }inforloops withi < arr.lengthis 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
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
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.

