Skip to content

test_call_insufficient_balance_returns_reservoir()

Documentation for tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_call.py::test_call_insufficient_balance_returns_reservoir@636b5f17.

Generate fixtures for these test cases for Bogota with:

fill -v tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_call.py::test_call_insufficient_balance_returns_reservoir --fork Bogota

Test CALL with insufficient balance returns the reservoir to parent.

A value-bearing CALL to an existing account fails the balance check before entering the child frame; gas_left and state_gas_left are returned to the parent. A probe handed only its SSTORE's execution cost then succeeds, proving the reservoir came back rather than the gas landing in gas_left. The new-account variant (where NEW_ACCOUNT is charged then refilled on the same failure) is pinned by test_call_insufficient_balance_refunds_new_account_state_gas.

Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_call.py
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
@pytest.mark.valid_from("EIP8037")
def test_call_insufficient_balance_returns_reservoir(
    state_test: StateTestFiller,
    pre: Alloc,
    fork: Fork,
) -> None:
    """
    Test CALL with insufficient balance returns the reservoir to parent.

    A value-bearing CALL to an existing account fails the balance check
    before entering the child frame; gas_left and state_gas_left are
    returned to the parent. A probe handed only its SSTORE's execution
    cost then succeeds, proving the reservoir came back rather than the
    gas landing in `gas_left`. The new-account variant (where
    NEW_ACCOUNT is charged then refilled on the same failure) is pinned
    by test_call_insufficient_balance_refunds_new_account_state_gas.
    """
    sstore_state_gas = Op.SSTORE(new_value=1).state_cost(fork)

    target = pre.deploy_contract(code=Op.STOP)

    probe_code = Op.SSTORE(0, 1)
    probe = pre.deploy_contract(code=probe_code)
    probe_gas = probe_code.execution_cost(fork)

    storage = Storage()
    call_slot = storage.store_next(0, "call_fails")
    probe_slot = storage.store_next(1, "probe_succeeds")
    contract_code = Op.SSTORE(
        call_slot, Op.CALL(gas=0, address=target, value=1)
    ) + Op.SSTORE(
        probe_slot,
        Op.CALL(gas=probe_gas, address=probe),
        # gas accounting
        original_value=1,
        current_value=1,
        new_value=1,
        key_warm=False,
    )
    contract = pre.deploy_contract(code=contract_code, storage={probe_slot: 1})

    # The probe is handed only its execution cost, so its SSTORE lands
    # only if the failed call handed the reservoir back intact.
    tx = Transaction(
        to=contract,
        state_gas_reservoir=sstore_state_gas,
        sender=pre.fund_eoa(),
    )

    post = {
        contract: Account(storage=storage),
        probe: Account(storage={0: 1}),
    }
    state_test(pre=pre, post=post, tx=tx)

Parametrized Test Cases

This test generates 1 parametrized test case across 2 forks.