diff --git a/crates/vm/levm/src/gas_cost.rs b/crates/vm/levm/src/gas_cost.rs index 1e1f87c20..5a4333dd2 100644 --- a/crates/vm/levm/src/gas_cost.rs +++ b/crates/vm/levm/src/gas_cost.rs @@ -235,6 +235,11 @@ pub fn codecopy( ) } +// Used in return and revert opcodes +pub fn exit_opcode(new_memory_size: usize, current_memory_size: usize) -> Result { + memory::expansion_cost(new_memory_size, current_memory_size) +} + pub fn returndatacopy( new_memory_size: usize, current_memory_size: usize, diff --git a/crates/vm/levm/src/opcode_handlers/system.rs b/crates/vm/levm/src/opcode_handlers/system.rs index bfc44adc7..ad2ccba32 100644 --- a/crates/vm/levm/src/opcode_handlers/system.rs +++ b/crates/vm/levm/src/opcode_handlers/system.rs @@ -172,11 +172,12 @@ impl VM { } let new_memory_size = calculate_memory_size(offset, size)?; + let current_memory_size = current_call_frame.memory.len(); - let memory_expansion_cost = - memory::expansion_cost(new_memory_size, current_call_frame.memory.len())?; - - self.increase_consumed_gas(current_call_frame, memory_expansion_cost)?; + self.increase_consumed_gas( + current_call_frame, + gas_cost::exit_opcode(new_memory_size, current_memory_size)?, + )?; current_call_frame.output = memory::load_range(&mut current_call_frame.memory, offset, size)? @@ -405,11 +406,12 @@ impl VM { .map_err(|_err| VMError::VeryLargeNumber)?; let new_memory_size = calculate_memory_size(offset, size)?; + let current_memory_size = current_call_frame.memory.len(); - let memory_expansion_cost: u64 = - memory::expansion_cost(new_memory_size, current_call_frame.memory.len())?; - - self.increase_consumed_gas(current_call_frame, memory_expansion_cost)?; + self.increase_consumed_gas( + current_call_frame, + gas_cost::exit_opcode(new_memory_size, current_memory_size)?, + )?; current_call_frame.output = memory::load_range(&mut current_call_frame.memory, offset, size)?