{"eip":7877,"title":"Enhanced RETURN opcodes","description":"Deprecate RETURN opcode in favor of new opcodes that allow returning data from various locations without first having to write to memory.","authors":["Josh Weintraub (@jhweintraub)"],"status":"Stagnant","type":"Standards Track","category":"Core","created":"2025-01-31","requires":[6,1153,3855],"discussionsTo":"https://ethereum-magicians.org/t/eip-7877-new-m-s-t-rreturn-opcodes/22731","repo":"EIPs","label":"EIP-7877","officialUrl":"https://eips.ethereum.org/EIPS/eip-7877","sourceUrl":"https://github.com/ethereum/EIPs/blob/master/EIPS/eip-7877.md","url":"https://eips.huatuo.xyz/eip-7877/","tldr":{"en":"Proposes SRETURN, TRETURN and RRETURN opcodes that return data straight from storage, transient storage or return data, skipping the copy into memory that RETURN requires.","ja":"RETURN が必要とするメモリへのコピーを省き、ストレージ、transient storage、return data から直接データを返す SRETURN、TRETURN、RRETURN オペコードを提案する。","ko":"RETURN이 요구하는 메모리 복사를 건너뛰고 스토리지, transient storage, return data에서 곧바로 데이터를 반환하는 SRETURN, TRETURN, RRETURN 오피코드를 제안한다.","zh":"提议新增 SRETURN、TRETURN 和 RRETURN 操作码，直接从存储、瞬态存储或返回数据中返回数据，省去 RETURN 所需的拷贝到内存的步骤。"},"tags":["evm","opcode","gas","transient-storage","core"],"explainers":{"en":{"lang":"en","tldr":"Proposes SRETURN, TRETURN and RRETURN opcodes that return data straight from storage, transient storage or return data, skipping the copy into memory that RETURN requires.","tags":["evm","opcode","gas","transient-storage","core"],"related":[1153,3855,211,6],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/eip-7877/","markdown":"## What problem does it solve?\n\n`RETURN` can only return bytes from memory. If the data you want to return sits elsewhere, you first copy it into memory and then return it:\n\n- With [EIP-1153](/eip-1153/) transient storage, many callbacks stash data in `TSTORE` and later return it, paying for `TLOAD` + `MSTORE` loops and memory expansion.\n- Returning values held in persistent storage has the same overhead with `SLOAD`.\n- Forwarding (part of) another call's return data needs `RETURNDATACOPY` into memory first.\n\nEIP-7877 lets a contract name the source directly, which saves gas and makes the bytecode simpler to analyze.\n\n## How it works\n\nThree new opcodes, and `RETURN` gets an alias:\n\n| Opcode | Byte | Returns |\n| --- | --- | --- |\n| `MRETURN` | `0xf3` | Memory (just a new name for `RETURN`, unchanged) |\n| `SRETURN` | `0xf6` | Consecutive storage slots |\n| `TRETURN` | `0xf7` | Consecutive transient-storage slots |\n| `RRETURN` | `0xf8` | A slice of the current return-data buffer |\n\n- **`SRETURN` / `TRETURN`** pop `slot` and `length`. They read `slot`, `slot+1`, ..., write each as its 32-byte big-endian word (exactly as `MSTORE` would), concatenate them and return the first `length` bytes. A partial final slot contributes only its leading bytes; unset slots read as zeros.\n- **`RRETURN`** pops `offset` and `length` and returns `RETURNDATA[offset : offset+length]`. Out-of-bounds reads fail, with the same rules as `RETURNDATACOPY` ([EIP-211](/eip-211/)).\n\nProposed gas: `SRETURN` charges 2,100 per cold slot and 100 per warm slot; `TRETURN` 100 per slot; `RRETURN` like `RETURNDATACOPY` minus memory expansion (3 + 3 per word). The renaming has precedent in [EIP-6](/eip-6/) (`SUICIDE` to `SELFDESTRUCT`), and the gas-saving motive mirrors [EIP-3855](/eip-3855/) `PUSH0`.\n\n## Sample code\n\nReturning two words from transient storage, today vs. proposed (assembly pseudocode):\n\n```solidity\n// Today: copy to memory, then RETURN\nassembly {\n    mstore(0x00, tload(0))\n    mstore(0x20, tload(1))\n    return(0x00, 0x40)\n}\n\n// With EIP-7877 (not valid Solidity today; illustrative)\nassembly {\n    treturn(0, 0x40) // slots 0 and 1, 64 bytes, no memory touched\n}\n```\n\nOpcode-level view:\n\n```text\n6040  PUSH1 0x40   // length = 64 bytes\n5f    PUSH0        // slot = 0\nf7    TRETURN\n```\n\n## Things to know\n\n- Status: **Stagnant**. No upgrade has scheduled it, and the gas formulas are written as a rough proposal (\"should be similar to the cost of accessing data now\").\n- The spec suggests activating it in a future EVM version once EOF is implemented; EOF itself has not shipped on mainnet.\n- Existing contracts are unaffected: `MRETURN` is byte-for-byte the old `RETURN`.\n- Compilers would need to adopt the opcodes before typical Solidity code benefits.\n"},"ja":{"lang":"ja","tldr":"RETURN が必要とするメモリへのコピーを省き、ストレージ、transient storage、return data から直接データを返す SRETURN、TRETURN、RRETURN オペコードを提案する。","tags":["evm","opcode","gas","transient-storage","core"],"related":[1153,3855,211,6],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ja/eip-7877/","markdown":"## 何を解決するのか\n\n`RETURN` が返せるのは、メモリ上のバイト列だけです。返したいデータが別の場所にある場合は、まずメモリにコピーしてから返すことになります。\n\n- [EIP-1153](/eip-1153/) の transient storage では、多くのコールバックがデータを `TSTORE` に置き、後でそれを返します。そのため `TLOAD` + `MSTORE` のループとメモリ拡張の分を支払います。\n- 永続ストレージに保持された値を返す場合も、`SLOAD` で同じオーバーヘッドがかかります。\n- 別の呼び出しの return data（の一部）を転送するには、まず `RETURNDATACOPY` でメモリにコピーする必要があります。\n\nEIP-7877 は、コントラクトが取得元を直接指定できるようにすることで、gas を節約し、バイトコードを解析しやすくします。\n\n## 仕組み\n\n新しいオペコードが 3 つ追加され、`RETURN` にはエイリアスが付きます。\n\n| オペコード | バイト | 返すもの |\n| --- | --- | --- |\n| `MRETURN` | `0xf3` | メモリ（`RETURN` の新しい名前にすぎず、変更なし） |\n| `SRETURN` | `0xf6` | 連続するストレージスロット |\n| `TRETURN` | `0xf7` | 連続する transient storage スロット |\n| `RRETURN` | `0xf8` | 現在の return-data バッファのスライス |\n\n- **`SRETURN` / `TRETURN`** は `slot` と `length` を pop します。`slot`、`slot+1`、… を読み取り、それぞれを 32 バイトのビッグエンディアンのワードとして書き出し（`MSTORE` とまったく同じ）、連結して先頭 `length` バイトを返します。最後のスロットが一部だけの場合は、先頭のバイトだけが使われ、未設定のスロットはゼロとして読まれます。\n- **`RRETURN`** は `offset` と `length` を pop し、`RETURNDATA[offset : offset+length]` を返します。範囲外の読み取りは失敗し、`RETURNDATACOPY`（[EIP-211](/eip-211/)）と同じルールが適用されます。\n\n提案されている gas：`SRETURN` は cold なスロットごとに 2,100、warm なスロットごとに 100。`TRETURN` はスロットごとに 100。`RRETURN` は `RETURNDATACOPY` からメモリ拡張を除いたもの（ワードごとに 3 + 3）。名前の付け替えには [EIP-6](/eip-6/)（`SUICIDE` から `SELFDESTRUCT`）という前例があり、gas を節約するという動機は [EIP-3855](/eip-3855/) の `PUSH0` と同じです。\n\n## サンプルコード\n\ntransient storage から 2 ワードを返す、現状と提案後の比較（アセンブリの疑似コード）：\n\n```solidity\n// Today: copy to memory, then RETURN\nassembly {\n    mstore(0x00, tload(0))\n    mstore(0x20, tload(1))\n    return(0x00, 0x40)\n}\n\n// With EIP-7877 (not valid Solidity today; illustrative)\nassembly {\n    treturn(0, 0x40) // slots 0 and 1, 64 bytes, no memory touched\n}\n```\n\nオペコードレベルの見え方：\n\n```text\n6040  PUSH1 0x40   // length = 64 bytes\n5f    PUSH0        // slot = 0\nf7    TRETURN\n```\n\n## 知っておくべきこと\n\n- ステータス：**Stagnant**。どのアップグレードにも予定されておらず、gas の式は大まかな提案（「現在のデータアクセスのコストに近いものであるべき」）として書かれています。\n- 仕様は、EOF が実装された後の将来の EVM バージョンで有効化することを提案しています。EOF 自体はメインネットに出荷されていません。\n- 既存のコントラクトには影響しません。`MRETURN` は従来の `RETURN` とバイト単位で同一です。\n- 一般的な Solidity コードが恩恵を受けるには、コンパイラがこれらのオペコードに対応する必要があります。\n"},"ko":{"lang":"ko","tldr":"RETURN이 요구하는 메모리 복사를 건너뛰고 스토리지, transient storage, return data에서 곧바로 데이터를 반환하는 SRETURN, TRETURN, RRETURN 오피코드를 제안한다.","tags":["evm","opcode","gas","transient-storage","core"],"related":[1153,3855,211,6],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ko/eip-7877/","markdown":"## 어떤 문제를 해결하나요?\n\n`RETURN`은 메모리에 있는 바이트만 반환할 수 있습니다. 반환하려는 데이터가 다른 곳에 있다면 먼저 메모리로 복사한 다음 반환해야 합니다.\n\n- [EIP-1153](/eip-1153/) transient storage에서는 많은 콜백이 데이터를 `TSTORE`에 두었다가 나중에 반환하므로, `TLOAD` + `MSTORE` 루프와 메모리 확장 비용을 냅니다.\n- 영구 스토리지에 있는 값을 반환할 때도 `SLOAD`로 같은 오버헤드가 듭니다.\n- 다른 호출의 return data(의 일부)를 전달하려면 먼저 `RETURNDATACOPY`로 메모리에 복사해야 합니다.\n\nEIP-7877은 컨트랙트가 출처를 직접 지정하게 해 gas를 절약하고 바이트코드를 분석하기 쉽게 만듭니다.\n\n## 어떻게 동작하나요?\n\n새 오피코드 세 개가 추가되고 `RETURN`에는 별칭이 생깁니다.\n\n| 오피코드 | 바이트 | 반환하는 것 |\n| --- | --- | --- |\n| `MRETURN` | `0xf3` | 메모리(`RETURN`의 새 이름일 뿐, 변경 없음) |\n| `SRETURN` | `0xf6` | 연속된 스토리지 슬롯 |\n| `TRETURN` | `0xf7` | 연속된 transient storage 슬롯 |\n| `RRETURN` | `0xf8` | 현재 return-data 버퍼의 일부 |\n\n- **`SRETURN` / `TRETURN`**은 `slot`과 `length`를 pop합니다. `slot`, `slot+1`, …을 읽어 각각을 32바이트 빅엔디언 워드로 기록하고(`MSTORE`와 똑같이), 이어 붙여 앞의 `length`바이트를 반환합니다. 마지막 슬롯이 일부만 필요하면 앞쪽 바이트만 기여하고, 설정되지 않은 슬롯은 0으로 읽힙니다.\n- **`RRETURN`**은 `offset`과 `length`를 pop하고 `RETURNDATA[offset : offset+length]`를 반환합니다. 범위를 벗어난 읽기는 실패하며, 규칙은 `RETURNDATACOPY`([EIP-211](/eip-211/))와 같습니다.\n\n제안된 gas: `SRETURN`은 cold 슬롯당 2,100, warm 슬롯당 100을 부과하고, `TRETURN`은 슬롯당 100, `RRETURN`은 메모리 확장을 뺀 `RETURNDATACOPY`와 같습니다(워드당 3 + 3). 이름을 바꾸는 데는 [EIP-6](/eip-6/)(`SUICIDE`에서 `SELFDESTRUCT`로)이라는 선례가 있고, gas를 절약한다는 동기는 [EIP-3855](/eip-3855/)의 `PUSH0`와 같습니다.\n\n## 샘플 코드\n\ntransient storage에서 두 워드를 반환하는 방식, 현재와 제안 후 비교(어셈블리 의사 코드):\n\n```solidity\n// Today: copy to memory, then RETURN\nassembly {\n    mstore(0x00, tload(0))\n    mstore(0x20, tload(1))\n    return(0x00, 0x40)\n}\n\n// With EIP-7877 (not valid Solidity today; illustrative)\nassembly {\n    treturn(0, 0x40) // slots 0 and 1, 64 bytes, no memory touched\n}\n```\n\n오피코드 수준에서 본 모습:\n\n```text\n6040  PUSH1 0x40   // length = 64 bytes\n5f    PUSH0        // slot = 0\nf7    TRETURN\n```\n\n## 알아둘 점\n\n- 상태: **Stagnant**. 어떤 업그레이드에도 예정되어 있지 않으며, gas 공식은 대략적인 제안(\"지금 데이터에 접근하는 비용과 비슷해야 함\")으로 쓰여 있습니다.\n- 스펙은 EOF가 구현된 뒤 미래 EVM 버전에서 활성화하자고 제안합니다. EOF 자체는 메인넷에 출시되지 않았습니다.\n- 기존 컨트랙트는 영향을 받지 않습니다. `MRETURN`은 예전 `RETURN`과 바이트 단위로 같습니다.\n- 일반적인 Solidity 코드가 혜택을 보려면 컴파일러가 이 오피코드를 채택해야 합니다.\n"},"zh":{"lang":"zh","tldr":"提议新增 SRETURN、TRETURN 和 RRETURN 操作码，直接从存储、瞬态存储或返回数据中返回数据，省去 RETURN 所需的拷贝到内存的步骤。","tags":["evm","opcode","gas","transient-storage","core"],"related":[1153,3855,211,6],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/zh/eip-7877/","markdown":"## 它解决什么问题？\n\n`RETURN` 只能返回内存中的字节。如果想返回的数据在别处，就必须先把它拷贝到内存，再返回：\n\n- 使用 [EIP-1153](/eip-1153/) 瞬态存储时，许多回调把数据暂存在 `TSTORE` 中，之后再返回，需要为 `TLOAD` + `MSTORE` 循环和内存扩展付费。\n- 返回持久存储中的值，用 `SLOAD` 也有同样的开销。\n- 转发另一次调用的返回数据（的一部分），需要先用 `RETURNDATACOPY` 拷贝到内存。\n\nEIP-7877 让合约直接指定数据来源，从而节省 gas，并使字节码更易于分析。\n\n## 它如何运作\n\n新增三个操作码，并且 `RETURN` 获得一个别名：\n\n| 操作码 | 字节 | 返回内容 |\n| --- | --- | --- |\n| `MRETURN` | `0xf3` | 内存（只是 `RETURN` 的新名字，行为不变） |\n| `SRETURN` | `0xf6` | 连续的存储槽 |\n| `TRETURN` | `0xf7` | 连续的瞬态存储槽 |\n| `RRETURN` | `0xf8` | 当前返回数据缓冲区的一个切片 |\n\n- **`SRETURN` / `TRETURN`** 弹出 `slot` 和 `length`。它们读取 `slot`、`slot+1`……，把每个槽写成 32 字节的大端字（与 `MSTORE` 完全一样），拼接起来并返回前 `length` 个字节。最后一个槽如果只用到一部分，则只贡献其开头的字节；未设置的槽读取为零。\n- **`RRETURN`** 弹出 `offset` 和 `length`，返回 `RETURNDATA[offset : offset+length]`。越界读取会失败，规则与 `RETURNDATACOPY`（[EIP-211](/eip-211/)）相同。\n\n提议的 gas：`SRETURN` 对每个 cold 槽收取 2,100，对每个 warm 槽收取 100；`TRETURN` 每个槽 100；`RRETURN` 与 `RETURNDATACOPY` 相同但不含内存扩展（每个字 3 + 3）。重命名有先例，即 [EIP-6](/eip-6/)（`SUICIDE` 改为 `SELFDESTRUCT`），节省 gas 的动机与 [EIP-3855](/eip-3855/) 的 `PUSH0` 相同。\n\n## 示例代码\n\n从瞬态存储返回两个字，现状与提议后的对比（汇编伪代码）：\n\n```solidity\n// Today: copy to memory, then RETURN\nassembly {\n    mstore(0x00, tload(0))\n    mstore(0x20, tload(1))\n    return(0x00, 0x40)\n}\n\n// With EIP-7877 (not valid Solidity today; illustrative)\nassembly {\n    treturn(0, 0x40) // slots 0 and 1, 64 bytes, no memory touched\n}\n```\n\n操作码层面的视图：\n\n```text\n6040  PUSH1 0x40   // length = 64 bytes\n5f    PUSH0        // slot = 0\nf7    TRETURN\n```\n\n## 需要注意\n\n- 状态：**Stagnant**。没有任何升级将其纳入计划，gas 公式也只是粗略的提议（“应与目前访问数据的成本相近”）。\n- 规范建议在 EOF 实现之后的未来 EVM 版本中激活它；EOF 本身尚未在主网上线。\n- 现有合约不受影响：`MRETURN` 与旧的 `RETURN` 逐字节相同。\n- 编译器需要先采用这些操作码，典型的 Solidity 代码才能受益。\n"}}}
