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

Use gas price in place of effective gas price for initial balance check #359

Merged
merged 4 commits into from
Feb 9, 2023
Merged
Changes from 2 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
4 changes: 2 additions & 2 deletions crates/revm/src/evm_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ impl<'a, GSPEC: Spec, DB: Database, const INSPECT: bool> Transact<DB::Error>
.balance;

let payment_value = U256::from(gas_limit)
.checked_mul(effective_gas_price)
.checked_mul(self.data.env.tx.gas_price)
.ok_or(EVMError::Transaction(
InvalidTransaction::OverflowPaymentInTransaction,
))?;
Expand Down Expand Up @@ -282,7 +282,7 @@ impl<'a, GSPEC: Spec, DB: Database, const INSPECT: bool> EVMImpl<'a, GSPEC, DB,
acc_caller.info.balance = acc_caller
.info
.balance
.saturating_add(effective_gas_price * U256::from(gas.remaining() + gas_refunded));
.saturating_add(self.data.env.tx.gas_price * U256::from(gas.remaining() + gas_refunded));
Copy link
Member

@rakita rakita Feb 8, 2023

Choose a reason for hiding this comment

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

@rakita I've implemented the change but looks like the tests are still failing. Maybe I misunderstood what you meant?

I said the incorrect thing, didn't take into account that, in finalization, we need to return the difference of (gas_price-effective_price)*gas_limit

Suggested change
.saturating_add(self.data.env.tx.gas_price * U256::from(gas.remaining() + gas_refunded));
.saturating_add((self.data.env.tx.gas_price-effective_gas_price) * self.data.env.tx.gas_limit)
.saturating_add(effective_gas_price * U256::from(gas.remaining() + gas_refunded));

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm still not quite sure what you mean. I tried applying this change and the tests are still failing.
Also when checking Geth it looks like gasPrice is used? https://github.com/ethereum/go-ethereum/blob/3a79a99f804c4bd2002fe52768c965c4be8106ea/core/state_transition.go#L400

Copy link
Member

Choose a reason for hiding this comment

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

At the start:
we have done it as: balance -= min(base_fee+tip,max_gas_price)*gas_limit => balance -= effective*gas_limit
and now we are doing: balance -= max_gas_price * gas_limit

In finalize we need to return it back:
previously it was: balance += effective*(remaining_gas+gas_refund)
but now it needs to take into account additional gas that we subbed, and it would become:
balance +=(gas_price-effective_price)*gas_limit+effective*(remaining-refunded)

it can be done as you did below, as do this only for the balance check. Not sure why it panics, will need to look at at detail

Copy link
Contributor Author

Choose a reason for hiding this comment

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

aha gotcha. That makes sense, thanks :D

Geth does it the way I did it below by only subtracting the effective price from the account: https://github.com/ethereum/go-ethereum/blob/0c9eb8c9a47285526078beef4ab5aed5a90ab938/core/state_transition.go#L217 so this seems like the best way to go imo? *note st.gasPrice here is effective_gas_price: https://github.com/ethereum/go-ethereum/blob/0c9eb8c9a47285526078beef4ab5aed5a90ab938/core/types/transaction.go#L633

Copy link
Member

Choose a reason for hiding this comment

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

yeah, I agree it is better to do as your latest, it is best to be aligned with geth with this kind of sensitive things.


// EIP-1559
let coinbase_gas_price = if SPEC::enabled(LONDON) {
Expand Down