Skip to content

test_create_initcode_halt_no_code_deposit_state_gas()

Documentation for tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_create.py::test_create_initcode_halt_no_code_deposit_state_gas@87aba1a3.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_create.py::test_create_initcode_halt_no_code_deposit_state_gas --fork Amsterdam

Verify initcode exceptional halt excludes code deposit state gas.

A CREATE tx runs initcode that hits INVALID (exceptional halt) before returning any code. Code deposit never happens, so code deposit state gas must NOT be charged. Only the intrinsic state gas (new account creation) should count.

Complements test_create_revert_no_code_deposit_state_gas which covers the REVERT path.

Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_create.py
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
@pytest.mark.valid_from("EIP8037")
def test_create_initcode_halt_no_code_deposit_state_gas(
    blockchain_test: BlockchainTestFiller,
    pre: Alloc,
    fork: Fork,
) -> None:
    """
    Verify initcode exceptional halt excludes code deposit state gas.

    A CREATE tx runs initcode that hits INVALID (exceptional halt)
    before returning any code. Code deposit never happens, so code
    deposit state gas must NOT be charged. Only the intrinsic state
    gas (new account creation) should count.

    Complements test_create_revert_no_code_deposit_state_gas which
    covers the REVERT path.
    """
    gas_limit_cap = fork.transaction_gas_limit_cap()
    assert gas_limit_cap is not None

    # Initcode that immediately halts, no code returned
    initcode = Op.INVALID

    # State gas = new account only (no code deposit on halt)
    intrinsic_state_gas = fork.create_state_gas(code_size=0)

    gas_limit = gas_limit_cap + intrinsic_state_gas

    tx = Transaction(
        to=None,
        data=initcode,
        state_gas_reservoir=intrinsic_state_gas,
        sender=pre.fund_eoa(),
    )

    # On exceptional halt all gas_left is consumed.
    # block_gas_used = max(block_regular, block_state)
    # block_state = intrinsic_state_gas (new account only, no deposit)
    # block_regular = gas_limit - intrinsic_state_gas (all remaining)
    tx_regular = gas_limit - intrinsic_state_gas
    tx_state = intrinsic_state_gas
    expected_gas_used = max(tx_regular, tx_state)

    blockchain_test(
        pre=pre,
        blocks=[
            Block(
                txs=[tx],
                header_verify=Header(gas_used=expected_gas_used),
            ),
        ],
        post={},
    )

Parametrized Test Cases

This test generates 1 parametrized test case across 1 fork.