Skip to content

Commit

Permalink
fix(evm): SHL/SHR shift > 255 check must come before operation
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon-Becker committed Dec 9, 2023
1 parent 92fee5a commit b440e81
Showing 1 changed file with 4 additions and 13 deletions.
17 changes: 4 additions & 13 deletions common/src/ether/evm/core/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -637,12 +637,9 @@ impl VM {
let a = self.stack.pop();
let b = self.stack.pop();

let mut result = b.value.shl(a.value);

// if shift is greater than 255, result is 0
if a.value > U256::from(255u8) {
result = U256::zero();
}
let result =
if a.value > U256::from(255u8) { U256::zero() } else { b.value.shl(a.value) };

// if both inputs are PUSH instructions, simplify the operation
let mut simplified_operation = operation;
Expand All @@ -660,15 +657,9 @@ impl VM {
let a = self.stack.pop();
let b = self.stack.pop();

let mut result = U256::zero();
if !b.value.is_zero() {
result = b.value.shr(a.value);
}

// if shift is greater than 255, result is 0
if a.value > U256::from(255u8) {
result = U256::zero();
}
let result =
if a.value > U256::from(255u8) { U256::zero() } else { b.value.shr(a.value) };

// if both inputs are PUSH instructions, simplify the operation
let mut simplified_operation = operation;
Expand Down

0 comments on commit b440e81

Please sign in to comment.