Overview
Opcode:0x3f
Introduced: Constantinople (EIP-1052)
EXTCODEHASH returns the keccak256 hash of an account’s bytecode, or 0 for empty accounts.
Specification
Stack Input:- Constantinople: 400 gas
- Istanbul (EIP-1884): 700 gas
- Berlin (EIP-2929): 2600 gas (cold) / 100 gas (warm)
Behavior
Returns keccak256(account.code) for contracts, or 0 for:- EOAs (externally owned accounts)
- Non-existent accounts
- Empty code (code.length == 0)
Examples
Basic Usage
Implementation Verification
Factory Pattern
Gas Cost
Historical evolution:| Hardfork | Cold | Warm |
|---|---|---|
| Constantinople | 400 | - |
| Istanbul | 700 | - |
| Berlin | 2600 | 100 |
Common Usage
Contract Identity Check
Minimal Proxy Detection
Upgrade Validation
Security
Empty Account Returns 0
Constructor Bypass
Like EXTCODESIZE, returns 0 during contract construction:Code Immutability Check
Implementation
- TypeScript
Edge Cases
EOA Hash
Non-Existent Account
Empty Code Contract
Some contracts may have zero-length code (rare):References
- EIP-1052 - EXTCODEHASH opcode
- EVM Codes - EXTCODEHASH
- EIP-1884 - Repricing (Istanbul)
- EIP-2929 - Access lists (Berlin)
- Yellow Paper - Appendix H

