From b440e81075bc752d7b836b72a5d1645eca9c2b3c Mon Sep 17 00:00:00 2001 From: Jon-Becker Date: Fri, 8 Dec 2023 20:57:05 -0500 Subject: [PATCH] fix(evm): SHL/SHR `shift > 255` check must come before operation --- common/src/ether/evm/core/vm.rs | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/common/src/ether/evm/core/vm.rs b/common/src/ether/evm/core/vm.rs index 93f83d81..8207a05c 100644 --- a/common/src/ether/evm/core/vm.rs +++ b/common/src/ether/evm/core/vm.rs @@ -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; @@ -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;