Skip to content

EIP-8024: DUPN, SWAPN, EXCHANGE opcodes - #2874

Open
anvacaru wants to merge 12 commits into
masterfrom
eip-8024
Open

EIP-8024: DUPN, SWAPN, EXCHANGE opcodes#2874
anvacaru wants to merge 12 commits into
masterfrom
eip-8024

Conversation

@anvacaru

Copy link
Copy Markdown
Contributor

Implements EIP-8024: immediate-operand stack manipulation opcodes for legacy EVM.

  • evm.md: DUPN/SWAPN/EXCHANGE with one-byte immediates; schedule.md: Ghaseip8024 + gas.

Added helpers based on the EIP's reference functions:

  • #immByte(PGM, PC) reads the operand like PUSH does (#range, total, zero-padding at end-of-code),
  • #decodeSingle is the EIP's decode_single ((x+145) mod 256, mapping the valid bytes onto the contiguous depth range 17..235),
  • #decodePairA/#decodePairB are the two components of decode_pair (the pair is exposed as two projections; each dispatches to an arity-2 overload on the nibbles of x^0x8F, with complementary Q <Int R / Q >=Int R requires clauses).
  • #validSingle/#validPair implement the EIP's valid-immediate byte ranges; invalid immediates halt with EVMC_INVALID_INSTRUCTION, insufficient depth with EVMC_STACK_UNDERFLOW.

Jumpdest analysis is intentionally unchanged: valid immediates can never be a JUMPDEST or PUSH byte, which is the EIP's backward-compatibility property.

anvacaru and others added 12 commits July 24, 2026 15:46
….py: parse Amsterdam block header (blockAccessListHash, slotNumber); discard receipts/blockAccessList fixture keys in the harness
… max 21 / fraction 11684671)

AMSTERDAM inherited the Osaka/Prague blob parameters (target 6 / max 9 /
fraction 5007716). EELS amsterdam vm/gas.py has BLOB_SCHEDULE_TARGET = 14
and BLOB_SCHEDULE_MAX = 21 (at PER_BLOB = 2^17: Gtargetblobgas = 1835008,
Gmaxblobgas = 2752512) and BLOB_BASE_FEE_UPDATE_FRACTION = 11684671,
matching the mainnet BPO2 blob schedule (EIP-8135 / EIP-7892) that
Amsterdam starts from.

Raising Gmaxblobgas from 9 to 21 blobs exposes the pre-existing missing
EIP-7594 per-tx blob limit (EELS BLOB_COUNT_LIMIT = 6, fork.py:150):
the blob_count_21 sub-case of invalid_max_blobs_per_tx was previously
rejected by the too-small inherited block max instead of the per-tx
check. Mask it in failing.llvm next to its already-masked blob_count_7/8
siblings until the per-tx limit is implemented.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
read_csv_file crashed test collection with IndexError on any blank
line in failing.llvm/slow.llvm — which the fixtures-failing-list
Makefile target itself can produce via its sort/sed post-processing.
Skip empty rows.
# Conflicts:
#	kevm-pyk/src/kevm_pyk/kproj/evm-semantics/driver.md
Add the three backward-compatible stack opcodes (EIP-8024): DUPN (0xe6),
SWAPN (0xe7), EXCHANGE (0xe8), each with a 1-byte immediate and Gverylow (3)
cost, gated on the new Ghaseip8024 flag (true at AMSTERDAM). Modeled as
StackOps that read and decode their immediate from <program> at exec time
(like PUSH): decode_single ((x+145)%256, valid x in [0,90]u[128,255]) for
DUPN/SWAPN, decode_pair (k=x^143; divmod(k,16)) for EXCHANGE. DUPN(n)/SWAPN(n)
reuse the DUP/SWAP stack logic; EXCHANGE swaps two arbitrary positions.
Out-of-range immediates halt EVMC_INVALID_INSTRUCTION, insufficient depth
halts EVMC_STACK_UNDERFLOW; #widthOp is 2 (pc advances past the immediate).

Jumpdest analysis (#widthOpCode) is intentionally left unchanged: EIP-8024's
immediates are constrained to never be a JUMPDEST or PUSH byte, so scanning
the immediate as an ordinary opcode keeps old jumpdest analysis valid (the
backward-compatibility property; confirmed by the jump_to_immediate_byte
fixtures). Unmask all 53 eip8024 fixtures.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Base automatically changed from amsterdam-foundation to master September 8, 2026 11:52
An error occurred while trying to automatically change base from amsterdam-foundation to master September 8, 2026 11:52
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.

1 participant