-
Notifications
You must be signed in to change notification settings - Fork 167
feat(tests): EIP-1153: Convert tests from ethereum/tests
#440
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
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
8970cac
convert a few eip1153 json tests
winsvega b0dab90
rebase on macro opcode, fix comments
winsvega 4abf10c
add changelog
winsvega 954b63d
split basic tload tests
winsvega 2220667
address comments
winsvega 3181ff0
use Bytecodes
winsvega eec333e
convert test to latest notation
winsvega c4f700d
don't use yul code in yul_coverage
winsvega 076f6c9
fix: move coverage 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
([#440](https://github.com/ethereum/execution-spec-tests/pull/440)) | ||
GeneralStateTests/Cancun/stEIP1153-transientStorage/01_tloadBeginningTxn.json | ||
GeneralStateTests/Cancun/stEIP1153-transientStorage/02_tloadAfterTstore.json | ||
GeneralStateTests/Cancun/stEIP1153-transientStorage/03_tloadAfterStoreIs0.json | ||
GeneralStateTests/Cancun/stEIP1153-transientStorage/04_tloadAfterCall.json | ||
GeneralStateTests/Cancun/stEIP1153-transientStorage/05_tloadReentrancy.json | ||
GeneralStateTests/Cancun/stEIP1153-transientStorage/06_tstoreInReentrancyCall.json | ||
GeneralStateTests/Cancun/stEIP1153-transientStorage/07_tloadAfterReentrancyStore.json | ||
GeneralStateTests/Cancun/stEIP1153-transientStorage/08_revertUndoesTransientStore.json | ||
GeneralStateTests/Cancun/stEIP1153-transientStorage/09_revertUndoesAll.json | ||
|
||
GeneralStateTests/Cancun/stEIP1153-transientStorage/11_tstoreDelegateCall.json | ||
GeneralStateTests/Cancun/stEIP1153-transientStorage/12_tloadDelegateCall.json | ||
GeneralStateTests/Cancun/stEIP1153-transientStorage/13_tloadStaticCall.json | ||
|
||
GeneralStateTests/Cancun/stEIP1153-transientStorage/16_tloadGas.json | ||
GeneralStateTests/Cancun/stEIP1153-transientStorage/18_tloadAfterStore.json | ||
|
||
GeneralStateTests/Cancun/stEIP1153-transientStorage/20_oogUndoesTransientStoreInCall.json |
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
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,284 @@ | ||
""" | ||
Ethereum Transient Storage EIP Tests | ||
https://eips.ethereum.org/EIPS/eip-1153 | ||
""" | ||
|
||
from typing import Dict, Union | ||
|
||
import pytest | ||
|
||
from ethereum_test_tools import Account, Address, Alloc, Environment, StateTestFiller, Transaction | ||
from ethereum_test_tools.vm.opcode import Opcodes as Op | ||
|
||
from .spec import Spec, ref_spec_1153 | ||
|
||
REFERENCE_SPEC_GIT_PATH = ref_spec_1153.git_path | ||
REFERENCE_SPEC_VERSION = ref_spec_1153.version | ||
|
||
|
||
@pytest.mark.valid_from("Cancun") | ||
def test_basic_tload_transaction_begin( | ||
state_test: StateTestFiller, | ||
pre: Alloc, | ||
): | ||
""" | ||
Ported .json vectors: | ||
|
||
(01_tloadBeginningTxnFiller.yml) | ||
load arbitrary value is 0 at beginning of transaction | ||
""" | ||
slot_tload_at_transaction_begin_result = 1 | ||
slot_code_worked = 2 | ||
|
||
address_to = pre.deploy_contract( | ||
code=Op.JUMPDEST() | ||
# 01 test | ||
+ Op.SSTORE(slot_tload_at_transaction_begin_result, Op.TLOAD(0)) | ||
+ Op.SSTORE(slot_code_worked, 1), | ||
storage={ | ||
slot_tload_at_transaction_begin_result: 0xFF, | ||
}, | ||
) | ||
|
||
post = { | ||
address_to: Account( | ||
storage={ | ||
slot_tload_at_transaction_begin_result: 0x00, | ||
slot_code_worked: 0x01, | ||
} | ||
) | ||
} | ||
|
||
tx = Transaction( | ||
sender=pre.fund_eoa(7_000_000_000_000_000_000), | ||
to=address_to, | ||
gas_price=10, | ||
data=b"", | ||
gas_limit=5000000, | ||
value=0, | ||
) | ||
|
||
state_test(env=Environment(), pre=pre, post=post, tx=tx) | ||
|
||
|
||
@pytest.mark.valid_from("Cancun") | ||
def test_basic_tload_works( | ||
state_test: StateTestFiller, | ||
pre: Alloc, | ||
): | ||
""" | ||
Ported .json vectors: | ||
|
||
(02_tloadAfterTstoreFiller.yml) | ||
tload from same slot after tstore returns correct value | ||
""" | ||
tstore_value = 88 | ||
|
||
slot_tload_after_tstore_result = 0 | ||
slot_tload_after_tstore_result_second_time = 1 | ||
slot_code_worked = 2 | ||
|
||
address_to = pre.deploy_contract( | ||
code=Op.JUMPDEST() | ||
# 02 test | ||
+ Op.TSTORE(2, tstore_value) | ||
+ Op.SSTORE(slot_tload_after_tstore_result, Op.TLOAD(2)) | ||
+ Op.SSTORE(slot_tload_after_tstore_result_second_time, Op.TLOAD(2)) | ||
+ Op.SSTORE(slot_code_worked, 1), | ||
storage={ | ||
slot_tload_after_tstore_result: 0xFF, | ||
slot_tload_after_tstore_result_second_time: 0xFF, | ||
}, | ||
) | ||
|
||
post = { | ||
address_to: Account( | ||
storage={ | ||
slot_tload_after_tstore_result: tstore_value, | ||
slot_tload_after_tstore_result_second_time: tstore_value, | ||
slot_code_worked: 0x01, | ||
} | ||
) | ||
} | ||
|
||
tx = Transaction( | ||
sender=pre.fund_eoa(7_000_000_000_000_000_000), | ||
to=address_to, | ||
gas_price=10, | ||
data=b"", | ||
gas_limit=5000000, | ||
value=0, | ||
) | ||
|
||
state_test(env=Environment(), pre=pre, post=post, tx=tx) | ||
|
||
|
||
@pytest.mark.valid_from("Cancun") | ||
def test_basic_tload_other_after_tstore( | ||
state_test: StateTestFiller, | ||
pre: Alloc, | ||
): | ||
""" | ||
Ported .json vectors: | ||
|
||
(03_tloadAfterStoreIs0Filler.yml) | ||
Loading any other slot after storing to a slot returns 0. | ||
""" | ||
tstore_value = 88 | ||
|
||
slot_tload_untouched_slot_after_tstore_result = 1 | ||
slot_code_worked = 2 | ||
|
||
address_to = pre.deploy_contract( | ||
code=Op.JUMPDEST() | ||
# 03 test | ||
+ Op.TSTORE(3, tstore_value) | ||
+ Op.SSTORE(slot_tload_untouched_slot_after_tstore_result, Op.TLOAD(0)) | ||
+ Op.SSTORE(slot_code_worked, 1), | ||
storage={ | ||
slot_tload_untouched_slot_after_tstore_result: 0xFF, | ||
}, | ||
) | ||
|
||
post = { | ||
address_to: Account( | ||
storage={ | ||
slot_tload_untouched_slot_after_tstore_result: 0x00, | ||
slot_code_worked: 0x01, | ||
} | ||
) | ||
} | ||
|
||
tx = Transaction( | ||
sender=pre.fund_eoa(7_000_000_000_000_000_000), | ||
to=address_to, | ||
gas_price=10, | ||
data=b"", | ||
gas_limit=5000000, | ||
value=0, | ||
) | ||
|
||
state_test(env=Environment(), pre=pre, post=post, tx=tx) | ||
|
||
|
||
@pytest.mark.valid_from("Cancun") | ||
def test_basic_tload_gasprice( | ||
state_test: StateTestFiller, | ||
pre: Alloc, | ||
): | ||
""" | ||
Ported .json vectors: | ||
|
||
(16_tloadGasFiller.yml) | ||
tload costs 100 gas same as a warm sload | ||
""" | ||
slot_tload_nonzero_gas_price_result = 1 | ||
slot_tload_zero_gas_price_result = 2 | ||
slot_code_worked = 3 | ||
|
||
""" | ||
N OPNAME GAS_COST TOTAL_GAS REMAINING_GAS STACK | ||
28-1 MSTORE 2 20748 4958252 2:[4ba82f,0,] | ||
MSTORE [0] = 4958255 | ||
29-1 PUSH1 3 20754 4958246 | ||
30-1 TLOAD 100 20757 4958243 1:[10,] | ||
31-1 GAS 2 20857 4958143 1:[2,] | ||
32-1 PUSH1 3 20859 4958141 2:[2,4ba7bd,] | ||
33-1 MSTORE 6 20862 4958138 3:[2,4ba7bd,20,] | ||
MSTORE [32] = 4958141 | ||
""" | ||
extra_opcode_gas = 11 # mstore(3), push1(3),gas(2),push1(3) | ||
|
||
address_to = pre.deploy_contract( | ||
code=Op.JUMPDEST() | ||
# 16 test | ||
+ Op.TSTORE(16, 2) | ||
+ Op.MSTORE(0, Op.GAS()) # hot load the memory to make the extra_opcode_gas be 11 | ||
+ Op.MSTORE(0, Op.GAS()) | ||
+ Op.TLOAD(16) | ||
+ Op.MSTORE(32, Op.GAS()) | ||
+ Op.SSTORE(slot_tload_nonzero_gas_price_result, Op.SUB(Op.MLOAD(0), Op.MLOAD(32))) | ||
+ Op.SSTORE( | ||
slot_tload_nonzero_gas_price_result, | ||
Op.SUB(Op.SLOAD(slot_tload_nonzero_gas_price_result), extra_opcode_gas), | ||
) | ||
+ Op.MSTORE(0, Op.GAS()) | ||
+ Op.TLOAD(5) # tload slot at 5 is 0 | ||
+ Op.MSTORE(32, Op.GAS()) | ||
+ Op.SSTORE(slot_tload_zero_gas_price_result, Op.SUB(Op.MLOAD(0), Op.MLOAD(32))) | ||
+ Op.SSTORE( | ||
slot_tload_zero_gas_price_result, | ||
Op.SUB(Op.SLOAD(slot_tload_zero_gas_price_result), extra_opcode_gas), | ||
) | ||
+ Op.SSTORE(slot_code_worked, 1), | ||
storage={ | ||
slot_tload_nonzero_gas_price_result: 0xFF, | ||
slot_tload_zero_gas_price_result: 0xFF, | ||
}, | ||
) | ||
|
||
post = { | ||
address_to: Account( | ||
storage={ | ||
slot_tload_nonzero_gas_price_result: Spec.TLOAD_GAS_COST, | ||
slot_tload_zero_gas_price_result: Spec.TLOAD_GAS_COST, | ||
slot_code_worked: 0x01, | ||
} | ||
) | ||
} | ||
|
||
tx = Transaction( | ||
sender=pre.fund_eoa(7_000_000_000_000_000_000), | ||
to=address_to, | ||
gas_price=10, | ||
data=b"", | ||
gas_limit=5000000, | ||
value=0, | ||
) | ||
|
||
state_test(env=Environment(), pre=pre, post=post, tx=tx) | ||
|
||
|
||
@pytest.mark.valid_from("Cancun") | ||
def test_basic_tload_after_store( | ||
state_test: StateTestFiller, | ||
pre: Alloc, | ||
): | ||
""" | ||
Ported .json vectors: | ||
|
||
(18_tloadAfterStoreFiller.yml) | ||
tload from same slot after store returns 0 | ||
""" | ||
slot_tload_from_sstore_result = 1 | ||
slot_code_worked = 2 | ||
|
||
address_to = pre.deploy_contract( | ||
code=Op.JUMPDEST() | ||
# 18 test | ||
+ Op.SSTORE(slot_tload_from_sstore_result, 22) | ||
+ Op.SSTORE(slot_tload_from_sstore_result, Op.TLOAD(slot_tload_from_sstore_result)) | ||
+ Op.SSTORE(slot_code_worked, 1), | ||
storage={ | ||
slot_tload_from_sstore_result: 0xFF, | ||
}, | ||
) | ||
|
||
post: Dict[Address, Union[Account, object]] = {} | ||
post[address_to] = Account( | ||
storage={ | ||
slot_tload_from_sstore_result: 0x00, | ||
slot_code_worked: 0x01, | ||
} | ||
) | ||
|
||
tx = Transaction( | ||
sender=pre.fund_eoa(7_000_000_000_000_000_000), | ||
to=address_to, | ||
gas_price=10, | ||
data=b"", | ||
gas_limit=5000000, | ||
value=0, | ||
) | ||
|
||
state_test(env=Environment(), pre=pre, post=post, tx=tx) |
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.
Uh oh!
There was an error while loading. Please reload this page.