-
Notifications
You must be signed in to change notification settings - Fork 414
refactor(test-tests): port EXTCODEHASH dynamicAccountOverwriteEmpty #2032
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
Open
chfast
wants to merge
3
commits into
ethereum:forks/amsterdam
Choose a base branch
from
ipsilon:tests/port_account_overwrite
base: forks/amsterdam
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
Some comments aren't visible on the classic Files Changed page.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| """Cross-client EIP-1052 EXTCODEHASH Tests.""" |
158 changes: 158 additions & 0 deletions
158
tests/constantinople/eip1052_extcodehash/test_extcodehash.py
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,158 @@ | ||
| """ | ||
| Test EIP-1052 EXTCODEHASH. | ||
| """ | ||
|
|
||
| import pytest | ||
| from execution_testing import ( | ||
| Account, | ||
| Alloc, | ||
| Initcode, | ||
| Op, | ||
| StateTestFiller, | ||
| Storage, | ||
| Transaction, | ||
| compute_create2_address, | ||
| ) | ||
|
|
||
| from ethereum.crypto.hash import keccak256 | ||
|
|
||
| REFERENCE_SPEC_GIT_PATH = "EIPS/eip-1052.md" | ||
| REFERENCE_SPEC_VERSION = "b0a21c42cb76b9f4f120dd4bd2bd3d83f6682b8a" | ||
|
|
||
|
|
||
| @pytest.mark.valid_from("Constantinople") | ||
| @pytest.mark.ported_from( | ||
| [ | ||
| "https://github.com/ethereum/tests/tree/v13.3/src/GeneralStateTestsFiller/stExtCodeHash/dynamicAccountOverwriteEmpty_ParisFiller.yml", # noqa: E501 | ||
| ], | ||
| pr=["https://github.com/ethereum/execution-specs/pull/2032"], | ||
| ) | ||
| @pytest.mark.parametrize( | ||
| "target_exists", | ||
| [True, False], | ||
| ) | ||
| def test_extcodehash_dynamic_account_overwrite( | ||
| state_test: StateTestFiller, | ||
| pre: Alloc, | ||
| target_exists: bool, | ||
| ) -> None: | ||
| """ | ||
| Test EXTCODEHASH of non-existent/no-code account, | ||
| then with code deployed at the address via CREATE2. | ||
|
|
||
| This verifies that the code hash cache is correctly updated during the | ||
| transaction when an account is overwritten by CREATE2. | ||
|
|
||
| The target address is computed after the caller contract code is deployed, | ||
| and passed as calldata to the caller contract. | ||
|
|
||
| The target account code sets a fixed storage slot. This code is executed | ||
| at the caller account via DELEGATECALL and at the target account via CALL. | ||
|
|
||
| Modified from original test: target account has no storage to avoid | ||
| EIP-7610 collision behavior. | ||
| """ | ||
| target_storage_slot = 0x4A | ||
| caller_storage = Storage() | ||
| target_storage = Storage() | ||
|
|
||
| deploy_code = Op.SSTORE(target_storage_slot, 1) | ||
| create2_initcode = Initcode(deploy_code=deploy_code) | ||
|
|
||
| caller_code = ( | ||
| # EXTCODEHASH of the pre-CREATE2 target account. | ||
| Op.SSTORE( | ||
| caller_storage.store_next(keccak256(b"") if target_exists else 0), | ||
| Op.EXTCODEHASH(Op.CALLDATALOAD(0)), | ||
| ) | ||
| # EXTCODESIZE of non-existent target account. | ||
| + Op.SSTORE( | ||
| caller_storage.store_next(0), Op.EXTCODESIZE(Op.CALLDATALOAD(0)) | ||
| ) | ||
| # EXTCODECOPY of non-existent target account. | ||
| + Op.EXTCODECOPY(Op.CALLDATALOAD(0), 0, 0, 32) | ||
| + Op.SSTORE(caller_storage.store_next(0), Op.MLOAD(0)) | ||
| # DELEGATECALL the non-existent target account. | ||
| + Op.SSTORE( | ||
| caller_storage.store_next(1), | ||
| Op.DELEGATECALL( | ||
| address=Op.CALLDATALOAD(0), | ||
| gas=0, # Pass zero gas to ensure no execution. | ||
| ), | ||
| ) | ||
| ) | ||
| # Target address to be set later. | ||
| target_address_slot = caller_storage.store_next(0, "target_address") | ||
| caller_code += ( | ||
| # CREATE2 to overwrite the account | ||
| Op.MSTORE(0, Op.PUSH32(bytes(create2_initcode).ljust(32, b"\0"))) | ||
| + Op.SSTORE( | ||
| target_address_slot, | ||
| Op.CREATE2(value=0, offset=0, size=len(create2_initcode), salt=0), | ||
| ) | ||
| # EXTCODEHASH of the target account. | ||
| + Op.SSTORE( | ||
| caller_storage.store_next(deploy_code.keccak256()), | ||
| Op.EXTCODEHASH(Op.CALLDATALOAD(0)), | ||
| ) | ||
| # EXTCODESIZE of the target account. | ||
| + Op.SSTORE( | ||
| caller_storage.store_next(len(deploy_code)), | ||
| Op.EXTCODESIZE(Op.CALLDATALOAD(0)), | ||
| ) | ||
| # EXTCODECOPY of the target account. | ||
| + Op.EXTCODECOPY(Op.CALLDATALOAD(0), 0, 0, 32) | ||
| + Op.SSTORE( | ||
| caller_storage.store_next(bytes(deploy_code).ljust(32, b"\0")), | ||
| Op.MLOAD(0), | ||
| ) | ||
| # DELEGATECALL the target account. | ||
| + Op.SSTORE( | ||
| caller_storage.store_next(1), | ||
| Op.DELEGATECALL( | ||
| address=Op.CALLDATALOAD(0), | ||
| gas=Op.GAS, | ||
| ), | ||
| ) | ||
| # Call the deployed contract to execute its "deploy_code". | ||
| + Op.SSTORE( | ||
| caller_storage.store_next(1), | ||
| Op.CALL(address=Op.CALLDATALOAD(0), gas=Op.GAS), | ||
| ) | ||
| ) | ||
LouisTsai-Csie marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| caller_address = pre.deploy_contract(caller_code, balance=1) | ||
|
|
||
| target_address = compute_create2_address( | ||
| address=caller_address, | ||
| salt=0, | ||
| initcode=create2_initcode, | ||
| ) | ||
|
|
||
| if target_exists: | ||
| pre.fund_address(target_address, 1) | ||
|
|
||
| caller_storage[target_address_slot] = target_address | ||
| caller_storage[target_storage_slot] = 1 | ||
| target_storage[target_storage_slot] = 1 | ||
|
|
||
| sender = pre.fund_eoa() | ||
| tx = Transaction( | ||
| sender=sender, | ||
| to=caller_address, | ||
| data=bytes(target_address).rjust(32, b"\0"), | ||
| gas_limit=400_000, | ||
| ) | ||
|
|
||
| state_test( | ||
| pre=pre, | ||
| post={ | ||
| caller_address: Account(storage=caller_storage), | ||
| target_address: Account( | ||
| nonce=1, | ||
| code=deploy_code, | ||
| storage=target_storage, | ||
| ), | ||
| }, | ||
| tx=tx, | ||
| ) | ||
95 changes: 0 additions & 95 deletions
95
tests/static/state_tests/stExtCodeHash/dynamicAccountOverwriteEmpty_ParisFiller.yml
This file was deleted.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new test format looks good, but in the legacy test the target account (created via
CREATE2) had pre-existing storage. We’ve removed that setup, do we lose the coverage here?I now understand why
pytest.mark.pre_alloc_modifyis required: we want to configure an account storage viapre.I’m thinking of parameterizing the cases like this:
And configuring
prelike:However, this setting keeps failing in
fill: it looks liket8ndoesn’t handle theinitial storage + nonce=0scenario as I expected. Am I missing something in how pre-state is applied here?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could add multiple markers like this, for the pre-alloc modification, we should also skip the execute-remote mode.