EIP-7923 · Draft · Core · 2025-03-27
EIP-7923: Linear, Page-Based Memory Costing
Proposes replacing the EVM's quadratic memory-expansion cost with a flat 100 gas per newly touched 4 KB page, plus a 64 MB per-transaction cap, so contracts can use large, sparse, virtually addressed memory cheaply.
What problem does it solve?
Today EVM memory is priced with a quadratic formula: expanding memory gets more expensive the larger it already is. This was a DoS defence, but it has side effects:
- Memory is artificially scarce. The spec notes that even 64 KB costs 14,336 gas, and a whole 30M-gas block only buys about 3 MB.
- It is hard to bound how much memory a transaction can really use, because the answer depends on call depth and the 63/64 rule from EIP-150.
- Memory has to be contiguous, so compilers cannot use the classic layout where a heap grows up from the bottom and a call stack grows down from the top.
EIP-7923 prices memory the way modern hardware actually works: by pages that are allocated on demand.
How it works
ALLOCATE_PAGE_COST = 100
PAGE_SIZE = 4096
MAXIMUM_MEMORY_SIZE = 64 * 1024 * 1024 # 16384 pages per transaction
- Memory becomes virtually addressed. Any instruction that touches a page not yet used in the current call frame pays 100 gas for it; page 0 is free.
- Base costs of memory opcodes (
MLOAD,MSTORE, ...) stay at 3 gas. The old linear and quadratic expansion terms are removed. - Addresses must fit in 32 bits; touching an address above
2**32 - 1is an exceptional halt. - A transaction-wide limit of 16,384 pages (64 MB) applies across all call frames; exceeding it halts. Pages allocated by a sub-call stop counting once that sub-call returns.
MSIZEkeeps its old meaning (highest byte touched, rounded up to 32), so existing contracts are unaffected; new code should not rely on it for allocation.
Clients can implement this with an mmap-backed 4 GB region, letting the operating system supply pages only when touched, plus a set tracking which pages have been charged.
Sample code
Cost of touching memory under the proposal (pseudocode):
def charge_memory(frame, tx, start, size):
if size == 0:
return
for page in range(start >> 12, ((start + size - 1) >> 12) + 1):
if page not in frame.pages:
if tx.num_pages >= MAXIMUM_MEMORY_SIZE // PAGE_SIZE:
raise ExceptionalHalt("out of memory")
tx.num_pages += 1
if page != 0:
frame.gas -= ALLOCATE_PAGE_COST
frame.pages.add(page)
# A compiler could now place its call stack near the top of the address space:
# MSTORE(0xFFFFF000, x) -> one page, 100 gas, instead of a huge quadratic cost
Things to know
- Status is Draft; it has not been scheduled for any network upgrade and the test cases section is empty.
- It is backwards compatible in the sense that no valid contract breaks, but some calls that used to run out of gas would now succeed.
- Accesses within the first page cost the same or less than today, which is why page 0 is free.
- The hard 64 MB cap is deliberately independent of the gas limit, so nodes and RPC providers can bound memory regardless of how much gas an
eth_callis given.