Skip to content

test_calldata_remains_after_subcall()

Documentation for tests/osaka/eip7692_eof_v1/eip7069_extcall/test_calldata.py::test_calldata_remains_after_subcall@008e492e.

Generate fixtures for these test cases for Osaka with:

fill -v tests/osaka/eip7692_eof_v1/eip7069_extcall/test_calldata.py::test_calldata_remains_after_subcall --fork Osaka

Tests call data remains after a call to another contract.

Caller pushes data into memory, then calls the target. Target calls 3rd contract. 3rd contract returns. Target writes calldata to storage.

Source code in tests/osaka/eip7692_eof_v1/eip7069_extcall/test_calldata.py
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
@pytest.mark.parametrize(
    "opcode",
    [
        Op.CALL,
        Op.CALLCODE,
        Op.DELEGATECALL,
        Op.STATICCALL,
        Op.EXTCALL,
        Op.EXTDELEGATECALL,
        Op.EXTSTATICCALL,
    ],
)
def test_calldata_remains_after_subcall(
    state_test: StateTestFiller,
    pre: Alloc,
    opcode: Op,
):
    """
    Tests call data remains after a call to another contract.

    Caller pushes data into memory, then calls the target.  Target calls 3rd contract. 3rd contract
    returns. Target writes calldata to storage.
    """
    env = Environment()

    sender = pre.fund_eoa()

    address_sub_called = pre.deploy_contract(
        Container(
            sections=[
                Section.Code(
                    code=Op.SSTORE(slot_delegate_code_worked, value_code_worked) + Op.STOP
                )
            ]
        ),
        storage={slot_delegate_code_worked: value_exceptional_abort_canary},
    )
    called_code = (
        Op.MSTORE(0, value_calldata_2)
        + Op.SSTORE(slot_call_status, value_exceptional_abort_canary)
        + Op.SSTORE(slot_calldata_1, value_exceptional_abort_canary)
        + Op.SSTORE(slot_code_worked, value_exceptional_abort_canary)
        + Op.SSTORE(
            slot_call_status,
            opcode(
                address=address_sub_called,
                args_offset=0,
                args_size=size_calldata,
            ),
        )
        + Op.SSTORE(slot_calldata_1, Op.CALLDATALOAD(0))
        + Op.SSTORE(slot_code_worked, value_code_worked)
        + Op.STOP
    )
    match opcode:
        case Op.CALL | Op.CALLCODE | Op.DELEGATECALL | Op.STATICCALL:
            address_called = pre.deploy_contract(code=called_code)
        case Op.EXTCALL | Op.EXTDELEGATECALL | Op.EXTSTATICCALL:
            address_called = pre.deploy_contract(
                Container(
                    sections=[
                        Section.Code(code=called_code),
                    ]
                ),
            )
    address_caller = pre.deploy_contract(
        Container(
            sections=[
                Section.Code(
                    code=Op.MSTORE(0, value_calldata_1)
                    + Op.SSTORE(slot_calldata_1, value_exceptional_abort_canary)
                    + Op.SSTORE(slot_code_worked, value_exceptional_abort_canary)
                    + Op.SSTORE(
                        slot_call_status,
                        Op.EXTCALL(address_called, 0, size_calldata, 0),
                    )
                    + Op.SSTORE(slot_calldata_1, Op.RETURNDATALOAD(0))
                    + Op.SSTORE(slot_code_worked, value_code_worked)
                    + Op.STOP
                ),
            ]
        ),
        storage={slot_call_status: value_exceptional_abort_canary},
        balance=10**9,
    )

    match opcode:
        case Op.STATICCALL:
            called_storage = {
                slot_code_worked: value_code_worked,
                slot_call_status: LEGACY_CALL_FAILURE,
                slot_calldata_1: value_calldata_1,
            }
            sub_called_storage = {
                slot_delegate_code_worked: value_exceptional_abort_canary,
            }
        case Op.DELEGATECALL | Op.CALLCODE:
            called_storage = {
                slot_code_worked: value_code_worked,
                slot_delegate_code_worked: value_code_worked,
                slot_call_status: LEGACY_CALL_SUCCESS,
                slot_calldata_1: value_calldata_1,
            }
            sub_called_storage = {
                slot_delegate_code_worked: value_exceptional_abort_canary,
            }
        case Op.CALL:
            called_storage = {
                slot_code_worked: value_code_worked,
                slot_call_status: LEGACY_CALL_SUCCESS,
                slot_calldata_1: value_calldata_1,
            }
            sub_called_storage = {
                slot_delegate_code_worked: value_code_worked,
            }
        case Op.EXTSTATICCALL:
            called_storage = {
                slot_code_worked: value_code_worked,
                slot_call_status: EXTCALL_FAILURE,
                slot_calldata_1: value_calldata_1,
            }
            sub_called_storage = {
                slot_delegate_code_worked: value_exceptional_abort_canary,
            }
        case Op.EXTDELEGATECALL:
            called_storage = {
                slot_code_worked: value_code_worked,
                slot_delegate_code_worked: value_code_worked,
                slot_call_status: EXTCALL_SUCCESS,
                slot_calldata_1: value_calldata_1,
            }
            sub_called_storage = {
                slot_delegate_code_worked: value_exceptional_abort_canary,
            }
        case Op.EXTCALL:
            called_storage = {
                slot_code_worked: value_code_worked,
                slot_call_status: EXTCALL_SUCCESS,
                slot_calldata_1: value_calldata_1,
            }
            sub_called_storage = {
                slot_delegate_code_worked: value_code_worked,
            }
        case _:
            raise ValueError(f"Unexpected opcode: {opcode}")

    post = {
        address_caller: Account(storage={slot_code_worked: value_code_worked}),
        address_called: Account(storage=called_storage),
        address_sub_called: Account(storage=sub_called_storage),
    }

    tx = Transaction(to=address_caller, gas_limit=4_000_000, sender=sender)

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

Parametrized Test Cases

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

Test ID (Abbreviated) opcode
...fork_Osaka-state_test-opcode_CALL CALL
...fork_Osaka-state_test-opcode_CALLCODE CALLCODE
...fork_Osaka-state_test-opcode_DELEGATECALL DELEGATECALL
...fork_Osaka-state_test-opcode_STATICCALL STATICCALL
...fork_Osaka-state_test-opcode_EXTCALL EXTCALL
...fork_Osaka-state_test-opcode_EXTDELEGATECALL EXTDELEGATECALL
...fork_Osaka-state_test-opcode_EXTSTATICCALL EXTSTATICCALL
...fork_Osaka-blockchain_test_from_state_test-opcode_CALL CALL
...fork_Osaka-blockchain_test_from_state_test-opcode_CALLCODE CALLCODE
...fork_Osaka-blockchain_test_from_state_test-opcode_DELEGATECALL DELEGATECALL
...fork_Osaka-blockchain_test_from_state_test-opcode_STATICCALL STATICCALL
...fork_Osaka-blockchain_test_from_state_test-opcode_EXTCALL EXTCALL
...fork_Osaka-blockchain_test_from_state_test-opcode_EXTDELEGATECALL EXTDELEGATECALL
...fork_Osaka-blockchain_test_from_state_test-opcode_EXTSTATICCALL EXTSTATICCALL