Skip to content

test_transient_storage_gas_unchanged()

Documentation for tests/amsterdam/eip8038_state_access_gas_cost_increase/test_transient_storage_regression.py::test_transient_storage_gas_unchanged@26332146.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip8038_state_access_gas_cost_increase/test_transient_storage_regression.py::test_transient_storage_gas_unchanged --fork Amsterdam

Measure TLOAD and TSTORE gas and confirm EIP-8038 left them at the transient-storage price of 100 each.

The bare-opcode costs (excluding their PUSH wrappers) must equal OPCODE_TLOAD / OPCODE_TSTORE. The guard OPCODE_TSTORE != COLD_STORAGE_WRITE ensures the persistent write repricing did not bleed into transient storage.

Source code in tests/amsterdam/eip8038_state_access_gas_cost_increase/test_transient_storage_regression.py
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
@EIPChecklist.GasCostChanges.Test.GasUpdatesMeasurement()
def test_transient_storage_gas_unchanged(
    state_test: StateTestFiller,
    env: Environment,
    pre: Alloc,
    fork: Fork,
) -> None:
    """
    Measure ``TLOAD`` and ``TSTORE`` gas and confirm EIP-8038 left them
    at the transient-storage price of 100 each.

    The bare-opcode costs (excluding their PUSH wrappers) must equal
    ``OPCODE_TLOAD`` / ``OPCODE_TSTORE``. The guard
    ``OPCODE_TSTORE != COLD_STORAGE_WRITE`` ensures the persistent
    write repricing did not bleed into transient storage.
    """
    gas_costs = fork.gas_costs()
    # Guard against over-eager repricing: the transient write must not
    # have been folded into the (repriced) persistent cold write cost.
    assert gas_costs.OPCODE_TSTORE != gas_costs.COLD_STORAGE_WRITE

    # Measure TSTORE then TLOAD of the same transient slot in one frame,
    # subtracting the PUSH wrapper so the stored value is the bare opcode
    # cost.
    push_cost = Op.PUSH1(0).execution_cost(fork)
    tstore_code = CodeGasMeasure(
        code=Op.TSTORE(0, 1),
        overhead_cost=2 * push_cost,
        extra_stack_items=0,
        sstore_key=0,
    )
    tload_code = CodeGasMeasure(
        code=Op.TLOAD(0),
        overhead_cost=1 * push_cost,
        extra_stack_items=1,
        sstore_key=1,
    )
    contract = pre.deploy_contract(code=tstore_code + tload_code)

    tx = Transaction(to=contract, sender=pre.fund_eoa())

    # Slot 0: measured TSTORE cost. Slot 1: measured TLOAD cost. Both must
    # equal the fork's declared transient-storage opcode costs, which
    # EIP-8038 leaves unchanged.
    post = {
        contract: Account(
            storage={
                0: gas_costs.OPCODE_TSTORE,
                1: gas_costs.OPCODE_TLOAD,
            }
        )
    }
    state_test(env=env, pre=pre, post=post, tx=tx)

Parametrized Test Cases

This test generates 1 parametrized test case across 1 fork.