Integer Underflow
1 min read
Pronunciation
[in-tuh-jer un-der-floh]
Analogy
Integer underflow is like a countdown timer going below zero and wrapping to the highest value.
Definition
A vulnerability where subtracting below zero wraps the value to the maximum of the data type.
Key Points Intro
Underflows happen via fixed‑width subtraction through:
Key Points
Wrapping behavior: Negative results modulo 2ⁿ.
Unchecked operations: Pre‑0.8 Solidity allowed wrap.
Balance manipulation: Can inflate values unexpectedly.
Mitigation: Built‑in checks or SafeMath subtraction.
Example
```
uint8 x = 0;
x -= 1; // x becomes 255 in older Solidity
```
Technical Deep Dive
Security Warning
Underflow can be exploited to set large balances or bypass limits—always enable compiler checks.
Caveat
Unchecked contexts reintroduce underflow risk; audit `unchecked` usage carefully.
Integer Underflow - Related Articles
No related articles for this term.