EIP-8024: DUPN, SWAPN, EXCHANGE opcodes - #2874
Open
anvacaru wants to merge 2 commits into
Open
Conversation
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>
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.
Implements EIP-8024: immediate-operand stack manipulation opcodes for legacy EVM.
evm.md:DUPN/SWAPN/EXCHANGEwith 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),#decodeSingleis the EIP'sdecode_single((x+145) mod 256, mapping the valid bytes onto the contiguous depth range17..235),#decodePairA/#decodePairBare the two components ofdecode_pair(the pair is exposed as two projections; each dispatches to an arity-2 overload on the nibbles ofx^0x8F, with complementaryQ <Int R/Q >=Int Rrequires clauses).#validSingle/#validPairimplement the EIP's valid-immediate byte ranges; invalid immediates halt withEVMC_INVALID_INSTRUCTION, insufficient depth withEVMC_STACK_UNDERFLOW.Jumpdest analysis is intentionally unchanged: valid immediates can never be a
JUMPDESTorPUSHbyte, which is the EIP's backward-compatibility property.