Skip to content

test_call_value_to_self_destructed_header_gas_used()

Documentation for tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_call.py::test_call_value_to_self_destructed_header_gas_used@c74f1a67.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_call.py::test_call_value_to_self_destructed_header_gas_used --fork Amsterdam

Verify block gas accounting for CALL with value to a same transaction selfdestructed account.

Reservoir is sized for the CREATE's state charge only. Under the spec no new account charge fires on the CALL, so block state gas used equals exactly the single account creation charge and the header reports that value. The created account is queued for destruction regardless of whether SELFDESTRUCT targeted itself or an external beneficiary, so the no charge behavior holds across both cases.

Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_call.py
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
@pytest.mark.parametrize(
    "selfdestruct_beneficiary",
    [
        pytest.param("self", id="self_beneficiary"),
        pytest.param("external", id="external_beneficiary"),
    ],
)
@pytest.mark.parametrize(
    "create_opcode",
    [
        pytest.param(Op.CREATE, id="create"),
        pytest.param(Op.CREATE2, id="create2"),
    ],
)
@pytest.mark.valid_from("EIP8037")
def test_call_value_to_self_destructed_header_gas_used(
    blockchain_test: BlockchainTestFiller,
    pre: Alloc,
    fork: Fork,
    create_opcode: Op,
    selfdestruct_beneficiary: str,
) -> None:
    """
    Verify block gas accounting for CALL with value to a same
    transaction selfdestructed account.

    Reservoir is sized for the CREATE's state charge only. Under
    the spec no new account charge fires on the CALL, so block
    state gas used equals exactly the single account creation
    charge and the header reports that value. The created account
    is queued for destruction regardless of whether SELFDESTRUCT
    targeted itself or an external beneficiary, so the no charge
    behavior holds across both cases.
    """
    new_account_state_gas = fork.gas_costs().NEW_ACCOUNT

    if selfdestruct_beneficiary == "self":
        inner_code = Op.SELFDESTRUCT(Op.ADDRESS)
    else:
        # Alive EOA so the SELFDESTRUCT itself does not charge a
        # new account state gas for the beneficiary.
        alive_beneficiary = pre.fund_eoa(amount=1)
        inner_code = Op.SELFDESTRUCT(alive_beneficiary)
    mstore_value, size = init_code_at_high_bytes(inner_code)

    orchestrator = pre.deploy_contract(
        code=(
            Op.MSTORE(0, mstore_value)
            + (
                Op.CREATE2(1, 0, size, 0)
                if create_opcode == Op.CREATE2
                else Op.CREATE(1, 0, size)
            )
            + Op.MSTORE(0x20, Op.DUP1)
            + Op.POP
            + Op.POP(Op.CALL(gas=Op.GAS, address=Op.MLOAD(0x20), value=1))
        ),
        balance=3,
    )

    tx = Transaction(
        to=orchestrator,
        state_gas_reservoir=new_account_state_gas,
        sender=pre.fund_eoa(),
    )

    blockchain_test(
        pre=pre,
        blocks=[Block(txs=[tx])],
        post={},
    )

Parametrized Test Cases

This test generates 4 parametrized test cases across 1 fork.