Alert Source Discuss
⚠️ Draft Standards Track: Core

EIP-7843: SLOTNUM opcode

Opcode to get the current slot number

Authors Marc Harvey-Hill (@Marchhill)
Created 2024-12-06
Discussion Link https://ethereum-magicians.org/t/eip-7843-slotnum-opcode/22234

Abstract

This EIP proposes to add a new opcode SLOTNUM (0x4b), that returns the corresponding slot number for the current block.

Motivation

There are currently two ways to get the current slot number onchain:

1) Calculate from the block timestamp. This requires hardcoding the chain slot length into a smart contract.

2) Provide the slot number as calldata and prove it against the beacon block root (using EIP-4788).

Both of these approaches have significant drawbacks. (1) would break contracts in the event of a change to the slot length. (2) is expensive in terms of gas, encouraging approach (1) to be used instead.

A better approach is for the slot length to be abstracted away from applications, and instead the slot number can be calculated in the consensus layer client and exposed by an opcode. This paves the way for future changes to the slot length.

Specification

A new opcode SLOTNUM is introduced at 0x4b. It shall return one stack element.

Output

Stack

Stack Value
top - 0 SlotNumber

SlotNumber is an 8 byte uint in big endian encoding.

Gas Cost

The gas cost for SLOTNUM is a fixed fee of 2.

RPC changes

The slot number is calculated in the consensus layer and passed to the execution layer through the engine API.

Header extension

The header encoding shall be extended to include a slot_number field of type uint64.

PayloadAttributes change

The engine API’s PayloadAttributes object shall be extended to include a slot_number field of type uint64.

Rationale

Gas Price

The opcode is priced to match similar opcodes in the W_base set.

Calculation in consensus layer

The slot number could alternatively be calculated in the execution layer using the timestamp, but it is more appropriate to calculate values pertaining to the beacon chain in the consensus layer. Additionally this avoids code duplication, as the slot number is already calculated in the consensus layer.

ZK-VM proving

The SLOTNUM opcode should not increase the complexity of proving EVM execution, as it is similar to existing opcodes such as TIMESTAMP. The slot number is included in the block header rather than as a new_payload parameter, ensuring that the block is self-contained for proving; no extra inputs to the circuit are required.

Backwards Compatibility

No backward compatibility issues found.

Test Cases

N/A

Security Considerations

None.

Copyright and related rights waived via CC0.

Citation

Please cite this document as:

Marc Harvey-Hill (@Marchhill), "EIP-7843: SLOTNUM opcode [DRAFT]," Ethereum Improvement Proposals, no. 7843, December 2024. [Online serial]. Available: https://eips.ethereum.org/EIPS/eip-7843.