Skip to content

test_create2_collision_storage()

Documentation for tests/paris/eip7610_create_collision/test_revert_in_create.py::test_create2_collision_storage@9c2813ee.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/paris/eip7610_create_collision/test_revert_in_create.py::test_create2_collision_storage --fork Amsterdam

Test that CREATE2 fails when targeting an address with pre-existing storage.

A CREATE transaction deploys a contract that executes CREATE2. The CREATE2 target address has pre-existing storage, which should cause the CREATE2 to fail per EIP-7610. The deployer stores the CREATE2 result to slot 0 (0 on failure).

Source code in tests/paris/eip7610_create_collision/test_revert_in_create.py
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
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
@pytest.mark.ported_from(
    [
        "https://github.com/ethereum/tests/tree/v13.3/src/GeneralStateTestsFiller/stCreate2/create2collisionStorageParisFiller.json",  # noqa: E501
    ],
    pr=["https://github.com/ethereum/execution-specs/pull/2031"],
)
@pytest.mark.parametrize(
    "create2_initcode",
    [
        pytest.param(b"", id="empty-initcode"),
        pytest.param(Op.SSTORE(1, 1), id="sstore-initcode"),
        pytest.param(
            Initcode(deploy_code=Op.SSTORE(1, 1)),
            id="initcode-with-deploy",
        ),
    ],
)
@pytest.mark.eels_base_coverage
def test_create2_collision_storage(
    state_test: StateTestFiller,
    pre: Alloc,
    create2_initcode: Bytecode,
) -> None:
    """
    Test that CREATE2 fails when targeting an address with pre-existing
    storage.

    A CREATE transaction deploys a contract that executes CREATE2. The CREATE2
    target address has pre-existing storage, which should cause the CREATE2 to
    fail per EIP-7610. The deployer stores the CREATE2 result to slot 0 (0 on
    failure).
    """
    deployer_code = (
        Op.MSTORE(0, Op.PUSH32(bytes(create2_initcode).ljust(32, b"\0")))
        + Op.SSTORE(
            0,
            Op.CREATE2(value=0, offset=0, size=len(create2_initcode), salt=0),
        )
        + Op.STOP
    )

    sender = pre.fund_eoa()
    tx = Transaction(
        sender=sender,
        to=None,
        data=deployer_code,
        value=1,
        gas_limit=400_000,
    )

    deployer_address = tx.created_contract

    create2_address = compute_create2_address(
        address=deployer_address,
        salt=0,
        initcode=create2_initcode,
    )

    pre[create2_address] = Account(
        balance=10,
        storage={0x00: 0x01},
    )

    state_test(
        pre=pre,
        post={
            # CREATE2 target unchanged due to collision
            create2_address: Account(
                balance=10,
                nonce=0,
                storage={0x00: 0x01},
            ),
            # Deployer: nonce=2 (1 for creation + 1 for failed CREATE2 attempt)
            # storage[0]=0 indicates CREATE2 returned 0 (failure)
            deployer_address: Account(
                balance=1,
                nonce=2,
                storage={0x00: 0x00},
            ),
        },
        tx=tx,
    )

Parametrized Test Cases

This test generates 1 parametrized test case across 6 forks.