Skip to content

Commit

Permalink
Revert "fix(evm): SHL/SHR shift > 255 check must come before operat…
Browse files Browse the repository at this point in the history
…ion"

This reverts commit 8ed8cba.
  • Loading branch information
Jon-Becker committed Dec 9, 2023
1 parent 8ed8cba commit 92fee5a
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions common/src/ether/evm/core/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,6 @@ impl VM {
let input_operations =
input_frames.iter().map(|x| x.operation.clone()).collect::<Vec<WrappedOpcode>>();
let inputs = input_frames.iter().map(|x| x.value).collect::<Vec<U256>>();
println!("opcode_details: {:?}", opcode_details);

// Consume the minimum gas for the opcode
let gas_cost = opcode_details.mingas;
Expand Down Expand Up @@ -638,9 +637,12 @@ 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
let result =
if a.value > U256::from(255u8) { U256::zero() } else { b.value.shl(a.value) };
if a.value > U256::from(255u8) {
result = U256::zero();
}

// if both inputs are PUSH instructions, simplify the operation
let mut simplified_operation = operation;
Expand All @@ -658,9 +660,15 @@ 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
let result =
if a.value > U256::from(255u8) { U256::zero() } else { b.value.shr(a.value) };
if a.value > U256::from(255u8) {
result = U256::zero();
}

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

0 comments on commit 92fee5a

Please sign in to comment.