← All MIPs

MIP-3: Linear Memory 💬🔗

Redefine memory expansion cost to be linear and enforce an explicit maximum memory usage per transaction.

AuthorCategory Labs
StatusReview
TypeStandards Track
CategoryCore
Created2025-12-10
Discussionhttps://forum.monad.xyz/t/mip-3-linear-evm-memory-cost/362

Abstract

Redefine memory expansion cost to be linear and enforce an explicit maximum memory usage per transaction.

Motivation

Currently, EVM memory usage is bounded by a quadratic expansion cost and the 63/64 rule. The theoretical memory limit of a transaction is at least 26 MB. Historical transaction analysis shows that average memory usage is ~2 KB and maximum observed memory usage is ~2 MB.

Benchmarks also indicate that the current memory expansion formula overcharges for actual resource usage.

This update aligns cost with actual resource consumption. It makes memory usage more predictable, particularly for contracts that rely on large memory allocations.

Specification

Memory expansion cost is redefined as:

memory_size_words = (memory_byte_size + 31) // 32
memory_cost = memory_size_words // 2

The max memory usage is capped at 8 MB. Memory allocation is bounded across call contexts with the following rule:

  1. Let k be the memory used by the current call, and j the memory used by parent calls.
  2. The remaining memory available to a child call is:
 remaining_memory = 8 * 1024 * 1024 - j - k
  1. Once a call returns, the memory is returned to the pool.
  2. If a call exceeds the remaining memory limit, it reverts.

Backwards Compatibility

This proposal is highly compatible with existing contracts. Almost all standard EVM operations remain valid and ERC-4337 contracts continue to function correctly, as child call memory is released upon completion. Replay testing of historical Ethereum transactions will be used to quantify compatibility.

However, contracts that allocate more than 8 MB of memory will now revert.

Security Considerations

The cost to expand memory to the 8MB ceiling is 131,072 gas. The result is that it is cheaper to expand memory than current costs. Potentially concurrency limits for RPC nodes should be adjusted to prevent OOM issue.

Acknowledgements

The proposals in this MIP are based on two previous EIP documents. Additionally, conversations with Charles Cooper were instructive in developing the Monad memory model:

MIP-3 differs from EIP-7686 in that EIP-7686 defines a direct relationship between memory limit and gas limit, and from EIP-7923 in that MIP-3 does not adopt the page-based thrashing cost model.

Copyright and related rights waived via CC0.

Citation

Please cite this document as:

Category Labs, "MIP-3: Linear Memory," Monad Improvement Proposals, no. 3, December 2025. [Online serial]. Available: https://monad-crypto.github.io/MIPs/MIPS/MIP-3.