Integer Overflow Explained in Detail
An integer overflow happens when a calculation exceeds the maximum value of its type. Solidity 0.8.x reverts on overflow by default, but unchecked blocks and older Solidity versions can still wrap.
Auditors should also review downcasts, fixed-point math, rounding, and decimal conversions, especially in DeFi accounting and ERC-4626 vaults.
Smart contract example
pragma solidity ^0.8.20;
contract Counter {
uint8 public count = 255;
function inc() external {
unchecked {
count += 1; // wraps to 0
}
}
}
Integer Overflow in Auditing
Classic overflow bugs are less common in modern Solidity, but arithmetic edge cases still break DeFi accounting, token limits, reward math, share conversions, and loop counters.
Red flags in code
-
Solidity version below
0.8.0. -
uncheckedblocks around user-controlled math. -
Narrow types such as
uint8,uint32, oruint128. -
Downcasts without range checks.
-
Multiplication before division in fixed-point math.
-
Token decimals, oracle decimals, and share decimals mixed together.
How to test or review it
-
Fuzz
0,1, max values, max minus one, and extreme token amounts. -
Test every
uncheckedblock with boundary inputs. -
Review explicit casts separately from arithmetic checks.
-
Check rounding direction for mint, redeem, borrow, repay, and liquidation math.
-
Verify scaling factors and decimals across tokens and oracles.
-
Add invariants for total supply, shares, reserves, and user balances.
Keep learning this topic
Price Manipulation
Price manipulation is the intentional movement of an asset, pool, share, or collateral price so a protocol values assets incorrectly.
Fuzz Testing
Fuzz testing sends many generated inputs through smart contract code to find edge cases, unexpected reverts, broken assumptions, and state transitions that normal unit tests miss.
Invariant Testing
Invariant testing checks that important smart contract properties stay true across many generated call sequences, actors, and state transitions.
Arithmetic Overflows Underflows
Arithmetic overflows and underflows in Solidity: how math bugs become exploits and how to prevent them with safe invariants and checks.
Smart Contract Audit Checklist
Use this SCH tool to turn the concept into practical audit work.
Practice this in real audit scenarios
Definitions help, but auditors need reps. SCH turns concepts like Integer Overflow into exploit labs, code review habits, and report-writing practice.
Start the free trial or see the full smart contract auditing course.