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
17 changes: 9 additions & 8 deletions crates/revm/src/evm_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,9 @@ impl<'a, GSPEC: Spec, DB: Database, const INSPECT: bool> Transact
if crate::USE_GAS {
gas.reimburse_unspend(&exit_reason, ret_gas);
}
match self.finalize::<GSPEC>(caller, &gas) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ack - the error branch would never get hit before

Err(e) => (e, out, gas.spend(), Map::new(), Vec::new()),
Ok((state, logs)) => (exit_reason, out, gas.spend(), state, logs),
}

let (state, logs, gas_used) = self.finalize::<GSPEC>(caller, &gas);
(exit_reason, out, gas_used, state, logs)
}
}

Expand Down Expand Up @@ -192,9 +191,9 @@ impl<'a, GSPEC: Spec, DB: Database, const INSPECT: bool> EVMImpl<'a, GSPEC, DB,
&mut self,
caller: H160,
gas: &Gas,
) -> Result<(Map<H160, Account>, Vec<Log>), Return> {
) -> (Map<H160, Account>, Vec<Log>, u64) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function signature change should be OK given that this function is not exposed

let coinbase = self.data.env.block.coinbase;
if crate::USE_GAS {
let gas_used = if crate::USE_GAS {
let effective_gas_price = self.data.env.effective_gas_price();
let basefee = self.data.env.block.basefee;
let max_refund_quotient = if SPEC::enabled(LONDON) { 5 } else { 2 }; // EIP-3529: Reduction in refunds
Expand All @@ -213,11 +212,13 @@ impl<'a, GSPEC: Spec, DB: Database, const INSPECT: bool> EVMImpl<'a, GSPEC, DB,
self.data
.subroutine
.balance_add(coinbase, coinbase_gas_price * (gas.spend() - gas_refunded));
gas.spend() - gas_refunded
} else {
// touch coinbase
self.data.subroutine.load_account(coinbase, self.data.db);
self.data.subroutine.balance_add(coinbase, U256::zero());
}
0
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unsure if we still want to do the gas refund calculation stuff here? Does crate::USE_GAS toggle if we even record gas at all?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good q. @rakita wdyt?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fine, USE_GAS in general is to disable gas calculation if evm is needed in some wasm env where pricing is done differently.

};
let (mut new_state, logs) = self.data.subroutine.finalize();
// precompiles are special case. If there is precompiles in finalized Map that means some balance is
// added to it, we need now to load precompile address from db and add this amount to it so that we
Expand All @@ -231,7 +232,7 @@ impl<'a, GSPEC: Spec, DB: Database, const INSPECT: bool> EVMImpl<'a, GSPEC, DB,
}
}

Ok((new_state, logs))
(new_state, logs, gas_used)
}

fn inner_load_account(&mut self, caller: H160) -> bool {
Expand Down
2 changes: 1 addition & 1 deletion crates/revm/src/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ impl Interpreter {
&self.contract
}

pub fn gas(&mut self) -> &Gas {
pub fn gas(&self) -> &Gas {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

&self.gas
}

Expand Down