Skip to content

test_factory_via_eip7702_delegation()

Documentation for tests/amsterdam/eip7997_deterministic_factory_predeploy/test_factory.py::test_factory_via_eip7702_delegation@a9abd46e.

Generate fixtures for these test cases for Amsterdam with:

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

An EOA delegates its code to the factory via an EIP-7702 authorization. When the EOA is then called with salt || initcode, the factory bytecode runs in the EOA's context, so CREATE2 treats the EOA as the deployer. The deterministic address therefore derives from the EOA, not from the factory.

Source code in tests/amsterdam/eip7997_deterministic_factory_predeploy/test_factory.py
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
def test_factory_via_eip7702_delegation(
    state_test: StateTestFiller,
    pre: Alloc,
) -> None:
    """
    An EOA delegates its code to the factory via an EIP-7702
    authorization. When the EOA is then called with `salt || initcode`,
    the factory bytecode runs in the EOA's context, so `CREATE2` treats
    the EOA as the deployer. The deterministic address therefore
    derives from the EOA, not from the factory.
    """
    auth_signer = pre.fund_eoa()
    auth_signer_nonce = auth_signer.nonce

    salt = 0x42
    runtime_code = Op.PUSH1(0x01) + Op.PUSH1(0x00) + Op.RETURN
    initcode = Initcode(deploy_code=runtime_code)
    expected_address = compute_create2_address(auth_signer, salt, initcode)

    caller = pre.deploy_contract(
        Op.CALLDATACOPY(0, 0, Op.CALLDATASIZE)
        + Op.POP(
            Op.CALL(
                gas=Op.GAS,
                address=auth_signer,
                value=0,
                args_offset=0,
                args_size=Op.CALLDATASIZE,
                ret_offset=0x100,
                ret_size=20,
            ),
        )
        + Op.STOP,
    )

    state_test(
        pre=pre,
        tx=Transaction(
            sender=pre.fund_eoa(),
            to=caller,
            data=Hash(salt) + bytes(initcode),
            authorization_list=[
                AuthorizationTuple(
                    address=Address(FACTORY),
                    nonce=auth_signer_nonce,
                    signer=auth_signer,
                ),
            ],
        ),
        post={
            auth_signer: Account(
                nonce=auth_signer_nonce + 2,
                code=Spec7702.delegation_designation(Address(FACTORY)),
            ),
            expected_address: Account(nonce=1, code=bytes(runtime_code)),
            FACTORY: Account(
                nonce=1,
                balance=0,
                code=Spec.FACTORY_BYTECODE,
            ),
        },
    )

Parametrized Test Cases

This test generates 1 parametrized test case across 1 fork.