{"eip":7843,"title":"SLOTNUM opcode","description":"Opcode to get the current slot number","authors":["Marc Harvey-Hill (@Marchhill)"],"status":"Last Call","type":"Standards Track","category":"Core","created":"2024-12-06","discussionsTo":"https://ethereum-magicians.org/t/eip-7843-slotnum-opcode/22234","repo":"EIPs","label":"EIP-7843","officialUrl":"https://eips.ethereum.org/EIPS/eip-7843","sourceUrl":"https://github.com/ethereum/EIPs/blob/master/EIPS/eip-7843.md","url":"https://eips.huatuo.xyz/eip-7843/","tldr":{"en":"Adds a SLOTNUM opcode (0x4b) that returns the beacon-chain slot number of the current block, so contracts no longer hardcode the 12-second slot length.","ja":"現在のブロックのビーコンチェーンのスロット番号を返す SLOTNUM オペコード（0x4b）を追加する。コントラクトが 12 秒というスロット長をハードコードしなくて済むようにする。","ko":"현재 블록의 비콘 체인 슬롯 번호를 반환하는 SLOTNUM 오피코드(0x4b)를 추가한다. 컨트랙트가 12초라는 슬롯 길이를 하드코딩하지 않아도 된다.","zh":"新增 SLOTNUM 操作码（0x4b），返回当前区块的信标链 slot 编号，使合约不再需要硬编码 12 秒的 slot 时长。"},"tags":["evm","opcode","consensus","slots","core"],"explainers":{"en":{"lang":"en","tldr":"Adds a SLOTNUM opcode (0x4b) that returns the beacon-chain slot number of the current block, so contracts no longer hardcode the 12-second slot length.","tags":["evm","opcode","consensus","slots","core"],"related":[4788],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/eip-7843/","markdown":"## What problem does it solve?\n\nSince the Merge, every Ethereum block belongs to a beacon-chain slot. Some contracts care about the slot number: for example, anything that lines up with validator duties, preconfirmations or beacon-chain proofs. Today they have two options:\n\n1. **Compute it from `block.timestamp`** using a hardcoded genesis time and slot length. Cheap, but it silently breaks if the slot length ever changes, and shortening slots is under active discussion.\n2. **Pass the slot in calldata and prove it** against the beacon block root exposed by [EIP-4788](/eip-4788/). Robust, but expensive, so people tend to use option 1 anyway.\n\nEIP-7843 removes the dilemma by exposing the slot number directly.\n\n## How it works\n\n- New opcode **`SLOTNUM` at `0x4b`**. It takes no inputs and pushes one word: the current block's slot number, a `uint64`.\n- Gas cost is a flat **2**, like other simple block-context opcodes (`TIMESTAMP`, `NUMBER`, ...).\n- The consensus layer, which already knows the slot, passes it to the execution layer via the Engine API: new `ExecutionPayloadV4` and `PayloadAttributesV4` objects with a `slotNumber` field, used by `engine_newPayloadV5`, `engine_getPayloadV6` and `engine_forkchoiceUpdatedV4`.\n- The execution block header gains a `slotNumber` field, so each block is self-contained. Light clients and ZK-EVM provers need no extra inputs, much as for `TIMESTAMP`.\n\nComputing the value in the consensus layer avoids duplicating the slot/timestamp logic in execution clients, and leaves room to change slot timing later.\n\n## Sample code\n\nRaw EVM bytecode for a function that just returns the slot number (no compiler support is needed to see the semantics):\n\n```text\n4b        SLOTNUM          // stack: [slot]\n5f        PUSH0            // stack: [0, slot]\n52        MSTORE           // memory[0..32] = slot\n6020      PUSH1 0x20\n5f        PUSH0\nf3        RETURN           // return 32 bytes\n```\n\nExecution-client pseudocode:\n\n```python\ndef slotnum(evm):\n    charge_gas(evm, 2)                       # same tier as TIMESTAMP\n    evm.stack.push(U256(evm.block_env.slot_number))  # from the block header\n```\n\nThe fragile pattern it replaces:\n\n```solidity\n// Breaks if slot duration changes.\nuint256 constant GENESIS = 1606824023;\nuint256 constant SLOT_SECONDS = 12;\nuint256 slot = (block.timestamp - GENESIS) / SLOT_SECONDS;\n```\n\n## Things to know\n\n- Status: **Last Call**, with a deadline of 2026-11-01 in the spec. It is not yet Final, and the opcode is not live until a network upgrade activates it.\n- Engine API method and object version numbers in the spec depend on what other upgrades ship alongside it and may be renumbered.\n- Solidity and other compilers need to add support before contracts can use it without hand-written bytecode.\n- Header extensions affect anyone who RLP-decodes block headers directly.\n"},"ja":{"lang":"ja","tldr":"現在のブロックのビーコンチェーンのスロット番号を返す SLOTNUM オペコード（0x4b）を追加する。コントラクトが 12 秒というスロット長をハードコードしなくて済むようにする。","tags":["evm","opcode","consensus","slots","core"],"related":[4788],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ja/eip-7843/","markdown":"## 何を解決するのか\n\nMerge 以降、Ethereum のすべてのブロックはビーコンチェーンのスロットに属しています。コントラクトの中には、スロット番号を必要とするものがあります。たとえば、バリデーターの職務、preconfirmation、ビーコンチェーンの証明と足並みをそろえるものです。現状、選択肢は 2 つあります。\n\n1. ハードコードした genesis 時刻とスロット長を使い、**`block.timestamp` から計算する**。安価ですが、スロット長が変わると気付かないうちに壊れます。スロットを短くすることは活発に議論されています。\n2. **スロットを calldata で渡して**、[EIP-4788](/eip-4788/) が公開するビーコンブロックの root に対して証明する。堅牢ですが高価なため、結局 1 を使う人が多いのが実情です。\n\nEIP-7843 は、スロット番号を直接公開することで、このジレンマを解消します。\n\n## 仕組み\n\n- 新しいオペコード **`SLOTNUM`（`0x4b`）**。入力はなく、現在のブロックのスロット番号（`uint64`）を 1 ワード push します。\n- gas コストは、他の単純なブロックコンテキストのオペコード（`TIMESTAMP`、`NUMBER` など）と同じく、一律 **2** です。\n- すでにスロットを知っているコンセンサスレイヤーが、Engine API を通じて実行レイヤーに渡します。`slotNumber` フィールドを持つ新しい `ExecutionPayloadV4` と `PayloadAttributesV4` オブジェクトが、`engine_newPayloadV5`、`engine_getPayloadV6`、`engine_forkchoiceUpdatedV4` で使われます。\n- 実行ブロックヘッダーに `slotNumber` フィールドが加わるため、各ブロックは自己完結します。ライトクライアントや ZK-EVM の prover は、`TIMESTAMP` のときと同様に、追加の入力を必要としません。\n\nこの値をコンセンサスレイヤーで計算することで、実行クライアントにスロットとタイムスタンプのロジックを重複して持たせずに済み、将来スロットのタイミングを変更する余地も残ります。\n\n## サンプルコード\n\nスロット番号を返すだけの関数の生の EVM バイトコード（意味を理解するのにコンパイラのサポートは不要です）：\n\n```text\n4b        SLOTNUM          // stack: [slot]\n5f        PUSH0            // stack: [0, slot]\n52        MSTORE           // memory[0..32] = slot\n6020      PUSH1 0x20\n5f        PUSH0\nf3        RETURN           // return 32 bytes\n```\n\n実行クライアントの疑似コード：\n\n```python\ndef slotnum(evm):\n    charge_gas(evm, 2)                       # same tier as TIMESTAMP\n    evm.stack.push(U256(evm.block_env.slot_number))  # from the block header\n```\n\nこれが置き換える、壊れやすいパターン：\n\n```solidity\n// Breaks if slot duration changes.\nuint256 constant GENESIS = 1606824023;\nuint256 constant SLOT_SECONDS = 12;\nuint256 slot = (block.timestamp - GENESIS) / SLOT_SECONDS;\n```\n\n## 知っておくべきこと\n\n- ステータス：**Last Call**。仕様上の期限は 2026-11-01 です。まだ Final ではなく、ネットワークアップグレードで有効化されるまで、このオペコードは使えません。\n- 仕様にある Engine API のメソッドやオブジェクトのバージョン番号は、一緒に出荷される他のアップグレードに依存しており、振り直される可能性があります。\n- 手書きのバイトコードなしでコントラクトから使えるようにするには、Solidity などのコンパイラが対応する必要があります。\n- ヘッダーの拡張は、ブロックヘッダーを直接 RLP デコードしている人に影響します。\n"},"ko":{"lang":"ko","tldr":"현재 블록의 비콘 체인 슬롯 번호를 반환하는 SLOTNUM 오피코드(0x4b)를 추가한다. 컨트랙트가 12초라는 슬롯 길이를 하드코딩하지 않아도 된다.","tags":["evm","opcode","consensus","slots","core"],"related":[4788],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ko/eip-7843/","markdown":"## 어떤 문제를 해결하나요?\n\nThe Merge 이후 모든 이더리움 블록은 비콘 체인의 슬롯에 속합니다. 일부 컨트랙트는 슬롯 번호를 필요로 합니다. 예를 들어 검증자 의무, preconfirmation, 비콘 체인 증명과 맞물리는 모든 것이 그렇습니다. 지금은 두 가지 선택지가 있습니다.\n\n1. 하드코딩한 제네시스 시각과 슬롯 길이로 **`block.timestamp`에서 계산**합니다. 저렴하지만 슬롯 길이가 바뀌면 조용히 깨지며, 슬롯을 줄이는 방안은 활발히 논의되고 있습니다.\n2. **슬롯을 calldata로 넘기고** [EIP-4788](/eip-4788/)이 노출하는 비콘 블록 루트에 대해 증명합니다. 견고하지만 비싸서, 결국 사람들은 1번을 쓰는 경향이 있습니다.\n\nEIP-7843은 슬롯 번호를 직접 노출해 이 딜레마를 없앱니다.\n\n## 어떻게 동작하나요?\n\n- 새 오피코드 **`SLOTNUM`, `0x4b`**. 입력이 없고 현재 블록의 슬롯 번호(`uint64`)를 한 워드로 push합니다.\n- gas 비용은 다른 단순한 블록 컨텍스트 오피코드(`TIMESTAMP`, `NUMBER` 등)처럼 고정 **2**입니다.\n- 이미 슬롯을 알고 있는 합의 계층이 Engine API를 통해 실행 계층에 전달합니다. `slotNumber` 필드를 가진 새 `ExecutionPayloadV4`와 `PayloadAttributesV4` 객체가 `engine_newPayloadV5`, `engine_getPayloadV6`, `engine_forkchoiceUpdatedV4`에서 쓰입니다.\n- 실행 블록 헤더에 `slotNumber` 필드가 추가되므로 각 블록이 자체 완결적입니다. 라이트 클라이언트와 ZK-EVM prover는 `TIMESTAMP`와 마찬가지로 추가 입력이 필요 없습니다.\n\n값을 합의 계층에서 계산하면 실행 클라이언트에서 슬롯/타임스탬프 로직이 중복되는 것을 피하고, 나중에 슬롯 타이밍을 바꿀 여지도 남습니다.\n\n## 샘플 코드\n\n슬롯 번호만 반환하는 함수의 원시 EVM 바이트코드(의미를 보는 데 컴파일러 지원은 필요 없습니다):\n\n```text\n4b        SLOTNUM          // stack: [slot]\n5f        PUSH0            // stack: [0, slot]\n52        MSTORE           // memory[0..32] = slot\n6020      PUSH1 0x20\n5f        PUSH0\nf3        RETURN           // return 32 bytes\n```\n\n실행 클라이언트 의사 코드:\n\n```python\ndef slotnum(evm):\n    charge_gas(evm, 2)                       # same tier as TIMESTAMP\n    evm.stack.push(U256(evm.block_env.slot_number))  # from the block header\n```\n\n이것이 대체하는 취약한 패턴:\n\n```solidity\n// Breaks if slot duration changes.\nuint256 constant GENESIS = 1606824023;\nuint256 constant SLOT_SECONDS = 12;\nuint256 slot = (block.timestamp - GENESIS) / SLOT_SECONDS;\n```\n\n## 알아둘 점\n\n- 상태: **Last Call**, 스펙상 마감일은 2026-11-01입니다. 아직 Final이 아니며, 네트워크 업그레이드로 활성화되기 전에는 이 오피코드를 쓸 수 없습니다.\n- 스펙에 있는 Engine API 메서드와 객체의 버전 번호는 함께 출시되는 다른 업그레이드에 따라 달라지며 번호가 다시 매겨질 수 있습니다.\n- 손으로 쓴 바이트코드 없이 컨트랙트에서 사용하려면 Solidity 등 컴파일러가 지원을 추가해야 합니다.\n- 헤더 확장은 블록 헤더를 직접 RLP 디코딩하는 모든 사람에게 영향을 줍니다.\n"},"zh":{"lang":"zh","tldr":"新增 SLOTNUM 操作码（0x4b），返回当前区块的信标链 slot 编号，使合约不再需要硬编码 12 秒的 slot 时长。","tags":["evm","opcode","consensus","slots","core"],"related":[4788],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/zh/eip-7843/","markdown":"## 它解决什么问题？\n\n自 The Merge 以来，每个以太坊区块都属于一个信标链 slot。有些合约关心 slot 编号：例如任何需要与验证者职责、预确认或信标链证明对齐的场景。目前它们有两种选择：\n\n1. **根据 `block.timestamp` 计算**，使用硬编码的创世时间和 slot 时长。成本低，但一旦 slot 时长改变就会悄无声息地失效，而缩短 slot 正在被积极讨论。\n2. **通过 calldata 传入 slot**，并针对 [EIP-4788](/eip-4788/) 暴露的信标区块根进行证明。稳健，但成本高，所以人们往往还是选择方案 1。\n\nEIP-7843 通过直接暴露 slot 编号，消除了这一两难。\n\n## 它如何运作\n\n- 新操作码 **`SLOTNUM`，位于 `0x4b`**。它没有输入，压入一个字：当前区块的 slot 编号，类型为 `uint64`。\n- gas 成本固定为 **2**，与其他简单的区块上下文操作码（`TIMESTAMP`、`NUMBER` 等）相同。\n- 共识层本来就知道 slot，它通过 Engine API 把 slot 传给执行层：新增带有 `slotNumber` 字段的 `ExecutionPayloadV4` 和 `PayloadAttributesV4` 对象，供 `engine_newPayloadV5`、`engine_getPayloadV6` 和 `engine_forkchoiceUpdatedV4` 使用。\n- 执行区块头新增 `slotNumber` 字段，因此每个区块都是自包含的。轻客户端和 ZK-EVM 证明者不需要额外输入，就像 `TIMESTAMP` 一样。\n\n在共识层计算该值，可以避免在执行客户端中重复 slot/时间戳逻辑，并为日后更改 slot 时序留出空间。\n\n## 示例代码\n\n一个只返回 slot 编号的函数的原始 EVM 字节码（无需编译器支持即可看清其语义）：\n\n```text\n4b        SLOTNUM          // stack: [slot]\n5f        PUSH0            // stack: [0, slot]\n52        MSTORE           // memory[0..32] = slot\n6020      PUSH1 0x20\n5f        PUSH0\nf3        RETURN           // return 32 bytes\n```\n\n执行客户端伪代码：\n\n```python\ndef slotnum(evm):\n    charge_gas(evm, 2)                       # same tier as TIMESTAMP\n    evm.stack.push(U256(evm.block_env.slot_number))  # from the block header\n```\n\n它所取代的脆弱写法：\n\n```solidity\n// Breaks if slot duration changes.\nuint256 constant GENESIS = 1606824023;\nuint256 constant SLOT_SECONDS = 12;\nuint256 slot = (block.timestamp - GENESIS) / SLOT_SECONDS;\n```\n\n## 需要注意\n\n- 状态：**Last Call**，规范中的截止日期为 2026-11-01。它尚未 Final，在网络升级将其激活之前，该操作码不会生效。\n- 规范中的 Engine API 方法和对象版本号取决于与之同时发布的其他升级，可能会重新编号。\n- Solidity 等编译器需要先添加支持，合约才能在不手写字节码的情况下使用它。\n- 区块头扩展会影响任何直接对区块头做 RLP 解码的人。\n"}},"requiredBy":[7793,8272,8369]}
