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
| @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),
"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,
)
|