@pytest.mark.parametrize(
"account_warm,storage_key_warm",
[
(True, True),
(True, False),
# (False, True), Not possible
(False, False),
],
)
@pytest.mark.ported_from(
[
"https://github.com/ethereum/tests/blob/v13.3/src/GeneralStateTestsFiller/stSLoadTest/sloadGasCostFiller.json",
],
pr=["https://github.com/ethereum/execution-specs/pull/2489"],
)
def test_account_storage_warm_cold_state(
state_test: StateTestFiller,
pre: Alloc,
fork: Fork,
account_warm: bool,
storage_key_warm: bool,
) -> None:
"""Test type 1 transaction."""
env = Environment()
storage_reader_contract = pre.deploy_contract(Op.SLOAD(1) + Op.STOP)
# Overhead: PUSH args for CALL (popped_stack_items - 1)
# + GAS opcode + PUSH for SLOAD
overhead_cost = (
Op.PUSH1(0) * (Op.CALL.popped_stack_items - 1)
+ Op.GAS
+ Op.PUSH1(0) # SLOAD push
).gas_cost(fork)
contract_address = pre.deploy_contract(
CodeGasMeasure(
code=Op.CALL(address=storage_reader_contract),
overhead_cost=overhead_cost,
extra_stack_items=1,
sstore_key=0,
)
)
access_list_address = Address(0)
access_list_storage_key = Hash(0)
# Expected gas: CALL access cost + SLOAD cost
expected_gas_cost = Op.CALL(address_warm=account_warm).gas_cost(
fork
) + Op.SLOAD(key_warm=storage_key_warm).gas_cost(fork)
if account_warm:
access_list_address = storage_reader_contract
if storage_key_warm:
access_list_storage_key = Hash(1)
access_lists: List[AccessList] = [
AccessList(
address=access_list_address,
storage_keys=[access_list_storage_key],
),
]
sender = pre.fund_eoa()
contract_creation = False
tx_data = b""
intrinsic_gas_calculator = fork.transaction_intrinsic_cost_calculator()
tx_gas_limit = (
intrinsic_gas_calculator(
calldata=tx_data,
contract_creation=contract_creation,
access_list=access_lists,
)
+ 100_000
)
tx = Transaction(
ty=1,
data=tx_data,
to=contract_address,
gas_limit=tx_gas_limit,
access_list=access_lists,
sender=sender,
)
post = {
contract_address: Account(
nonce=1,
storage={0: expected_gas_cost},
),
}
state_test(env=env, pre=pre, post=post, tx=tx)