Skip to content

test_sstore_restoration_create_init_success()

Documentation for tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_sstore.py::test_sstore_restoration_create_init_success@c74f1a67.

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_create_init_success --fork Amsterdam

Verify 0 to x to 0 reservoir refund applies across CREATE init.

Init code writes and clears slot 0, then returns empty runtime. The CREATE succeeds (returns a nonzero address), confirming the restoration path works inside init and the refund doesn't disturb deployment.

Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_sstore.py
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
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
@pytest.mark.with_all_create_opcodes
@pytest.mark.valid_from("EIP8037")
def test_sstore_restoration_create_init_success(
    state_test: StateTestFiller,
    pre: Alloc,
    fork: Fork,
    create_opcode: Op,
) -> None:
    """
    Verify 0 to x to 0 reservoir refund applies across CREATE init.

    Init code writes and clears slot 0, then returns empty runtime.
    The CREATE succeeds (returns a nonzero address), confirming the
    restoration path works inside init and the refund doesn't disturb
    deployment.
    """
    sstore_state_gas = Op.SSTORE(new_value=1).state_cost(fork)
    create_state_gas = fork.create_state_gas(code_size=0)

    init_code = (
        Op.SSTORE(0, 1)
        + Op.SSTORE.with_metadata(
            key_warm=True,
            original_value=0,
            current_value=1,
            new_value=0,
        )(0, 0)
        + Op.RETURN(0, 0)
    )

    if create_opcode == Op.CREATE:
        create_call = Op.CREATE(0, 0, len(init_code))
    else:
        create_call = Op.CREATE2(0, 0, len(init_code), 0)

    caller_storage = Storage()
    caller = pre.deploy_contract(
        code=(
            Op.MSTORE(
                0,
                int.from_bytes(bytes(init_code), "big")
                << (256 - 8 * len(init_code)),
            )
            + Op.SSTORE(
                caller_storage.store_next(True, "create_succeeded"),
                Op.GT(create_call, 0),
            )
        ),
    )

    tx = Transaction(
        to=caller,
        state_gas_reservoir=create_state_gas + sstore_state_gas,
        sender=pre.fund_eoa(),
    )

    post = {caller: Account(storage=caller_storage)}
    state_test(pre=pre, tx=tx, post=post)

Parametrized Test Cases

This test generates 2 parametrized test cases across 1 fork.