EIPs Explained

EIP-7676 · Stagnant · Core · 2024-04-03

EIP-7676: EOF - Prepare for Address Space Extension

Makes EOF contracts reject addresses with non-zero upper 12 bytes instead of silently trimming them, leaving room for a future move from 20-byte to 32-byte addresses.

What problem does it solve?

EVM addresses are 20 bytes, but stack words are 32 bytes. When a legacy opcode such as BALANCE or CALL takes an address from the stack, it quietly throws away the top 12 bytes and uses only the low 20. Reference tests even check for this behaviour.

That masking is a roadblock for any plan to widen addresses to 32 bytes (ideas like "address space extension" for state expiry). If old code already treats 0xFFFF…<20 bytes> as the same account as 0x0000…<20 bytes>, you cannot later give the upper bytes a meaning without changing what existing contracts do.

The EVM Object Format (EOF, EIP-3540) is a fresh container format, so it can bake in stricter rules from day one without breaking legacy contracts. This EIP does exactly that for address operands.

How it works

Most address-taking opcodes are already gone or replaced in EOF: EXTCODESIZE, EXTCODECOPY, EXTCODEHASH, CALLCODE and SELFDESTRUCT are banned, and the call family is replaced by EXTCALL, EXTDELEGATECALL and EXTSTATICCALL (EIP-7069). The remaining gap is BALANCE.

The proposal:

  • Adds EXTBALANCE (opcode number still "tbd" in the spec). It pops an address and pushes that account's balance. Gas follows the EIP-2929 BALANCE schedule: 2600 for a cold address (which is then added to accessed_addresses), 100 for a warm one.
  • Halts on dirty addresses. If any of the high 12 bytes of the operand are non-zero, EXTBALANCE causes an exceptional halt that consumes all gas in the frame.
  • Adds the same check to EXTCALL, EXTDELEGATECALL, EXTSTATICCALL, performed just before the memory expansion check.

The legacy BALANCE opcode is left alone, so it behaves identically in legacy and EOF code. The spec rejects the alternative of treating dirty addresses as "empty accounts", because that would force clients to track 256-bit addresses in the access list and could strand ETH sent to unreachable accounts.

Sample code

Illustrative behaviour (pseudocode for the new address check):

def check_address(operand: int) -> int:
    # operand is a 256-bit stack word
    if operand >> 160 != 0:
        raise ExceptionalHalt  # all remaining gas in the frame is consumed
    return operand            # no masking: the value is used as-is

# EXTBALANCE
addr = check_address(stack.pop())
charge_gas(100 if addr in accessed_addresses else 2600)
accessed_addresses.add(addr)
stack.push(state.get_balance(addr))

Compilers are expected to clean addresses that come from calldata before using them, the way Solidity already does for the address type:

// Solidity masks to 160 bits when decoding an `address` parameter,
// so `who` can never carry dirty upper bytes into EXTBALANCE / EXTCALL.
function balanceOfAccount(address who) external view returns (uint256) {
    return who.balance;
}

Things to know

  • Status: Stagnant. No work has happened on it recently, and the opcode number was never assigned.
  • It depends entirely on EOF (EIP-3540, EIP-3670, EIP-7069); it has no effect on legacy contracts.
  • The halt is meant as a placeholder. The spec says future address-extension EIPs will likely change it, so contracts should not rely on the halt.
  • Old contracts would keep working but may never be able to talk to addresses in an extended space.

#eof #evm #addresses #opcodes #core

Details

Authors
Danno Ferrin (@shemnon)
Status
Stagnant
Type
Standards Track / Core
Created
2024-04-03
Requires

Machine-readable: Markdown · JSON