feat: EIP-7843 — SLOTNUM opcode (Amsterdam)#10
Merged
garyschulte merged 2 commits intoConsensys:mainfrom Mar 23, 2026
Merged
Conversation
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>
garyschulte
approved these changes
Mar 20, 2026
Collaborator
garyschulte
left a comment
There was a problem hiding this comment.
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, |
Collaborator
There was a problem hiding this comment.
we should add a setSlotNumber(slotnum: ?u64) function just to be consistent
src/context/block.zig
Outdated
| /// 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, |
Collaborator
There was a problem hiding this comment.
should be optional right?
Comment on lines
+519
to
+521
| const h = ctx.host orelse { | ||
| ctx.interpreter.halt(.invalid_opcode); | ||
| return; |
Collaborator
There was a problem hiding this comment.
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; |
Collaborator
There was a problem hiding this comment.
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>
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements EIP-7843 for the Amsterdam hardfork.
Adds the
SLOTNUMopcode (0x4B) that pushes the current beacon chain slot number onto the stack, reading it fromBlockEnv.G_BASE(2)slot_numberis?u64—nullon pre-Amsterdam or non-beacon chains;SLOTNUMhalts withinvalid_opcodein that caseChanges
src/bytecode/main.zig—SLOTNUM = 0x4Bconstant + opcode info entrysrc/context/block.zig—slot_number: ?u64field onBlockEnv(defaultnull) andBlockEnvBuilder;setSlotNumber(?u64)builder method; all existing setters propagateslot_numbersrc/interpreter/host.zig—slotNumber() ?u64host methodsrc/interpreter/opcodes/environment.zig—opSlotnumimplementation; halts withinvalid_opcodewhen slot number is absentsrc/interpreter/opcodes/main.zig— re-exportopSlotnumsrc/interpreter/protocol_schedule.zig—applyAmsterdamChangesactivatingSLOTNUMsrc/spec_test/runner.zig—slot_number: nulldefaultPart of Amsterdam hardfork
Related PRs: EIP-8024 (DUPN/SWAPN/EXCHANGE), EIP-7954 (max code size), EIP-7708 (transfer logs), EIP-8037 (state gas reservoir)