feat: (levm) Flow operations#553
Merged
Merged
Conversation
MegaRedHand
reviewed
Sep 25, 2024
ilitteri
reviewed
Sep 26, 2024
…/feat/flow_operations
ilitteri
reviewed
Sep 27, 2024
ilitteri
reviewed
Sep 27, 2024
ilitteri
reviewed
Sep 27, 2024
Comment on lines
+45
to
+56
| fn valid_jump(&self, offset: U256) -> bool { | ||
| // In the future this should be the Opcode::Invalid and halt | ||
| self.opcode_at(offset).eq(&Opcode::JUMPDEST) | ||
| } | ||
|
|
||
| fn opcode_at(&self, offset: U256) -> Opcode { | ||
| self.bytecode | ||
| .get(offset.as_usize()) | ||
| .copied() | ||
| .map(Opcode::from) | ||
| .unwrap_or(Opcode::STOP) | ||
| } |
Collaborator
There was a problem hiding this comment.
Firstly, I misunderstood the purpose of the unwrap_or, I thought that we could abstract that logic into opcode_at to reuse it in other functions if needed. After discussing this, I came up with this new suggestion:
Suggested change
| fn valid_jump(&self, offset: U256) -> bool { | |
| // In the future this should be the Opcode::Invalid and halt | |
| self.opcode_at(offset).eq(&Opcode::JUMPDEST) | |
| } | |
| fn opcode_at(&self, offset: U256) -> Opcode { | |
| self.bytecode | |
| .get(offset.as_usize()) | |
| .copied() | |
| .map(Opcode::from) | |
| .unwrap_or(Opcode::STOP) | |
| } | |
| fn valid_jump(&self, offset: U256) -> bool { | |
| // In the future this should be the Opcode::Invalid and halt | |
| self.bytecode | |
| .get(offset.as_usize()) | |
| .copied() | |
| .map(Opcode::from) | |
| .map(|opcode| opcode.eq(&Opcode::JUMPDEST)) | |
| .is_some_and(|is_jumpdest| is_jumpdest) | |
| } |
Collaborator
There was a problem hiding this comment.
We can later define an opcode_at function used by next_opcode and valid_jump that returns an Option<Opcode>:
fn opcode_at(&self, offset: U256) -> Option<Opcode> {
self.bytecode
.get(offset.as_usize())
.copied()
.map(Opcode::from)
}
Contributor
Author
There was a problem hiding this comment.
Just updated it and added the opcode_at function, changing next_opcode and valid_jump to use it
Co-authored-by: Ivan Litteri <67517699+ilitteri@users.noreply.github.com>
emirongrr
pushed a commit
to emirongrr/ethrex
that referenced
this pull request
Nov 10, 2024
**Motivation** <!-- Why does this pull request exist? What are its goals? --> **Description** <!-- A clear and concise general description of the changes this PR introduces --> <!-- Link to issues: Resolves lambdaclass#111, Resolves lambdaclass#222 --> Closes lambdaclass#490 Closes lambdaclass#491 Closes lambdaclass#489 Closes lambdaclass#494 --------- Co-authored-by: Ivan Litteri <67517699+ilitteri@users.noreply.github.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.
Motivation
Description
Closes #490
Closes #491
Closes #489
Closes #494