Skip to content

test_call_large_offset_mstore()

Documentation for tests/frontier/opcodes/test_call.py::test_call_large_offset_mstore@e9958ed2.

Generate fixtures for these test cases for Osaka with:

fill -v tests/frontier/opcodes/test_call.py::test_call_large_offset_mstore --fork Osaka

CALL with ret_offset larger than memory size and ret_size zero Then do an MSTORE in that offset to see if memory was expanded in CALL.

This is for bug in a faulty EVM implementation where memory is expanded when it shouldn't.

Source code in tests/frontier/opcodes/test_call.py
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
@pytest.mark.valid_from("Berlin")
def test_call_large_offset_mstore(
    state_test: StateTestFiller,
    pre: Alloc,
    fork: Fork,
) -> None:
    """
    CALL with ret_offset larger than memory size and ret_size zero Then do an
    MSTORE in that offset to see if memory was expanded in CALL.

    This is for bug in a faulty EVM implementation where memory is expanded
    when it shouldn't.
    """
    sender = pre.fund_eoa()

    gsc = fork.gas_costs()
    mem_offset = 128  # arbitrary number

    call_measure = CodeGasMeasure(
        code=Op.CALL(gas=0, ret_offset=mem_offset, ret_size=0),
        # Cost of pushing CALL args
        overhead_cost=gsc.G_VERY_LOW * len(Op.CALL.kwargs),
        extra_stack_items=1,  # Because CALL pushes 1 item to the stack
        sstore_key=0,
        stop=False,  # Because it's the first CodeGasMeasure
    )
    mstore_measure = CodeGasMeasure(
        code=Op.MSTORE(offset=mem_offset, value=1),
        # Cost of pushing MSTORE args
        overhead_cost=gsc.G_VERY_LOW * len(Op.MSTORE.kwargs),
        extra_stack_items=0,
        sstore_key=1,
    )

    contract = pre.deploy_contract(call_measure + mstore_measure)

    tx = Transaction(
        gas_limit=500_000,
        to=contract,
        value=0,
        sender=sender,
    )

    # this call cost is just the address_access_cost
    call_cost = gsc.G_COLD_ACCOUNT_ACCESS

    memory_expansion_gas_calc = fork.memory_expansion_gas_calculator()
    # mstore cost: base cost + expansion cost
    mstore_cost = gsc.G_MEMORY + memory_expansion_gas_calc(new_bytes=mem_offset + 1)
    state_test(
        env=Environment(),
        pre=pre,
        tx=tx,
        post={
            contract: Account(
                storage={
                    0: call_cost,
                    1: mstore_cost,
                },
            )
        },
    )

Parametrized Test Cases

This test case is only parametrized by fork and fixture format.

Test ID (Abbreviated)
...fork_Berlin-state_test
...fork_Berlin-blockchain_test_from_state_test
...fork_London-state_test
...fork_London-blockchain_test_from_state_test
...fork_Paris-state_test
...fork_Paris-blockchain_test_from_state_test
...fork_Shanghai-state_test
...fork_Shanghai-blockchain_test_from_state_test
...fork_Cancun-state_test
...fork_Cancun-blockchain_test_from_state_test
...fork_Prague-state_test
...fork_Prague-blockchain_test_from_state_test
...fork_Osaka-state_test
...fork_Osaka-blockchain_test_from_state_test