Introduction

Hi, I'm cardene, a software engineer and technical writer focused on blockchain and AI.

I've also authored Japanese technical books on specification-driven development with LLMs and decentralized application (DApp) development.

I also build and publish a variety of tools, libraries, and open-source projects.

This article examines EIP-7923, which proposes replacing the EVM's quadratic memory cost model with a linear, page-based cost model. It covers the proposal as discussed in the original article published on February 12, 2026.

This article translates, summarizes, and expands on the specification linked below.

I also cover a variety of EIPs, BIPs, SLIPs, CAIPs, ENSIPs, RFCs, and ACPs.

Overview

EIP-7923 proposes replacing the EVM's quadratic memory model with a linear, page-based cost model. Memory becomes virtually addressable, and page allocation becomes part of the cost model. After the proposed changes, memory limits no longer depend on the state of the message call stack.

A page-based cost model divides memory into units called pages, each containing 4,096 bytes (4KB), and charges a fixed amount of gas per page. This follows the same principle as memory management in operating systems on computers and smartphones: only the required pages are allocated, so unused memory does not incur unnecessary costs. In the existing EVM model, costs rise quadratically as more memory is used. Under this proposal, each allocated page costs a fixed 100 gas.

Key features

Feature Description
Linear cost Eliminates quadratic memory expansion costs
Page-based allocation Manages memory in pages of 4,096 bytes
Virtual addressing Memory pages are not allocated until they are accessed
Transaction-global limit Maximum memory limit of 64MB
32-bit address limit Memory addresses are limited to 32 bits

In the existing EVM model, memory expansion costs increase quadratically. The quadratic component of the gas cost begins to take effect beyond 724 bytes of memory. Although this design was introduced to defend against denial-of-service (DoS) attacks, it no longer reflects modern hardware capabilities well.

Motivation

The EVM currently uses a quadratic pricing model for memory. This model was originally introduced as a defense against DoS attacks. However, it has several drawbacks.

Problems with the existing model

Outdated design

Even with a gas limit of 30 million gas, a user can allocate only 3MB of memory in a message call, consuming the entire gas budget in the process. Because the quadratic component of memory expansion costs starts taking effect at 724 bytes, users typically use even less memory in practice. Using just 64KB of memory, an amount available on personal computers in the early 1980s, costs 14,336 gas.

Difficulty reasoning about memory usage

Under the quadratic model, it is difficult to determine how much memory a transaction can allocate. One must calculate how many recursive message calls are possible under call stack limits, including the 63/64 rule introduced by EIP-150, and solve an optimization problem that maximizes memory usage across those calls.

Inability to benefit from virtual memory

The quadratic model prevents high-level smart contract languages from taking advantage of virtual memory. Most modern programming languages maintain both a heap and a call stack. The heap is used to allocate objects whose lifetimes extend beyond the current function frame, whereas the call stack is used to allocate objects that live within the current function frame.

The important property is that the call stack starts at the top of the address space and grows downward, while the heap starts at the bottom and grows upward. This allows language implementations to use the two memory regions without worrying about them interfering with one another. Virtual paged memory, a feature available in operating systems since the early 1990s, makes this approach possible. Smart contract languages such as Vyper and Solidity cannot implement this model efficiently under the existing memory pricing scheme, resulting in inefficient memory management.

Advantages of the new model

EIP-7923 proposes a linear cost model that more accurately reflects today's hardware. Modern hardware uses hierarchical memory, where hot memory is much faster to access than cold memory, and virtual addressing, where memory does not need to be allocated contiguously and is provided on demand by the operating system.

Item Existing model New model
Cost calculation Quadratic Linear (per page)
Memory expansion Contiguous expansion Virtual addressing
Cost of using 64KB 14,336 gas Approximately 1,600 gas (16 pages × 100 gas)
Maximum memory Depends on the call stack Fixed at 64MB

Specification

Constants

The following constants are defined.

python
ALLOCATE_PAGE_COST = 100
PAGE_SIZE = 4096
MAXIMUM_MEMORY_SIZE = 64 * 1024 * 1024

These constants define the page allocation cost, page size, and maximum memory size. ALLOCATE_PAGE_COST is the gas charged when a new page is allocated. PAGE_SIZE is 4,096 bytes (4KB), matching the page size used by most architectures. MAXIMUM_MEMORY_SIZE is 64MB, the maximum amount of memory that can be used across the transaction.

Changes to the memory cost algorithm

The memory cost algorithm changes as follows.

  1. For each page accessed by an instruction, charge ALLOCATE_PAGE_COST gas if that page has not previously been accessed during the current message call. Page 0 is free.
  2. The base gas cost of all memory instructions, such as MLOAD and MSTORE, remains 3 gas.
  3. Remove the linear and quadratic terms of the existing memory expansion cost.
Component Change
First access to a page 100 gas (except page 0)
Base memory instruction cost 3 gas (unchanged)
Linear and quadratic expansion terms Removed

Behavior of MSIZE

The behavior of MSIZE remains unchanged. It returns the highest byte position accessed by any memory instruction, rounded up to a multiple of 32.

Address limits

Memory addresses are restricted to 32 bits. An exceptional halt must occur if an address is greater than 2**32 - 1.

Transaction-global memory limit

A transaction-global memory limit is enforced. An exceptional halt must occur if the number of pages allocated in the transaction exceeds MAXIMUM_MEMORY_SIZE // PAGE_SIZE, or 16,384.

Additional details

Benchmark results

Benchmarks conducted on a CPU from around 2019 showed that keccak256 could run at approximately 256MB per second. Given that keccak256 costs 6 gas per 32 bytes, this yields a ratio of approximately 20 nanoseconds per gas.

Operation Time
Allocate a new page 1–2 microseconds
Read a random byte from a 2MB region 1.8 nanoseconds
Read a random byte from a 32MB region 7 nanoseconds
Read a random byte from a 4GB region 40 nanoseconds
Update a hash map with 512 entries 8 nanoseconds
Update a hash map with 8,192 entries 9 nanoseconds
Update a hash map with 5 million entries 108 nanoseconds
Execute the mmap system call 230 nanoseconds

Based on these results, the proposal prices page allocation at 100 gas.

Why page 0 is free

The cost of executing mmap, approximately 11 gas, is already more than covered by the base cost of CALL-family instructions, which is 100 gas. Page 0 is free for the same reason: the CALL overhead has already paid for allocating the first page. This also improves backward compatibility, as accesses within the first page cost the same as or less than under the existing model.

Rationale for the transaction-global limit

Client implementers have expressed a desire to enforce a global limit independently of the gas limit for DoS protection. For example, an RPC provider may be configured to allow many concurrent eth_call computations with much higher gas limits than the mainnet gas limit. Avoiding an implicit dependency between the memory limit and gas limit removes one possible source of configuration errors.

The hard limit applies to the transaction globally rather than to each message call. A reasonable alternative would be to limit the number of pages allocated in a particular message call, for example to 2MB, but this would not substantially reduce implementation complexity.

Why MSIZE semantics remain unchanged

Although users are expected to use the entire address space rather than simply growing memory linearly, the reason for preserving MSIZE semantics is to avoid breaking backward compatibility with existing contracts that expect linear growth. New contracts that take advantage of virtual addressing should not rely on MSIZE for memory allocation.

Rationale for the 32-bit address limit

Addressing is subject to a hard limit of 2**32 bytes. This makes it easier for modern 64-bit computers to reserve that amount of virtual address space, given that clients run on various operating systems and architectures with different per-process virtual memory limits. This limit may be reconsidered in the future, for example if gas limits or client memory sizes increase substantially.

Implementation approaches

There are two possible implementation approaches.

Manual implementation

This approach is intended for systems without mmap or virtual addressing capabilities. The implementation must maintain a mapping of map[page_id -> char[4096]]. Here, page_id is an integer calculated as memory_address >> 12. When a read or write crosses a page boundary, both pages must be loaded and the results combined.

mmap-based implementation

This is a simpler approach for systems with mmap or equivalent functionality. To store the actual memory data, the implementation uses mmap to reserve a memory region of 2**32 bytes. Memory operations can then be implemented as reads and writes to this buffer. With anonymous mmap, the operating system does not allocate the entire buffer in advance. Instead, it allocates pages on demand as they are accessed.

Implementation Characteristics
Manual implementation Maintains a page ID map on systems without mmap
mmap-based implementation Simpler; the OS allocates pages automatically on demand

Reference implementation

The following reference implementation is presented as patches to the py-evm codebase.

Changes to memory expansion logic (computation.py)
diff
-        before_size = ceil32(len(self._memory))
-        after_size = ceil32(start_position + size)
-
-        before_cost = memory_gas_cost(before_size)
-        after_cost = memory_gas_cost(after_size)
-
-        if size:
-            if before_cost < after_cost:
-                gas_fee = after_cost - before_cost
-                self._gas_meter.consume_gas(
-                    gas_fee,
-                    reason=" ".join(
-                        (
-                            "Expanding memory",
-                            str(before_size),
-                            "->",
-                            str(after_size),
-                        )
-                    ),
-                )
-
-            self._memory.extend(start_position, size)
+        if size == 0:
+            return
+
+        ALLOCATE_PAGE_COST = 100
+        LOWER_BITS = 12  # bits ignored for page calculations
+        PAGE_SIZE = 4096
+        assert 2**LOWER_BITS == PAGE_SIZE   # sanity check
+        MAXIMUM_MEMORY_SIZE = 64 * 1024 * 1024
+        TRANSACTION_MAX_PAGES = MAXIMUM_MEMORY_SIZE // PAGE_SIZE
+
+        end_position = start_position + size - 1
+
+        start_page = start_position >> LOWER_BITS
+        end_page = end_position >> LOWER_BITS
+
+        for page in range(start_page, end_page + 1):
+            if page not in self._memory.pages:
+                if self.transaction_context.num_pages >= TRANSACTION_MAX_PAGES:
+                    raise VMError("Out Of Memory")
+                self.transaction_context.num_pages += 1
+
+                reason = f"Allocating page {hex(page << LOWER_BITS)}"
+                self._gas_meter.consume_gas(ALLOCATE_PAGE_COST, reason)
+                self._memory.pages[page] = True

This change replaces the existing quadratic memory cost calculation with a linear, page-based calculation. It charges 100 gas when a page (4,096 bytes) is accessed for the first time and checks the transaction-global page limit.

Transaction-global memory limit (frontier/computation.py)
diff
+        # implement transaction-global memory limit
+        num_pages_anchor = transaction_context.num_pages
+        try:
+            computation = cls.apply_computation(
+                state,
+                message,
+                transaction_context,
+                parent_computation=parent_computation,
+            )
+        finally:
+            # "deallocate" all the pages allocated in the child computation
+            allocated_pages = len(computation._memory.pages)
+            assert transaction_context.num_pages == num_pages_anchor + allocated_pages
+            transaction_context.num_pages = num_pages_anchor

The transaction-global limit is implemented by tracking the pages allocated by child computations and deallocating them when those computations finish.

Changes to the MSIZE opcode (memory.py)
diff
 def msize(computation: ComputationAPI) -> None:
-    computation.stack_push_int(len(computation._memory))
+    computation.stack_push_int(computation._memory.msize)

MSIZE is changed to return the msize property rather than the length of the memory buffer.

Changes to the Memory class (memory.py)
diff
 class Memory(MemoryAPI):
-    __slots__ = ["_bytes"]
+    __slots__ = ("pages", "msize")

     def __init__(self) -> None:
-        self._bytes = bytearray()
+        self.memview = mmap.mmap(-1, 2**32, flags=mmap.MAP_PRIVATE | mmap.MAP_ANONYMOUS)
+        self.pages = {0: True}  # page 0 is free (per spec)
+        self.msize = 0

     def extend(self, start_position: int, size: int) -> None:
         if size == 0:
             return
-        new_size = ceil32(start_position + size)
-        if new_size <= len(self):
+        if start_position + size > self.msize:
+            self.msize = ceil32(start_position + size)
+
+    def write(self, start_position: int, size: int, value: bytes) -> None:
+        if size == 0:
             return
-        size_to_extend = new_size - len(self)
-        try:
-            self._bytes.extend(bytearray(size_to_extend))
-        except BufferError:
-            self._bytes = self._bytes + bytearray(size_to_extend)
+        if start_position + size >= 2**32:
+            raise VMError("Non 32-bit address")
+        end_position = start_position + size
+        self.memview[start_position : end_position] = value

The Memory class uses mmap to reserve 4GB of virtual address space and maintains page tracking and an msize property. Page 0 is initialized without charge, as specified.

Backward compatibility

This is addressed in the security considerations section. Backward compatibility is maintained, but some contracts that previously failed because they ran out of gas may now complete successfully.

Regarding whether existing contracts depend on memory limits, aside from changes in gas costs, existing contracts may simply complete execution instead of running out of gas.

Security

There are two main security considerations for this proposal.

Impact on existing contracts

The first question is whether the proposal breaks existing contracts. In other words, do existing contracts depend on memory being limited? Aside from changes in gas costs, existing contracts may simply complete execution instead of running out of gas.

Memory-based DoS attacks

The second question is whether the proposal enables memory-based DoS attacks against clients. This requires analyzing the maximum memory usage.

With the existing gas limit of 30 million gas, a contract that recursively calls itself while allocating 256KB of memory in each call frame can allocate a total of 54MB. This is not substantially different from the proposed limit of 64MB.

Security consideration Description
Impact on existing contracts Execution may complete instead of running out of gas
DoS resistance Comparable to the existing model (approximately 54MB versus the 64MB limit)
Transaction-global limit Changes to call stack limits do not affect total memory usage

The transaction-global memory limit introduced by the proposal provides a useful invariant. Future changes to call stack limits do not affect the total amount of memory that can be allocated in a given transaction.

References

Conclusion

This article covered the linear, page-based EVM memory cost model proposed by EIP-7923. I hope this explanation was helpful.

If you have questions, feel free to reach out via direct message on Twitter.

Twitter @cardene777

I also publish content on other platforms, which you can find below.