EIPs Explained

EIP-3338 · Withdrawn · Core · 2021-03-07

EIP-3338: Limit account nonce to 2^52

A withdrawn proposal to cap account nonces at 2^52 so they fit in compact encodings and float64; it was dropped in favour of the 2^64-1 limit in EIP-2681.

What problem does it solve?

In the original protocol an account nonce is an arbitrarily large unsigned integer. That is awkward in a few places:

  • State proofs and witnesses have to handle variable-length data instead of a compact fixed-size field.
  • Some transaction-format proposals wanted a bounded nonce.
  • Clients store nonces as 256-bit numbers when 64 bits would do.

ERC-3338 proposed a hard upper bound to clean this up. It picked 2^52 specifically because every integer up to 2^52 can be represented exactly in a 64-bit floating-point number, which helps languages such as JavaScript that only have floats.

How it works

After a fork block, two rules would apply:

  1. Any transaction whose nonce exceeds 2^52 is invalid.
  2. CREATE aborts with an exceptional halt if the creating account's nonce is 2^52.

The spec argues no one would ever hit the limit in practice. Sending enough transactions to reach even a 64-bit limit would cost an absurd amount of gas, and at the time of writing the highest nonce on mainnet was about 29 million.

It also notes that the old Morden testnet started account nonces at 2^20 as a crude form of replay protection, an approach made obsolete by chain IDs in EIP-155.

Sample code

Pseudocode for the proposed checks:

MAX_NONCE = 2**52

def validate_transaction(tx, state):
    if tx.nonce > MAX_NONCE:
        raise InvalidTransaction("nonce too high")
    ...

def op_create(evm, sender):
    if state.get_nonce(sender) == MAX_NONCE:
        raise ExceptionalHalt("nonce limit")
    ...

Why 2^52 was attractive for JavaScript:

console.log(Number.isSafeInteger(2 ** 52));   // true
console.log(Number.MAX_SAFE_INTEGER);         // 9007199254740991 (2^53 - 1)

Things to know

  • Status is Withdrawn. The authors withdrew it in favour of EIP-2681, which limits nonces to 2^64 - 1 instead.
  • The 2^64-1 limit matches what clients such as go-ethereum already did internally, so it achieves the compactness goal without the float-specific bound.
  • If you need to handle nonces in JavaScript, use bigint rather than relying on any float-safe ceiling.

#nonce #core #state #withdrawn

Details

Authors
Micah Zoltu (@MicahZoltu), Alex Beregszaszi (@axic)
Status
Withdrawn
Type
Standards Track / Core
Created
2021-03-07

Machine-readable: Markdown · JSON