---
eip: 7637
label: EIP-7637
title: Optimize EOA EXTCODEHASH
status: Stagnant
type: Standards Track
category: Core
created: 2024-02-26
requires: 1052
official: https://eips.ethereum.org/EIPS/eip-7637
source: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-7637.md
canonical: https://eips.huatuo.xyz/eip-7637/
lang: en
tldr: "Proposed making EXTCODEHASH return 0 for any account with no code, instead of keccak256(\"\") for code-less accounts that hold a balance, so 'codehash == 0' becomes a safe, cheap 'is there no contract here?' check."
tags: [evm, opcodes, extcodehash, core]
---

# EIP-7637: Optimize EOA EXTCODEHASH

> Modify the output value of EXTCODEHASH for EOA accounts to `0x`

**TL;DR:** Proposed making EXTCODEHASH return 0 for any account with no code, instead of keccak256("") for code-less accounts that hold a balance, so 'codehash == 0' becomes a safe, cheap 'is there no contract here?' check.

## What problem does it solve?

[EIP-1052](/eip-1052/) added `EXTCODEHASH`, which returns the hash of an account's code more cheaply than copying it. Its rules give two different answers for "no code":

- `0` if the account does not exist or is *empty* (in the [EIP-161](/eip-161/) sense: no code, zero balance, zero nonce),
- `keccak256("")` = `0xc5d2…a470` if the account exists but has no code, for example an address that has received ETH.

That distinction surprises developers. Contract addresses can be predicted in advance (especially with [CREATE2](/eip-1014/)), and anyone can send a little ETH to an address before a contract is deployed there. Code that checks `codehash == 0` to mean "not deployed yet" then silently gets a different value. As a result, careful contracts fall back to `extcodesize`/`code.length == 0`, and the gas-saving purpose of `EXTCODEHASH` is partly lost.

## How it works

The proposal changes one rule: if an account has no code, `EXTCODEHASH` returns `0`, regardless of balance. In the spec's execution-specs style reference implementation, after computing the hash, a result equal to `keccak256("")` is replaced with `0`.

| Account | Today | Proposed |
| --- | --- | --- |
| Non-existent / empty | `0` | `0` |
| Exists, no code (e.g. funded address) | `keccak256("")` | `0` |
| Has code | `keccak256(code)` | `keccak256(code)` |

## Sample code

The pitfall the proposal targets:

```solidity
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

contract Checker {
    // Fragile today: returns false if someone sent ETH to `a` before deployment,
    // because codehash is then keccak256("") instead of 0.
    function notDeployedFragile(address a) external view returns (bool) {
        return a.codehash == bytes32(0);
    }

    // Robust today: treats both "no account" and "account without code" as not deployed.
    bytes32 constant EMPTY_CODEHASH = keccak256("");
    function notDeployed(address a) external view returns (bool) {
        bytes32 h = a.codehash;
        return h == bytes32(0) || h == EMPTY_CODEHASH;
    }
}
```

Under EIP-7637 both functions would give the same answer.

## Things to know

- Status is **Stagnant**; current mainnet behaviour still follows EIP-1052, so write checks like `notDeployed` above.
- It is a consensus change to an existing opcode. Contracts that use `codehash` to tell "never touched" from "funded but code-less" addresses would lose that distinction, as the spec notes.
- The spec motivates the change only in terms of balance; accounts that are non-empty for other reasons (such as a non-zero nonce) are also code-less and would likewise return `0` under the reference implementation.
- Since [EIP-7702](/eip-7702/), EOAs can carry delegation code, which is another case to consider when reasoning about `EXTCODEHASH` on EOAs.


---

This is an unofficial plain-language summary. Read the full specification: https://eips.ethereum.org/EIPS/eip-7637
