Skip to content

test_call_value_to_pre_existing_selfdestructed_account()

Documentation for tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_call.py::test_call_value_to_pre_existing_selfdestructed_account@622620d8.

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

Verify CALL with value to a pre existing contract that ran SELFDESTRUCT charges no new account state gas.

Per EIP-6780 a pre existing contract that executes SELFDESTRUCT is not queued for end of the transaction destruction, so a subsequent CALL sees an existing, code carrying account and the new account creation gate does not fire.

Several cold SSTOREs after the CALLs make block state gas dominate the block execution gas component, so the block header reflects exactly num_probes * sstore_state_gas. A spurious new account charge on the value bearing CALL would push the header up by that charge, breaking the assertion.

Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_call.py
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
@pytest.mark.parametrize(
    "beneficiary_type",
    [
        pytest.param("eoa", id="eoa_beneficiary"),
        pytest.param("contract", id="contract_beneficiary"),
    ],
)
@pytest.mark.valid_from("EIP8037")
def test_call_value_to_pre_existing_selfdestructed_account(
    blockchain_test: BlockchainTestFiller,
    pre: Alloc,
    fork: Fork,
    beneficiary_type: str,
) -> None:
    """
    Verify CALL with value to a pre existing contract that ran
    SELFDESTRUCT charges no new account state gas.

    Per EIP-6780 a pre existing contract that executes SELFDESTRUCT
    is not queued for end of the transaction destruction, so a
    subsequent CALL sees an existing, code carrying account and the
    new account creation gate does not fire.

    Several cold SSTOREs after the CALLs make block state gas
    dominate the block execution gas component, so the block header
    reflects exactly `num_probes * sstore_state_gas`. A spurious
    new account charge on the value bearing CALL would push the
    header up by that charge, breaking the assertion.
    """
    sstore_state_gas = Op.SSTORE(new_value=1).state_cost(fork)

    # Enough probes that the combined probe state gas dominates the
    # transaction's execution gas component and the header reflects
    # block state gas alone.
    num_probes = 6
    probe_state_gas = num_probes * sstore_state_gas

    # Beneficiary must be alive so the target's SELFDESTRUCT itself
    # does not charge for creating a new beneficiary.
    beneficiary: Address = (
        pre.fund_eoa(amount=1)
        if beneficiary_type == "eoa"
        else pre.deploy_contract(code=Op.STOP)
    )
    target = pre.deploy_contract(
        code=Op.SELFDESTRUCT(beneficiary),
        balance=1,
    )

    probe_storage = Storage()
    probe_code = Bytecode()
    for _ in range(num_probes):
        probe_code += Op.SSTORE(probe_storage.store_next(1), 1)

    probe = pre.deploy_contract(code=probe_code)
    probe_gas = probe_code.execution_cost(fork)

    orchestrator = pre.deploy_contract(
        code=(
            Op.POP(Op.CALL(gas=Op.GAS, address=target))
            + Op.POP(Op.CALL(gas=Op.GAS, address=target, value=1))
            + Op.POP(Op.CALL(gas=probe_gas, address=probe))
        ),
        balance=3,
    )

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

    blockchain_test(
        pre=pre,
        blocks=[
            Block(
                txs=[tx],
                header_verify=Header(gas_used=probe_state_gas),
            ),
        ],
        post={probe: Account(storage=probe_storage)},
    )

Parametrized Test Cases

This test generates 2 parametrized test cases across 1 fork.