HomeEIPsNewsletter
EIPsEIP-7843
EIP-7843

SLOTNUM opcode

Opcode to get the current slot number
DraftStandards Track: Core
Created: 2024-12-06
Marc Harvey-Hill (@Marchhill)
Discussions ForumOriginal Proposal LinkEdit
1 min read
Anyone may contribute to propose contents.
Go propose
Video
Anyone may contribute to propose contents.
Go propose
Original

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

StackValue
top - 0SlotNumber

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.

Further reading
Anyone may contribute to propose contents.
Go propose

Not miss a beat of EIPs' update?

Subscribe EIPs Fun to receive the latest updates of EIPs Good for Buidlers to follow up.

View all
Serve Ethereum Builders, Scale the Community.
Resources
GitHub