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@2119b382.

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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
@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.
    """
    gas_costs = fork.gas_costs()
    intrinsic = fork.transaction_intrinsic_cost_calculator()
    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]),
    ]

    base = intrinsic(return_cost_deducted_prior_execution=True)
    with_al = intrinsic(
        access_list=access_list,
        return_cost_deducted_prior_execution=True,
    )
    surcharge = (
        with_al - base - _access_list_floor_token_gas(access_list, fork)
    )
    expected_surcharge = (
        2 * gas_costs.TX_ACCESS_LIST_ADDRESS
        + 2 * gas_costs.TX_ACCESS_LIST_STORAGE_KEY
    )
    assert surcharge == expected_surcharge

    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.