Skip to content

test_create_no_double_charge_new_account()

Documentation for tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_create.py::test_create_no_double_charge_new_account@c74f1a67.

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

Verify CREATE does not double-charge new-account gas.

CREATE charges REGULAR_GAS_CREATE as regular gas and new-account state gas separately. Provide exactly enough gas for both — if GAS_NEW_ACCOUNT were charged twice (once in regular, once in state), the CREATE would OOG.

Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_create.py
1167
1168
1169
1170
1171
1172
1173
1174
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
@pytest.mark.valid_from("EIP8037")
def test_create_no_double_charge_new_account(
    state_test: StateTestFiller,
    pre: Alloc,
    fork: Fork,
) -> None:
    """
    Verify CREATE does not double-charge new-account gas.

    CREATE charges REGULAR_GAS_CREATE as regular gas and new-account
    state gas separately. Provide exactly enough gas for both — if
    GAS_NEW_ACCOUNT were charged twice (once in regular, once in
    state), the CREATE would OOG.
    """
    create_state_gas = fork.create_state_gas(code_size=0)

    # Child: just does CREATE(value=0, offset=0, size=0) and stores result.
    # This creates an empty account (no code deposit).
    child_code = Op.SSTORE(0, Op.CREATE(value=0, offset=0, size=0))
    child = pre.deploy_contract(child_code)

    # Compute exact gas: child bytecode + CREATE child frame.
    # The child frame is empty (size=0) so only the CREATE opcode
    # charges matter: regular (REGULAR_GAS_CREATE) + state (new account).
    child_total = child_code.gas_cost(fork)

    create_address = compute_create_address(address=child, nonce=1)

    # Caller forwards exact regular gas via CALL. State gas for
    # new account comes from the reservoir (gas_limit above the cap).
    caller_storage = Storage()
    regular_gas = child_total - create_state_gas
    caller = pre.deploy_contract(
        Op.SSTORE(
            caller_storage.store_next(1, "create_succeeds"),
            Op.CALL(gas=regular_gas, address=child),
        )
    )

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

    post = {
        caller: Account(storage=caller_storage),
        child: Account(storage={0: create_address}),
        create_address: Account(nonce=1),
    }
    state_test(pre=pre, tx=tx, post=post)

Parametrized Test Cases

This test generates 1 parametrized test case across 1 fork.