Skip to content

test_set_code_tx_below_total_intrinsic()

Documentation for tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_set_code.py::test_set_code_tx_below_total_intrinsic@622620d8.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_set_code.py::test_set_code_tx_below_total_intrinsic --fork Amsterdam

Reject a set_code tx one gas below the (now execution-only) intrinsic.

Under EIP-2780 the authorization intrinsic is entirely execution (the state-dependent costs moved to the top frame), so the intrinsic gas the transaction must cover is exactly fork.transaction_intrinsic_cost_calculator()(auth_list). Sweeping num_auths and pinning gas_limit at intrinsic - 1 catches an implementation that omits the repriced per-authorization base cost from the pre-validate check.

Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_set_code.py
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
@pytest.mark.inclusion_test
@pytest.mark.exception_test
@pytest.mark.parametrize(
    "num_auths",
    [
        pytest.param(1, id="single_auth"),
        pytest.param(2, id="two_auths"),
        pytest.param(3, id="three_auths"),
    ],
)
@pytest.mark.valid_from("EIP8037")
def test_set_code_tx_below_total_intrinsic(
    state_test: StateTestFiller,
    pre: Alloc,
    fork: Fork,
    num_auths: int,
) -> None:
    """
    Reject a set_code tx one gas below the (now execution-only) intrinsic.

    Under EIP-2780 the authorization intrinsic is entirely execution (the
    state-dependent costs moved to the top frame), so the intrinsic gas
    the transaction must cover is exactly
    ``fork.transaction_intrinsic_cost_calculator()(auth_list)``. Sweeping
    ``num_auths`` and pinning ``gas_limit`` at ``intrinsic - 1`` catches
    an implementation that omits the repriced per-authorization base cost
    from the pre-validate check.
    """
    contract = pre.deploy_contract(code=Op.STOP)
    authorization_list = [
        AuthorizationTuple(
            address=contract,
            nonce=0,
            signer=pre.fund_eoa(),
            creates_account=False,
            writes_delegation=True,
        )
        for _ in range(num_auths)
    ]

    intrinsic = fork.transaction_intrinsic_cost_calculator()(
        authorization_list_or_count=authorization_list,
    )

    tx = Transaction(
        to=contract,
        gas_limit=intrinsic - 1,
        authorization_list=authorization_list,
        sender=pre.fund_eoa(),
        error=TransactionException.INTRINSIC_GAS_TOO_LOW,
    )

    state_test(pre=pre, post={}, tx=tx)

Parametrized Test Cases

This test generates 3 parametrized test cases across 1 fork.