Raw word arithmetic wraps modulo two to the power of 256.
LET’S PICTURE IT
A fixed-width counter returns to zero after reaching its largest representable value.
SEE IT FOR YOURSELF
Watch a stack machine execute a tiny programStep 1 / 4
The program bytes are PUSH1 02, PUSH1 03, ADD, STOP. The program counter begins at byte zero.
The program bytes are PUSH1 02, PUSH1 03, ADD, STOP. The program counter begins at byte zero.PUSH1 reads its next byte as an immediate value and places two on the stack. The next instruction begins at byte two.The next PUSH1 places three above two. Stack order matters for operations that are not commutative.ADD consumes the top two values and pushes five. The next instruction is STOP at byte five; no storage write is implied by ADD.
Animated local teaching model. No wallet, RPC or live blockchain data. Some labels and hashes are abbreviated for readability.
Distinguish raw opcodes from language checks
EVM ADD and MUL operate on fixed-width words. Solidity can compile additional checks around arithmetic, so checked Solidity behavior is not simply the raw opcode alone.
Apply the modulus
Adding one to the largest 256-bit unsigned word produces zero under raw ADD. Multiplication also retains the result modulo 2²⁵⁶.
Track consumed values
ADD consumes two stack items and pushes one result. A trace must remove the operands instead of leaving them beside the result.
Use wider reasoning where required
ADDMOD and MULMOD have distinct semantics for a supplied modulus. Do not reproduce them by wrapping ordinary ADD or MUL first and then applying that modulus.