{"eip":7923,"title":"Linear, Page-Based Memory Costing","description":"Linearize Memory Costing and replace the current quadratic formula with a page-based cost model.","authors":["Charles Cooper (@charles-cooper)","Qi Zhou (@qizhou)"],"status":"Draft","type":"Standards Track","category":"Core","created":"2025-03-27","discussionsTo":"https://ethereum-magicians.org/t/eip-linearize-memory-costing/23290","repo":"EIPs","label":"EIP-7923","officialUrl":"https://eips.ethereum.org/EIPS/eip-7923","sourceUrl":"https://github.com/ethereum/EIPs/blob/master/EIPS/eip-7923.md","url":"https://eips.huatuo.xyz/eip-7923/","tldr":{"en":"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.","ja":"EVM のメモリ拡張コストの二次関数をやめ、新たに触れた 4 KB ページごとに一律 100 ガス、さらにトランザクションあたり 64 MB の上限に置き換えることを提案する。コントラクトが、大きくてまばらな仮想アドレスのメモリを安価に使えるようになる。","ko":"EVM의 이차식 메모리 확장 비용을 새로 접근한 4 KB 페이지당 고정 100 가스와 트랜잭션당 64 MB 상한으로 대체하는 것을 제안한다. 컨트랙트가 크고 듬성듬성한 가상 주소 메모리를 저렴하게 쓸 수 있게 한다.","zh":"提议用每个新触及的 4 KB 页面固定 100 gas、外加每笔交易 64 MB 上限，取代 EVM 的二次方内存扩展成本，使合约能够以低成本使用大型、稀疏、虚拟寻址的内存。"},"tags":["evm","memory","gas","core","compilers"],"explainers":{"en":{"lang":"en","tldr":"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.","tags":["evm","memory","gas","core","compilers"],"related":[150],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/eip-7923/","markdown":"## What problem does it solve?\n\nToday 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:\n\n- 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.\n- 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](/eip-150/).\n- 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.\n\nEIP-7923 prices memory the way modern hardware actually works: by pages that are allocated on demand.\n\n## How it works\n\n```python\nALLOCATE_PAGE_COST = 100\nPAGE_SIZE = 4096\nMAXIMUM_MEMORY_SIZE = 64 * 1024 * 1024   # 16384 pages per transaction\n```\n\n- 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.\n- Base costs of memory opcodes (`MLOAD`, `MSTORE`, ...) stay at 3 gas. The old linear and quadratic expansion terms are removed.\n- Addresses must fit in 32 bits; touching an address above `2**32 - 1` is an exceptional halt.\n- 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.\n- `MSIZE` keeps its old meaning (highest byte touched, rounded up to 32), so existing contracts are unaffected; new code should not rely on it for allocation.\n\nClients 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.\n\n## Sample code\n\nCost of touching memory under the proposal (pseudocode):\n\n```python\ndef charge_memory(frame, tx, start, size):\n    if size == 0:\n        return\n    for page in range(start \u003e\u003e 12, ((start + size - 1) \u003e\u003e 12) + 1):\n        if page not in frame.pages:\n            if tx.num_pages \u003e= MAXIMUM_MEMORY_SIZE // PAGE_SIZE:\n                raise ExceptionalHalt(\"out of memory\")\n            tx.num_pages += 1\n            if page != 0:\n                frame.gas -= ALLOCATE_PAGE_COST\n            frame.pages.add(page)\n\n# A compiler could now place its call stack near the top of the address space:\n#   MSTORE(0xFFFFF000, x)   -\u003e one page, 100 gas, instead of a huge quadratic cost\n```\n\n## Things to know\n\n- Status is **Draft**; it has not been scheduled for any network upgrade and the test cases section is empty.\n- 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.\n- Accesses within the first page cost the same or less than today, which is why page 0 is free.\n- 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_call` is given.\n"},"ja":{"lang":"ja","tldr":"EVM のメモリ拡張コストの二次関数をやめ、新たに触れた 4 KB ページごとに一律 100 ガス、さらにトランザクションあたり 64 MB の上限に置き換えることを提案する。コントラクトが、大きくてまばらな仮想アドレスのメモリを安価に使えるようになる。","tags":["evm","memory","gas","core","compilers"],"related":[150],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ja/eip-7923/","markdown":"## 何を解決するのか\n\n現在、EVM のメモリは二次式で価格付けされています。メモリを拡張するコストは、すでに大きいほど高くなります。これは DoS 対策でしたが、副作用があります。\n\n- メモリが人為的に希少になっています。仕様によれば、64 KB だけでも 14,336 ガスかかり、30M ガスのブロック全体でも約 3 MB しか買えません。\n- トランザクションが実際に使えるメモリ量に上限を設けるのが難しくなります。答えがコールの深さと [EIP-150](/eip-150/) の 63/64 ルールに依存するためです。\n- メモリは連続していなければならないため、コンパイラは、ヒープを下から、コールスタックを上から伸ばすという古典的なレイアウトを使えません。\n\nEIP-7923 は、現代のハードウェアが実際に動作する方法、つまり必要に応じて割り当てられるページ単位でメモリに価格を付けます。\n\n## 仕組み\n\n```python\nALLOCATE_PAGE_COST = 100\nPAGE_SIZE = 4096\nMAXIMUM_MEMORY_SIZE = 64 * 1024 * 1024   # 16384 pages per transaction\n```\n\n- メモリは仮想アドレス指定になります。現在のコールフレームでまだ使われていないページに触れる命令は、そのページに 100 ガスを支払います。ページ 0 は無料です。\n- メモリ opcode（`MLOAD`、`MSTORE` など）の基本コストは 3 ガスのままです。従来の線形および二次の拡張項は取り除かれます。\n- アドレスは 32 ビットに収まらなければなりません。`2**32 - 1` を超えるアドレスに触れると、異常終了します。\n- 16,384 ページ（64 MB）というトランザクション全体の上限がすべてのコールフレームにわたって適用され、超過すると停止します。サブコールが割り当てたページは、そのサブコールが戻るとカウントされなくなります。\n- `MSIZE` は従来の意味（触れた最大のバイト、32 に切り上げ）を保つため、既存のコントラクトは影響を受けません。新しいコードは割り当てのためにこれに頼るべきではありません。\n\nクライアントは、`mmap` を使った 4 GB の領域で実装でき、OS が触れられたときにのみページを供給し、課金済みのページを追跡するセットを併用します。\n\n## サンプルコード\n\nこの提案でメモリに触れたときのコスト（擬似コード）:\n\n```python\ndef charge_memory(frame, tx, start, size):\n    if size == 0:\n        return\n    for page in range(start \u003e\u003e 12, ((start + size - 1) \u003e\u003e 12) + 1):\n        if page not in frame.pages:\n            if tx.num_pages \u003e= MAXIMUM_MEMORY_SIZE // PAGE_SIZE:\n                raise ExceptionalHalt(\"out of memory\")\n            tx.num_pages += 1\n            if page != 0:\n                frame.gas -= ALLOCATE_PAGE_COST\n            frame.pages.add(page)\n\n# A compiler could now place its call stack near the top of the address space:\n#   MSTORE(0xFFFFF000, x)   -\u003e one page, 100 gas, instead of a huge quadratic cost\n```\n\n## 知っておくべきこと\n\n- ステータスは **Draft** で、どのネットワークアップグレードにも予定されておらず、テストケースの節は空です。\n- 有効なコントラクトが壊れないという意味では後方互換ですが、これまで out-of-gas になっていた一部の呼び出しが成功するようになります。\n- 最初のページ内のアクセスは現在と同じかそれ以下のコストなので、ページ 0 は無料です。\n- 64 MB のハードな上限は、意図的にガス上限から独立しており、`eth_call` にどれだけガスが与えられても、ノードや RPC プロバイダーがメモリの上限を設けられるようにしています。\n"},"ko":{"lang":"ko","tldr":"EVM의 이차식 메모리 확장 비용을 새로 접근한 4 KB 페이지당 고정 100 가스와 트랜잭션당 64 MB 상한으로 대체하는 것을 제안한다. 컨트랙트가 크고 듬성듬성한 가상 주소 메모리를 저렴하게 쓸 수 있게 한다.","tags":["evm","memory","gas","core","compilers"],"related":[150],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ko/eip-7923/","markdown":"## 어떤 문제를 해결하나요?\n\n현재 EVM 메모리는 이차식으로 가격이 매겨집니다. 이미 클수록 메모리를 늘리는 데 더 많은 비용이 듭니다. 이는 DoS 방어책이었지만 부작용이 있습니다.\n\n- 메모리가 인위적으로 부족해집니다. 명세에 따르면 64 KB만 해도 14,336 가스가 들고, 30M 가스 블록 전체로도 약 3 MB밖에 살 수 없습니다.\n- 트랜잭션이 실제로 쓸 수 있는 메모리의 양을 제한하기 어렵습니다. 답이 호출 깊이와 [EIP-150](/eip-150/)의 63/64 규칙에 따라 달라지기 때문입니다.\n- 메모리가 연속적이어야 하므로, 컴파일러는 힙이 아래에서 위로 자라고 호출 스택이 위에서 아래로 자라는 고전적인 레이아웃을 쓸 수 없습니다.\n\nEIP-7923은 현대 하드웨어가 실제로 동작하는 방식, 즉 필요할 때 할당되는 페이지 단위로 메모리 가격을 매깁니다.\n\n## 어떻게 동작하나요?\n\n```python\nALLOCATE_PAGE_COST = 100\nPAGE_SIZE = 4096\nMAXIMUM_MEMORY_SIZE = 64 * 1024 * 1024   # 16384 pages per transaction\n```\n\n- 메모리는 가상 주소 방식이 됩니다. 현재 호출 프레임에서 아직 사용하지 않은 페이지에 접근하는 모든 명령은 그 페이지에 100 가스를 냅니다. 페이지 0은 무료입니다.\n- 메모리 opcode(`MLOAD`, `MSTORE` 등)의 기본 비용은 3 가스로 유지됩니다. 기존의 선형 및 이차 확장 항은 제거됩니다.\n- 주소는 32비트에 들어가야 하며, `2**32 - 1`보다 큰 주소에 접근하면 비정상 종료됩니다.\n- 모든 호출 프레임에 걸쳐 16,384 페이지(64 MB)의 트랜잭션 전체 한도가 적용되며, 초과하면 중단됩니다. 서브 호출이 할당한 페이지는 그 서브 호출이 반환되면 더 이상 집계되지 않습니다.\n- `MSIZE`는 기존 의미(접근한 가장 높은 바이트를 32로 올림)를 유지하므로 기존 컨트랙트는 영향을 받지 않습니다. 새 코드는 할당을 위해 이에 의존해서는 안 됩니다.\n\n클라이언트는 `mmap` 기반의 4 GB 영역으로 구현할 수 있습니다. 운영체제가 접근될 때만 페이지를 제공하게 하고, 이미 비용이 청구된 페이지를 추적하는 집합을 함께 둡니다.\n\n## 샘플 코드\n\n이 제안에서 메모리에 접근할 때의 비용(의사 코드):\n\n```python\ndef charge_memory(frame, tx, start, size):\n    if size == 0:\n        return\n    for page in range(start \u003e\u003e 12, ((start + size - 1) \u003e\u003e 12) + 1):\n        if page not in frame.pages:\n            if tx.num_pages \u003e= MAXIMUM_MEMORY_SIZE // PAGE_SIZE:\n                raise ExceptionalHalt(\"out of memory\")\n            tx.num_pages += 1\n            if page != 0:\n                frame.gas -= ALLOCATE_PAGE_COST\n            frame.pages.add(page)\n\n# A compiler could now place its call stack near the top of the address space:\n#   MSTORE(0xFFFFF000, x)   -\u003e one page, 100 gas, instead of a huge quadratic cost\n```\n\n## 알아둘 점\n\n- 상태는 **Draft**이며, 어떤 네트워크 업그레이드에도 예정되어 있지 않고 테스트 케이스 섹션은 비어 있습니다.\n- 유효한 컨트랙트가 깨지지 않는다는 의미에서는 하위 호환이지만, 예전에는 out-of-gas가 났던 일부 호출이 이제는 성공하게 됩니다.\n- 첫 페이지 안의 접근은 현재와 같거나 더 낮은 비용이므로 페이지 0은 무료입니다.\n- 64 MB의 하드 상한은 의도적으로 가스 한도와 독립적이어서, `eth_call`에 가스가 얼마나 주어지든 노드와 RPC 제공자가 메모리를 제한할 수 있습니다.\n"},"zh":{"lang":"zh","tldr":"提议用每个新触及的 4 KB 页面固定 100 gas、外加每笔交易 64 MB 上限，取代 EVM 的二次方内存扩展成本，使合约能够以低成本使用大型、稀疏、虚拟寻址的内存。","tags":["evm","memory","gas","core","compilers"],"related":[150],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/zh/eip-7923/","markdown":"## 它解决什么问题？\n\n如今 EVM 内存采用二次方公式定价：内存已经越大，继续扩展就越贵。这原本是一种 DoS 防御，但也有副作用：\n\n- 内存被人为地变得稀缺。规范指出，即使是 64 KB 也要花 14,336 gas，整个 30M gas 的区块也只能买到约 3 MB。\n- 很难限定一笔交易实际能用多少内存，因为答案取决于调用深度和 [EIP-150](/eip-150/) 的 63/64 规则。\n- 内存必须是连续的，因此编译器无法使用经典布局，即堆从底部向上增长、调用栈从顶部向下增长。\n\nEIP-7923 按现代硬件实际的工作方式为内存定价：按需分配的页面。\n\n## 它如何运作\n\n```python\nALLOCATE_PAGE_COST = 100\nPAGE_SIZE = 4096\nMAXIMUM_MEMORY_SIZE = 64 * 1024 * 1024   # 16384 pages per transaction\n```\n\n- 内存变为虚拟寻址。任何触及当前调用帧中尚未使用的页面的指令，都要为该页面支付 100 gas；第 0 页免费。\n- 内存 opcode（`MLOAD`、`MSTORE` 等）的基础成本仍为 3 gas。旧的线性和二次方扩展项被移除。\n- 地址必须能放进 32 位；触及高于 `2**32 - 1` 的地址属于异常终止。\n- 所有调用帧共用每笔交易 16,384 页（64 MB）的上限；超出则终止。子调用分配的页面在该子调用返回后不再计数。\n- `MSIZE` 保持其原有含义（触及的最高字节，向上取整到 32），因此现有合约不受影响；新代码不应依赖它来做分配。\n\n客户端可以用基于 `mmap` 的 4 GB 区域来实现，让操作系统只在页面被触及时才提供页面，再配合一个记录哪些页面已被收费的集合。\n\n## 示例代码\n\n按该提案触及内存的成本（伪代码）：\n\n```python\ndef charge_memory(frame, tx, start, size):\n    if size == 0:\n        return\n    for page in range(start \u003e\u003e 12, ((start + size - 1) \u003e\u003e 12) + 1):\n        if page not in frame.pages:\n            if tx.num_pages \u003e= MAXIMUM_MEMORY_SIZE // PAGE_SIZE:\n                raise ExceptionalHalt(\"out of memory\")\n            tx.num_pages += 1\n            if page != 0:\n                frame.gas -= ALLOCATE_PAGE_COST\n            frame.pages.add(page)\n\n# A compiler could now place its call stack near the top of the address space:\n#   MSTORE(0xFFFFF000, x)   -\u003e one page, 100 gas, instead of a huge quadratic cost\n```\n\n## 需要注意\n\n- 状态为 **Draft**；尚未被安排进任何网络升级，测试用例部分为空。\n- 它在\"不会破坏任何有效合约\"的意义上是向后兼容的，但一些过去会 out-of-gas 的调用现在会成功。\n- 第一页内的访问成本与现在相同或更低，这就是第 0 页免费的原因。\n- 64 MB 的硬上限被刻意设计为独立于 gas 上限，这样无论一次 `eth_call` 被给予多少 gas，节点和 RPC 服务商都能限定内存。\n"}},"requiredBy":[8007]}
