@pytest.mark.ported_from(
[
"https://github.com/ethereum/tests/blob/v13.3/src/GeneralStateTestsFiller/Cancun/stEIP1153-transientStorage/16_tloadGasFiller.yml",
],
pr=["https://github.com/ethereum/execution-spec-tests/pull/440"],
)
@pytest.mark.valid_from("Cancun")
def test_basic_tload_gasprice(
state_test: StateTestFiller,
pre: Alloc,
fork: Fork,
) -> None:
"""
Ported .json vectors.
(16_tloadGasFiller.yml)
tload costs 100 gas same as a warm sload
"""
slot_tload_nonzero_gas_price_result = 1
slot_tload_zero_gas_price_result = 2
slot_code_worked = 3
"""
N OPNAME GAS_COST TOTAL_GAS REMAINING_GAS STACK
28-1 MSTORE 2 20748 4958252 2:[4ba82f,0,]
MSTORE [0] = 4958255
29-1 PUSH1 3 20754 4958246
30-1 TLOAD 100 20757 4958243 1:[10,]
31-1 GAS 2 20857 4958143 1:[2,]
32-1 PUSH1 3 20859 4958141 2:[2,4ba7bd,]
33-1 MSTORE 6 20862 4958138 3:[2,4ba7bd,20,]
MSTORE [32] = 4958141
"""
extra_opcode_gas = 11 # mstore(3), push1(3),gas(2),push1(3)
address_to = pre.deploy_contract(
code=Op.JUMPDEST()
# 16 test
+ Op.TSTORE(16, 2)
+ Op.MSTORE(
0, Op.GAS()
) # hot load the memory to make the extra_opcode_gas be 11
+ Op.MSTORE(0, Op.GAS())
+ Op.TLOAD(16)
+ Op.MSTORE(32, Op.GAS())
+ Op.SSTORE(
slot_tload_nonzero_gas_price_result,
Op.SUB(Op.MLOAD(0), Op.MLOAD(32)),
)
+ Op.SSTORE(
slot_tload_nonzero_gas_price_result,
Op.SUB(
Op.SLOAD(slot_tload_nonzero_gas_price_result), extra_opcode_gas
),
)
+ Op.MSTORE(0, Op.GAS())
+ Op.TLOAD(5) # tload slot at 5 is 0
+ Op.MSTORE(32, Op.GAS())
+ Op.SSTORE(
slot_tload_zero_gas_price_result, Op.SUB(Op.MLOAD(0), Op.MLOAD(32))
)
+ Op.SSTORE(
slot_tload_zero_gas_price_result,
Op.SUB(
Op.SLOAD(slot_tload_zero_gas_price_result), extra_opcode_gas
),
)
+ Op.SSTORE(slot_code_worked, 1),
storage={
slot_tload_nonzero_gas_price_result: 0xFF,
slot_tload_zero_gas_price_result: 0xFF,
},
)
post = {
address_to: Account(
storage={
slot_tload_nonzero_gas_price_result: Op.TLOAD.gas_cost(fork),
slot_tload_zero_gas_price_result: Op.TLOAD.gas_cost(fork),
slot_code_worked: 0x01,
}
)
}
tx = Transaction(sender=pre.fund_eoa(), to=address_to)
state_test(pre=pre, post=post, tx=tx)