-
Notifications
You must be signed in to change notification settings - Fork 994
Gas fixes #83
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
Gas fixes #83
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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) { | ||
| 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) | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -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) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
|
@@ -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 | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good q. @rakita wdyt?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
|
@@ -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 { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -53,7 +53,7 @@ impl Interpreter { | |
| &self.contract | ||
| } | ||
|
|
||
| pub fn gas(&mut self) -> &Gas { | ||
| pub fn gas(&self) -> &Gas { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
| &self.gas | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
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