Blockchain & Cryptocurrency Glossary

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

  • search-icon Clear Definitions
  • search-icon Practical
  • search-icon Technical
  • search-icon Related Terms

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
EVM `SUB` opcode wraps on underflow. Solidity ≥0.8 inserts a check that reverts on underflow. Developers can use `unchecked` blocks to skip checks when safe.
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.