Skip to content

Commit

Permalink
fix(levm): minor fix in BYTE opcode handling (#1340)
Browse files Browse the repository at this point in the history
It is not right to default to `usize::MAX` when the incoming `U256` does
not fit in `usize`.
  • Loading branch information
ilitteri authored Nov 28, 2024
1 parent e99e3a2 commit 0303d4d
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion crates/vm/levm/src/opcode_handlers/bitwise_comparison.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,14 @@ impl VM {
self.increase_consumed_gas(current_call_frame, gas_cost::BYTE)?;
let op1 = current_call_frame.stack.pop()?;
let op2 = current_call_frame.stack.pop()?;
let byte_index = op1.try_into().unwrap_or(usize::MAX);
let byte_index = match op1.try_into() {
Ok(byte_index) => byte_index,
Err(_) => {
// Index is out of bounds, then push 0
current_call_frame.stack.push(U256::zero())?;
return Ok(OpcodeSuccess::Continue);
}
};

if byte_index < WORD_SIZE {
let byte_to_push = WORD_SIZE
Expand Down

0 comments on commit 0303d4d

Please sign in to comment.