Skip to content

test_call_value_to_self_destructed_burns_value()

Documentation for tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_call.py::test_call_value_to_self_destructed_burns_value@2119b382.

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_burns_value --fork Amsterdam

Verify value transferred to a same transaction selfdestructed account is burned when end of the transaction destruction runs.

The orchestrator funds the inner contract via CREATE, the initcode immediately selfdestructs, and then the orchestrator transfers more value into the now queued for destruction address. At the end of the transaction the account is removed and the accumulated balance is lost.

Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_call.py
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
@pytest.mark.parametrize(
    "call_value",
    [
        pytest.param(1, id="one_wei"),
        pytest.param(10**18, id="one_ether"),
    ],
)
@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_burns_value(
    blockchain_test: BlockchainTestFiller,
    pre: Alloc,
    fork: Fork,
    create_opcode: Op,
    call_value: int,
) -> None:
    """
    Verify value transferred to a same transaction selfdestructed
    account is burned when end of the transaction destruction runs.

    The orchestrator funds the inner contract via CREATE, the
    initcode immediately selfdestructs, and then the orchestrator
    transfers more value into the now queued for destruction
    address. At the end of the transaction the account is removed
    and the accumulated balance is lost.
    """
    new_account_state_gas = fork.gas_costs().NEW_ACCOUNT

    inner_code = Op.SELFDESTRUCT(Op.ADDRESS)
    mstore_value, size = init_code_at_high_bytes(inner_code)

    initial_balance = 2 * call_value
    orchestrator = pre.deploy_contract(
        code=(
            Op.MSTORE(0, mstore_value)
            + (
                Op.CREATE2(call_value, 0, size, 0)
                if create_opcode == Op.CREATE2
                else Op.CREATE(call_value, 0, size)
            )
            + Op.MSTORE(0x20, Op.DUP1)
            + Op.POP
            + Op.POP(
                Op.CALL(
                    gas=Op.GAS,
                    address=Op.MLOAD(0x20),
                    value=call_value,
                )
            )
        ),
        balance=initial_balance,
    )
    created_address = compute_create_address(
        address=orchestrator,
        nonce=1,
        salt=0,
        initcode=bytes(inner_code),
        opcode=create_opcode,
    )

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

    created_address_account = Account.NONEXISTENT
    if fork.is_eip_enabled(8246):
        created_address_account = Account(balance=call_value * 2)

    blockchain_test(
        pre=pre,
        blocks=[Block(txs=[tx])],
        post={
            created_address: created_address_account,
            orchestrator: Account(balance=0),
        },
    )

Parametrized Test Cases

This test generates 4 parametrized test cases across 1 fork.