Skip to content

test_selfdestruct_new_beneficiary_execution_gas()

Documentation for tests/amsterdam/eip8038_state_access_gas_cost_increase/test_selfdestruct_gas.py::test_selfdestruct_new_beneficiary_execution_gas@8acae1b0.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip8038_state_access_gas_cost_increase/test_selfdestruct_gas.py::test_selfdestruct_new_beneficiary_execution_gas --fork Amsterdam

SELFDESTRUCT to an empty beneficiary with balance charges ACCOUNT_WRITE.

The destructor has a non-zero balance and targets an empty, non-existent beneficiary, so the net-new ACCOUNT_WRITE applies: execution = OPCODE_SELFDESTRUCT_BASE + access + ACCOUNT_WRITE. The creation gas GAS_NEW_ACCOUNT is charged on the state axis (the EIP-8037 suite asserts it); here it is funded from the reservoir and the value transfer to the new beneficiary confirms the path.

Source code in tests/amsterdam/eip8038_state_access_gas_cost_increase/test_selfdestruct_gas.py
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
@EIPChecklist.GasCostChanges.Test.GasUpdatesMeasurement()
@pytest.mark.parametrize("warm", [False, True], ids=["cold", "warm"])
def test_selfdestruct_new_beneficiary_execution_gas(
    state_test: StateTestFiller,
    pre: Alloc,
    fork: Fork,
    warm: bool,
) -> None:
    """
    SELFDESTRUCT to an empty beneficiary with balance charges
    ACCOUNT_WRITE.

    The destructor has a non-zero balance and targets an empty,
    non-existent beneficiary, so the net-new ``ACCOUNT_WRITE`` applies:
    ``execution = OPCODE_SELFDESTRUCT_BASE + access + ACCOUNT_WRITE``. The
    creation gas ``GAS_NEW_ACCOUNT`` is charged on the state axis (the
    EIP-8037 suite asserts it); here it is funded from the reservoir and
    the value transfer to the new beneficiary confirms the path.
    """
    new_account_state_gas = Op.SELFDESTRUCT(account_new=True).state_cost(fork)

    beneficiary = Address(0xDEAD)  # empty, non-existent

    destructor_code = Op.SELFDESTRUCT(beneficiary)
    destructor = pre.deploy_contract(code=destructor_code, balance=1)

    storage = Storage()
    caller_code = Op.SSTORE(
        storage.store_next(1, "call_succeeds"),
        Op.CALL(gas=Op.GAS, address=destructor),
    )
    caller = pre.deploy_contract(code=caller_code)

    tx = Transaction(
        to=caller,
        sender=pre.fund_eoa(),
        access_list=[AccessList(address=beneficiary, storage_keys=[])]
        if warm
        else None,
        state_gas_reservoir=new_account_state_gas,
    )

    state_test(
        pre=pre,
        post={
            caller: Account(storage=storage),
            # New beneficiary created and credited the destructor balance.
            beneficiary: Account(balance=1),
        },
        tx=tx,
    )

Parametrized Test Cases

This test generates 2 parametrized test cases across 1 fork.