Skip to content

test_set_code_to_precompile_not_enough_gas_for_precompile_execution()

Documentation for tests/prague/eip7702_set_code_tx/test_set_code_txs.py::test_set_code_to_precompile_not_enough_gas_for_precompile_execution@26332146.

Generate fixtures for these test cases for Osaka with:

fill -v tests/prague/eip7702_set_code_tx/test_set_code_txs.py::test_set_code_to_precompile_not_enough_gas_for_precompile_execution --fork Osaka

Test set code to precompile and making direct call in same transaction with intrinsic gas only, no extra gas for precompile execution.

Redundant from EIP-8037: EIP-8037 replaces the one-dimensional gas model this test verifies. Auth intrinsic cost becomes (STATE_BYTES_PER_AUTH_BASE + STATE_BYTES_PER_NEW_ACCOUNT) * cost_per_state_byte per auth (state gas), plus PER_AUTH_BASE_COST (regular gas). Auth refund for existing accounts goes to state_gas_reservoir instead of refund_counter, making the discount calculation (PER_EMPTY_ACCOUNT_COST - PER_AUTH_BASE_COST) and receipt gas expectation invalid.

TODO: Add EIP-8037-specific variant in tests/amsterdam/ that verifies receipt gas and auth refund under EIP-8037's 2D model.

Source code in tests/prague/eip7702_set_code_tx/test_set_code_txs.py
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
@pytest.mark.with_all_precompiles
@pytest.mark.valid_before("EIP8037")
def test_set_code_to_precompile_not_enough_gas_for_precompile_execution(
    state_test: StateTestFiller,
    pre: Alloc,
    fork: Fork,
    precompile: int,
) -> None:
    """
    Test set code to precompile and making direct call in same transaction with
    intrinsic gas only, no extra gas for precompile execution.

    Redundant from EIP-8037: EIP-8037 replaces the one-dimensional
    gas model this test verifies. Auth intrinsic cost becomes
    (STATE_BYTES_PER_AUTH_BASE + STATE_BYTES_PER_NEW_ACCOUNT) *
    cost_per_state_byte per auth (state gas), plus
    PER_AUTH_BASE_COST (regular gas). Auth refund for existing
    accounts goes to state_gas_reservoir instead of refund_counter,
    making the discount calculation (PER_EMPTY_ACCOUNT_COST -
    PER_AUTH_BASE_COST) and receipt gas expectation invalid.

    TODO: Add EIP-8037-specific variant in tests/amsterdam/ that
    verifies receipt gas and auth refund under EIP-8037's 2D model.
    """
    auth_signer = pre.fund_eoa(amount=1)
    auth = AuthorizationTuple(
        address=Address(precompile), nonce=0, signer=auth_signer
    )

    intrinsic_gas = fork.transaction_intrinsic_cost_calculator()(
        authorization_list_or_count=[auth],
    )
    gas_costs = fork.gas_costs()
    per_auth_discount = (
        gas_costs.AUTH_PER_EMPTY_ACCOUNT
        - gas_costs.REFUND_AUTH_PER_EXISTING_ACCOUNT
    )
    discount = min(
        per_auth_discount,
        intrinsic_gas // 5,  # max discount EIP-3529
    )

    tx = Transaction(
        sender=pre.fund_eoa(),
        to=auth_signer,
        gas_limit=intrinsic_gas,
        value=1,
        authorization_list=[auth],
        # explicitly check expected gas, no precompile code executed
        expected_receipt=TransactionReceipt(
            cumulative_gas_used=intrinsic_gas - discount
        ),
    )

    state_test(
        pre=pre,
        tx=tx,
        post={
            auth_signer: Account(
                # implicitly checks no OOG, successful tx transfers ``value=1``
                balance=2,
                code=Spec.delegation_designation(Address(precompile)),
                nonce=1,
            ),
        },
    )

Parametrized Test Cases

This test generates 18 parametrized test cases across 2 forks.