Skip to content

test_factory_rejects_ef_prefix_deployment()

Documentation for tests/amsterdam/eip7997_deterministic_factory_predeploy/test_factory.py::test_factory_rejects_ef_prefix_deployment@5c024cbb.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip7997_deterministic_factory_predeploy/test_factory.py::test_factory_rejects_ef_prefix_deployment --fork Amsterdam

EIP-3541: deploying code that begins with 0xEF is rejected. The factory's CREATE2 fails when the initcode would return such code; the factory reverts and no contract is deployed.

Source code in tests/amsterdam/eip7997_deterministic_factory_predeploy/test_factory.py
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
def test_factory_rejects_ef_prefix_deployment(
    state_test: StateTestFiller,
    pre: Alloc,
) -> None:
    """
    EIP-3541: deploying code that begins with `0xEF` is rejected. The
    factory's `CREATE2` fails when the initcode would return such code;
    the factory reverts and no contract is deployed.
    """
    salt = 0x3541
    deploy_code = Bytes(b"\xef\x00")
    initcode = Initcode(deploy_code=deploy_code)
    expected_address = compute_create2_address(FACTORY, salt, initcode)

    storage = Storage()
    caller = pre.deploy_contract(
        Op.CALLDATACOPY(0, 0, Op.CALLDATASIZE)
        + Op.SSTORE(
            storage.store_next(0, "factory_call_failed"),
            Op.CALL(
                gas=Op.GAS,
                address=FACTORY,
                value=0,
                args_offset=0,
                args_size=Op.CALLDATASIZE,
            ),
        )
        + Op.STOP,
    )

    state_test(
        pre=pre,
        tx=Transaction(
            sender=pre.fund_eoa(),
            to=caller,
            data=Hash(salt) + bytes(initcode),
        ),
        post={
            caller: Account(storage=storage),
            expected_address: Account.NONEXISTENT,
        },
    )

Parametrized Test Cases

This test generates 1 parametrized test case across 1 fork.