Skip to content

test_blobhash_gas_cost()

Documentation for tests/cancun/eip4844_blobs/test_blobhash_opcode.py::test_blobhash_gas_cost@7b8124a7.

Generate fixtures for these test cases for Osaka with:

fill -v tests/cancun/eip4844_blobs/test_blobhash_opcode.py::test_blobhash_gas_cost --fork Osaka

Tests BLOBHASH opcode gas cost using a variety of indexes.

Asserts that the gas consumption of the BLOBHASH opcode is correct by ensuring it matches HASH_OPCODE_GAS = 3. Includes both valid and invalid random index sizes from the range [0, 2**256-1], for tx types 2 and 3.

Source code in tests/cancun/eip4844_blobs/test_blobhash_opcode.py
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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
@pytest.mark.parametrize("blobhash_index", blobhash_index_values)
@pytest.mark.with_all_tx_types
def test_blobhash_gas_cost(
    pre: Alloc,
    fork: Fork,
    tx_type: int,
    blobhash_index: int,
    state_test: StateTestFiller,
) -> None:
    """
    Tests `BLOBHASH` opcode gas cost using a variety of indexes.

    Asserts that the gas consumption of the `BLOBHASH` opcode is correct by
    ensuring it matches `HASH_OPCODE_GAS = 3`. Includes both valid and invalid
    random index sizes from the range `[0, 2**256-1]`, for tx types 2 and 3.
    """
    blobhash_code = Op.BLOBHASH(blobhash_index)
    gas_measure_code = CodeGasMeasure(
        code=blobhash_code,
        extra_stack_items=1,
    )

    address = pre.deploy_contract(gas_measure_code)
    sender = pre.fund_eoa()

    tx_kwargs = {
        "ty": tx_type,
        "sender": sender,
        "to": address,
        "data": Hash(0),
        "gas_limit": 500_000,
        "max_fee_per_blob_gas": (fork.min_base_fee_per_blob_gas() * 10)
        if tx_type == 3
        else None,
        "blob_versioned_hashes": random_blob_hashes[
            0 : fork.max_blobs_per_tx()
        ]
        if tx_type == 3
        else None,
    }
    if tx_type == 4:
        signer = pre.fund_eoa(amount=0)
        tx_kwargs["authorization_list"] = [
            AuthorizationTuple(
                signer=signer,
                address=Address(0),
                nonce=0,
            )
        ]

    tx = Transaction(**tx_kwargs)
    post = {address: Account(storage={0: blobhash_code.gas_cost(fork)})}

    state_test(
        env=Environment(),
        pre=pre,
        tx=tx,
        post=post,
    )

Parametrized Test Cases

This test generates 35 parametrized test cases across 3 forks.