Skip to content

test_initcode_selfdestruct_state_gas_in_header()

Documentation for tests/amsterdam/eip2780_reduce_intrinsic_tx_gas/test_top_frame_charges.py::test_initcode_selfdestruct_state_gas_in_header@26332146.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip2780_reduce_intrinsic_tx_gas/test_top_frame_charges.py::test_initcode_selfdestruct_state_gas_in_header --fork Amsterdam

The top-frame NEW_ACCOUNT surviving an init-code SELFDESTRUCT stays in the state dimension after settlement.

Receipts and balances only observe the sum of the two gas dimensions, so the sibling test_initcode_selfdestruct_keeps_top_frame_state_charge cannot distinguish which dimension the surviving charge settled into. The block header can: gas_used = max(block_execution, block_state), and with a zero endowment and a self beneficiary the whole created account vanishes while the state side (one NEW_ACCOUNT, dominating the small execution side) must still show in the header.

Bug signatures: a refill regression collapses the header to the small execution sum; an execution-gas mis-classification raises it to execution + NEW_ACCOUNT.

Source code in tests/amsterdam/eip2780_reduce_intrinsic_tx_gas/test_top_frame_charges.py
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
def test_initcode_selfdestruct_state_gas_in_header(
    fork: Fork,
    pre: Alloc,
    blockchain_test: BlockchainTestFiller,
) -> None:
    """
    The top-frame ``NEW_ACCOUNT`` surviving an init-code
    ``SELFDESTRUCT`` stays in the *state* dimension after settlement.

    Receipts and balances only observe the sum of the two gas
    dimensions, so the sibling
    ``test_initcode_selfdestruct_keeps_top_frame_state_charge`` cannot
    distinguish which dimension the surviving charge settled into. The
    block header can: ``gas_used = max(block_execution, block_state)``,
    and with a zero endowment and a self beneficiary the whole created
    account vanishes while the state side (one ``NEW_ACCOUNT``,
    dominating the small execution side) must still show in the header.

    Bug signatures: a refill regression collapses the header to the
    small execution sum; an execution-gas mis-classification raises it to
    ``execution + NEW_ACCOUNT``.
    """
    sender = pre.fund_eoa()
    created = compute_create_address(address=sender, nonce=sender.nonce)

    init_code = Op.SELFDESTRUCT.with_metadata(
        address_warm=True, account_new=False
    )(Op.ADDRESS)
    evm_execution = init_code.execution_cost(fork)

    intrinsic_gas = fork.transaction_intrinsic_cost_calculator()(
        calldata=init_code,
        contract_creation=True,
        return_cost_deducted_prior_execution=True,
    )
    state_side = fork.transaction_top_frame_state_gas(
        contract_creation=True,
    )
    calldata_floor = fork.transaction_data_floor_cost_calculator()(
        data=init_code,
        contract_creation=True,
    )
    # Block accounting carries the calldata floor in the execution
    # dimension.
    execution_side = max(intrinsic_gas + evm_execution, calldata_floor)
    assert state_side > execution_side, (
        "the state dimension must dominate for the header to pin it"
    )

    total_gas = intrinsic_gas + state_side + evm_execution
    tx = Transaction(
        sender=sender,
        to=None,
        data=init_code,
        gas_limit=total_gas,
        expected_receipt=TransactionReceipt(cumulative_gas_used=total_gas),
    )

    blockchain_test(
        pre=pre,
        blocks=[
            Block(
                txs=[tx],
                header_verify=Header(gas_used=state_side),
            ),
        ],
        post={
            sender: Account(nonce=1),
            created: None,
        },
    )

Parametrized Test Cases

This test generates 1 parametrized test case across 1 fork.