EIPs Explained

EIP-8219 · Draft · Core · 2026-04-08

EIP-8219: Checked Arithmetic Opcodes

Proposes four EVM opcodes (SAFEADD, SAFESUB, SAFEMUL, SAFEDIV) that revert on overflow, underflow or division by zero, so the checked arithmetic Solidity and Vyper already emit costs a single instruction instead of a long check sequence.

What problem does it solve?

Since Solidity 0.8, and in Vyper from the start, every a + b on a uint256 is checked: if it overflows, the transaction reverts. The EVM has no native support for this, so compilers wrap each operation in several extra instructions and jumps. The author's benchmark on an ERC-20 transfer measured about 79 gas for one checked addition in Solidity (about 41 in Vyper), versus 3 gas for a raw ADD.

That overhead tempts developers to use unchecked { } or unsafe_add() to save gas, sometimes where it is not actually safe. EIP-8219 aims to make safety cheap enough that there is no reason to opt out.

How it works

Four new opcodes fill the unused slots right after the existing arithmetic group:

Opcode Name Gas Reverts when
0x0c SAFEADD 5 a + b exceeds 2²⁵⁶ − 1
0x0d SAFESUB 5 b > a (result would be negative)
0x0e SAFEMUL 7 a ≠ 0 and a × b exceeds 2²⁵⁶ − 1
0x0f SAFEDIV 7 b == 0
  • Stack order matches ADD/SUB/MUL/DIV: a on top, b below, result a op b.
  • On error the current call frame reverts with empty returndata, exactly like REVERT(0, 0). It does not consume all remaining gas the way an invalid opcode would, which matters for normal guard paths such as slippage checks.
  • Each opcode is stateless. Earlier proposals (EIP-1051, EIP-6888) used overflow/carry flags that must be read and branched on afterward; this design avoids hidden state and the risk of a flag being silently overwritten.
  • Only unsigned 256-bit arithmetic is covered. Signed variants are left to a separate EIP.

Sample code

Checked addition today versus with SAFEADD (EVM assembly, simplified):

; today: roughly what a compiler emits for a checked add
DUP2 DUP2 ADD          ; a+b
DUP1 DUP3 GT           ; overflow if a > a+b
PUSH2 <panic> JUMPI
SWAP2 POP POP

; with EIP-8219
SAFEADD                ; 0x0c - pushes a+b or reverts(0,0)

Reference semantics, matching the spec's pseudocode:

MAX = 2**256 - 1

def safeadd(a, b):
    r = (a + b) & MAX
    if r < a: raise Revert(b"")
    return r

def safesub(a, b):
    if b > a: raise Revert(b"")
    return a - b

def safemul(a, b):
    if a == 0: return 0
    r = (a * b) & MAX
    if r // a != b: raise Revert(b"")
    return r

def safediv(a, b):
    if b == 0: raise Revert(b"")
    return a // b

Things to know

  • Status: Draft. No fork is scheduled (FORK_BLOCK is TBD), and compilers would only use the opcodes when targeting an EVM version that has them.
  • Existing ADD, SUB, MUL and DIV are unchanged. Code compiled for older EVM versions behaves the same.
  • Solidity today reverts with Panic(0x11) on overflow. These opcodes return empty data instead, so tools that decode the panic code would see a different revert payload.
  • The gas figures quoted come from the author's benchmarks with specific compiler versions; real savings depend on the compiler and code.

#evm #opcodes #arithmetic #gas #core

Details

Authors
Hubert Ritzdorf (@ritzdorf)
Status
Draft
Type
Standards Track / Core
Created
2026-04-08

Machine-readable: Markdown · JSON