Skip to content

test_blobhash_opcode_contexts()

Documentation for tests/cancun/eip4844_blobs/test_blobhash_opcode_contexts.py::test_blobhash_opcode_contexts@0fe4295f.

Generate fixtures for these test cases for Prague with:

fill -v tests/cancun/eip4844_blobs/test_blobhash_opcode_contexts.py::test_blobhash_opcode_contexts --fork Prague

Tests that the BLOBHASH opcode functions correctly when called in different contexts.

  • BLOBHASH opcode on the top level of the call stack.
  • BLOBHASH opcode on the max value.
  • BLOBHASH opcode on CALL, DELEGATECALL, STATICCALL, and CALLCODE.
  • BLOBHASH opcode on Initcode.
  • BLOBHASH opcode on CREATE and CREATE2.
  • BLOBHASH opcode on transaction types 0, 1 and 2.
Source code in tests/cancun/eip4844_blobs/test_blobhash_opcode_contexts.py
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
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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
@pytest.mark.parametrize(
    "test_case",
    [
        "on_top_level_call_stack",
        "on_max_value",
        "on_CALL",
        "on_DELEGATECALL",
        "on_STATICCALL",
        "on_CALLCODE",
        "on_CREATE",
        "on_CREATE2",
    ],
    ids=lambda x: x,
)
def test_blobhash_opcode_contexts(
    pre: Alloc,
    test_case: str,
    max_blobs_per_block: int,
    simple_blob_hashes: List[bytes],
    fork: Fork,
    state_test: StateTestFiller,
):
    """
    Tests that the `BLOBHASH` opcode functions correctly when called in different contexts.

    - `BLOBHASH` opcode on the top level of the call stack.
    - `BLOBHASH` opcode on the max value.
    - `BLOBHASH` opcode on `CALL`, `DELEGATECALL`, `STATICCALL`, and `CALLCODE`.
    - `BLOBHASH` opcode on Initcode.
    - `BLOBHASH` opcode on `CREATE` and `CREATE2`.
    - `BLOBHASH` opcode on transaction types 0, 1 and 2.
    """
    tx_to: Address
    post: dict[Address, Account]

    match test_case:
        case "on_top_level_call_stack":
            blobhash_sstore_address = BlobhashContext.BLOBHASH_SSTORE.deploy_contract(
                pre=pre, indexes=range(max_blobs_per_block + 1)
            )
            tx_to = blobhash_sstore_address
            post = {
                blobhash_sstore_address: Account(
                    storage=dict(
                        zip(
                            range(len(simple_blob_hashes)),
                            simple_blob_hashes,
                            strict=False,
                        )
                    )
                ),
            }
        case "on_max_value":
            blobhash_sstore_address = BlobhashContext.BLOBHASH_SSTORE.deploy_contract(
                pre=pre, indexes=[2**256 - 1]
            )
            tx_to = blobhash_sstore_address
            post = {
                blobhash_sstore_address: Account(storage={}),
            }
        case "on_CALL" | "on_DELEGATECALL" | "on_STATICCALL" | "on_CALLCODE":
            call_context: BlobhashContext
            match test_case:
                case "on_CALL":
                    call_context = BlobhashContext.CALL
                case "on_DELEGATECALL":
                    call_context = BlobhashContext.DELEGATECALL
                case "on_STATICCALL":
                    call_context = BlobhashContext.STATICCALL
                case "on_CALLCODE":
                    call_context = BlobhashContext.CALLCODE
            call_address = call_context.deploy_contract(
                pre=pre, indexes=range(max_blobs_per_block + 1)
            )
            tx_to = call_address
            post = {
                call_address: Account(
                    storage=dict(
                        zip(
                            range(len(simple_blob_hashes)),
                            simple_blob_hashes,
                            strict=False,
                        )
                    )
                ),
            }
        case "on_CREATE" | "on_CREATE2":
            create_context: BlobhashContext
            opcode: Op
            match test_case:
                case "on_CREATE":
                    create_context = BlobhashContext.CREATE
                    opcode = Op.CREATE
                case "on_CREATE2":
                    create_context = BlobhashContext.CREATE2
                    opcode = Op.CREATE2
            factory_address = create_context.deploy_contract(
                pre=pre, indexes=range(max_blobs_per_block + 1)
            )
            created_contract_address = compute_create_address(
                address=factory_address,
                nonce=1,  # the create contract will have nonce 1 for its first create
                salt=0,
                initcode=BlobhashContext.INITCODE.code(indexes=range(max_blobs_per_block + 1)),
                opcode=opcode,
            )
            tx_to = factory_address
            post = {
                created_contract_address: Account(
                    storage=dict(
                        zip(range(len(simple_blob_hashes)), simple_blob_hashes, strict=False)
                    )
                ),
            }
        case _:
            raise Exception(f"Unknown test case {test_case}")

    state_test(
        pre=pre,
        tx=Transaction(
            ty=Spec.BLOB_TX_TYPE,
            to=tx_to,
            gas_limit=500_000,
            max_fee_per_blob_gas=fork.min_base_fee_per_blob_gas() * 10,
            blob_versioned_hashes=simple_blob_hashes,
            sender=pre.fund_eoa(),
        ),
        post=post,
    )

Parametrized Test Cases

The interactive table below is also available as a standalone page.

Test ID (Abbreviated) test_case
...fork_Cancun-state_test-on_top_level_call_stack on_top_level_call_stack
...fork_Cancun-state_test-on_max_value on_max_value
...fork_Cancun-state_test-on_CALL on_CALL
...fork_Cancun-state_test-on_DELEGATECALL on_DELEGATECALL
...fork_Cancun-state_test-on_STATICCALL on_STATICCALL
...fork_Cancun-state_test-on_CALLCODE on_CALLCODE
...fork_Cancun-state_test-on_CREATE on_CREATE
...fork_Cancun-state_test-on_CREATE2 on_CREATE2
...fork_Cancun-blockchain_test_from_state_test-on_top_level_call_stack on_top_level_call_stack
...fork_Cancun-blockchain_test_from_state_test-on_max_value on_max_value
...fork_Cancun-blockchain_test_from_state_test-on_CALL on_CALL
...fork_Cancun-blockchain_test_from_state_test-on_DELEGATECALL on_DELEGATECALL
...fork_Cancun-blockchain_test_from_state_test-on_STATICCALL on_STATICCALL
...fork_Cancun-blockchain_test_from_state_test-on_CALLCODE on_CALLCODE
...fork_Cancun-blockchain_test_from_state_test-on_CREATE on_CREATE
...fork_Cancun-blockchain_test_from_state_test-on_CREATE2 on_CREATE2
...fork_Prague-state_test-on_top_level_call_stack on_top_level_call_stack
...fork_Prague-state_test-on_max_value on_max_value
...fork_Prague-state_test-on_CALL on_CALL
...fork_Prague-state_test-on_DELEGATECALL on_DELEGATECALL
...fork_Prague-state_test-on_STATICCALL on_STATICCALL
...fork_Prague-state_test-on_CALLCODE on_CALLCODE
...fork_Prague-state_test-on_CREATE on_CREATE
...fork_Prague-state_test-on_CREATE2 on_CREATE2
...fork_Prague-blockchain_test_from_state_test-on_top_level_call_stack on_top_level_call_stack
...fork_Prague-blockchain_test_from_state_test-on_max_value on_max_value
...fork_Prague-blockchain_test_from_state_test-on_CALL on_CALL
...fork_Prague-blockchain_test_from_state_test-on_DELEGATECALL on_DELEGATECALL
...fork_Prague-blockchain_test_from_state_test-on_STATICCALL on_STATICCALL
...fork_Prague-blockchain_test_from_state_test-on_CALLCODE on_CALLCODE
...fork_Prague-blockchain_test_from_state_test-on_CREATE on_CREATE
...fork_Prague-blockchain_test_from_state_test-on_CREATE2 on_CREATE2
...fork_Osaka-state_test-on_top_level_call_stack on_top_level_call_stack
...fork_Osaka-state_test-on_max_value on_max_value
...fork_Osaka-state_test-on_CALL on_CALL
...fork_Osaka-state_test-on_DELEGATECALL on_DELEGATECALL
...fork_Osaka-state_test-on_STATICCALL on_STATICCALL
...fork_Osaka-state_test-on_CALLCODE on_CALLCODE
...fork_Osaka-state_test-on_CREATE on_CREATE
...fork_Osaka-state_test-on_CREATE2 on_CREATE2
...fork_Osaka-blockchain_test_from_state_test-on_top_level_call_stack on_top_level_call_stack
...fork_Osaka-blockchain_test_from_state_test-on_max_value on_max_value
...fork_Osaka-blockchain_test_from_state_test-on_CALL on_CALL
...fork_Osaka-blockchain_test_from_state_test-on_DELEGATECALL on_DELEGATECALL
...fork_Osaka-blockchain_test_from_state_test-on_STATICCALL on_STATICCALL
...fork_Osaka-blockchain_test_from_state_test-on_CALLCODE on_CALLCODE
...fork_Osaka-blockchain_test_from_state_test-on_CREATE on_CREATE
...fork_Osaka-blockchain_test_from_state_test-on_CREATE2 on_CREATE2