@EIPChecklist.GasCostChanges.Test.GasUpdatesMeasurement()
@pytest.mark.valid_from("EIP8037")
def test_create_charges_state_gas(
state_test: StateTestFiller,
pre: Alloc,
fork: Fork,
) -> None:
"""
Test CREATE charges state gas for new account and code deposit.
A successful CREATE charges new-account state gas plus code
deposit state gas proportional to the deployed code size.
"""
runtime_code = Op.STOP
init_code = Initcode(deploy_code=runtime_code)
mstore_value, size = init_code_at_high_bytes(init_code)
create_call = Op.CREATE(0, 0, size, init_code_size=size)
storage = Storage()
code = Op.MSTORE(0, mstore_value, new_memory_size=32) + Op.SSTORE(
storage.store_next(False),
Op.ISZERO(create_call),
original_value=0,
current_value=0,
new_value=0,
)
contract = pre.deploy_contract(code=code)
created = compute_create_address(address=contract, nonce=1)
new_account_state = create_call.state_cost(fork)
code_deposit_state = init_code.state_cost(fork)
assert new_account_state > 0, "test requires a NEW_ACCOUNT charge"
assert code_deposit_state > 0, "test requires a code-deposit charge"
expected_state = new_account_state + code_deposit_state
expected_execution = (
fork.transaction_intrinsic_cost_calculator()()
+ fork.transaction_top_frame_execution_gas(contract_creation=False)
+ code.execution_cost(fork)
+ init_code.gas_cost(fork)
)
assert expected_state > expected_execution, (
"requires state gas > execution gas"
)
tx = Transaction(
to=contract,
state_gas_reservoir=0,
sender=pre.fund_eoa(),
)
post = {
contract: Account(nonce=2, storage=storage),
created: Account(nonce=1, code=runtime_code),
}
state_test(
pre=pre,
post=post,
tx=tx,
blockchain_test_header_verify=Header(gas_used=expected_state),
)