Skip to content

test_returncontract_memory_expansion()

Documentation for tests/osaka/eip7692_eof_v1/eip7620_eof_create/test_returncontract.py::test_returncontract_memory_expansion@21fb11c8.

Generate fixtures for these test cases for Osaka with:

fill -v tests/osaka/eip7692_eof_v1/eip7620_eof_create/test_returncontract.py::test_returncontract_memory_expansion --fork Osaka

Attempts an EOFCREATE with a possibly too-large auxdata. Create either fails due to gas or contract too large, resulting in address or zero on failure in the create address slot.

The name id of *-mem-cost refers to the bit-length of the result of the calculated memory expansion cost. Their length choice is designed to cause problems on shorter bit-length representations with native integers.

The offset_field param indicates what part of the input data arguments are being tested, either the offset of the data in memory or the size of the data in memory.

The test_arg param is the value passed into the field being tested (offset or size), intending to trigger integer size bugs for that particular field.

Source code in tests/osaka/eip7692_eof_v1/eip7620_eof_create/test_returncontract.py
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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
@pytest.mark.parametrize(
    "offset_field",
    [
        pytest.param(True, id="offset"),
        pytest.param(False, id="size"),
    ],
)
@pytest.mark.parametrize(
    ("test_arg", "success"),
    [
        pytest.param(0, True, id="zero"),
        pytest.param(0xFF, True, id="8-bit"),
        pytest.param(0x100, True, id="9-bit"),
        pytest.param(0xFFFF, True, id="16-bit"),
        pytest.param(0x10000, True, id="17-bit"),
        pytest.param(0x1FFFF20, False, id="32-bit-mem-cost"),
        pytest.param(0x2D412E0, False, id="33-bit-mem-cost"),
        pytest.param(0xFFFFFFFF, False, id="32-bit"),
        pytest.param(0x100000000, False, id="33-bit"),
        pytest.param(0x1FFFFFFFF20, False, id="64-bit-mem-cost"),
        pytest.param(0x2D413CCCF00, False, id="65-bit-mem-cost"),
        pytest.param(0xFFFFFFFFFFFFFFFF, False, id="64-bit"),
        pytest.param(0x10000000000000000, False, id="65-bit"),
        pytest.param(0xFFFFFFFFFFFFFFFF, False, id="128-bit"),
        pytest.param(0x10000000000000000, False, id="129-bit"),
        pytest.param(0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF, False, id="256-bit"),
    ],
)
def test_returncontract_memory_expansion(
    state_test: StateTestFiller,
    pre: Alloc,
    offset_field: str,
    test_arg: int,
    success: bool,
):
    """
    Attempts an EOFCREATE with a possibly too-large auxdata.  Create either fails due to gas
    or contract too large, resulting in address or zero on failure in the create address slot.

    The name id of `*-mem-cost` refers to the bit-length of the result of the calculated memory
    expansion cost. Their length choice is designed to cause problems on shorter bit-length
    representations with native integers.

    The `offset_field` param indicates what part of the input data arguments are being tested,
    either the offset of the data in memory or the size of the data in memory.

    The `test_arg` param is the value passed into the field being tested (offset or size),
    intending to trigger integer size bugs for that particular field.
    """
    env = Environment()
    sender = pre.fund_eoa(10**27)

    eof_size_acceptable = offset_field or test_arg < MAX_BYTECODE_SIZE

    mem_size_initcode_container = Container(
        sections=[
            Section.Code(
                code=Op.RETURNCONTRACT[0](
                    auxdata_offset=test_arg if offset_field else 32,
                    auxdata_size=32 if offset_field else test_arg,
                )
            ),
            Section.Container(container=smallest_runtime_subcontainer),
        ],
    )
    contract_address = pre.deploy_contract(
        code=Container(
            sections=[
                Section.Code(
                    code=Op.SSTORE(slot_create_address, Op.EOFCREATE[0](0, 0, 0, 0)) + Op.STOP,
                ),
                Section.Container(container=mem_size_initcode_container),
            ],
        ),
        storage={
            slot_create_address: value_canary_to_be_overwritten,
        },
    )
    # Storage in 0 should have the address,
    post = {
        contract_address: Account(
            storage={
                slot_create_address: compute_eofcreate_address(
                    contract_address, 0, mem_size_initcode_container
                )
                if success and eof_size_acceptable
                else 0,
            }
        )
    }
    tx = Transaction(
        to=contract_address,
        gas_limit=2_000_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) test_arg success offset_field
...fork_Osaka-state_test-zero-offset 0 True True
...fork_Osaka-state_test-zero-size 0 True False
...fork_Osaka-state_test-8-bit-offset 255 True True
...fork_Osaka-state_test-8-bit-size 255 True False
...fork_Osaka-state_test-9-bit-offset 256 True True
...fork_Osaka-state_test-9-bit-size 256 True False
...fork_Osaka-state_test-16-bit-offset 65535 True True
...fork_Osaka-state_test-16-bit-size 65535 True False
...fork_Osaka-state_test-17-bit-offset 65536 True True
...fork_Osaka-state_test-17-bit-size 65536 True False
...fork_Osaka-state_test-32-bit-mem-cost-offset 33554208 False True
...fork_Osaka-state_test-32-bit-mem-cost-size 33554208 False False
...fork_Osaka-state_test-33-bit-mem-cost-offset 47452896 False True
...fork_Osaka-state_test-33-bit-mem-cost-size 47452896 False False
...fork_Osaka-state_test-32-bit-offset 4294967295 False True
...fork_Osaka-state_test-32-bit-size 4294967295 False False
...fork_Osaka-state_test-33-bit-offset 4294967296 False True
...fork_Osaka-state_test-33-bit-size 4294967296 False False
...fork_Osaka-state_test-64-bit-mem-cost-offset 2199023255328 False True
...fork_Osaka-state_test-64-bit-mem-cost-size 2199023255328 False False
...fork_Osaka-state_test-65-bit-mem-cost-offset 3109888511744 False True
...fork_Osaka-state_test-65-bit-mem-cost-size 3109888511744 False False
...fork_Osaka-state_test-64-bit-offset 18446744073709551615 False True
...fork_Osaka-state_test-64-bit-size 18446744073709551615 False False
...fork_Osaka-state_test-65-bit-offset 18446744073709551616 False True
...fork_Osaka-state_test-65-bit-size 18446744073709551616 False False
...fork_Osaka-state_test-128-bit-offset 18446744073709551615 False True
...fork_Osaka-state_test-128-bit-size 18446744073709551615 False False
...fork_Osaka-state_test-129-bit-offset 18446744073709551616 False True
...fork_Osaka-state_test-129-bit-size 18446744073709551616 False False
...fork_Osaka-state_test-256-bit-offset 340282366920938463463374607431768211455 False True
...fork_Osaka-state_test-256-bit-size 340282366920938463463374607431768211455 False False
...fork_Osaka-blockchain_test_from_state_test-zero-offset 0 True True
...fork_Osaka-blockchain_test_from_state_test-zero-size 0 True False
...fork_Osaka-blockchain_test_from_state_test-8-bit-offset 255 True True
...fork_Osaka-blockchain_test_from_state_test-8-bit-size 255 True False
...fork_Osaka-blockchain_test_from_state_test-9-bit-offset 256 True True
...fork_Osaka-blockchain_test_from_state_test-9-bit-size 256 True False
...fork_Osaka-blockchain_test_from_state_test-16-bit-offset 65535 True True
...fork_Osaka-blockchain_test_from_state_test-16-bit-size 65535 True False
...fork_Osaka-blockchain_test_from_state_test-17-bit-offset 65536 True True
...fork_Osaka-blockchain_test_from_state_test-17-bit-size 65536 True False
...fork_Osaka-blockchain_test_from_state_test-32-bit-mem-cost-offset 33554208 False True
...fork_Osaka-blockchain_test_from_state_test-32-bit-mem-cost-size 33554208 False False
...fork_Osaka-blockchain_test_from_state_test-33-bit-mem-cost-offset 47452896 False True
...fork_Osaka-blockchain_test_from_state_test-33-bit-mem-cost-size 47452896 False False
...fork_Osaka-blockchain_test_from_state_test-32-bit-offset 4294967295 False True
...fork_Osaka-blockchain_test_from_state_test-32-bit-size 4294967295 False False
...fork_Osaka-blockchain_test_from_state_test-33-bit-offset 4294967296 False True
...fork_Osaka-blockchain_test_from_state_test-33-bit-size 4294967296 False False
...fork_Osaka-blockchain_test_from_state_test-64-bit-mem-cost-offset 2199023255328 False True
...fork_Osaka-blockchain_test_from_state_test-64-bit-mem-cost-size 2199023255328 False False
...fork_Osaka-blockchain_test_from_state_test-65-bit-mem-cost-offset 3109888511744 False True
...fork_Osaka-blockchain_test_from_state_test-65-bit-mem-cost-size 3109888511744 False False
...fork_Osaka-blockchain_test_from_state_test-64-bit-offset 18446744073709551615 False True
...fork_Osaka-blockchain_test_from_state_test-64-bit-size 18446744073709551615 False False
...fork_Osaka-blockchain_test_from_state_test-65-bit-offset 18446744073709551616 False True
...fork_Osaka-blockchain_test_from_state_test-65-bit-size 18446744073709551616 False False
...fork_Osaka-blockchain_test_from_state_test-128-bit-offset 18446744073709551615 False True
...fork_Osaka-blockchain_test_from_state_test-128-bit-size 18446744073709551615 False False
...fork_Osaka-blockchain_test_from_state_test-129-bit-offset 18446744073709551616 False True
...fork_Osaka-blockchain_test_from_state_test-129-bit-size 18446744073709551616 False False
...fork_Osaka-blockchain_test_from_state_test-256-bit-offset 340282366920938463463374607431768211455 False True
...fork_Osaka-blockchain_test_from_state_test-256-bit-size 340282366920938463463374607431768211455 False False