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

feat(tests): callcode gas test when call stipend is applied to gas limit #371

Merged
merged 1 commit into from
Jan 19, 2024

Conversation

acolytec3
Copy link
Contributor

@acolytec3 acolytec3 commented Jan 5, 2024

🗒️ Description

Correctly evaluate CALLCODE gas usage when a call stipend is applied to gas limit

Adds a new test to cover a bug that was discovered in the EthereumJS EVM implementation of the CALLCODE opcode where we were incorrectly applying the call stipend to the gas limit applied to the new call frame before evaluating the gas consumed by the call frame so would incorrectly continue execution of the CALLCODE call frame instead of going OOG.

🔗 Related Issues

Covers the scenario described in this issue.

✅ Checklist

  • All: Set appropriate labels for the changes.
  • All: Considered squashing commits to improve commit history.
  • All: Added an entry to CHANGELOG.md.
  • All: Considered updating the online docs in the ./docs/ directory.
  • Tests: Included the type and version of evm t8n tool used to locally execute test cases: e.g., ref with commit hash or geth 1.13.1-stable-3f40e65.
  • Tests: Ran mkdocs serve locally and verified the auto-generated docs for new tests in the Test Case Reference are correctly formatted.

@acolytec3 acolytec3 marked this pull request as draft January 5, 2024 01:32
@acolytec3
Copy link
Contributor Author

This new test covers a bug that was identified in the EthereumJS EVM implementation that was recently fixed by @jochem-brouwer in our code. I'm not 100% sure where to place this test in the broader test suite so have opened this PR to get conversation started and will work through the checklist over the next day or two.

@spencer-tb spencer-tb added scope:tests Scope: Test cases type:feat type: Feature labels Jan 9, 2024
@spencer-tb spencer-tb changed the title Correctly evaluate CALLCODE gas usage when a call stipend is applied to gas limit feat(tests): callcode gas test when call stipend is applied to gas limit Jan 9, 2024
@spencer-tb
Copy link
Collaborator

Thanks for the contribution :)

I've added a refactor in a PR to your branch here: acolytec3#1
This uses some pytest parameterization, alongside the Opcodes class to replace the bytecode with.

Currently test placement is allocated based on when the feature/EIP was introduced.
As CALLCODE was introduced in frontier, I moved it there!

@acolytec3 acolytec3 marked this pull request as ready for review January 9, 2024 14:39
@acolytec3
Copy link
Contributor Author

Thanks for the contribution :)

I've added a refactor in a PR to your branch here: acolytec3#1 This uses some pytest parameterization, alongside the Opcodes class to replace the bytecode with.

Currently test placement is allocated based on when the feature/EIP was introduced. As CALLCODE was introduced in frontier, I moved it there!

Thanks! I wasn't sure where to put it but have merged your PR. Anything else you need from me on it?

@spencer-tb
Copy link
Collaborator

Thanks! I wasn't sure where to put it but have merged your PR. Anything else you need from me on it?

Great! A commit squash would be ideal so everything is in 1 commit

@acolytec3
Copy link
Contributor Author

Done. Looks like I mucked up something in the changelog when I squashed things 🤔 Any ideas here?

@spencer-tb
Copy link
Collaborator

All good! 💯

Copy link
Member

@danceratopz danceratopz left a comment

Choose a reason for hiding this comment

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

This is looking very good! I just proposed a small change in acolytec3#2 for readability, but it's not essential.

One thing that would be helpful would be a comment on the gas values used, see comment below.

tests/frontier/opcodes/test_callcode.py Outdated Show resolved Hide resolved
tests/frontier/opcodes/test_callcode.py Outdated Show resolved Hide resolved
@spencer-tb
Copy link
Collaborator

I added a PR re. the recent comments: acolytec3#3, but after looking over this again, I get a mismatch for the CALL opcode when filling with geth. That is when using the values specified in:

['f1', 36600, '0x'], // 36600 is CALL fee
['f2', 11600, '0x'], // 11600 is CALLCODE fee
['f1', 36600 + 7 * 3, '0x01'], // 36600 is CALL fee + 7 * 3 gas for 7 PUSH opcodes
['f2', 11600 + 7 * 3, '0x01'], // 11600 is CALLCODE fee + 7 * 3 gas for 7 PUSH opcodes

What values do you guys get in the dynamic gas formulas?

CALL gas breakdowns: (https://www.evm.codes/#f1)
memory_exp_cost + code_exec_cost + address_access_cost + positive_value_cost + empty_account_cost

CALLCODE gas breakdowns: (https://www.evm.codes/#f2)
memory_exp_cost + code_exec_cost + address_access_cost + positive_value_cost

Copy link
Member

@danceratopz danceratopz left a comment

Choose a reason for hiding this comment

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

The renaming made in acolytec3#3 got me thinking (as gets trickier to give a good name to tests targeting multiple opcodes!).

Does it make sense to expand this test to all execution opcodes, i.e., DELEGATECALL and STATICCALL while we're at it?

@jochem-brouwer
Copy link
Member

This test is specific for the call stipend which we erroneously added to the current gas limit. This only applies to CALL opcodes which allow endowment (sending value) so the other candidate besides CALLCODE is CALL. 😊

@jochem-brouwer
Copy link
Member

jochem-brouwer commented Jan 17, 2024

I wanted to resolve the merge conflict but for some reason the PR does not show up right. Could you cherry-pick acolytec3@76ed643 in here?

EDIT: that diff looks also weird 🤔 Not sure whats going on here

Co-authored-by: acolytec3 <17355484+acolytec3@users.noreply.github.com>
Co-authored-by: Jochem Brouwer <jochembrouwer96@gmail.com>
Co-authored-by: danceratopz <danceratopz@gmail.com>

feat(tests): fix state test error.
@danceratopz
Copy link
Member

Looks great! Thanks a lot for the gas calculation explanations / sufficient/insufficient gas improvements!

Copy link
Member

@danceratopz danceratopz left a comment

Choose a reason for hiding this comment

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

LGTM!

@danceratopz danceratopz merged commit 933508e into ethereum:main Jan 19, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
scope:tests Scope: Test cases type:feat type: Feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants