Skip to content

test_eofcreate_deploy_sizes()

Documentation for tests/osaka/eip7692_eof_v1/eip7620_eof_create/test_eofcreate_failures.py::test_eofcreate_deploy_sizes@49a16fac.

Generate fixtures for these test cases for Osaka with:

fill -v tests/osaka/eip7692_eof_v1/eip7620_eof_create/test_eofcreate_failures.py::test_eofcreate_deploy_sizes --fork Osaka

Verifies a mix of runtime contract sizes mixing success and multiple size failure modes.

Source code in tests/osaka/eip7692_eof_v1/eip7620_eof_create/test_eofcreate_failures.py
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
@pytest.mark.parametrize(
    "target_deploy_size",
    [
        pytest.param(0x4000, id="large"),
        pytest.param(MAX_BYTECODE_SIZE, id="max"),
        pytest.param(MAX_BYTECODE_SIZE + 1, id="overmax"),
        pytest.param(MAX_INITCODE_SIZE - factory_size, id="initcodemax"),
        pytest.param(
            MAX_INITCODE_SIZE - factory_size + 1,
            id="initcodeovermax",
            marks=pytest.mark.skip("Oversized container in pre-alloc"),
        ),
        pytest.param(
            0xFFFF - factory_size,
            id="64k-1",
            marks=pytest.mark.skip("Oversized container in pre-alloc"),
        ),
    ],
)
def test_eofcreate_deploy_sizes(
    state_test: StateTestFiller,
    pre: Alloc,
    target_deploy_size: int,
):
    """Verifies a mix of runtime contract sizes mixing success and multiple size failure modes."""
    env = Environment()

    runtime_container = Container(
        sections=[
            Section.Code(
                code=Op.JUMPDEST * (target_deploy_size - len(smallest_runtime_subcontainer))
                + Op.STOP,
            ),
        ]
    )

    initcode_subcontainer = Container(
        name="Initcode Subcontainer",
        sections=[
            Section.Code(
                code=Op.RETURNCONTRACT[0](0, 0),
            ),
            Section.Container(container=runtime_container),
        ],
    )

    factory_container = Container(
        sections=[
            Section.Code(
                code=Op.SSTORE(slot_create_address, Op.EOFCREATE[0](0, 0, 0, 0))
                + Op.SSTORE(slot_code_worked, value_code_worked)
                + Op.STOP,
            ),
            Section.Container(container=initcode_subcontainer),
        ]
    )

    assert factory_size == (len(factory_container) - len(runtime_container)), (
        "factory_size is wrong, expected factory_size is %d, calculated is %d"
        % (
            factory_size,
            len(factory_container),
        )
    )

    sender = pre.fund_eoa()
    contract_address = pre.deploy_contract(code=factory_container)
    # Storage in 0 should have the address,
    # Storage 1 is a canary of 1 to make sure it tried to execute, which also covers cases of
    #   data+code being greater than initcode_size_max, which is allowed.
    post = {
        contract_address: Account(
            storage={
                slot_create_address: compute_eofcreate_address(
                    contract_address, 0, initcode_subcontainer
                )
                if target_deploy_size <= MAX_BYTECODE_SIZE
                else EOFCREATE_FAILURE,
                slot_code_worked: value_code_worked,
            }
        )
    }
    tx = Transaction(
        to=contract_address,
        gas_limit=10_000_000,
        gas_price=10,
        protected=False,
        sender=sender,
    )

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

Parametrized Test Cases

The interactive table below is also available as a standalone page.

Test ID (Abbreviated) target_deploy_size
...fork_Osaka-blockchain_test-large 16384
...fork_Osaka-blockchain_test-max 24576
...fork_Osaka-blockchain_test-overmax 24577
...fork_Osaka-blockchain_test-initcodemax 49078
...fork_Osaka-blockchain_test-initcodeovermax 49079
...fork_Osaka-blockchain_test-64k-1 65461
...fork_Osaka-state_test-large 16384
...fork_Osaka-state_test-max 24576
...fork_Osaka-state_test-overmax 24577
...fork_Osaka-state_test-initcodemax 49078
...fork_Osaka-state_test-initcodeovermax 49079
...fork_Osaka-state_test-64k-1 65461