Skip to content

test_call_zero_value_to_self_destructed_same_tx_account()

Documentation for tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_call.py::test_call_zero_value_to_self_destructed_same_tx_account@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_zero_value_to_self_destructed_same_tx_account --fork Amsterdam

Verify CALL with zero value to a same transaction selfdestructed account charges no new account state gas.

Value transfer gates the new account creation charge. Under the correct spec the block header reflects only the CREATE's single new account state gas charge. A spurious charge on the zero value CALL (value gate broken) would double the state gas component.

Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_call.py
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
@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_zero_value_to_self_destructed_same_tx_account(
    blockchain_test: BlockchainTestFiller,
    pre: Alloc,
    fork: Fork,
    create_opcode: Op,
) -> None:
    """
    Verify CALL with zero value to a same transaction selfdestructed
    account charges no new account state gas.

    Value transfer gates the new account creation charge. Under the
    correct spec the block header reflects only the CREATE's single
    new account state gas charge. A spurious charge on the zero
    value CALL (value gate broken) would double the state gas
    component.
    """
    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)

    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=0))
        ),
        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 2 parametrized test cases across 1 fork.