Skip to content

Commit

Permalink
fix(GasInspector): calculate correct remaining gas after call return (b…
Browse files Browse the repository at this point in the history
  • Loading branch information
rakita authored Mar 28, 2024
1 parent c3107ec commit a114438
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions crates/revm/src/inspector/gas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,22 @@ impl<DB: Database> Inspector<DB> for GasInspector {
self.gas_remaining = interp.gas.limit();
}

fn step(
&mut self,
interp: &mut crate::interpreter::Interpreter,
_context: &mut EvmContext<DB>,
) {
self.gas_remaining = interp.gas.remaining();
}

fn step_end(
&mut self,
interp: &mut crate::interpreter::Interpreter,
_context: &mut EvmContext<DB>,
) {
let last_gas_remaining =
core::mem::replace(&mut self.gas_remaining, interp.gas.remaining());
self.last_gas_cost = last_gas_remaining.saturating_sub(self.gas_remaining);
let remaining = interp.gas.remaining();
self.last_gas_cost = self.gas_remaining.saturating_sub(remaining);
self.gas_remaining = remaining;
}

fn call_end(
Expand All @@ -65,8 +73,15 @@ impl<DB: Database> Inspector<DB> for GasInspector {
&mut self,
_context: &mut EvmContext<DB>,
_inputs: &CreateInputs,
outcome: CreateOutcome,
mut outcome: CreateOutcome,
) -> CreateOutcome {
if outcome.result.result.is_error() {
outcome
.result
.gas
.record_cost(outcome.result.gas.remaining());
self.gas_remaining = 0;
}
outcome
}
}
Expand Down

0 comments on commit a114438

Please sign in to comment.