Skip to content

test_eof_calls_precompile()

Documentation for tests/osaka/eip7692_eof_v1/eip7069_extcall/test_calls.py::test_eof_calls_precompile@14a7429a.

Generate fixtures for these test cases for Osaka with:

fill -v tests/osaka/eip7692_eof_v1/eip7069_extcall/test_calls.py::test_eof_calls_precompile --fork Osaka

Test EOF contracts calling precompiles.

Source code in tests/osaka/eip7692_eof_v1/eip7069_extcall/test_calls.py
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
@pytest.mark.parametrize(
    ["opcode", "precompile", "expected_result"],
    [
        pytest.param(Op.EXTCALL, identity, EXTCALL_SUCCESS, id="extcall_success"),
        pytest.param(Op.EXTDELEGATECALL, identity, EXTCALL_REVERT, id="extdelegatecall_blocked1"),
        pytest.param(Op.EXTSTATICCALL, identity, EXTCALL_SUCCESS, id="extstaticcall_success"),
        pytest.param(Op.EXTCALL, blake2f, EXTCALL_FAILURE, id="extcall_failure"),
        pytest.param(Op.EXTDELEGATECALL, blake2f, EXTCALL_REVERT, id="extdelegatecall_blocked2"),
        pytest.param(Op.EXTSTATICCALL, blake2f, EXTCALL_FAILURE, id="extstaticcall_failure"),
        pytest.param(Op.EXTCALL, p256verify, EXTCALL_SUCCESS, id="extcall_p256verify"),
        pytest.param(
            Op.EXTDELEGATECALL, p256verify, EXTCALL_REVERT, id="extdelegatecall_p256verify"
        ),
        pytest.param(Op.EXTSTATICCALL, p256verify, EXTCALL_SUCCESS, id="extstaticcall_p256verify"),
    ],
)
def test_eof_calls_precompile(
    state_test: StateTestFiller,
    pre: Alloc,
    sender: EOA,
    opcode: Op,
    precompile: Address,
    expected_result: int,
):
    """Test EOF contracts calling precompiles."""
    env = Environment()

    caller_contract = Container.Code(
        Op.MSTORE(0, value_returndata_magic)
        + Op.SSTORE(slot_call_result, opcode(address=precompile, args_offset=0, args_size=32))
        + Op.SSTORE(slot_returndatasize, Op.RETURNDATASIZE)
        + Op.SSTORE(slot_returndata, Op.RETURNDATALOAD(0))
        + Op.SSTORE(slot_code_worked, value_code_worked)
        + Op.STOP,
    )
    calling_contract_address = pre.deploy_contract(caller_contract)

    tx = Transaction(
        sender=sender,
        to=calling_contract_address,
        gas_limit=5000000,
    )

    success_identity = expected_result == EXTCALL_SUCCESS and precompile == identity

    calling_storage = {
        slot_code_worked: value_code_worked,
        slot_call_result: expected_result,
        slot_returndatasize: 32 if success_identity else 0,
        slot_returndata: value_returndata_magic if success_identity else 0,
    }

    post = {
        calling_contract_address: Account(storage=calling_storage),
    }

    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) opcode precompile expected_result
...fork_Osaka-state_test-extcall_success EXTCALL 0x000000000000000000000000000000 0000000004 0
...fork_Osaka-state_test-extdelegatecall_blocked1 EXTDELEGATECALL 0x000000000000000000000000000000 0000000004 1
...fork_Osaka-state_test-extstaticcall_success EXTSTATICCALL 0x000000000000000000000000000000 0000000004 0
...fork_Osaka-state_test-extcall_failure EXTCALL 0x000000000000000000000000000000 0000000009 2
...fork_Osaka-state_test-extdelegatecall_blocked2 EXTDELEGATECALL 0x000000000000000000000000000000 0000000009 1
...fork_Osaka-state_test-extstaticcall_failure EXTSTATICCALL 0x000000000000000000000000000000 0000000009 2
...fork_Osaka-state_test-extcall_p256verify EXTCALL 0x000000000000000000000000000000 0000000100 0
...fork_Osaka-state_test-extdelegatecall_p256verify EXTDELEGATECALL 0x000000000000000000000000000000 0000000100 1
...fork_Osaka-state_test-extstaticcall_p256verify EXTSTATICCALL 0x000000000000000000000000000000 0000000100 0
...fork_Osaka-blockchain_test_from_state_test-extcall_success EXTCALL 0x000000000000000000000000000000 0000000004 0
...fork_Osaka-blockchain_test_from_state_test-extdelegatecall_blocked1 EXTDELEGATECALL 0x000000000000000000000000000000 0000000004 1
...fork_Osaka-blockchain_test_from_state_test-extstaticcall_success EXTSTATICCALL 0x000000000000000000000000000000 0000000004 0
...fork_Osaka-blockchain_test_from_state_test-extcall_failure EXTCALL 0x000000000000000000000000000000 0000000009 2
...fork_Osaka-blockchain_test_from_state_test-extdelegatecall_blocked2 EXTDELEGATECALL 0x000000000000000000000000000000 0000000009 1
...fork_Osaka-blockchain_test_from_state_test-extstaticcall_failure EXTSTATICCALL 0x000000000000000000000000000000 0000000009 2
...fork_Osaka-blockchain_test_from_state_test-extcall_p256verify EXTCALL 0x000000000000000000000000000000 0000000100 0
...fork_Osaka-blockchain_test_from_state_test-extdelegatecall_p256verify EXTDELEGATECALL 0x000000000000000000000000000000 0000000100 1
...fork_Osaka-blockchain_test_from_state_test-extstaticcall_p256verify EXTSTATICCALL 0x000000000000000000000000000000 0000000100 0