Skip to content

test_subcall_failure_does_not_zero_top_level_state_gas()

Documentation for tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_reservoir.py::test_subcall_failure_does_not_zero_top_level_state_gas@c74f1a67.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_reservoir.py::test_subcall_failure_does_not_zero_top_level_state_gas --fork Amsterdam

Verify a subcall failure does not zero the top level execution state gas.

The top level tx succeeds end to end even though a subcall reverts, so the top level failure refund does not apply. The parent's own SSTORE contributes state gas that appears in block_state_gas_used.

Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_reservoir.py
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
@pytest.mark.valid_from("EIP8037")
def test_subcall_failure_does_not_zero_top_level_state_gas(
    blockchain_test: BlockchainTestFiller,
    pre: Alloc,
    fork: Fork,
) -> None:
    """
    Verify a subcall failure does not zero the top level execution
    state gas.

    The top level tx succeeds end to end even though a subcall
    reverts, so the top level failure refund does not apply. The
    parent's own SSTORE contributes state gas that appears in
    `block_state_gas_used`.
    """
    sstore_state_gas = Op.SSTORE(new_value=1).state_cost(fork)

    child = pre.deploy_contract(code=Op.REVERT(0, 0))
    parent_storage = Storage()
    parent = pre.deploy_contract(
        code=(
            Op.POP(Op.CALL(gas=Op.GAS, address=child))
            + Op.SSTORE(parent_storage.store_next(1, "parent_sstore"), 1)
        ),
    )

    tx = Transaction(
        to=parent,
        state_gas_reservoir=sstore_state_gas,
        sender=pre.fund_eoa(),
    )

    # Parent's SSTORE state gas dominates tx_regular and surfaces in
    # the block header, proving the top level refund is scoped to
    # top level failures and not child reverts.
    blockchain_test(
        pre=pre,
        blocks=[
            Block(
                txs=[tx],
                header_verify=Header(gas_used=sstore_state_gas),
            ),
        ],
        post={parent: Account(storage=parent_storage)},
    )

Parametrized Test Cases

This test generates 1 parametrized test case across 1 fork.