-
Notifications
You must be signed in to change notification settings - Fork 168
new(tests): TSTORE: ensure transient storage is cleared after transactions #798
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
marioevz
merged 6 commits into
ethereum:main
from
jochem-brouwer:tstore_clear_storage_between_txs
Sep 18, 2024
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
2da3856
new(tests): TSTORE: ensure transient storage is cleared after transac…
jochem-brouwer 7447330
address review
jochem-brouwer bf7b82a
tests: ensure eof/legacy gets properly switched
jochem-brouwer 9862410
chore: fix mypy tox errors
spencer-tb 7f4f518
Merge pull request #4 from spencer-tb/jochem-brouwer/tstore_clear_sto…
jochem-brouwer 48e070a
address comment
jochem-brouwer 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
109 changes: 109 additions & 0 deletions
109
tests/cancun/eip1153_tstore/test_tstorage_clear_after_tx.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,109 @@ | ||
""" | ||
Ethereum Transient Storage EIP Tests | ||
https://eips.ethereum.org/EIPS/eip-1153 | ||
""" | ||
|
||
from typing import Optional | ||
|
||
import pytest | ||
|
||
from ethereum_test_tools import ( | ||
Account, | ||
Alloc, | ||
Block, | ||
BlockchainTestFiller, | ||
Environment, | ||
EVMCodeType, | ||
Initcode, | ||
Transaction, | ||
) | ||
from ethereum_test_tools.eof.v1 import Container | ||
from ethereum_test_tools.vm.opcode import Opcodes as Op | ||
|
||
from .spec import ref_spec_1153 | ||
|
||
REFERENCE_SPEC_GIT_PATH = ref_spec_1153.git_path | ||
REFERENCE_SPEC_VERSION = ref_spec_1153.version | ||
|
||
|
||
@pytest.mark.valid_from("Cancun") | ||
@pytest.mark.with_all_evm_code_types | ||
def test_tstore_clear_after_deployment_tx( | ||
blockchain_test: BlockchainTestFiller, | ||
pre: Alloc, | ||
evm_code_type: EVMCodeType, | ||
): | ||
""" | ||
This test first creates a contract, which TSTOREs a value 1 in slot 1. | ||
After creating the contract, a new tx will call this contract, storing TLOAD(1) into slot 1. | ||
The transient storage should be cleared after creating the contract (at tx-level), so | ||
the storage should stay empty. | ||
""" | ||
env = Environment() | ||
|
||
init_code = Op.TSTORE(1, 1) | ||
deploy_code = Op.SSTORE(1, Op.TLOAD(1)) | ||
|
||
code: Optional[Container | Initcode] = None | ||
if evm_code_type == EVMCodeType.EOF_V1: | ||
code = Container.Init( | ||
deploy_container=Container.Code(deploy_code), initcode_prefix=init_code | ||
) | ||
else: | ||
code = Initcode(deploy_code=deploy_code, initcode_prefix=init_code) | ||
|
||
sender = pre.fund_eoa() | ||
|
||
deployment_tx = Transaction( | ||
gas_limit=100000, | ||
data=code, | ||
to=None, | ||
sender=sender, | ||
) | ||
|
||
address = deployment_tx.created_contract | ||
|
||
invoke_contract_tx = Transaction(gas_limit=100000, to=address, sender=sender) | ||
jochem-brouwer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
txs = [deployment_tx, invoke_contract_tx] | ||
|
||
post = { | ||
address: Account(storage={0x01: 0x00}), | ||
} | ||
|
||
blockchain_test(genesis_environment=env, pre=pre, post=post, blocks=[Block(txs=txs)]) | ||
|
||
|
||
@pytest.mark.valid_from("Cancun") | ||
@pytest.mark.with_all_evm_code_types | ||
def test_tstore_clear_after_tx( | ||
blockchain_test: BlockchainTestFiller, | ||
pre: Alloc, | ||
): | ||
""" | ||
This test first SSTOREs the TLOAD value of key 1 in slot 1. Then, it TSTOREs 1 in slot 1. | ||
The second tx will re-call the contract. The storage should stay empty, | ||
because the transient storage is cleared after the transaction. | ||
""" | ||
env = Environment() | ||
|
||
code = Op.SSTORE(1, Op.TLOAD(1)) + Op.TSTORE(1, 1) | ||
account = pre.deploy_contract(code) | ||
|
||
sender = pre.fund_eoa() | ||
|
||
poke_tstore_tx = Transaction( | ||
gas_limit=100000, | ||
to=account, | ||
sender=sender, | ||
) | ||
|
||
re_poke_tstore_tx = Transaction(gas_limit=100000, to=account, sender=sender) | ||
|
||
txs = [poke_tstore_tx, re_poke_tstore_tx] | ||
|
||
post = { | ||
account: Account(storage={0x01: 0x00}), | ||
} | ||
|
||
blockchain_test(genesis_environment=env, pre=pre, post=post, blocks=[Block(txs=txs)]) |
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.