Skip to content

test_code_deposit_halt_discards_initcode_state_gas()

Documentation for tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_create.py::test_code_deposit_halt_discards_initcode_state_gas@2119b382.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_create.py::test_code_deposit_halt_discards_initcode_state_gas --fork Amsterdam

Verify initcode state gas excluded from block on deposit halt.

A CREATE tx runs initcode that first performs a state-creating operation (charging GAS_NEW_ACCOUNT state gas), then returns code that triggers a deposit failure (oversized or OOG). The exceptional halt reverts all initcode state changes including the new account. The reverted GAS_NEW_ACCOUNT must NOT count in block_state_gas_used, which determines the block header gas_used via max(block_regular_gas, block_state_gas).

Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_create.py
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
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
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
@pytest.mark.parametrize(
    "state_opcode",
    [
        pytest.param(Op.CALL, id="call_new_account"),
        pytest.param(Op.CREATE, id="inner_create"),
    ],
)
@pytest.mark.parametrize(
    "deposit_fail_mode",
    [
        pytest.param("oversized_code", id="oversized_code"),
        pytest.param("oog_deposit", id="oog_deposit"),
    ],
)
@pytest.mark.valid_from("EIP8037")
def test_code_deposit_halt_discards_initcode_state_gas(
    blockchain_test: BlockchainTestFiller,
    pre: Alloc,
    fork: Fork,
    state_opcode: Op,
    deposit_fail_mode: str,
) -> None:
    """
    Verify initcode state gas excluded from block on deposit halt.

    A CREATE tx runs initcode that first performs a state-creating
    operation (charging GAS_NEW_ACCOUNT state gas), then returns
    code that triggers a deposit failure (oversized or OOG). The
    exceptional halt reverts all initcode state changes including
    the new account. The reverted GAS_NEW_ACCOUNT must NOT count
    in block_state_gas_used, which determines the block header
    gas_used via max(block_regular_gas, block_state_gas).
    """
    subcall_forwarded_value = 1
    entry_account_value = 1
    if state_opcode == Op.CALL:
        state_op = Op.POP(
            Op.CALL(
                address=pre.nonexistent_account(),
                value=subcall_forwarded_value,
            )
        )
    else:
        state_op = Op.POP(Op.CREATE(value=0, offset=0, size=1))

    if deposit_fail_mode == "oversized_code":
        deposit_fail = Op.RETURN(0, fork.max_code_size() + 1)
    else:
        # Return code at max size — passes the size check but code
        # deposit state gas (max_code_size * cost_per_state_byte)
        # exceeds available state gas in the child frame, causing OOG.
        deposit_fail = Op.RETURN(0, fork.max_code_size())

    initcode = state_op + deposit_fail

    blockchain_test(
        pre=pre,
        blocks=[
            Block(
                txs=[
                    Transaction(
                        to=None,
                        data=initcode,
                        value=entry_account_value + subcall_forwarded_value,
                        state_gas_reservoir=0,
                        sender=pre.fund_eoa(),
                    ),
                ],
            ),
        ],
        post={},
    )

Parametrized Test Cases

This test generates 4 parametrized test cases across 1 fork.