SKIP TO CONTENT
Security

Integer Overflow

A vulnerability where arithmetic operations exceed maximum values, causing numbers to wrap around to zero.

What is Integer Overflow?

Integer overflow is a critical vulnerability in smart contracts that occurs when an arithmetic operation attempts to create a number larger than the maximum value the data type can hold. In Solidity, this historically caused the number to wrap around to zero, enabling attackers to manipulate token balances and bypass security checks.

How it Works

Computers store numbers in fixed-size containers. A uint256 in Solidity can hold values from 0 to 2^256-1. When a calculation exceeds this maximum, older Solidity versions would silently wrap the result back to zero. For example, adding 1 to the maximum uint256 value would result in 0, not an error.

The technical mechanics involve:

  1. An arithmetic operation produces a result exceeding the type's maximum
  2. The result wraps around modulo 2^256
  3. The contract continues execution with the incorrect value
  4. Attackers exploit this to bypass balance checks or mint excess tokens

Practical Example

The Beauty Chain (BEC) token exploit in 2018 demonstrated this vulnerability dramatically. Attackers exploited an integer overflow in the batch transfer function to create an astronomical number of tokens from nothing. By carefully crafting input parameters, they made the multiplication overflow, allowing them to transfer more tokens than existed. The attack crashed the token's value to zero instantly.

Why it Matters

Since Solidity 0.8.0, arithmetic operations automatically revert on overflow and underflow, significantly reducing this risk. However, many legacy contracts still run on older versions, and developers can still disable these protections using unchecked blocks for gas optimization. Understanding integer overflow remains crucial for auditing older contracts and reviewing code that uses unchecked arithmetic.

Fensory surfaces protocol information including audit status and contract versions, helping users avoid legacy contracts that may contain unpatched integer overflow vulnerabilities.

Examples

  • Beauty Chain (BEC) token crashed to zero after an integer overflow exploit in 2018
  • Several ERC-20 tokens were vulnerable to batchOverflow attacks

From definition to application. Explore real opportunities.

Track live yields, compare protocols, and build your DeFi portfolio with Fensory.

GET EARLY ACCESSArrow right