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: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
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)
- 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:Implementation
- TypeScript
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:- User with balance 5 transfers amount = 10
balances[msg.sender] -= 10wraps to MAX_UINT256- Attacker now has infinite tokens
Safe Patterns
Check-Effects-Interactions: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+
- 3 gas per 256-bit addition
- ~0.33 million additions per million gas
- Highly optimized in all EVM implementations
References
- Yellow Paper - Section 9.1 (Arithmetic Operations)
- EVM Codes - ADD
- Solidity Docs - Checked vs Unchecked
- SWC-101: Integer Overflow and Underflow

