Skip to main content
This page is a placeholder. All examples on this page are currently AI-generated and are not correct. This documentation will be completed in the future with accurate, tested examples.

Overview

Opcode: 0x01 Introduced: Frontier (EVM genesis) ADD performs addition on two 256-bit unsigned integers with wrapping overflow semantics. When the result exceeds 2^256 - 1, it wraps around modulo 2^256, matching hardware integer register behavior. This is the most fundamental arithmetic operation in the EVM, used extensively in array indexing, counter increments, and numeric calculations.

Specification

Stack Input:
Stack Output:
Gas Cost: 3 (GasFastestStep) Operation:

Behavior

ADD pops two values from the stack, adds them, and pushes the result back. Overflow wraps around without throwing exceptions:
  • If a + b < 2^256: Result is the mathematical sum
  • If a + b >= 2^256: Result is (a + b) mod 2^256
No exceptions are thrown for overflow. The result always fits in 256 bits.

Examples

Basic Addition

Overflow Wrapping

Large Overflow

Identity Element

Commutative Property

Gas Cost

Cost: 3 gas (GasFastestStep) ADD is one of the cheapest operations in the EVM, sharing the lowest gas tier with:
  • SUB (0x03)
  • NOT (0x19)
  • ISZERO (0x15)
  • LT, GT, SLT, SGT, EQ (comparison ops)
Comparison:
  • ADD/SUB: 3 gas
  • MUL/DIV/MOD: 5 gas
  • ADDMOD/MULMOD: 8 gas
  • EXP: 10 + 50 per byte of exponent

Edge Cases

Maximum Overflow

Zero Addition

Stack Underflow

Out of Gas

Common Usage

Array Index Calculation

Counter Increments

Memory Pointer Arithmetic

Safe vs Unchecked

Pre-Solidity 0.8.0:
Solidity 0.8.0+:

Implementation

Testing

Test Coverage

Edge Cases Tested

  • Basic addition (5 + 10 = 15)
  • Overflow wrapping (MAX + 1 = 0)
  • Large overflow (MAX + MAX)
  • Zero addition (0 + 0 = 0, 42 + 0 = 42)
  • Stack underflow (< 2 items)
  • Out of gas (< 3 gas)
  • Commutative property (a + b = b + a)

Security

Overflow Vulnerabilities

Before Solidity 0.8.0:
Attack scenario:
  • User with balance 5 transfers amount = 10
  • balances[msg.sender] -= 10 wraps to MAX_UINT256
  • Attacker now has infinite tokens
Mitigation (pre-0.8.0):
Modern Solidity (0.8.0+):

Safe Patterns

Check-Effects-Interactions:
Explicit Bounds Checking:

Benchmarks

ADD is one of the fastest EVM operations: Execution time (relative):
  • ADD: 1.0x (baseline)
  • MUL: 1.2x
  • DIV: 2.5x
  • ADDMOD: 3.0x
  • EXP: 10x+
Gas efficiency:
  • 3 gas per 256-bit addition
  • ~0.33 million additions per million gas
  • Highly optimized in all EVM implementations

References