-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: (levm) Flow operations #553
Conversation
…/feat/flow_operations
crates/levm/src/call_frame.rs
Outdated
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) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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:
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) | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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)
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
**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>
**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>
Motivation
Description
Closes #490
Closes #491
Closes #489
Closes #494