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(GasInspector): calculate correct remaining gas after call return #1236

Merged
merged 1 commit into from
Mar 28, 2024
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
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
Loading