Skip to content

feat(tests): add eip-2929 precompile address warming tests #1495

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

Merged
merged 7 commits into from
Apr 29, 2025

Conversation

danceratopz
Copy link
Member

@danceratopz danceratopz commented Apr 25, 2025

🗒️ Description

Idea from @jochem-brouwer - thanks! Please check whether this test is doing what you intended.

Call BALANCE of a precompile address before and after a fork.

According to EIP-2929, when a transaction begins, accessed_addresses is initialized to include:

  • tx.sender, tx.to
  • and the set of all precompiles

This test verifies that:

  1. Precompiles that exist in the predecessor fork are always "warm" (lower gas cost)
  2. New precompiles added in a fork are "cold" before the fork and become "warm" after

These would perhaps be better as state tests. Feel free to close and implement a better suggestion, but happy for any feedback if you have time!

Also, this test should live in tests/paris, not tests/frontier, as they're only valid for EIP-2929, but it seemed silly to separate them from the other precompile generator tests.

The test uses a generator; it generates these tests:

fill --fork CancunToPragueAtTime15k tests/frontier/precompiles/test_precompiles.py -k test_precompile_warming --collect-only -q -m blockchain_test
 pytest-regex selected 37 tests to run for regex: .*
tests/frontier/precompiles/test_precompiles.py::test_precompile_warming[fork_CancunToPragueAtTime15k-address_0xb-exists_in_predecessor_False-blockchain_test]
tests/frontier/precompiles/test_precompiles.py::test_precompile_warming[fork_CancunToPragueAtTime15k-address_0xc-exists_in_predecessor_False-blockchain_test]
tests/frontier/precompiles/test_precompiles.py::test_precompile_warming[fork_CancunToPragueAtTime15k-address_0xd-exists_in_predecessor_False-blockchain_test]
tests/frontier/precompiles/test_precompiles.py::test_precompile_warming[fork_CancunToPragueAtTime15k-address_0xe-exists_in_predecessor_False-blockchain_test]
tests/frontier/precompiles/test_precompiles.py::test_precompile_warming[fork_CancunToPragueAtTime15k-address_0xf-exists_in_predecessor_False-blockchain_test]
tests/frontier/precompiles/test_precompiles.py::test_precompile_warming[fork_CancunToPragueAtTime15k-address_0x10-exists_in_predecessor_False-blockchain_test]
tests/frontier/precompiles/test_precompiles.py::test_precompile_warming[fork_CancunToPragueAtTime15k-address_0x11-exists_in_predecessor_False-blockchain_test]
tests/frontier/precompiles/test_precompiles.py::test_precompile_warming[fork_CancunToPragueAtTime15k-address_0xa-exists_in_predecessor_True-blockchain_test]
tests/frontier/precompiles/test_precompiles.py::test_precompile_warming[fork_CancunToPragueAtTime15k-address_0x9-exists_in_predecessor_True-blockchain_test]
tests/frontier/precompiles/test_precompiles.py::test_precompile_warming[fork_CancunToPragueAtTime15k-address_0x5-exists_in_predecessor_True-blockchain_test]
tests/frontier/precompiles/test_precompiles.py::test_precompile_warming[fork_CancunToPragueAtTime15k-address_0x6-exists_in_predecessor_True-blockchain_test]
tests/frontier/precompiles/test_precompiles.py::test_precompile_warming[fork_CancunToPragueAtTime15k-address_0x7-exists_in_predecessor_True-blockchain_test]
tests/frontier/precompiles/test_precompiles.py::test_precompile_warming[fork_CancunToPragueAtTime15k-address_0x8-exists_in_predecessor_True-blockchain_test]
tests/frontier/precompiles/test_precompiles.py::test_precompile_warming[fork_CancunToPragueAtTime15k-address_0x1-exists_in_predecessor_True-blockchain_test]
tests/frontier/precompiles/test_precompiles.py::test_precompile_warming[fork_CancunToPragueAtTime15k-address_0x2-exists_in_predecessor_True-blockchain_test]
tests/frontier/precompiles/test_precompiles.py::test_precompile_warming[fork_CancunToPragueAtTime15k-address_0x3-exists_in_predecessor_True-blockchain_test]
tests/frontier/precompiles/test_precompiles.py::test_precompile_warming[fork_CancunToPragueAtTime15k-address_0x4-exists_in_predecessor_True-blockchain_test]

🔗 Related Issues

None

✅ Checklist

  • All: Set appropriate labels for the changes.
  • All: Considered squashing commits to improve commit history.
  • All: Added an entry to CHANGELOG.md.

@danceratopz danceratopz added scope:tests Scope: Changes EL client test cases in `./tests` type:feat type: Feature labels Apr 25, 2025
Copy link
Member

@jochem-brouwer jochem-brouwer 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 a great start, some comments, because this mainly misses also checking that addresses which could have been precompiles in the past are now "normal" addresses (so should be cold)

Copy link
Member

@marioevz marioevz left a comment

Choose a reason for hiding this comment

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

Some comments but overall looks great!

Copy link
Contributor

@spencer-tb spencer-tb left a comment

Choose a reason for hiding this comment

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

LGTM from myside! I moved the test to Berlin btw, where 2929 was introduced, like we do with the other tests.

@marioevz
Copy link
Member

Created an issue in evmone's repo for the CI failure: ethereum/evmone#1210

We should be able to merge despite of this failure.

@spencer-tb spencer-tb merged commit bc691d1 into main Apr 29, 2025
21 of 23 checks passed
@spencer-tb spencer-tb deleted the test-precompile-warming branch April 29, 2025 13:47
predecessor_precompiles = set(get_transition_fork_predecessor(fork).precompiles())
successor_precompiles = set(get_transition_fork_successor(fork).precompiles())
all_precompiles = successor_precompiles | predecessor_precompiles
highest_precompile = int.from_bytes(max(all_precompiles))
Copy link
Collaborator

Choose a reason for hiding this comment

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

from_bytes requires two arguments, I had to change this line to:
highest_precompile: int = int.from_bytes(max(all_precompiles), sys.byteorder)
and import sys to make it work.

Copy link
Contributor

Choose a reason for hiding this comment

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

when you say make it work you mean fill?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Just having the file opened in an editor shows the problem. But now I know it depends on which Python version you use:
python 3.11 -> optional parameter
python 3.10 -> mandatory parameter

So I think it would be good if we find an exact Python version we enforce in EEST (everyone uses the exact same) to avoid stuff like this in the future.

Copy link
Contributor

Choose a reason for hiding this comment

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

#1516

created an issue for discussion on enforcing the python version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
scope:tests Scope: Changes EL client test cases in `./tests` type:feat type: Feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants