Skip to content

test_create_collision_no_log()

Documentation for tests/amsterdam/eip7708_eth_transfer_logs/test_transfer_logs.py::test_create_collision_no_log@c74f1a67.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip7708_eth_transfer_logs/test_transfer_logs.py::test_create_collision_no_log --fork Amsterdam

Test that CREATE/CREATE2 collision does not emit transfer log.

When CREATE fails because target address already has code/nonce, no value transfer occurs and no log should be emitted.

Source code in tests/amsterdam/eip7708_eth_transfer_logs/test_transfer_logs.py
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
@pytest.mark.pre_alloc_mutable
@pytest.mark.with_all_create_opcodes
def test_create_collision_no_log(
    state_test: StateTestFiller,
    env: Environment,
    pre: Alloc,
    sender: EOA,
    create_opcode: Op,
) -> None:
    """
    Test that CREATE/CREATE2 collision does not emit transfer log.

    When CREATE fails because target address already has code/nonce,
    no value transfer occurs and no log should be emitted.
    """
    initcode = Op.RETURN(0, 0)
    initcode_bytes = bytes(initcode)
    initcode_len = len(initcode_bytes)

    # Deploy factory first to compute created address
    if create_opcode == Op.CREATE:
        factory_code = Op.MSTORE(
            0, Op.PUSH32(initcode_bytes.rjust(32, b"\x00"))
        ) + Op.CREATE(value=1, offset=32 - initcode_len, size=initcode_len)
    else:
        factory_code = Op.MSTORE(
            0, Op.PUSH32(initcode_bytes.rjust(32, b"\x00"))
        ) + Op.CREATE2(
            value=1, offset=32 - initcode_len, size=initcode_len, salt=0
        )

    factory = pre.deploy_contract(factory_code, balance=1)

    # Compute and pre-populate the collision address
    if create_opcode == Op.CREATE:
        collision_address = compute_create_address(address=factory, nonce=1)
    else:
        collision_address = compute_create2_address(
            address=factory, salt=0, initcode=initcode_bytes
        )

    # Pre-deploy contract at collision address to cause collision
    pre.deploy_contract(Op.STOP, address=collision_address)

    tx = Transaction(
        sender=sender,
        to=factory,
        value=0,
        expected_receipt=TransactionReceipt(
            logs=[]
        ),  # No logs - CREATE failed
    )

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

Parametrized Test Cases

This test generates 2 parametrized test cases across 1 fork.