Skip to content

test_init_collision_create_opcode()

Documentation for tests/paris/eip7610_create_collision/test_initcollision.py::test_init_collision_create_opcode@b314d18e.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/paris/eip7610_create_collision/test_initcollision.py::test_init_collision_create_opcode --fork Amsterdam

Test that a contract creation opcode exceptionally aborts when the target address has a non-empty storage, balance, nonce, or code.

Source code in tests/paris/eip7610_create_collision/test_initcollision.py
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
@pytest.mark.parametrize("opcode", [Op.CREATE, Op.CREATE2])
def test_init_collision_create_opcode(
    state_test: StateTestFiller,
    pre: Alloc,
    opcode: Op,
    collision_nonce: int,
    collision_balance: int,
    collision_code: bytes,
    initcode: Bytecode,
) -> None:
    """
    Test that a contract creation opcode exceptionally aborts when the target
    address has a non-empty storage, balance, nonce, or code.
    """
    assert len(initcode) <= 32
    contract_creator_code = (
        Op.MSTORE(0, Op.PUSH32(bytes(initcode).ljust(32, b"\0")))
        + Op.SSTORE(0x01, opcode(value=0, offset=0, size=len(initcode)))
        + Op.STOP
    )
    contract_creator_address = pre.deploy_contract(
        contract_creator_code,
        storage={0x01: 0x01},
    )
    created_contract_address = compute_create_address(
        address=contract_creator_address,
        nonce=1,
        salt=0,
        initcode=initcode,
        opcode=opcode,
    )

    tx = Transaction(
        sender=pre.fund_eoa(),
        to=contract_creator_address,
        data=initcode,
    )

    pre[created_contract_address] = Account(
        storage={0x01: 0x01},
        nonce=collision_nonce,
        balance=collision_balance,
        code=collision_code,
    )

    state_test(
        pre=pre,
        post={
            created_contract_address: Account(
                storage={0x01: 0x01},
            ),
            contract_creator_address: Account(storage={0x01: 0x00}),
        },
        tx=tx,
    )

Parametrized Test Cases

This test generates 6 parametrized test cases across 6 forks.