Skip to content
Merged
Show file tree
Hide file tree
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: 10 additions & 4 deletions crates/handler/src/frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -655,14 +655,20 @@ where

// Return unspend gas.
if ins_result.is_ok_or_revert() {
interpreter.control.gas().erase_cost(out_gas.remaining());
interpreter
.control
.gas_mut()
.erase_cost(out_gas.remaining());
self.memory
.borrow_mut()
.set(mem_start, &interpreter.return_data.buffer()[..target_len]);
}

if ins_result.is_ok() {
interpreter.control.gas().record_refund(out_gas.refunded());
interpreter
.control
.gas_mut()
.record_refund(out_gas.refunded());
}
}
FrameResult::Create(outcome) => {
Expand All @@ -684,7 +690,7 @@ where
"Fatal external error in insert_eofcreate_outcome"
);

let this_gas = interpreter.control.gas();
let this_gas = interpreter.control.gas_mut();
if instruction_result.is_ok_or_revert() {
this_gas.erase_cost(outcome.gas().remaining());
}
Expand Down Expand Up @@ -716,7 +722,7 @@ where
"Fatal external error in insert_eofcreate_outcome"
);

let this_gas = interpreter.control.gas();
let this_gas = interpreter.control.gas_mut();
if instruction_result.is_ok_or_revert() {
this_gas.erase_cost(outcome.gas().remaining());
}
Expand Down
2 changes: 1 addition & 1 deletion crates/inspector/src/eip3155.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ where
}

fn step_end(&mut self, interp: &mut Interpreter<INTR>, context: &mut CTX) {
self.gas_inspector.step_end(interp.control.gas());
self.gas_inspector.step_end(interp.control.gas_mut());
if self.skip {
self.skip = false;
return;
Expand Down
2 changes: 1 addition & 1 deletion crates/inspector/src/gas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ mod tests {
}

fn step_end(&mut self, interp: &mut Interpreter<INTR>, _context: &mut CTX) {
self.gas_inspector.step_end(interp.control.gas());
self.gas_inspector.step_end(interp.control.gas_mut());
self.gas_remaining_steps
.push((self.pc, self.gas_inspector.gas_remaining()));
}
Expand Down
16 changes: 11 additions & 5 deletions crates/interpreter/src/instructions/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,10 +201,13 @@ pub fn sstore<WIRE: InterpreterTypes, H: Host + ?Sized>(
)
);

interpreter.control.gas().record_refund(gas::sstore_refund(
interpreter.runtime_flag.spec_id(),
&state_load.data,
));
interpreter
.control
.gas_mut()
.record_refund(gas::sstore_refund(
interpreter.runtime_flag.spec_id(),
&state_load.data,
));
}

/// EIP-1153: Transient storage opcodes
Expand Down Expand Up @@ -290,7 +293,10 @@ pub fn selfdestruct<WIRE: InterpreterTypes, H: Host + ?Sized>(

// EIP-3529: Reduction in refunds
if !interpreter.runtime_flag.spec_id().is_enabled_in(LONDON) && !res.previously_destroyed {
interpreter.control.gas().record_refund(gas::SELFDESTRUCT)
interpreter
.control
.gas_mut()
.record_refund(gas::SELFDESTRUCT)
}

gas!(
Expand Down
4 changes: 2 additions & 2 deletions crates/interpreter/src/instructions/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ macro_rules! gas {
$crate::gas!($interpreter, $gas, ())
};
($interpreter:expr, $gas:expr, $ret:expr) => {
if !$interpreter.control.gas().record_cost($gas) {
if !$interpreter.control.gas_mut().record_cost($gas) {
$interpreter
.control
.set_instruction_result($crate::InstructionResult::OutOfGas);
Expand Down Expand Up @@ -110,7 +110,7 @@ macro_rules! resize_memory {
let words_num = $crate::interpreter::num_words($offset.saturating_add($len));
match $interpreter
.control
.gas()
.gas_mut()
.record_memory_expansion(words_num)
{
$crate::gas::MemoryExtensionResult::Extended => {
Expand Down
6 changes: 5 additions & 1 deletion crates/interpreter/src/interpreter/loop_control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ impl LoopControlTr for LoopControl {
self.instruction_result = result;
}

fn gas(&mut self) -> &mut Gas {
fn gas(&self) -> &Gas {
&self.gas
}

fn gas_mut(&mut self) -> &mut Gas {
&mut self.gas
}

Expand Down
3 changes: 2 additions & 1 deletion crates/interpreter/src/interpreter_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,8 @@ pub trait ReturnData {
pub trait LoopControl {
fn set_instruction_result(&mut self, result: InstructionResult);
fn set_next_action(&mut self, action: InterpreterAction, result: InstructionResult);
fn gas(&mut self) -> &mut Gas;
fn gas(&self) -> &Gas;
fn gas_mut(&mut self) -> &mut Gas;
fn instruction_result(&self) -> InstructionResult;
fn take_next_action(&mut self) -> InterpreterAction;
}
Expand Down
Loading