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

EIP-7623: Apply correction after gas refund #1073

Open
SamWilsn opened this issue Jan 9, 2025 · 4 comments
Open

EIP-7623: Apply correction after gas refund #1073

SamWilsn opened this issue Jan 9, 2025 · 4 comments
Labels
A-spec Area: specification C-eip Category: tracking implementation of an EIP E-easy Experience: easy, good for newcomers

Comments

@SamWilsn
Copy link
Collaborator

SamWilsn commented Jan 9, 2025

          I believe this correction should be applied *after* the gas refund is applied. Argumentation and spec clarification here: https://github.com/ethereum/EIPs/pull/9227.

Originally posted by @chfast in #966 (comment)

@SamWilsn SamWilsn added A-spec Area: specification E-easy Experience: easy, good for newcomers C-eip Category: tracking implementation of an EIP labels Jan 9, 2025
@SamWilsn
Copy link
Collaborator Author

SamWilsn commented Jan 9, 2025

From @chfast on Discord:

Hi there, I'm late to the party, but I spent the last night debugging 7623. I think EELS implemented it incorrectly and EEST followed with incorrect tests.

I believe the evm_gas_used from the spec should include the gas refund (i.e. evm_gas_used should have the refund subtracted from). Otherwise the total tx gas used don't adds up. So the "floor" gas correction should be applied after gas refunds. However, EELS implements it before and EEST has dedicated tests for this behavior. I plan to send an update to the EIP to clarify this.

But for you to quickly verify this claim is to move the "floor" gas application before the gas refund. You should pass much more tests this way.

You either do (EEST):

gas_used = max(gas_used, floor_cost)
gas_used -= refund

or (spec):

gas_used -= refund
gas_used = max(gas_used, floor_cost)

@SamWilsn
Copy link
Collaborator Author

SamWilsn commented Jan 9, 2025

From @jochem-brouwer on Discord:

I'm not super sure now when thinking about applying the refunds. Here is a situation:

Simple tx which calls into a contract which sets a nonzero storage slot to zero: PUSH 0 PUSH 0 SSTORE. This yields a net gas of 13003 for me.

If we instead do the new rule (apply refunds before calculating the floor), this now means that I pay 21k gas. (there is no calldata, but we still apply this new floor rule).

This looks weird to me?

@jochem-brouwer
Copy link
Member

I applied the formula wrong, please disregard the comment 😊 👍

@jochem-brouwer
Copy link
Member

I think this is correct:

gas_used -= refund
gas_used = max(gas_used, floor_cost)

EthJS currently has this though:

gas_used = max(gas_used, floor_cost)
gas_used -= refund

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-spec Area: specification C-eip Category: tracking implementation of an EIP E-easy Experience: easy, good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants