|
| 1 | +import pytest |
| 2 | + |
| 3 | +from ethereum_test_tools import BlockchainTestFiller, Transaction, Account, TestAddress |
| 4 | +from ethereum_test_tools.vm.opcode import Opcodes as Op |
| 5 | +from .utils import stride, _state_conversion, accounts, ConversionTx |
| 6 | + |
| 7 | +REFERENCE_SPEC_GIT_PATH = "EIPS/eip-7748.md" |
| 8 | +REFERENCE_SPEC_VERSION = "TODO" |
| 9 | + |
| 10 | + |
| 11 | +@pytest.mark.valid_from("EIP6800Transition") |
| 12 | +@pytest.mark.parametrize( |
| 13 | + "storage_slot_write", |
| 14 | + [ |
| 15 | + 0, |
| 16 | + 1, |
| 17 | + 300, |
| 18 | + 301, |
| 19 | + ], |
| 20 | + ids=[ |
| 21 | + "Stale storage slot in the header", |
| 22 | + "New storage slot in the account header", |
| 23 | + "Stale storage slot outside the header", |
| 24 | + "New storage slot outside the header", |
| 25 | + ], |
| 26 | +) |
| 27 | +@pytest.mark.parametrize( |
| 28 | + "stale_basic_data", |
| 29 | + [True, False], |
| 30 | +) |
| 31 | +def test_stale_contract_writes( |
| 32 | + blockchain_test: BlockchainTestFiller, |
| 33 | + storage_slot_write: int, |
| 34 | + stale_basic_data: bool, |
| 35 | +): |
| 36 | + """ |
| 37 | + Test converting a contract where a previous transaction writes to: |
| 38 | + - Existing storage slots (i.e., storage slots that must not be converted (stale)) |
| 39 | + - New storage slots (i.e., storage slots that must not be converted (not overriden with zeros)) |
| 40 | + - Basic data (i.e., balance/nonce which must not be converted (stale)) |
| 41 | + """ |
| 42 | + pre_state = {} |
| 43 | + pre_state[TestAddress] = Account(balance=1000000000000000000000) |
| 44 | + |
| 45 | + # TODO(hack): today the testing-framework does not support us signaling that we want to |
| 46 | + # put the `ConversionTx(tx, **0**)` at the first block after genesis. To simulate that, we have |
| 47 | + # to do this here so we "shift" the target account to the second block in the fork. |
| 48 | + # If this is ever supported, remove this. |
| 49 | + for i in range(stride): |
| 50 | + pre_state[accounts[i]] = Account(balance=100 + 1000 * i) |
| 51 | + |
| 52 | + target_account = accounts[stride] |
| 53 | + pre_state[target_account] = Account( |
| 54 | + balance=1_000, |
| 55 | + nonce=0, |
| 56 | + code=Op.SSTORE(storage_slot_write, 9999), |
| 57 | + storage={ |
| 58 | + 0: 100, |
| 59 | + 300: 200, |
| 60 | + }, |
| 61 | + ) |
| 62 | + |
| 63 | + tx = Transaction( |
| 64 | + ty=0x0, |
| 65 | + chain_id=0x01, |
| 66 | + to=target_account, |
| 67 | + value=100 if stale_basic_data else 0, |
| 68 | + gas_limit=100_000, |
| 69 | + gas_price=10, |
| 70 | + ) |
| 71 | + |
| 72 | + _state_conversion(blockchain_test, pre_state, stride, 1, [ConversionTx(tx, 0)]) |
| 73 | + |
| 74 | + |
| 75 | +# @pytest.mark.valid_from("EIP6800Transition") |
| 76 | +# @pytest.mark.parametrize( |
| 77 | +# "num_storage_slots, num_stale_storage_slots", |
| 78 | +# [ |
| 79 | +# (0, 0), |
| 80 | +# (4, 0), |
| 81 | +# (4, 2), |
| 82 | +# (stride, stride), |
| 83 | +# ], |
| 84 | +# ids=[ |
| 85 | +# "EOA", |
| 86 | +# "Contract without stale storage", |
| 87 | +# "Contract with some stale storage", |
| 88 | +# "Contract with all stale storage", |
| 89 | +# ], |
| 90 | +# ) |
| 91 | +# @pytest.mark.parametrize( |
| 92 | +# "stale_basic_data", |
| 93 | +# [True, False], |
| 94 | +# ) |
| 95 | +# @pytest.mark.parametrize( |
| 96 | +# "fill_first_block", |
| 97 | +# [True, False], |
| 98 | +# ) |
| 99 | +# @pytest.mark.parametrize( |
| 100 | +# "fill_last_block", |
| 101 | +# [True, False], |
| 102 | +# ) |
| 103 | +# def test_stale_keys( |
| 104 | +# blockchain_test: BlockchainTestFiller, |
| 105 | +# account_configs: list[AccountConfig], |
| 106 | +# fill_first_block: bool, |
| 107 | +# fill_last_block: bool, |
| 108 | +# ): |
| 109 | +# """ |
| 110 | +# Test account conversion with full/partial stale storage slots and basic data. |
| 111 | +# """ |
| 112 | +# _generic_conversion(blockchain_test, account_configs, fill_first_block, fill_last_block) |
| 113 | + |
| 114 | + |
| 115 | +# @pytest.mark.valid_from("EIP6800Transition") |
| 116 | +# @pytest.mark.parametrize( |
| 117 | +# "fill_first_block", |
| 118 | +# [True, False], |
| 119 | +# ) |
| 120 | +# @pytest.mark.parametrize( |
| 121 | +# "fill_last_block", |
| 122 | +# [True, False], |
| 123 | +# ) |
| 124 | +# def test_stride_stale_eoas( |
| 125 | +# blockchain_test: BlockchainTestFiller, |
| 126 | +# account_configs: list[AccountConfig], |
| 127 | +# fill_first_block: bool, |
| 128 | +# fill_last_block: bool, |
| 129 | +# ): |
| 130 | +# """ |
| 131 | +# Test converting a stride number of stale EOAs. |
| 132 | +# """ |
| 133 | +# _generic_conversion(blockchain_test, account_configs, fill_first_block, fill_last_block) |
0 commit comments