{"eip":7958,"title":"EVM64 - Little endian opcodes","description":"Little endian opcodes `BYTE64`, `MLOAD64`, `MSTORE64`, and `PUSH*64` for EVM64","authors":["Wei Tang (@sorpaas)"],"status":"Stagnant","type":"Standards Track","category":"Core","created":"2025-05-26","requires":[7937],"discussionsTo":"https://ethereum-magicians.org/t/eip-7937-64-bit-mode-evm-opcodes-evm64/23794","repo":"EIPs","label":"EIP-7958","officialUrl":"https://eips.ethereum.org/EIPS/eip-7958","sourceUrl":"https://github.com/ethereum/EIPs/blob/master/EIPS/eip-7958.md","url":"https://eips.huatuo.xyz/eip-7958/","tldr":{"en":"Defines the little-endian companion opcodes (BYTE64, MLOAD64, MSTORE64, PUSH*64) for the proposed 64-bit EVM mode of EIP-7937.","ja":"EIP-7937 で提案されている 64 ビット EVM モード向けの、リトルエンディアンの補助オペコード（BYTE64、MLOAD64、MSTORE64、PUSH*64）を定義する。","ko":"EIP-7937에서 제안한 64비트 EVM 모드를 위한 리틀 엔디언 보조 오피코드(BYTE64, MLOAD64, MSTORE64, PUSH*64)를 정의한다.","zh":"为 EIP-7937 提议的 64 位 EVM 模式定义小端序的配套操作码（BYTE64、MLOAD64、MSTORE64、PUSH*64）。"},"tags":["evm","opcodes","evm64","performance","core"],"explainers":{"en":{"lang":"en","tldr":"Defines the little-endian companion opcodes (BYTE64, MLOAD64, MSTORE64, PUSH*64) for the proposed 64-bit EVM mode of EIP-7937.","tags":["evm","opcodes","evm64","performance","core"],"related":[7937],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/eip-7958/","markdown":"## What problem does it solve?\n\nThe EVM works on 256-bit words. That is convenient for hashes and token amounts, but wasteful for ordinary counters, indexes and loop arithmetic, which fit in 64 bits and run much faster natively on modern CPUs.\n\n[EIP-7937](/eip-7937/) proposes \"EVM64\", a set of 64-bit variants of arithmetic and bitwise opcodes. That core proposal deliberately avoids any byte-order decisions. A few operations, however, cannot avoid them: picking a byte out of a number, loading or storing a number from memory, and pushing a literal from bytecode. EIP-7958 defines those operations in **little-endian** form, matching the native byte order of most hardware.\n\n## How it works\n\nAll opcodes use the two-byte `0xc0xx` prefix space from EIP-7937 and cost `G_VERYLOW64 = 2` gas.\n\n| Opcode | Code | Behaviour |\n| --- | --- | --- |\n| `BYTE64` | `0xc01a` | `(x \u003e\u003e i * 8) \u0026 0xFF`, i.e. byte `i` counted from the least significant end |\n| `MLOAD64` | `0xc051` | Read 8 bytes from memory as a little-endian 64-bit integer |\n| `MSTORE64` | `0xc052` | Write the low 64 bits of a stack value to memory, little-endian |\n| `PUSH2_64` … `PUSH8_64` | `0xc061`–`0xc067` | Push a 2- to 8-byte literal read little-endian |\n\n64-bit mode only uses the least significant 64 bits; other 256-bit opcodes see the value zero-extended. Memory expansion for `MLOAD64`/`MSTORE64` is charged as 8 bytes.\n\nContrast with the existing EVM: `BYTE` counts from the most significant end and `MLOAD` reads 32 bytes big-endian.\n\n## Sample code\n\nWorked example from the spec, as annotated bytecode:\n\n```text\n; memory[0..8] = 01 02 03 04 05 06 07 08\nPUSH1 0x00\nMLOAD64          ; c0 51 -\u003e stack: 0x0000...0807060504030201\nPUSH1 0x00\nMSTORE64         ; c0 52 -\u003e memory[0..8] = 01 02 03 04 05 06 07 08 again\n\n; PUSH8_64 with an 8-byte literal\nc0 67 01 02 03 04 05 06 07 08   ; -\u003e stack: 0x0000...0807060504030201\n```\n\nThe same byte rule in Python:\n\n```python\ndef byte64(x: int, i: int) -\u003e int:\n    return (x \u003e\u003e (i * 8)) \u0026 0xFF   # i = 0 is the least significant byte\n\nassert byte64(0x0807060504030201, 0) == 0x01\n```\n\n## Things to know\n\n- **Status: Stagnant.** There has been no recent progress and it is not scheduled for any upgrade. It only makes sense if [EIP-7937](/eip-7937/) is adopted.\n- Test cases, a reference implementation and security considerations are still marked \"to be added\" in the spec.\n- Mixing these opcodes with existing big-endian `MLOAD`/`BYTE` code requires care: the same bytes in memory produce different numbers depending on which opcode reads them.\n- For the full rationale behind 64-bit mode and its gas assumptions, read EIP-7937.\n"},"ja":{"lang":"ja","tldr":"EIP-7937 で提案されている 64 ビット EVM モード向けの、リトルエンディアンの補助オペコード（BYTE64、MLOAD64、MSTORE64、PUSH*64）を定義する。","tags":["evm","opcodes","evm64","performance","core"],"related":[7937],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ja/eip-7958/","markdown":"## 何を解決するのか\n\nEVM は 256 ビットのワードで動作します。ハッシュやトークン量には便利ですが、64 ビットに収まり、現代の CPU ではネイティブにはるかに高速に動く通常のカウンタ、インデックス、ループ演算にとっては無駄が多くなります。\n\n[EIP-7937](/eip-7937/) は、算術およびビット演算オペコードの 64 ビット版の集合である「EVM64」を提案しています。このコア提案は、バイトオーダーに関する決定を意図的に避けています。しかし、一部の操作はそれを避けられません。数値から 1 バイトを取り出すこと、メモリから数値をロードまたはストアすること、バイトコードからリテラルを push することです。EIP-7958 は、これらの操作を、ほとんどのハードウェアのネイティブなバイトオーダーに合わせた**リトルエンディアン**の形で定義します。\n\n## 仕組み\n\nすべてのオペコードは EIP-7937 の 2 バイトの `0xc0xx` プレフィックス空間を使い、gas は `G_VERYLOW64 = 2` です。\n\n| オペコード | コード | 動作 |\n| --- | --- | --- |\n| `BYTE64` | `0xc01a` | `(x \u003e\u003e i * 8) \u0026 0xFF`、つまり最下位側から数えて `i` 番目のバイト |\n| `MLOAD64` | `0xc051` | メモリから 8 バイトを読み、リトルエンディアンの 64 ビット整数として扱う |\n| `MSTORE64` | `0xc052` | スタック値の下位 64 ビットを、リトルエンディアンでメモリに書く |\n| `PUSH2_64` … `PUSH8_64` | `0xc061`～`0xc067` | リトルエンディアンで読んだ 2～8 バイトのリテラルを push する |\n\n64 ビットモードが使うのは最下位 64 ビットだけで、他の 256 ビットのオペコードからは、その値はゼロ拡張されて見えます。`MLOAD64`/`MSTORE64` のメモリ拡張は 8 バイトとして課金されます。\n\n既存の EVM との違い：`BYTE` は最上位側から数え、`MLOAD` は 32 バイトをビッグエンディアンで読みます。\n\n## サンプルコード\n\n仕様にある実例を、注釈付きバイトコードで示します：\n\n```text\n; memory[0..8] = 01 02 03 04 05 06 07 08\nPUSH1 0x00\nMLOAD64          ; c0 51 -\u003e stack: 0x0000...0807060504030201\nPUSH1 0x00\nMSTORE64         ; c0 52 -\u003e memory[0..8] = 01 02 03 04 05 06 07 08 again\n\n; PUSH8_64 with an 8-byte literal\nc0 67 01 02 03 04 05 06 07 08   ; -\u003e stack: 0x0000...0807060504030201\n```\n\n同じバイトのルールを Python で書くと：\n\n```python\ndef byte64(x: int, i: int) -\u003e int:\n    return (x \u003e\u003e (i * 8)) \u0026 0xFF   # i = 0 is the least significant byte\n\nassert byte64(0x0807060504030201, 0) == 0x01\n```\n\n## 知っておくべきこと\n\n- **ステータス：Stagnant。** 最近の進展はなく、どのアップグレードにも予定されていません。[EIP-7937](/eip-7937/) が採用された場合にのみ意味を持ちます。\n- テストケース、リファレンス実装、セキュリティに関する考慮事項は、仕様ではまだ「追加予定」とされています。\n- これらのオペコードを既存のビッグエンディアンの `MLOAD`/`BYTE` のコードと混在させるには注意が必要です。メモリ上の同じバイト列でも、どのオペコードで読むかによって異なる数値になります。\n- 64 ビットモードの根拠全体と gas の前提については、EIP-7937 を読んでください。\n"},"ko":{"lang":"ko","tldr":"EIP-7937에서 제안한 64비트 EVM 모드를 위한 리틀 엔디언 보조 오피코드(BYTE64, MLOAD64, MSTORE64, PUSH*64)를 정의한다.","tags":["evm","opcodes","evm64","performance","core"],"related":[7937],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ko/eip-7958/","markdown":"## 어떤 문제를 해결하나요?\n\nEVM은 256비트 워드로 동작합니다. 해시와 토큰 수량에는 편리하지만, 64비트에 들어가고 현대 CPU에서 네이티브로 훨씬 빠르게 도는 일반적인 카운터, 인덱스, 루프 연산에는 낭비입니다.\n\n[EIP-7937](/eip-7937/)은 산술 및 비트 연산 오피코드의 64비트 변형 모음인 \"EVM64\"를 제안합니다. 이 핵심 제안은 바이트 순서에 관한 결정을 의도적으로 피합니다. 하지만 일부 연산은 이를 피할 수 없습니다. 숫자에서 바이트 하나를 골라내기, 메모리에서 숫자를 로드하거나 저장하기, 바이트코드에서 리터럴을 push하기가 그렇습니다. EIP-7958은 이 연산들을 대부분 하드웨어의 네이티브 바이트 순서에 맞춘 **리틀 엔디언** 형태로 정의합니다.\n\n## 어떻게 동작하나요?\n\n모든 오피코드는 EIP-7937의 2바이트 `0xc0xx` 접두사 공간을 쓰며 gas 비용은 `G_VERYLOW64 = 2`입니다.\n\n| 오피코드 | 코드 | 동작 |\n| --- | --- | --- |\n| `BYTE64` | `0xc01a` | `(x \u003e\u003e i * 8) \u0026 0xFF`, 즉 최하위 쪽에서부터 센 `i`번째 바이트 |\n| `MLOAD64` | `0xc051` | 메모리에서 8바이트를 리틀 엔디언 64비트 정수로 읽음 |\n| `MSTORE64` | `0xc052` | 스택 값의 하위 64비트를 리틀 엔디언으로 메모리에 기록 |\n| `PUSH2_64` … `PUSH8_64` | `0xc061`–`0xc067` | 리틀 엔디언으로 읽은 2~8바이트 리터럴을 push |\n\n64비트 모드는 최하위 64비트만 사용하며, 다른 256비트 오피코드에는 값이 0으로 확장된 것으로 보입니다. `MLOAD64`/`MSTORE64`의 메모리 확장은 8바이트로 부과됩니다.\n\n기존 EVM과의 대비: `BYTE`는 최상위 쪽에서부터 세고, `MLOAD`는 32바이트를 빅 엔디언으로 읽습니다.\n\n## 샘플 코드\n\n스펙의 실제 예시를 주석이 달린 바이트코드로 나타내면:\n\n```text\n; memory[0..8] = 01 02 03 04 05 06 07 08\nPUSH1 0x00\nMLOAD64          ; c0 51 -\u003e stack: 0x0000...0807060504030201\nPUSH1 0x00\nMSTORE64         ; c0 52 -\u003e memory[0..8] = 01 02 03 04 05 06 07 08 again\n\n; PUSH8_64 with an 8-byte literal\nc0 67 01 02 03 04 05 06 07 08   ; -\u003e stack: 0x0000...0807060504030201\n```\n\n같은 바이트 규칙을 Python으로 쓰면:\n\n```python\ndef byte64(x: int, i: int) -\u003e int:\n    return (x \u003e\u003e (i * 8)) \u0026 0xFF   # i = 0 is the least significant byte\n\nassert byte64(0x0807060504030201, 0) == 0x01\n```\n\n## 알아둘 점\n\n- **상태: Stagnant.** 최근 진전이 없고 어떤 업그레이드에도 예정되어 있지 않습니다. [EIP-7937](/eip-7937/)이 채택될 때만 의미가 있습니다.\n- 테스트 케이스, 참조 구현, 보안 고려사항은 스펙에서 아직 \"추가 예정\"으로 표시되어 있습니다.\n- 이 오피코드를 기존 빅 엔디언 `MLOAD`/`BYTE` 코드와 섞어 쓸 때는 주의가 필요합니다. 메모리에 있는 같은 바이트라도 어떤 오피코드로 읽느냐에 따라 다른 숫자가 나옵니다.\n- 64비트 모드의 전체 근거와 gas 가정은 EIP-7937을 읽어 보세요.\n"},"zh":{"lang":"zh","tldr":"为 EIP-7937 提议的 64 位 EVM 模式定义小端序的配套操作码（BYTE64、MLOAD64、MSTORE64、PUSH*64）。","tags":["evm","opcodes","evm64","performance","core"],"related":[7937],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/zh/eip-7958/","markdown":"## 它解决什么问题？\n\nEVM 以 256 位字为单位工作。这对哈希和代币数额很方便，但对普通的计数器、索引和循环运算来说很浪费，因为它们能放进 64 位，并且在现代 CPU 上原生运行要快得多。\n\n[EIP-7937](/eip-7937/) 提议了“EVM64”，即算术和位运算操作码的一组 64 位变体。这个核心提案有意回避了任何字节序方面的决定。但有几个操作无法回避：从一个数中取出某个字节、从内存加载或存储一个数，以及从字节码中压入一个字面量。EIP-7958 以**小端序**定义这些操作，与大多数硬件的原生字节序一致。\n\n## 它如何运作\n\n所有操作码都使用 EIP-7937 中的两字节 `0xc0xx` 前缀空间，成本为 `G_VERYLOW64 = 2` gas。\n\n| 操作码 | 编码 | 行为 |\n| --- | --- | --- |\n| `BYTE64` | `0xc01a` | `(x \u003e\u003e i * 8) \u0026 0xFF`，即从最低有效端起数的第 `i` 个字节 |\n| `MLOAD64` | `0xc051` | 从内存读取 8 个字节，按小端序的 64 位整数处理 |\n| `MSTORE64` | `0xc052` | 将栈值的低 64 位按小端序写入内存 |\n| `PUSH2_64` … `PUSH8_64` | `0xc061`–`0xc067` | 压入按小端序读取的 2 到 8 字节字面量 |\n\n64 位模式只使用最低有效的 64 位；其他 256 位操作码看到的是零扩展后的值。`MLOAD64`/`MSTORE64` 的内存扩展按 8 字节计费。\n\n与现有 EVM 对比：`BYTE` 从最高有效端起数，`MLOAD` 以大端序读取 32 字节。\n\n## 示例代码\n\n规范中的实例，以带注释的字节码表示：\n\n```text\n; memory[0..8] = 01 02 03 04 05 06 07 08\nPUSH1 0x00\nMLOAD64          ; c0 51 -\u003e stack: 0x0000...0807060504030201\nPUSH1 0x00\nMSTORE64         ; c0 52 -\u003e memory[0..8] = 01 02 03 04 05 06 07 08 again\n\n; PUSH8_64 with an 8-byte literal\nc0 67 01 02 03 04 05 06 07 08   ; -\u003e stack: 0x0000...0807060504030201\n```\n\n同一条字节规则的 Python 写法：\n\n```python\ndef byte64(x: int, i: int) -\u003e int:\n    return (x \u003e\u003e (i * 8)) \u0026 0xFF   # i = 0 is the least significant byte\n\nassert byte64(0x0807060504030201, 0) == 0x01\n```\n\n## 需要注意\n\n- **状态：Stagnant。** 近期没有进展，也没有被排入任何升级。只有在 [EIP-7937](/eip-7937/) 被采纳时它才有意义。\n- 测试用例、参考实现和安全注意事项在规范中仍标注为“待补充”。\n- 将这些操作码与现有的大端序 `MLOAD`/`BYTE` 代码混用时需要小心：内存中的同样字节，由哪个操作码读取，得到的数值会不同。\n- 关于 64 位模式的完整理由及其 gas 假设，请阅读 EIP-7937。\n"}}}
