EIP-7667 · Stagnant · Core · 2024-03-31
EIP-7667: Raise gas costs of hash functions
Proposes raising the gas cost of KECCAK256, SHA-256, BLAKE2 and LOG data so that hash-heavy blocks no longer blow up the time needed to generate a ZK proof of the block.
What problem does it solve?
Gas prices for hashing were set long ago based on how fast a normal CPU runs them. On a CPU, Keccak and SHA-256 are very cheap, so their gas costs are low. Inside a ZK-SNARK prover the picture is reversed: hash functions are among the most expensive things to prove.
That mismatch means an attacker (or just an unusual workload) can fill a block with cheap hashing and make it far slower to prove than an average block. ZK rollups currently defend against this with ad-hoc limits enforced by centralized sequencers, and any plan to SNARK-prove Ethereum L1 blocks needs a tight bound on worst-case proving time. The spec estimates that, with 30M gas, opcodes alone can force hundreds of millions of bytes of hashing in one block.
How it works
The proposal simply changes gas constants. Everything is moved to at least "300 per hash call plus 60 per 32-byte word"; anything already more expensive is left alone.
| Parameter | Today | Proposed |
|---|---|---|
KECCAK_BASE_COST (opcode KECCAK256) |
30 | 300 |
KECCAK_WORD_COST |
6 | 60 |
SHA256_BASE_COST (precompile 0x02) |
60 | 300 |
SHA256_WORD_COST |
12 | 60 |
RIPEMD_BASE_COST / WORD_COST |
600 / 120 | unchanged |
BLAKE2_GFROUND (per round of 0x09) |
1 | 10 |
GLOGBYTE (per byte of LOG* data) |
8 | 10 |
No new opcodes or transaction types are introduced. The author considered multidimensional gas or a cost floor (like EIP-7623 for calldata), but rejected them as much harder to apply to in-EVM costs, since contracts set gas limits for their own sub-calls.
Sample code
Estimating the cost change for one KECCAK256 over n bytes (pseudocode):
def keccak_gas(n_bytes, base, word):
words = (n_bytes + 31) // 32
return base + word * words
# Hashing two 32-byte words, e.g. one step of a binary Merkle proof
print(keccak_gas(64, 30, 6)) # today: 42
print(keccak_gas(64, 300, 60)) # EIP-7667: 420
The spec's own example: a 20-level Keccak Merkle proof brought in via calldata goes from about 11,080 gas to about 18,640 gas, i.e. less than 2x, because calldata still dominates.
Things to know
- Status: Stagnant. It was not scheduled for any network upgrade. Treat the numbers as a proposal, not current mainnet pricing.
- Contracts that hash a lot (Merkle proof verification, signature schemes, on-chain commitment schemes) would pay noticeably more if something like this ships. Avoid hard-coding gas amounts for calls that hash.
- Later repricing work, such as EIP-7904, looks at compute costs more broadly; check it for the current direction rather than relying on this EIP.
- No operation becomes cheaper, so the spec sees no new security risk, only higher costs for hash-heavy applications.