Skip to content

test_insufficient_initcode_gas()

Documentation for tests/prague/eip7692_eof_v1/eip7620_eof_create/test_eofcreate_failures.py::test_insufficient_initcode_gas@verkle@v0.0.6.

Generate fixtures for these test cases for Pragueeip7692 with:

Pragueeip7692 only:

fill -v tests/prague/eip7692_eof_v1/eip7620_eof_create/test_eofcreate_failures.py::test_insufficient_initcode_gas --fork=PragueEIP7692 --evm-bin=/path/to/evm-tool-dev-version

For all forks up to and including Pragueeip7692:

fill -v tests/prague/eip7692_eof_v1/eip7620_eof_create/test_eofcreate_failures.py::test_insufficient_initcode_gas --until=PragueEIP7692

Excercises an EOFCREATE when there is not enough gas for the initcode charge

Source code in tests/prague/eip7692_eof_v1/eip7620_eof_create/test_eofcreate_failures.py
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
def test_insufficient_initcode_gas(
    state_test: StateTestFiller,
    pre: Alloc,
):
    """
    Excercises an EOFCREATE when there is not enough gas for the initcode charge
    """
    env = Environment()

    initcode_data = b"a" * 0x5000
    initcode_container = Container(
        name="Large Initcode Subcontainer",
        sections=[
            Section.Code(
                code=Op.RETURNCONTRACT[0](0, 0),
            ),
            Section.Container(container=smallest_runtime_subcontainer),
            Section.Data(data=initcode_data),
        ],
    )

    sender = pre.fund_eoa()
    contract_address = pre.deploy_contract(
        code=Container(
            sections=[
                Section.Code(
                    code=Op.SSTORE(slot_create_address, Op.EOFCREATE[0](0, 0, 0, 0))
                    + Op.SSTORE(slot_code_should_fail, value_code_worked)
                    + Op.STOP,
                ),
                Section.Container(container=initcode_container),
            ],
        ),
        storage={
            slot_create_address: value_canary_should_not_change,
            slot_code_should_fail: value_canary_should_not_change,
        },
    )
    # enough gas for everything but EVM opcodes and EIP-150 reserves
    gas_limit = 21_000 + 32_000 + (len(initcode_data) + 31) // 32 * 6
    # out_of_gas is triggered, so canary won't set value
    # also validate target created contract fails
    post = {
        contract_address: Account(
            storage={
                slot_create_address: value_canary_should_not_change,
                slot_code_should_fail: value_canary_should_not_change,
            },
        ),
        compute_eofcreate_address(contract_address, 0, initcode_container): Account.NONEXISTENT,
    }
    tx = Transaction(
        to=contract_address,
        gas_limit=gas_limit,
        gas_price=10,
        protected=False,
        sender=sender,
    )

    state_test(env=env, pre=pre, post=post, tx=tx)