EIP-1985 Safe ranges for EVM parameters (Sane limits for certain EVM parameters)

No call decision · EVM & execution · EIP status Stagnant · created 2018-08-01

A proposal to set explicit upper and lower bounds on values the EVM handles, such as gas, block number, timestamp, addresses, and various size fields, excluding unrealistic extreme values from the specification.

Why it is needed

The EVM specification theoretically allows values such as gas, gas limit, block number, timestamp, addresses, and buffer/code/memory sizes to be expressed across the full 256-bit range. In practice, however, constraints such as the block gas limit prevent these values from growing that large. If this implicit limit is not stated explicitly in the specification, clients may end up using different internal data types (32-bit, 64-bit, 256-bit, etc.), and building consensus-critical test cases must needlessly account for extreme values that can never occur in reality. Explicitly specifying the ranges can unify client implementations, simplify certain operations, and reduce unrealistic test cases.

What changes

Today

After EIP-1985

Who is affected

In depth

Gas and gas limit range

The values the GASLIMIT (0x45) and GAS (0x5a) instructions push onto the stack are restricted to between 0 and 0x7fffffffffffffff (2^63-1, 9223372036854775807). This range applies to gas, gas limit, and block gas limit alike, and after FORK_BLOCK no result outside this range can occur.

Block number and timestamp range

The block timestamp and block number returned by the TIMESTAMP (0x42) and NUMBER (0x43) instructions are likewise restricted to the same range of 0 to 2^63-1. The Yellow Paper defines the timestamp as a reasonable value that Unix time() would plausibly return when this block is created, but the original text notes that the exact implementation is defined differently across implementations even within the POSIX.1 standard, which is why an explicit upper bound is set.

Account address range

The address values returned by the ADDRESS (0x30), ORIGIN (0x32), CALLER (0x33), COINBASE (0x41), CREATE (0xf0), and CREATE2 (0xf5) instructions must be between 0 and 2^160-1, meaning only the lower 160 bits of the 256-bit value are used and the upper 96 bits must always be 0. This pins down as an explicit range what the Yellow Paper already defines as a 20-byte address size.

Buffer, code, and memory size range

The values returned by the CALLDATASIZE (0x36), CODESIZE (0x38), EXTCODESIZE (0x3b), RETURNDATASIZE (0x3d), MSIZE (0x59), and PC (0x58) instructions are restricted to between 0 and 0xffffffff (2^32-1, 4294967295). EIP-170 already limits code size to 0x6000, and even before that, deploying code exceeding 2^32-1 bytes was not realistically possible.

Why 2^63-1 is used

The constant 2^63-1 has the advantage of being representable as a signed 64-bit integer. It is easy to handle even in programming languages that lack unsigned types, and it allows an out-of-gas check to be expressed as a simple comparison such as gas_counter < 0. This range was first proposed by EVMC, and some clients including Aleth, geth, Parity, and ethereumjs have already partially implemented it.

Relationship between memory expansion cost and the upper bound

Memory expansion cost is a non-linear cost calculated as cost_per_word * number_of_words + (number_of_words^2 / 512). Expanding memory to 2^32-1 bytes would cost 35184774742016 gas, which at 1 Gwei per gas requires about 35184 ETH, a level that is achievable on mainnet. Nevertheless, the authors believe it is more desirable from a VM design standpoint to let the block gas limit regulate memory usage rather than directly capping memory size at 2^32-1.

Status and open issues

This EIP's status is Stagnant: it has not yet been included in a fork or activated, and it may still change or be abandoned. The specification itself leaves open, as a TODO item, whether this gas limit also applies to the gas argument of CALL-type instructions, and the Test Cases and Implementation sections remain TBA (to be announced).

Original EIP · ← EIPs