Skip to content

test_sstore_restoration_reservoir_spillover()

Documentation for tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_sstore.py::test_sstore_restoration_reservoir_spillover@87aba1a3.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_sstore.py::test_sstore_restoration_reservoir_spillover --fork Amsterdam

Verify restoration refund when state gas spilled into gas_left.

With tx.gas at the cap, reservoir is zero. SSTORE 0 to 1 state gas comes from gas_left. At x to 0 the refund goes to state_gas_reservoir (not back to gas_left), moving gas between buckets. Block state gas is zero.

Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_sstore.py
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
@pytest.mark.valid_from("EIP8037")
def test_sstore_restoration_reservoir_spillover(
    blockchain_test: BlockchainTestFiller,
    pre: Alloc,
    fork: Fork,
) -> None:
    """
    Verify restoration refund when state gas spilled into gas_left.

    With tx.gas at the cap, reservoir is zero.  SSTORE 0 to 1 state
    gas comes from gas_left.  At x to 0 the refund goes to
    `state_gas_reservoir` (not back to gas_left), moving gas between
    buckets.  Block state gas is zero.
    """
    sstore_state_gas = Op.SSTORE(new_value=1).state_cost(fork)
    intrinsic_gas = fork.transaction_intrinsic_cost_calculator()()

    code = Op.SSTORE(0, 1) + Op.SSTORE.with_metadata(
        key_warm=True,
        original_value=0,
        current_value=1,
        new_value=0,
    )(0, 0)
    tx_regular = intrinsic_gas + code.gas_cost(fork) - sstore_state_gas

    contract = pre.deploy_contract(code=code)
    tx = Transaction(
        to=contract,
        state_gas_reservoir=0,
        sender=pre.fund_eoa(),
    )

    blockchain_test(
        pre=pre,
        blocks=[Block(txs=[tx], header_verify=Header(gas_used=tx_regular))],
        post={contract: Account(storage={0: 0})},
    )

Parametrized Test Cases

This test generates 1 parametrized test case across 1 fork.