{"eip":3337,"title":"Frame pointer support for memory load and store operations","description":"Introduces four new opcodes for loading data from and storing data to memory offset by a frame pointer.","authors":["Nick Johnson (@arachnid)"],"status":"Stagnant","type":"Standards Track","category":"Core","created":"2021-03-06","requires":[3336],"discussionsTo":"https://ethereum-magicians.org/t/eips-3336-and-3337-improving-the-evms-memory-model/5482","repo":"EIPs","label":"EIP-3337","officialUrl":"https://eips.ethereum.org/EIPS/eip-3337","sourceUrl":"https://github.com/ethereum/EIPs/blob/master/EIPS/eip-3337.md","url":"https://eips.huatuo.xyz/eip-3337/","tldr":{"en":"Proposed four EVM opcodes for a frame pointer (`SETFP`, `GETFP`, `MLOADFP`, `MSTOREFP`) so compilers could keep local variables in memory cheaply and escape the \"stack too deep\" limit.","ja":"フレームポインタのための 4 つの EVM opcode（`SETFP`、`GETFP`、`MLOADFP`、`MSTOREFP`）を提案した。コンパイラがローカル変数を安価にメモリに置け、「stack too deep」の制限を回避できる。","ko":"프레임 포인터를 위한 EVM opcode 네 개(`SETFP`, `GETFP`, `MLOADFP`, `MSTOREFP`)를 제안해, 컴파일러가 지역 변수를 메모리에 저렴하게 두고 \"stack too deep\" 한계를 벗어날 수 있게 했다.","zh":"提议了四个用于帧指针的 EVM 操作码（`SETFP`、`GETFP`、`MLOADFP`、`MSTOREFP`），让编译器能够低成本地把局部变量放在内存中，摆脱“stack too deep”的限制。"},"tags":["evm","opcodes","memory","compilers","core"],"explainers":{"en":{"lang":"en","tldr":"Proposed four EVM opcodes for a frame pointer (`SETFP`, `GETFP`, `MLOADFP`, `MSTOREFP`) so compilers could keep local variables in memory cheaply and escape the \"stack too deep\" limit.","tags":["evm","opcodes","memory","compilers","core"],"related":[3336,1153,5656,3855,663],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/eip-3337/","markdown":"## What problem does it solve?\n\nMost CPUs and VMs keep local variables, arguments and return addresses in a randomly accessible \"call stack\" region of memory, addressed relative to a **frame pointer**. The EVM instead keeps them on its evaluation stack, which can only reach the top 16 items with `DUPn`/`SWAPn`. Functions with many locals hit Solidity's familiar *stack too deep* error.\n\nCompilers could use memory instead, but without a dedicated frame pointer that is expensive. Loading a frame-relative value today takes five operations:\n\n| Before | Gas |\n| --- | --- |\n| `PUSHn x`, `PUSH1 0`, `MLOAD` (read FP), `ADD`, `MLOAD` | 15 gas, ≥ 7 bytes |\n| **With this EIP:** `PUSH1 x`, `MLOADFP` | 6 gas, ≥ 3 bytes |\n\nThat makes memory locals only about twice as costly as a `DUPn`, rather than five times, and a frame-relative store becomes as cheap as `SWAPn POP`.\n\n## How it works\n\nThe EVM gains an internal **frame pointer**, a signed integer that starts at 0 in each execution, and four opcodes:\n\n| Opcode | Byte | Gas | Effect |\n| --- | --- | --- | --- |\n| `SETFP` | `0x5c` | 3 | Pop a value and set the frame pointer to it |\n| `GETFP` | `0x5d` | 3 | Push the current frame pointer |\n| `MLOADFP` | `0x5e` | 3* | Like `MLOAD`, but address = operand + FP |\n| `MSTOREFP` | `0x5f` | 3* | Like `MSTORE`, but address = operand + FP |\n\n\\* Same cost as `MLOAD`/`MSTORE`, including memory expansion.\n\nIf `operand + FP` is negative, the instruction fails like an invalid opcode (all gas consumed, context reverted). There is deliberately no `MSTORE8FP` to save opcode space.\n\nIt is designed alongside [EIP-3336](/eip-3336/), which proposed paged memory so that sparse use of memory (such as a stack growing downward from a high address) would not be priced as one huge linear block.\n\n## Sample code\n\nHow a compiler might use it for a function frame (illustrative assembly):\n\n```text\n; prologue: allocate a 0x60-byte frame below the caller's frame\nGETFP               ; [old_fp]\nDUP1                ; [old_fp, old_fp]\nPUSH1 0x60\nSWAP1\nSUB                 ; [old_fp, old_fp - 0x60]\nSETFP               ; fp = old_fp - 0x60   (old_fp kept on stack to restore)\n\n; local a = 42  (slot at fp + 0x00)\nPUSH1 0x2a\nPUSH1 0x00\nMSTOREFP\n\n; b = a + 1     (slot at fp + 0x20)\nPUSH1 0x00\nMLOADFP             ; [old_fp, a]\nPUSH1 0x01\nADD\nPUSH1 0x20\nMSTOREFP\n\n; epilogue\nSETFP               ; restore fp = old_fp\n```\n\n## Things to know\n\n- Status is **Stagnant**; it was never scheduled for a network upgrade, and `FORK_BLOCK` was left TBD.\n- The opcode bytes it proposed have since been assigned to other instructions: `0x5c` `TLOAD` and `0x5d` `TSTORE` ([EIP-1153](/eip-1153/)), `0x5e` `MCOPY` ([EIP-5656](/eip-5656/)) and `0x5f` `PUSH0` ([EIP-3855](/eip-3855/)). Any revival would need new numbers.\n- The underlying \"stack too deep\" problem has mostly been tackled in other ways, such as compilers moving variables to memory automatically and proposals for deeper stack access like [EIP-663](/eip-663/).\n"},"ja":{"lang":"ja","tldr":"フレームポインタのための 4 つの EVM opcode（`SETFP`、`GETFP`、`MLOADFP`、`MSTOREFP`）を提案した。コンパイラがローカル変数を安価にメモリに置け、「stack too deep」の制限を回避できる。","tags":["evm","opcodes","memory","compilers","core"],"related":[3336,1153,5656,3855,663],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ja/eip-3337/","markdown":"## 何を解決するのか\n\nほとんどの CPU や VM は、ローカル変数、引数、戻りアドレスを、メモリ上のランダムアクセス可能な「コールスタック」領域に置き、**フレームポインタ**からの相対位置でアドレス指定します。一方 EVM は、これらを評価スタックに置きますが、`DUPn`/`SWAPn` で届くのは上位 16 個だけです。ローカル変数の多い関数は、Solidity でおなじみの *stack too deep* エラーに突き当たります。\n\nコンパイラはメモリを使うこともできますが、専用のフレームポインタがないとコストが高くなります。現状では、フレーム相対の値を読み込むのに 5 つの操作が必要です。\n\n| 変更前 | ガス |\n| --- | --- |\n| `PUSHn x`、`PUSH1 0`、`MLOAD`（FP の読み取り）、`ADD`、`MLOAD` | 15 gas、7 バイト以上 |\n| **この EIP を適用：** `PUSH1 x`、`MLOADFP` | 6 gas、3 バイト以上 |\n\nこれにより、メモリ上のローカル変数のコストは `DUPn` の 5 倍ではなく、約 2 倍で済み、フレーム相対のストアは `SWAPn POP` と同じくらい安価になります。\n\n## 仕組み\n\nEVM に内部の**フレームポインタ**が加わります。これは符号付き整数で、各実行の開始時に 0 です。そして 4 つの opcode が追加されます。\n\n| Opcode | バイト | ガス | 効果 |\n| --- | --- | --- | --- |\n| `SETFP` | `0x5c` | 3 | 値を pop し、フレームポインタをその値に設定する |\n| `GETFP` | `0x5d` | 3 | 現在のフレームポインタを push する |\n| `MLOADFP` | `0x5e` | 3* | `MLOAD` と同様だが、アドレス = オペランド + FP |\n| `MSTOREFP` | `0x5f` | 3* | `MSTORE` と同様だが、アドレス = オペランド + FP |\n\n\\* メモリ拡張を含め、`MLOAD`/`MSTORE` と同じコストです。\n\n`operand + FP` が負の場合、この命令は無効な opcode と同様に失敗します（すべてのガスを消費し、コンテキストが revert される）。opcode 空間を節約するため、`MSTORE8FP` は意図的に用意されていません。\n\nこれは [EIP-3336](/eip-3336/) と合わせて設計されました。EIP-3336 は、ページ化されたメモリを提案しており、メモリのまばらな使い方（高いアドレスから下向きに伸びるスタックなど）が、巨大な 1 つの連続ブロックとして課金されないようにするものです。\n\n## サンプルコード\n\nコンパイラが関数フレームにどのように使うかの例です（説明用のアセンブリ）。\n\n```text\n; prologue: allocate a 0x60-byte frame below the caller's frame\nGETFP               ; [old_fp]\nDUP1                ; [old_fp, old_fp]\nPUSH1 0x60\nSWAP1\nSUB                 ; [old_fp, old_fp - 0x60]\nSETFP               ; fp = old_fp - 0x60   (old_fp kept on stack to restore)\n\n; local a = 42  (slot at fp + 0x00)\nPUSH1 0x2a\nPUSH1 0x00\nMSTOREFP\n\n; b = a + 1     (slot at fp + 0x20)\nPUSH1 0x00\nMLOADFP             ; [old_fp, a]\nPUSH1 0x01\nADD\nPUSH1 0x20\nMSTOREFP\n\n; epilogue\nSETFP               ; restore fp = old_fp\n```\n\n## 知っておくべきこと\n\n- ステータスは **Stagnant** です。ネットワークアップグレードに予定されたことはなく、`FORK_BLOCK` は TBD のままでした。\n- 提案された opcode のバイト値は、その後ほかの命令に割り当てられました。`0x5c` は `TLOAD`、`0x5d` は `TSTORE`（[EIP-1153](/eip-1153/)）、`0x5e` は `MCOPY`（[EIP-5656](/eip-5656/)）、`0x5f` は `PUSH0`（[EIP-3855](/eip-3855/)）です。復活させる場合は、新しい番号が必要になります。\n- 根本にある「stack too deep」問題は、コンパイラが変数を自動的にメモリへ移す方法や、[EIP-663](/eip-663/) のようなより深いスタックアクセスの提案など、他の方法でほぼ対処されてきました。\n"},"ko":{"lang":"ko","tldr":"프레임 포인터를 위한 EVM opcode 네 개(`SETFP`, `GETFP`, `MLOADFP`, `MSTOREFP`)를 제안해, 컴파일러가 지역 변수를 메모리에 저렴하게 두고 \"stack too deep\" 한계를 벗어날 수 있게 했다.","tags":["evm","opcodes","memory","compilers","core"],"related":[3336,1153,5656,3855,663],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ko/eip-3337/","markdown":"## 어떤 문제를 해결하나요?\n\n대부분의 CPU와 VM은 지역 변수, 인자, 반환 주소를 메모리의 임의 접근 가능한 \"콜 스택\" 영역에 두고 **프레임 포인터**를 기준으로 주소를 지정합니다. 반면 EVM은 이를 평가 스택에 두는데, `DUPn`/`SWAPn`으로는 맨 위 16개 항목에만 접근할 수 있습니다. 지역 변수가 많은 함수는 Solidity에서 익숙한 *stack too deep* 오류에 부딪힙니다.\n\n컴파일러가 메모리를 대신 쓸 수도 있지만, 전용 프레임 포인터가 없으면 비용이 큽니다. 지금은 프레임 기준 값 하나를 로드하는 데 다섯 개의 연산이 필요합니다.\n\n| 이전 | 가스 |\n| --- | --- |\n| `PUSHn x`, `PUSH1 0`, `MLOAD`(FP 읽기), `ADD`, `MLOAD` | 15 gas, 7바이트 이상 |\n| **이 EIP 적용:** `PUSH1 x`, `MLOADFP` | 6 gas, 3바이트 이상 |\n\n그 결과 메모리 지역 변수의 비용이 `DUPn`의 다섯 배가 아니라 약 두 배에 그치고, 프레임 기준 저장은 `SWAPn POP`만큼 저렴해집니다.\n\n## 어떻게 동작하나요?\n\nEVM에 내부 **프레임 포인터**가 추가됩니다. 부호 있는 정수이며 각 실행이 시작될 때 0입니다. 그리고 opcode 네 개가 추가됩니다.\n\n| Opcode | 바이트 | 가스 | 효과 |\n| --- | --- | --- | --- |\n| `SETFP` | `0x5c` | 3 | 값을 pop해 프레임 포인터로 설정 |\n| `GETFP` | `0x5d` | 3 | 현재 프레임 포인터를 push |\n| `MLOADFP` | `0x5e` | 3* | `MLOAD`와 같지만 주소 = 피연산자 + FP |\n| `MSTOREFP` | `0x5f` | 3* | `MSTORE`와 같지만 주소 = 피연산자 + FP |\n\n\\* 메모리 확장을 포함해 `MLOAD`/`MSTORE`와 같은 비용입니다.\n\n`operand + FP`가 음수이면 이 명령은 잘못된 opcode처럼 실패합니다(모든 가스를 소모하고 컨텍스트가 revert됨). opcode 공간을 아끼기 위해 `MSTORE8FP`는 의도적으로 두지 않았습니다.\n\n이는 [EIP-3336](/eip-3336/)과 함께 설계되었습니다. EIP-3336은 페이지 메모리를 제안하여, 메모리를 드문드문 사용하는 경우(예: 높은 주소에서 아래로 자라는 스택)가 거대한 선형 블록 하나로 가격이 매겨지지 않게 하려는 것이었습니다.\n\n## 샘플 코드\n\n컴파일러가 함수 프레임에 이를 어떻게 사용할 수 있는지 보여 주는 예시입니다(설명용 어셈블리).\n\n```text\n; prologue: allocate a 0x60-byte frame below the caller's frame\nGETFP               ; [old_fp]\nDUP1                ; [old_fp, old_fp]\nPUSH1 0x60\nSWAP1\nSUB                 ; [old_fp, old_fp - 0x60]\nSETFP               ; fp = old_fp - 0x60   (old_fp kept on stack to restore)\n\n; local a = 42  (slot at fp + 0x00)\nPUSH1 0x2a\nPUSH1 0x00\nMSTOREFP\n\n; b = a + 1     (slot at fp + 0x20)\nPUSH1 0x00\nMLOADFP             ; [old_fp, a]\nPUSH1 0x01\nADD\nPUSH1 0x20\nMSTOREFP\n\n; epilogue\nSETFP               ; restore fp = old_fp\n```\n\n## 알아둘 점\n\n- 상태는 **Stagnant**입니다. 네트워크 업그레이드에 예정된 적이 없으며 `FORK_BLOCK`은 TBD로 남았습니다.\n- 제안된 opcode 바이트는 이후 다른 명령에 배정되었습니다. `0x5c`는 `TLOAD`, `0x5d`는 `TSTORE`([EIP-1153](/eip-1153/)), `0x5e`는 `MCOPY`([EIP-5656](/eip-5656/)), `0x5f`는 `PUSH0`([EIP-3855](/eip-3855/))입니다. 부활시키려면 새 번호가 필요합니다.\n- 근본적인 \"stack too deep\" 문제는 컴파일러가 변수를 자동으로 메모리로 옮기는 방법이나 [EIP-663](/eip-663/) 같은 더 깊은 스택 접근 제안 등 다른 방식으로 대부분 해결되었습니다.\n"},"zh":{"lang":"zh","tldr":"提议了四个用于帧指针的 EVM 操作码（`SETFP`、`GETFP`、`MLOADFP`、`MSTOREFP`），让编译器能够低成本地把局部变量放在内存中，摆脱“stack too deep”的限制。","tags":["evm","opcodes","memory","compilers","core"],"related":[3336,1153,5656,3855,663],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/zh/eip-3337/","markdown":"## 它解决什么问题？\n\n大多数 CPU 和虚拟机把局部变量、参数和返回地址放在内存中一块可随机访问的\"调用栈\"区域，并相对于**帧指针**寻址。而 EVM 则把它们放在求值栈上，用 `DUPn`/`SWAPn` 只能访问栈顶的 16 个元素。局部变量很多的函数会碰到 Solidity 中常见的 *stack too deep* 错误。\n\n编译器本可以改用内存，但没有专用的帧指针，这样做代价很高。目前加载一个相对于帧的值需要五个操作：\n\n| 之前 | Gas |\n| --- | --- |\n| `PUSHn x`、`PUSH1 0`、`MLOAD`（读取 FP）、`ADD`、`MLOAD` | 15 gas，≥ 7 字节 |\n| **采用本 EIP：** `PUSH1 x`、`MLOADFP` | 6 gas，≥ 3 字节 |\n\n这样一来，内存中的局部变量的成本只有 `DUPn` 的约两倍，而不是五倍，相对于帧的存储也会变得和 `SWAPn POP` 一样便宜。\n\n## 它如何运作\n\nEVM 新增一个内部的**帧指针**，这是一个有符号整数，在每次执行开始时为 0，并新增四个操作码：\n\n| 操作码 | 字节 | Gas | 作用 |\n| --- | --- | --- | --- |\n| `SETFP` | `0x5c` | 3 | 弹出一个值并把帧指针设为该值 |\n| `GETFP` | `0x5d` | 3 | 压入当前帧指针 |\n| `MLOADFP` | `0x5e` | 3* | 类似 `MLOAD`，但地址 = 操作数 + FP |\n| `MSTOREFP` | `0x5f` | 3* | 类似 `MSTORE`，但地址 = 操作数 + FP |\n\n\\* 与 `MLOAD`/`MSTORE` 成本相同，包括内存扩展。\n\n如果 `operand + FP` 为负数，该指令会像无效操作码一样失败（消耗所有 gas，上下文被回滚）。为节省操作码空间，刻意没有设置 `MSTORE8FP`。\n\n它与 [EIP-3336](/eip-3336/) 一同设计，后者提议了分页内存，使得对内存的稀疏使用（例如从高地址向下增长的栈）不会被按一整块巨大的线性内存计价。\n\n## 示例代码\n\n编译器可能如何为函数帧使用它（示意性汇编）：\n\n```text\n; prologue: allocate a 0x60-byte frame below the caller's frame\nGETFP               ; [old_fp]\nDUP1                ; [old_fp, old_fp]\nPUSH1 0x60\nSWAP1\nSUB                 ; [old_fp, old_fp - 0x60]\nSETFP               ; fp = old_fp - 0x60   (old_fp kept on stack to restore)\n\n; local a = 42  (slot at fp + 0x00)\nPUSH1 0x2a\nPUSH1 0x00\nMSTOREFP\n\n; b = a + 1     (slot at fp + 0x20)\nPUSH1 0x00\nMLOADFP             ; [old_fp, a]\nPUSH1 0x01\nADD\nPUSH1 0x20\nMSTOREFP\n\n; epilogue\nSETFP               ; restore fp = old_fp\n```\n\n## 需要注意\n\n- 状态为 **Stagnant**；它从未被排入任何网络升级，`FORK_BLOCK` 一直是 TBD。\n- 它提议的操作码字节后来已被分配给其他指令：`0x5c` `TLOAD` 和 `0x5d` `TSTORE`（[EIP-1153](/eip-1153/)）、`0x5e` `MCOPY`（[EIP-5656](/eip-5656/)）以及 `0x5f` `PUSH0`（[EIP-3855](/eip-3855/)）。任何复活该提案的尝试都需要新的编号。\n- 底层的\"stack too deep\"问题已大多通过其他方式解决，例如编译器自动把变量移到内存中，以及像 [EIP-663](/eip-663/) 这样提议提供更深栈访问的方案。\n"}}}
