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(levm): disable arithmetic shifts for forks before Constantinople #1948

Merged
merged 2 commits into from
Feb 13, 2025
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
14 changes: 13 additions & 1 deletion crates/vm/levm/src/opcode_handlers/bitwise_comparison.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::{
gas_cost,
vm::VM,
};
use ethrex_common::U256;
use ethrex_common::{types::Fork, U256};
use std::collections::HashMap;
use std::sync::LazyLock;

Expand Down Expand Up @@ -196,6 +196,10 @@ impl VM {

// SHL operation (shift left)
pub fn op_shl(&mut self, current_call_frame: &mut CallFrame) -> Result<OpcodeResult, VMError> {
// Shift opcodes introduced in Constantinople https://eips.ethereum.org/EIPS/eip-145
if self.env.config.fork < Fork::Constantinople {
return Err(VMError::InvalidOpcode);
}
current_call_frame.increase_consumed_gas(gas_cost::SHL)?;
let shift = current_call_frame.stack.pop()?;
let value = current_call_frame.stack.pop()?;
Expand Down Expand Up @@ -240,6 +244,10 @@ impl VM {

// SHR operation (shift right)
pub fn op_shr(&mut self, current_call_frame: &mut CallFrame) -> Result<OpcodeResult, VMError> {
// Shift opcodes introduced in Constantinople https://eips.ethereum.org/EIPS/eip-145
if self.env.config.fork < Fork::Constantinople {
return Err(VMError::InvalidOpcode);
}
current_call_frame.increase_consumed_gas(gas_cost::SHR)?;
let shift = current_call_frame.stack.pop()?;
let value = current_call_frame.stack.pop()?;
Expand All @@ -257,6 +265,10 @@ impl VM {

// SAR operation (arithmetic shift right)
pub fn op_sar(&mut self, current_call_frame: &mut CallFrame) -> Result<OpcodeResult, VMError> {
// Shift opcodes introduced in Constantinople https://eips.ethereum.org/EIPS/eip-145
if self.env.config.fork < Fork::Constantinople {
return Err(VMError::InvalidOpcode);
}
current_call_frame.increase_consumed_gas(gas_cost::SAR)?;
let shift = current_call_frame.stack.pop()?;
let value = current_call_frame.stack.pop()?;
Expand Down
Loading