EIPs Explained

EIP-4803 · Stagnant · Core · 2022-02-02

EIP-4803: Limit transaction gas to a maximum of 2^63-1

Proposed making any transaction with a gas limit above 2^63-1 invalid, retroactively from genesis, so the consensus rules match the 64-bit gas handling clients already use.

What problem does it solve?

A transaction's gasLimit field is RLP-encoded, so in principle it can be an arbitrarily large integer. Real clients do not work that way: most cap it at 256 bits, and clients such as geth handle gas internally as a 64-bit number. That mismatch between "what the spec allows" and "what clients can represent" is a latent source of consensus edge cases.

EIP-4803 proposed writing a reasonable upper bound into consensus.

How it works

One rule, applied retroactively from genesis:

A transaction whose gas limit exceeds 2^63 - 1 is invalid and cannot be included in a block.

Why 2^63 - 1 and not 2^64 - 1? It fits in a signed 64-bit integer, so an implementation can subtract gas and detect "out of gas" with a simple remaining < 0 check.

The spec also considered 2^31 - 1, which is easy to handle in JavaScript, but chose the 64-bit-friendly bound.

Applying it from genesis is safe because no historical transaction could have exceeded it: every transaction must fit in its block's gas limit, and the block gas limit can only change slowly, so it has never come anywhere near 2^63.

Sample code

The validity check a client would add:

MAX_TX_GAS = 2**63 - 1  # 9_223_372_036_854_775_807

def validate_gas_limit(tx) -> None:
    if tx.gas_limit > MAX_TX_GAS:
        raise InvalidTransaction("gas limit exceeds 2^63-1")

The same bound in Go, where it is simply math.MaxInt64:

import "math"

func validGasLimit(gas uint64) bool {
    return gas <= math.MaxInt64
}

Things to know

  • Status is Stagnant: the rule was not adopted through this EIP.
  • The spec expects no visible effect on the chain: it only formalizes a limit that real blocks already respect.
  • A much lower per-transaction gas cap was later introduced by EIP-7825, for different reasons (bounding the cost of a single transaction).
  • JavaScript numbers are only exact up to 2^53 - 1, so tooling that handles gas values near this bound should use bigint, not number.
  • Before EIP-1559 a zero gas price let gasLimit * gasPrice stay within any balance, but the block gas limit still kept historical values small.

#gas #transactions #consensus #core

Details

Authors
Alex Beregszaszi (@axic)
Status
Stagnant
Type
Standards Track / Core
Created
2022-02-02
Required by

Machine-readable: Markdown · JSON