Skip to content

test_reentrant_selfdestructing_call()

Documentation for tests/cancun/eip1153_tstore/test_tstorage_selfdestruct.py::test_reentrant_selfdestructing_call@49a16fac.

Generate fixtures for these test cases for Prague with:

fill -v tests/cancun/eip1153_tstore/test_tstorage_selfdestruct.py::test_reentrant_selfdestructing_call --fork Prague

Test transient storage in different reentrancy contexts after selfdestructing.

Source code in tests/cancun/eip1153_tstore/test_tstorage_selfdestruct.py
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
@SelfDestructCases.parametrize()
def test_reentrant_selfdestructing_call(
    state_test: StateTestFiller,
    pre: Alloc,
    pre_existing_contract: bool,
    caller_bytecode: Bytecode,
    callee_bytecode: Bytecode,
    expected_storage: Dict,
):
    """Test transient storage in different reentrancy contexts after selfdestructing."""
    env = Environment()

    caller_address = pre.deploy_contract(code=caller_bytecode)

    data: bytes | Bytecode
    if pre_existing_contract:
        callee_address = pre.deploy_contract(code=callee_bytecode)
        data = Hash(callee_address, left_padding=True)
    else:
        callee_address = compute_create_address(address=caller_address, nonce=1)
        data = Initcode(deploy_code=callee_bytecode)

    tx = Transaction(
        sender=pre.fund_eoa(),
        to=caller_address,
        gas_limit=1_000_000,
        data=data,
    )

    expected_storage[0] = callee_address

    post: Dict = {caller_address: Account(storage=expected_storage)}

    if pre_existing_contract:
        post[callee_address] = Account(code=callee_bytecode)
    else:
        post[callee_address] = Account.NONEXISTENT

    state_test(env=env, pre=pre, post=post, tx=tx)

Parametrized Test Cases

The interactive table below is also available as a standalone page.

Test ID (Abbreviated) callee_bytecode caller_bytecode expected_storage pre_existing_contract
...fork_Cancun-blockchain_test-tload_after_selfdestruct_pre_existing_contract {1: 1, 2: 1, 3: 256} True
...fork_Cancun-blockchain_test-tload_after_selfdestruct_new_contract {1: 1, 2: 1, 3: 256} False
...fork_Cancun-blockchain_test-tload_after_inner_selfdestruct_pre_existing_contract {1: 1, 2: 256} True
...fork_Cancun-blockchain_test-tload_after_inner_selfdestruct_new_contract {1: 1, 2: 256} False
...fork_Cancun-blockchain_test-tstore_after_selfdestruct_pre_existing_contract {1: 1, 2: 1, 3: 1, 4: 256} True
...fork_Cancun-blockchain_test-tstore_after_selfdestruct_new_contract {1: 1, 2: 1, 3: 1, 4: 256} False
...fork_Cancun-state_test-tload_after_selfdestruct_pre_existing_contract {1: 1, 2: 1, 3: 256} True
...fork_Cancun-state_test-tload_after_selfdestruct_new_contract {1: 1, 2: 1, 3: 256} False
...fork_Cancun-state_test-tload_after_inner_selfdestruct_pre_existing_contract {1: 1, 2: 256} True
...fork_Cancun-state_test-tload_after_inner_selfdestruct_new_contract {1: 1, 2: 256} False
...fork_Cancun-state_test-tstore_after_selfdestruct_pre_existing_contract {1: 1, 2: 1, 3: 1, 4: 256} True
...fork_Cancun-state_test-tstore_after_selfdestruct_new_contract {1: 1, 2: 1, 3: 1, 4: 256} False
...fork_Prague-blockchain_test-tload_after_selfdestruct_pre_existing_contract {1: 1, 2: 1, 3: 256} True
...fork_Prague-blockchain_test-tload_after_selfdestruct_new_contract {1: 1, 2: 1, 3: 256} False
...fork_Prague-blockchain_test-tload_after_inner_selfdestruct_pre_existing_contract {1: 1, 2: 256} True
...fork_Prague-blockchain_test-tload_after_inner_selfdestruct_new_contract {1: 1, 2: 256} False
...fork_Prague-blockchain_test-tstore_after_selfdestruct_pre_existing_contract {1: 1, 2: 1, 3: 1, 4: 256} True
...fork_Prague-blockchain_test-tstore_after_selfdestruct_new_contract {1: 1, 2: 1, 3: 1, 4: 256} False
...fork_Prague-state_test-tload_after_selfdestruct_pre_existing_contract {1: 1, 2: 1, 3: 256} True
...fork_Prague-state_test-tload_after_selfdestruct_new_contract {1: 1, 2: 1, 3: 256} False
...fork_Prague-state_test-tload_after_inner_selfdestruct_pre_existing_contract {1: 1, 2: 256} True
...fork_Prague-state_test-tload_after_inner_selfdestruct_new_contract {1: 1, 2: 256} False
...fork_Prague-state_test-tstore_after_selfdestruct_pre_existing_contract {1: 1, 2: 1, 3: 1, 4: 256} True
...fork_Prague-state_test-tstore_after_selfdestruct_new_contract {1: 1, 2: 1, 3: 1, 4: 256} False
...fork_Osaka-blockchain_test-tload_after_selfdestruct_pre_existing_contract {1: 1, 2: 1, 3: 256} True
...fork_Osaka-blockchain_test-tload_after_selfdestruct_new_contract {1: 1, 2: 1, 3: 256} False
...fork_Osaka-blockchain_test-tload_after_inner_selfdestruct_pre_existing_contract {1: 1, 2: 256} True
...fork_Osaka-blockchain_test-tload_after_inner_selfdestruct_new_contract {1: 1, 2: 256} False
...fork_Osaka-blockchain_test-tstore_after_selfdestruct_pre_existing_contract {1: 1, 2: 1, 3: 1, 4: 256} True
...fork_Osaka-blockchain_test-tstore_after_selfdestruct_new_contract {1: 1, 2: 1, 3: 1, 4: 256} False
...fork_Osaka-state_test-tload_after_selfdestruct_pre_existing_contract {1: 1, 2: 1, 3: 256} True
...fork_Osaka-state_test-tload_after_selfdestruct_new_contract {1: 1, 2: 1, 3: 256} False
...fork_Osaka-state_test-tload_after_inner_selfdestruct_pre_existing_contract {1: 1, 2: 256} True
...fork_Osaka-state_test-tload_after_inner_selfdestruct_new_contract {1: 1, 2: 256} False
...fork_Osaka-state_test-tstore_after_selfdestruct_pre_existing_contract {1: 1, 2: 1, 3: 1, 4: 256} True
...fork_Osaka-state_test-tstore_after_selfdestruct_new_contract {1: 1, 2: 1, 3: 1, 4: 256} False