Skip to content

test_eof_calls_precompile()

Documentation for tests/osaka/eip7692_eof_v1/eip7069_extcall/test_calls.py::test_eof_calls_precompile@21fb11c8.

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
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
@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=Address(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