Skip to content

Commit

Permalink
Remove implicit conversions in callframe.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
maximopalopoli committed Nov 14, 2024
1 parent 8176a36 commit 5594610
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
18 changes: 11 additions & 7 deletions crates/vm/levm/src/call_frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,16 +133,20 @@ impl CallFrame {
}

/// Jump to the given address, returns false if the jump position wasn't a JUMPDEST
pub fn jump(&mut self, jump_address: U256) -> bool {
if !self.valid_jump(jump_address) {
return false;
pub fn jump(&mut self, jump_address: U256) -> Result<bool, VMError> {
let jump_address_usize = jump_address
.try_into()
.map_err(|_err| VMError::VeryLargeNumber)?;

if !self.valid_jump(jump_address_usize) {
return Ok(false);
}
self.pc = jump_address.as_usize();
true
self.pc = jump_address_usize;
Ok(true)
}

fn valid_jump(&self, jump_address: U256) -> bool {
self.opcode_at(jump_address.as_usize())
fn valid_jump(&self, jump_address: usize) -> bool {
self.opcode_at(jump_address)
.map(|opcode| opcode.eq(&Opcode::JUMPDEST))
.is_some_and(|is_jumpdest| is_jumpdest)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ impl VM {
self.increase_consumed_gas(current_call_frame, gas_cost::JUMP)?;

let jump_address = current_call_frame.stack.pop()?;
if !current_call_frame.jump(jump_address) {
if !current_call_frame.jump(jump_address)? {
return Err(VMError::InvalidJump);
}

Expand All @@ -359,7 +359,7 @@ impl VM {
let jump_address = current_call_frame.stack.pop()?;
let condition = current_call_frame.stack.pop()?;

if condition != U256::zero() && !current_call_frame.jump(jump_address) {
if condition != U256::zero() && !current_call_frame.jump(jump_address)? {
return Err(VMError::InvalidJump);
}

Expand Down

0 comments on commit 5594610

Please sign in to comment.