Skip to content

test_access_list_duplicate_address_key_intrinsic_and_warmth()

Documentation for tests/amsterdam/eip8038_state_access_gas_cost_increase/test_access_list_gas.py::test_access_list_duplicate_address_key_intrinsic_and_warmth@622620d8.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip8038_state_access_gas_cost_increase/test_access_list_gas.py::test_access_list_duplicate_address_key_intrinsic_and_warmth --fork Amsterdam

A duplicated (address, storage_key) access-list entry is billed twice intrinsically but warms the slot only once.

The same (contract, slot) pair is listed twice. The intrinsic surcharge (floor tokens isolated as in test_access_list_intrinsic_surcharge) bills both listings: 2 * TX_ACCESS_LIST_ADDRESS + 2 * TX_ACCESS_LIST_STORAGE_KEY. At runtime the slot is nonetheless warm on its first SLOAD (WARM_SLOAD), since warmth is set-membership, not a counter.

Source code in tests/amsterdam/eip8038_state_access_gas_cost_increase/test_access_list_gas.py
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
@EIPChecklist.GasCostChanges.Test.GasUpdatesMeasurement()
def test_access_list_duplicate_address_key_intrinsic_and_warmth(
    state_test: StateTestFiller,
    env: Environment,
    pre: Alloc,
    fork: Fork,
) -> None:
    """
    A duplicated ``(address, storage_key)`` access-list entry is billed
    twice intrinsically but warms the slot only once.

    The same ``(contract, slot)`` pair is listed twice. The intrinsic
    surcharge (floor tokens isolated as in
    ``test_access_list_intrinsic_surcharge``) bills both listings:
    ``2 * TX_ACCESS_LIST_ADDRESS + 2 * TX_ACCESS_LIST_STORAGE_KEY``. At
    runtime the slot is nonetheless warm on its first ``SLOAD``
    (``WARM_SLOAD``), since warmth is set-membership, not a counter.
    """
    slot = 0x42

    # First runtime SLOAD of the listed slot stores the warm access cost.
    measured_read = Op.SLOAD(slot)
    overhead = measured_read.gas_cost(fork) - Op.SLOAD(
        key_warm=False
    ).gas_cost(fork)
    contract = pre.deploy_contract(
        code=CodeGasMeasure(
            code=measured_read,
            overhead_cost=overhead,
            extra_stack_items=1,
            sstore_key=1,
        ),
        storage={slot: 1},
    )

    # Build the access list after deploying so the address is real, then
    # list the identical (contract, slot) pair twice.
    access_list = [
        AccessList(address=contract, storage_keys=[slot]),
        AccessList(address=contract, storage_keys=[slot]),
    ]

    expected_gas = Op.SLOAD(key_warm=True).gas_cost(fork)
    tx = Transaction(
        to=contract,
        sender=pre.fund_eoa(),
        access_list=access_list,
    )

    # Slot 1 holds the measured warm cost; the read slot keeps its value.
    post = {contract: Account(storage={1: expected_gas, slot: 1})}
    state_test(env=env, pre=pre, post=post, tx=tx)

Parametrized Test Cases

This test generates 1 parametrized test case across 1 fork.