Skip to content

feat: EIP-7843 — SLOTNUM opcode (Amsterdam)#10

Merged
garyschulte merged 2 commits intoConsensys:mainfrom
Gabriel-Trintinalia:eip-7843
Mar 23, 2026
Merged

feat: EIP-7843 — SLOTNUM opcode (Amsterdam)#10
garyschulte merged 2 commits intoConsensys:mainfrom
Gabriel-Trintinalia:eip-7843

Conversation

@Gabriel-Trintinalia
Copy link
Copy Markdown

@Gabriel-Trintinalia Gabriel-Trintinalia commented Mar 20, 2026

Summary

Implements EIP-7843 for the Amsterdam hardfork.

Adds the SLOTNUM opcode (0x4B) that pushes the current beacon chain slot number onto the stack, reading it from BlockEnv.

  • Gas cost: G_BASE (2)
  • slot_number is ?u64null on pre-Amsterdam or non-beacon chains; SLOTNUM halts with invalid_opcode in that case

Changes

  • src/bytecode/main.zigSLOTNUM = 0x4B constant + opcode info entry
  • src/context/block.zigslot_number: ?u64 field on BlockEnv (default null) and BlockEnvBuilder; setSlotNumber(?u64) builder method; all existing setters propagate slot_number
  • src/interpreter/host.zigslotNumber() ?u64 host method
  • src/interpreter/opcodes/environment.zigopSlotnum implementation; halts with invalid_opcode when slot number is absent
  • src/interpreter/opcodes/main.zig — re-export opSlotnum
  • src/interpreter/protocol_schedule.zigapplyAmsterdamChanges activating SLOTNUM
  • src/spec_test/runner.zigslot_number: null default

Part of Amsterdam hardfork

Related PRs: EIP-8024 (DUPN/SWAPN/EXCHANGE), EIP-7954 (max code size), EIP-7708 (transfer logs), EIP-8037 (state gas reservoir)

Adds SLOTNUM (0x4B): pushes the beacon chain slot number from the block
environment. Gas: G_BASE (2). Adds slot_number field to BlockEnv and
BlockEnvBuilder (defaults to 0).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown
Collaborator

@garyschulte garyschulte left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

generally LGTM, but IMO slotnum should be treated as optional everywhere, not just in the block env builder. Approving to unblock merge on fix.

difficulty: ?primitives.U256,
prevrandao: ?primitives.Hash,
blob_excess_gas_and_price: ?BlobExcessGasAndPrice,
slot_number: ?u64,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should add a setSlotNumber(slotnum: ?u64) function just to be consistent

/// Incorporated as part of the Cancun upgrade via EIP-4844.
blob_excess_gas_and_price: ?BlobExcessGasAndPrice,
/// Beacon chain slot number (EIP-7843, Amsterdam+).
slot_number: u64,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be optional right?

Comment on lines +519 to +521
const h = ctx.host orelse {
ctx.interpreter.halt(.invalid_opcode);
return;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

eval slotnum as optional would make sense here - halt with invalid opcode if not present

}

pub fn slotNumber(self: *Host) u64 {
return self.ctx.block.slot_number;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

again, I think optional

- `BlockEnv.slot_number`: `u64` → `?u64`; default is `null` (absent on
  pre-Amsterdam / non-beacon chains)
- `BlockEnvBuilder`: add `setSlotNumber(?u64)`; propagate `slot_number`
  through all existing setter methods (previously silently dropped)
- `Host.slotNumber()`: returns `?u64`
- `opSlotnum`: halt with `invalid_opcode` when slot number is absent
- `spec_test/runner.zig`: initialize `slot_number` to `null`

Addresses review comment from @garyschulte on PR Consensys#10.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Gabriel-Trintinalia added a commit to Gabriel-Trintinalia/zevm that referenced this pull request Mar 22, 2026
- `BlockEnv.slot_number`: `u64` → `?u64`; default is `null` (absent on
  pre-Amsterdam / non-beacon chains)
- `BlockEnvBuilder`: add `setSlotNumber(?u64)`; propagate `slot_number`
  through all existing setter methods (previously silently dropped)
- `Host.slotNumber()`: returns `?u64`
- `opSlotnum`: halt with `invalid_opcode` when slot number is absent
- `spec_test/runner.zig`: initialize `slot_number` to `null`

Addresses review comment from @garyschulte on PR Consensys#10.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@garyschulte garyschulte merged commit 96b3306 into Consensys:main Mar 23, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants