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

Remove buffer gas added in the gas consumption of EVM.dryRun #6844

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

m-Peter
Copy link
Collaborator

@m-Peter m-Peter commented Dec 31, 2024

Closes: #6843
Relevant issue: #6301

The buffer gas added in EVM.dryRun, was a best-effort solution, to find the minimum required gas, that would make a transaction succeed. The calculation was based on top of the actual gas used for a given transaction. However, this did have some issues, and it would fail for certain cases.

With the implementation of the local state index on EVM Gateway, we have completely reworked the eth_estimateGas endpoint, and it uses the same logic as Geth, to calculate the minimum required gas needed for a transaction to succeed.

With that change deployed, we no longer need to add any buffer gas to the result of EVM.dryRun. And this can in fact cause confusion to developers, as it is always a bit higher that the gas usage they would get from tracing the same transaction / contract call.

@codecov-commenter
Copy link

codecov-commenter commented Dec 31, 2024

Codecov Report

Attention: Patch coverage is 0% with 2 lines in your changes missing coverage. Please review.

Project coverage is 41.18%. Comparing base (8ff124c) to head (532136b).

Files with missing lines Patch % Lines
fvm/evm/emulator/emulator.go 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6844      +/-   ##
==========================================
- Coverage   41.19%   41.18%   -0.01%     
==========================================
  Files        2109     2109              
  Lines      185664   185630      -34     
==========================================
- Hits        76479    76452      -27     
+ Misses     102777   102766      -11     
- Partials     6408     6412       +4     
Flag Coverage Δ
unittests 41.18% <0.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@m-Peter m-Peter force-pushed the mpeter/dry-run-remove-buffer-gas branch from 99d8c10 to 0b7c592 Compare January 6, 2025 10:34
@janezpodhostnik
Copy link
Contributor

The code looks good, but I'm not too familiar with why we have this and why we can now remove it.

Could you please add some text describing this in the PR description?

@m-Peter
Copy link
Collaborator Author

m-Peter commented Jan 6, 2025

The code looks good, but I'm not too familiar with why we have this and why we can now remove it.

Could you please add some text describing this in the PR description?

Good point 👌 Updated the description #6844 (comment)

Copy link
Contributor

@janezpodhostnik janezpodhostnik left a comment

Choose a reason for hiding this comment

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

Thank you!

@@ -1779,11 +1764,13 @@ func TestDryRun(t *testing.T) {
evmAddress,
))

// use the gas estimation from Evm.dryRun with the necessary buffer gas
gasLimit := dryRunResult.GasConsumed + gethParams.SstoreSentryGasEIP2200 + gethParams.SstoreClearsScheduleRefundEIP3529
Copy link
Member

Choose a reason for hiding this comment

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

Why choosing SstoreSentryGasEIP2200 and SstoreClearsScheduleRefundEIP3529 as gas buffer? Is there any specific reason?

Copy link
Collaborator Author

@m-Peter m-Peter Jan 10, 2025

Choose a reason for hiding this comment

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

Yep, this specific case is testing the scenario test dry run clear current value.
Whenever a user executes a tx that clears the value at a storage slot, he will get some gas refund (SstoreClearsScheduleRefundEIP3529). However, this gas amount has to be present in the gas limit set by the tx, and after the successful execution, the user will get refunded.

Note: SstoreSentryGasEIP2200 was not really necessary here, so I removed it in 532136b .

@@ -1513,11 +1512,13 @@ func TestDryRun(t *testing.T) {
evmAddress,
))

// Use the gas estimation from Evm.dryRun with some buffer
gasLimit := dryRunResult.GasConsumed + gethParams.SstoreSentryGasEIP2200
Copy link
Member

Choose a reason for hiding this comment

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

Any specific reason to use SstoreSentryGasEIP2200 as buffer?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Here as well, the buffer gas is required to be present in the gas limit.
This case is testing the scenario: test dry run store current value.
The description of SstoreSentryGasEIP2200 is the following:

Minimum gas required to be present for an SSTORE call, not consumed

I think this is something special for avoiding re-entrancy attacks.

@m-Peter m-Peter force-pushed the mpeter/dry-run-remove-buffer-gas branch from 0b7c592 to 532136b Compare January 10, 2025 10:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Flow EVM] Remove buffer gas applied in EVM.dryRun
4 participants