Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(evm): SHL/SHR shift > 255 check must come before operation #220

Merged
merged 1 commit into from
Dec 9, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading