Conversation
Track both previous and current opcode in the analysis loop to handle edge cases where opcodes with immediates (SWAPN, DUPN, EXCHANGE) have their immediate byte appear as STOP. For example, [SWAPN, STOP] needs padding because the STOP is consumed as the immediate operand, not as an actual instruction. Add test to verify [SWAPN, STOP] is padded to [SWAPN, STOP, STOP].
Remove obsolete GasParams import and argument, use DummyHost::new() constructor instead of unit struct syntax.
Remove dupn_offset calculation from the main loop, keeping only PUSH handling. The SWAPN/DUPN/EXCHANGE padding logic via prev_opcode is retained for edge case handling.
These opcodes have 1-byte immediates that aren't handled by the main analysis loop, so we need extra padding to ensure safe execution regardless of whether the bytecode ends with STOP.
Member
Author
|
This fixed the inconsistency in padding that immediates would do |
frangio
reviewed
Jan 20, 2026
Comment on lines
+206
to
+210
| let bytecode = vec![op]; | ||
| let (_, padded_bytecode) = analyze_legacy(bytecode.into()); | ||
| assert_eq!(padded_bytecode.len(), 2); | ||
| assert_eq!(padded_bytecode[0], op); | ||
| assert_eq!(padded_bytecode[1], opcode::STOP); |
Contributor
There was a problem hiding this comment.
Is this right? This corresponds to a single instruction. My understanding was you always want a final STOP instruction. In that case, you'd expect 2 bytes of padding where the first is an immediate and the second is an instruction.
Open
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
analyze_legacypadding logic for SWAPN/DUPN/EXCHANGE edge cases usingprev_opcodetrackingTest plan