Skip to content

execution/vm: report invalid EOF stack-op operands in ErrInvalidOpCode#20529

Open
Sahil-4555 wants to merge 2 commits intoerigontech:mainfrom
Sahil-4555:fix-immediate
Open

execution/vm: report invalid EOF stack-op operands in ErrInvalidOpCode#20529
Sahil-4555 wants to merge 2 commits intoerigontech:mainfrom
Sahil-4555:fix-immediate

Conversation

@Sahil-4555
Copy link
Copy Markdown
Contributor

This PR improves invalid opcode reporting for the EOF stack-manipulation instructions. For DUPN, SWAPN, and EXCHANGE, when the immediate byte falls into an excluded range, ErrInvalidOpCode now preserves the parent opcode that triggered the failure and also records the offending operand byte. This makes the error more accurate and easier to diagnose, since the failure is now tied to the actual instruction family instead of the raw immediate value being interpreted as the opcode.

The accompanying tests were updated to match that behavior. They now verify not only that invalid low- and high-range immediates return ErrInvalidOpCode, but also that the error contains the correct opcode (DUPN, SWAPN, or EXCHANGE) and the exact invalid operand value.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR refines EOF stack-manipulation invalid-operand reporting by ensuring ErrInvalidOpCode attributes failures to the parent instruction (DUPN/SWAPN/EXCHANGE) and captures the offending immediate byte, improving diagnosability and aligning tests with the new behavior.

Changes:

  • Extend ErrInvalidOpCode to optionally store an operand byte and include it in the error string.
  • Update DUPN/SWAPN/EXCHANGE immediate-range rejection to return ErrInvalidOpCode with the parent opcode plus the invalid operand.
  • Update EIP-8024 execution tests to assert both the opcode and the invalid operand for excluded immediate ranges.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
execution/vm/instructions.go Return ErrInvalidOpCode tagged with the parent opcode and invalid immediate for excluded operand ranges in DUPN/SWAPN/EXCHANGE.
execution/vm/errors.go Add optional operand metadata to ErrInvalidOpCode and surface it in Error() output.
execution/vm/instructions_test.go Enhance tests to validate ErrInvalidOpCode includes correct opcode and operand for invalid immediates.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@yperbasis yperbasis added this to the 3.5.0 milestone Apr 14, 2026
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.

3 participants