-
Notifications
You must be signed in to change notification settings - Fork 186
new(tests): Add generic precompile-absence test #1036
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
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
201e9f8
new(tests): Add precompile-absence test
marioevz bb7693a
more parametrize
marioevz 47e4fa7
fix(tests): Use zero gas to guarantee failure in case of unexpected p…
marioevz b45b797
docs: Changelog
marioevz e5d05c8
fix: ruff
marioevz 92c0401
Merge branch 'main' into no-precompile-addresses-check-test
marioevz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| """Test for precompiles that apply for all forks starting from Frontier.""" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| """abstract: Test Calling Precompile Range (close to zero).""" | ||
|
|
||
| import pytest | ||
|
|
||
| from ethereum_test_forks import Fork | ||
| from ethereum_test_tools import ( | ||
| Account, | ||
| Address, | ||
| Alloc, | ||
| Bytecode, | ||
| StateTestFiller, | ||
| Storage, | ||
| Transaction, | ||
| ) | ||
| from ethereum_test_tools import Opcodes as Op | ||
|
|
||
| UPPER_BOUND = 0x101 | ||
| RETURNDATASIZE_OFFSET = 0x10000000000000000 # Must be greater than UPPER_BOUND | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "calldata_size", | ||
| [ | ||
| pytest.param(0, id="empty_calldata"), | ||
| pytest.param(31, id="31_bytes"), | ||
| pytest.param(32, id="32_bytes"), | ||
| ], | ||
| ) | ||
| @pytest.mark.valid_from("Byzantium") | ||
| def test_precompile_absence( | ||
| state_test: StateTestFiller, | ||
| pre: Alloc, | ||
| fork: Fork, | ||
| calldata_size: int, | ||
| ): | ||
| """Test that addresses close to zero are not precompiles unless active in the fork.""" | ||
| active_precompiles = fork.precompiles() | ||
| storage = Storage() | ||
| call_code = Bytecode() | ||
| for address in range(1, UPPER_BOUND + 1): | ||
| if Address(address) in active_precompiles: | ||
| continue | ||
| call_code += Op.SSTORE( | ||
| address, | ||
| Op.CALL(gas=0, address=address, args_size=calldata_size), | ||
| ) | ||
| storage[address] = 1 | ||
| if Op.RETURNDATASIZE in fork.valid_opcodes(): | ||
| call_code += Op.SSTORE( | ||
| address + RETURNDATASIZE_OFFSET, | ||
| Op.RETURNDATASIZE, | ||
marioevz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ) | ||
| storage[address + RETURNDATASIZE_OFFSET] = 0 | ||
|
|
||
| call_code += Op.STOP | ||
|
|
||
| entry_point_address = pre.deploy_contract(call_code, storage=storage.canary()) | ||
|
|
||
| tx = Transaction( | ||
| to=entry_point_address, | ||
| gas_limit=10_000_000, | ||
| sender=pre.fund_eoa(), | ||
| protected=True, | ||
| ) | ||
|
|
||
| state_test( | ||
| pre=pre, | ||
| tx=tx, | ||
| post={ | ||
| entry_point_address: Account( | ||
| storage=storage, | ||
| ) | ||
| }, | ||
| ) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.