Skip to content

Test Excess Data Gas

Documentation for test cases from tests/cancun/eip4844_blobs/test_excess_data_gas.py.

Generate fixtures for these test cases for Cancun with:

Cancun only:

fill -v tests/cancun/eip4844_blobs/test_excess_data_gas.py --fork=Cancun --evm-bin=/path/to/evm-tool-dev-version
For all forks up to and including Cancun:
fill -v tests/cancun/eip4844_blobs/test_excess_data_gas.py --until=Cancun --evm-bin=/path/to/evm-tool-dev-version

Tests excessDataGas and dataGasUsed block fields for EIP-4844: Shard Blob Transactions

Test excessDataGas and dataGasUsed block fields for EIP-4844: Shard Blob Transactions.

Adding a new test

Add a function that is named test_<test_name> and takes at least the following arguments:

  • blockchain_test
  • env
  • pre
  • blocks
  • post
  • correct_excess_data_gas

The following arguments need to be parametrized or the test will not be generated:

  • new_blobs

All other pytest.fixture fixtures can be parametrized to generate new combinations and test cases.

test_correct_excess_data_gas_calculation(blockchain_test, env, pre, blocks, post, correct_excess_data_gas)

Test calculation of the excessDataGas increase/decrease across multiple blocks with and without blobs:

  • With parent block containing [0, MAX_BLOBS_PER_BLOCK] blobs
  • With parent block containing [0, TARGET_BLOBS_PER_BLOCK] equivalent value of excess data gas
Source code in tests/cancun/eip4844_blobs/test_excess_data_gas.py
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
@pytest.mark.parametrize("parent_blobs", range(0, MAX_BLOBS_PER_BLOCK + 1))
@pytest.mark.parametrize("parent_excess_blobs", range(0, TARGET_BLOBS_PER_BLOCK + 1))
@pytest.mark.parametrize("new_blobs", [1])
def test_correct_excess_data_gas_calculation(
    blockchain_test: BlockchainTestFiller,
    env: Environment,
    pre: Mapping[str, Account],
    blocks: List[Block],
    post: Mapping[str, Account],
    correct_excess_data_gas: int,
):
    """
    Test calculation of the `excessDataGas` increase/decrease across
    multiple blocks with and without blobs:

    - With parent block containing `[0, MAX_BLOBS_PER_BLOCK]` blobs
    - With parent block containing `[0, TARGET_BLOBS_PER_BLOCK]` equivalent value of excess data gas
    """  # noqa: E501
    blockchain_test(
        pre=pre,
        post=post,
        blocks=blocks,
        genesis_environment=env,
        tag=f"expected_excess_data_gas:{hex(correct_excess_data_gas)}",
    )

test_correct_increasing_data_gas_costs(blockchain_test, env, pre, blocks, post, correct_excess_data_gas)

Test calculation of the excessDataGas and data gas tx costs at value points where the cost increases to interesting amounts:

  • At the first data gas cost increase (1 to 2)
  • At total transaction data cost increase to > 2^32
  • At data gas wei cost increase to > 2^32
  • At total transaction data cost increase to > 2^64
  • At data gas wei cost increase to > 2^64
  • At data gas wei cost increase of around current total Ether supply
Source code in tests/cancun/eip4844_blobs/test_excess_data_gas.py
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
@pytest.mark.parametrize(
    "parent_excess_blobs",
    [g - 1 for g in DATA_GAS_COST_INCREASES],
)
@pytest.mark.parametrize("parent_blobs", [TARGET_BLOBS_PER_BLOCK + 1])
@pytest.mark.parametrize("new_blobs", [1])
def test_correct_increasing_data_gas_costs(
    blockchain_test: BlockchainTestFiller,
    env: Environment,
    pre: Mapping[str, Account],
    blocks: List[Block],
    post: Mapping[str, Account],
    correct_excess_data_gas: int,
):
    """
    Test calculation of the `excessDataGas` and data gas tx costs at
    value points where the cost increases to interesting amounts:

    - At the first data gas cost increase (1 to 2)
    - At total transaction data cost increase to `> 2^32`
    - At data gas wei cost increase to `> 2^32`
    - At total transaction data cost increase to `> 2^64`
    - At data gas wei cost increase to `> 2^64`
    - At data gas wei cost increase of around current total Ether supply
    """
    blockchain_test(
        pre=pre,
        post=post,
        blocks=blocks,
        genesis_environment=env,
        tag=f"expected_excess_data_gas:{hex(correct_excess_data_gas)}",
    )

test_correct_decreasing_data_gas_costs(blockchain_test, env, pre, blocks, post, correct_excess_data_gas)

Test calculation of the excessDataGas and data gas tx costs at value points where the cost decreases to interesting amounts.

See test_correct_increasing_data_gas_costs.

Source code in tests/cancun/eip4844_blobs/test_excess_data_gas.py
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
@pytest.mark.parametrize(
    "parent_excess_blobs",
    [g for g in DATA_GAS_COST_INCREASES],
)
@pytest.mark.parametrize("parent_blobs", [TARGET_BLOBS_PER_BLOCK - 1])
@pytest.mark.parametrize("new_blobs", [1])
def test_correct_decreasing_data_gas_costs(
    blockchain_test: BlockchainTestFiller,
    env: Environment,
    pre: Mapping[str, Account],
    blocks: List[Block],
    post: Mapping[str, Account],
    correct_excess_data_gas: int,
):
    """
    Test calculation of the `excessDataGas` and data gas tx costs at
    value points where the cost decreases to interesting amounts.

    See test_correct_increasing_data_gas_costs.
    """
    blockchain_test(
        pre=pre,
        post=post,
        blocks=blocks,
        genesis_environment=env,
        tag=f"expected_excess_data_gas:{hex(correct_excess_data_gas)}",
    )

test_invalid_zero_excess_data_gas_in_header(blockchain_test, env, pre, blocks, correct_excess_data_gas, header_excess_data_gas)

Test rejection of blocks where the excessDataGas in the header drops to zero in a block with or without data blobs, but the excess blobs in the parent are greater than target.

Source code in tests/cancun/eip4844_blobs/test_excess_data_gas.py
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
@pytest.mark.parametrize("header_excess_data_gas", [0])
@pytest.mark.parametrize("new_blobs", [0, 1])
@pytest.mark.parametrize("parent_blobs", range(0, MAX_BLOBS_PER_BLOCK + 1))
def test_invalid_zero_excess_data_gas_in_header(
    blockchain_test: BlockchainTestFiller,
    env: Environment,
    pre: Mapping[str, Account],
    blocks: List[Block],
    correct_excess_data_gas: int,
    header_excess_data_gas: Optional[int],
):
    """
    Test rejection of blocks where the `excessDataGas` in the header drops to
    zero in a block with or without data blobs, but the excess blobs in the parent are
    greater than target.
    """
    if header_excess_data_gas is None:
        raise Exception("test case is badly formatted")

    if header_excess_data_gas == correct_excess_data_gas:
        raise Exception("invalid test case")

    blockchain_test(
        pre=pre,
        post={},
        blocks=blocks,
        genesis_environment=env,
        tag="-".join(
            [
                f"correct:{hex(correct_excess_data_gas)}",
                f"header:{hex(header_excess_data_gas)}",
            ]
        ),
    )

test_invalid_data_gas_used_in_header(blockchain_test, env, pre, blocks, new_blobs, header_data_gas_used)

Test rejection of blocks where the dataGasUsed in the header is invalid:

  • dataGasUsed is not equal to the number of data blobs in the block
  • dataGasUsed is the max uint64 value
Source code in tests/cancun/eip4844_blobs/test_excess_data_gas.py
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
@pytest.mark.parametrize(
    "new_blobs,header_data_gas_used",
    all_invalid_data_gas_used_combinations(),
)
@pytest.mark.parametrize("parent_blobs", [0])
def test_invalid_data_gas_used_in_header(
    blockchain_test: BlockchainTestFiller,
    env: Environment,
    pre: Mapping[str, Account],
    blocks: List[Block],
    new_blobs: int,
    header_data_gas_used: Optional[int],
):
    """
    Test rejection of blocks where the `dataGasUsed` in the header is invalid:

    - `dataGasUsed` is not equal to the number of data blobs in the block
    - `dataGasUsed` is the max uint64 value
    """
    if header_data_gas_used is None:
        raise Exception("test case is badly formatted")
    blockchain_test(
        pre=pre,
        post={},
        blocks=blocks,
        genesis_environment=env,
        tag="-".join(
            [
                f"correct:{hex(new_blobs * DATA_GAS_PER_BLOB)}",
                f"header:{hex(header_data_gas_used)}",
            ]
        ),
    )

test_invalid_excess_data_gas_above_target_change(blockchain_test, env, pre, blocks, correct_excess_data_gas, header_excess_data_gas)

Test rejection of blocks where the excessDataGas

  • decreases more than TARGET_DATA_GAS_PER_BLOCK in a single block with zero blobs
  • increases more than TARGET_DATA_GAS_PER_BLOCK in a single block with max blobs
Source code in tests/cancun/eip4844_blobs/test_excess_data_gas.py
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
@pytest.mark.parametrize(
    "header_excess_blobs_delta,parent_blobs",
    [
        (-1, 0),
        (+1, MAX_BLOBS_PER_BLOCK),
    ],
    ids=["zero_blobs_decrease_more_than_expected", "max_blobs_increase_more_than_expected"],
)
@pytest.mark.parametrize("new_blobs", [1])
def test_invalid_excess_data_gas_above_target_change(
    blockchain_test: BlockchainTestFiller,
    env: Environment,
    pre: Mapping[str, Account],
    blocks: List[Block],
    correct_excess_data_gas: int,
    header_excess_data_gas: Optional[int],
):
    """
    Test rejection of blocks where the `excessDataGas`

    - decreases more than `TARGET_DATA_GAS_PER_BLOCK` in a single block with zero blobs
    - increases more than `TARGET_DATA_GAS_PER_BLOCK` in a single block with max blobs
    """
    if header_excess_data_gas is None:
        raise Exception("test case is badly formatted")

    if header_excess_data_gas == correct_excess_data_gas:
        raise Exception("invalid test case")

    blockchain_test(
        pre=pre,
        post={},
        blocks=blocks,
        genesis_environment=env,
        tag="-".join(
            [
                f"correct:{hex(correct_excess_data_gas)}",
                f"header:{hex(header_excess_data_gas)}",
            ]
        ),
    )

test_invalid_static_excess_data_gas(blockchain_test, env, pre, blocks, correct_excess_data_gas, parent_excess_data_gas)

Test rejection of blocks where the excessDataGas remains unchanged but the parent blobs included are not TARGET_BLOBS_PER_BLOCK.

Test is parametrized to MAX_BLOBS_PER_BLOCK and TARGET_BLOBS_PER_BLOCK.

Source code in tests/cancun/eip4844_blobs/test_excess_data_gas.py
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
@pytest.mark.parametrize(
    "parent_blobs",
    [b for b in range(0, MAX_BLOBS_PER_BLOCK + 1) if b != TARGET_BLOBS_PER_BLOCK],
)
@pytest.mark.parametrize("parent_excess_blobs", [1, TARGET_BLOBS_PER_BLOCK])
@pytest.mark.parametrize("new_blobs", [1])
def test_invalid_static_excess_data_gas(
    blockchain_test: BlockchainTestFiller,
    env: Environment,
    pre: Mapping[str, Account],
    blocks: List[Block],
    correct_excess_data_gas: int,
    parent_excess_data_gas: int,
):
    """
    Test rejection of blocks where the `excessDataGas` remains unchanged
    but the parent blobs included are not `TARGET_BLOBS_PER_BLOCK`.

    Test is parametrized to `MAX_BLOBS_PER_BLOCK` and `TARGET_BLOBS_PER_BLOCK`.
    """
    blocks[-1].rlp_modifier = Header(excess_data_gas=parent_excess_data_gas)
    blocks[-1].exception = "invalid excessDataGas"
    blockchain_test(
        pre=pre,
        post={},
        blocks=blocks,
        genesis_environment=env,
        tag="-".join(
            [
                f"correct:{hex(correct_excess_data_gas)}",
                f"header:{hex(parent_excess_data_gas)}",
            ]
        ),
    )

test_invalid_excess_data_gas_target_blobs_increase_from_zero(blockchain_test, env, pre, blocks, correct_excess_data_gas, header_excess_data_gas)

Test rejection of blocks where the excessDataGas increases from zero, even when the included blobs are on or below target.

Test is parametrized according to [0, TARGET_BLOBS_PER_BLOCK] new blobs.

Source code in tests/cancun/eip4844_blobs/test_excess_data_gas.py
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
@pytest.mark.parametrize("header_excess_blobs_delta", range(1, MAX_BLOBS_PER_BLOCK))
@pytest.mark.parametrize("parent_blobs", range(0, TARGET_BLOBS_PER_BLOCK + 1))
@pytest.mark.parametrize("parent_excess_blobs", [0])  # Start at 0
@pytest.mark.parametrize("new_blobs", [1])
def test_invalid_excess_data_gas_target_blobs_increase_from_zero(
    blockchain_test: BlockchainTestFiller,
    env: Environment,
    pre: Mapping[str, Account],
    blocks: List[Block],
    correct_excess_data_gas: int,
    header_excess_data_gas: Optional[int],
):
    """
    Test rejection of blocks where the `excessDataGas` increases from zero,
    even when the included blobs are on or below target.

    Test is parametrized according to `[0, TARGET_BLOBS_PER_BLOCK]` new blobs.
    """
    if header_excess_data_gas is None:
        raise Exception("test case is badly formatted")

    if header_excess_data_gas == correct_excess_data_gas:
        raise Exception("invalid test case")

    blockchain_test(
        pre=pre,
        post={},
        blocks=blocks,
        genesis_environment=env,
        tag="-".join(
            [
                f"correct:{hex(correct_excess_data_gas)}",
                f"header:{hex(header_excess_data_gas)}",
            ]
        ),
    )

test_invalid_static_excess_data_gas_from_zero_on_blobs_above_target(blockchain_test, env, pre, blocks, correct_excess_data_gas, header_excess_data_gas)

Test rejection of blocks where the excessDataGas does not increase from zero, even when the included blobs is above target.

Test is parametrized to [TARGET_BLOBS_PER_BLOCK+1, MAX_BLOBS_PER_BLOCK] new blobs.

Source code in tests/cancun/eip4844_blobs/test_excess_data_gas.py
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
@pytest.mark.parametrize("header_excess_data_gas", [0])
@pytest.mark.parametrize(
    "parent_blobs", range(TARGET_BLOBS_PER_BLOCK + 1, MAX_BLOBS_PER_BLOCK + 1)
)
@pytest.mark.parametrize("parent_excess_blobs", [0])  # Start at 0
@pytest.mark.parametrize("new_blobs", [1])
def test_invalid_static_excess_data_gas_from_zero_on_blobs_above_target(
    blockchain_test: BlockchainTestFiller,
    env: Environment,
    pre: Mapping[str, Account],
    blocks: List[Block],
    correct_excess_data_gas: int,
    header_excess_data_gas: Optional[int],
):
    """
    Test rejection of blocks where the `excessDataGas` does not increase from
    zero, even when the included blobs is above target.

    Test is parametrized to `[TARGET_BLOBS_PER_BLOCK+1, MAX_BLOBS_PER_BLOCK]` new blobs.
    """
    if header_excess_data_gas is None:
        raise Exception("test case is badly formatted")

    if header_excess_data_gas == correct_excess_data_gas:
        raise Exception("invalid test case")

    blockchain_test(
        pre=pre,
        post={},
        blocks=blocks,
        genesis_environment=env,
        tag="-".join(
            [
                f"correct:{hex(correct_excess_data_gas)}",
                f"header:{hex(header_excess_data_gas)}",
            ]
        ),
    )

test_invalid_excess_data_gas_change(blockchain_test, env, pre, blocks, correct_excess_data_gas, header_excess_data_gas)

Test rejection of blocks where the excessDataGas changes to an invalid value.

Given a parent block containing [0, MAX_BLOBS_PER_BLOCK] blobs, test an invalid excessDataGas value by changing it by [-TARGET_BLOBS_PER_BLOCK, TARGET_BLOBS_PER_BLOCK] from the correct value.

Source code in tests/cancun/eip4844_blobs/test_excess_data_gas.py
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
@pytest.mark.parametrize(
    "parent_blobs,header_excess_blobs_delta",
    itertools.product(
        # parent_blobs
        range(0, MAX_BLOBS_PER_BLOCK + 1),
        # header_excess_blobs_delta (from correct value)
        [x for x in range(-TARGET_BLOBS_PER_BLOCK, TARGET_BLOBS_PER_BLOCK + 1) if x != 0],
    ),
)
@pytest.mark.parametrize("new_blobs", [1])
def test_invalid_excess_data_gas_change(
    blockchain_test: BlockchainTestFiller,
    env: Environment,
    pre: Mapping[str, Account],
    blocks: List[Block],
    correct_excess_data_gas: int,
    header_excess_data_gas: Optional[int],
):
    """
    Test rejection of blocks where the `excessDataGas` changes to an invalid
    value.

    Given a parent block containing `[0, MAX_BLOBS_PER_BLOCK]` blobs, test an invalid
    `excessDataGas` value by changing it by `[-TARGET_BLOBS_PER_BLOCK, TARGET_BLOBS_PER_BLOCK]`
    from the correct value.
    """
    if header_excess_data_gas is None:
        raise Exception("test case is badly formatted")

    if header_excess_data_gas == correct_excess_data_gas:
        raise Exception("invalid test case")

    blockchain_test(
        pre=pre,
        post={},
        blocks=blocks,
        genesis_environment=env,
        tag="-".join(
            [
                f"correct:{hex(correct_excess_data_gas)}",
                f"header:{hex(header_excess_data_gas)}",
            ]
        ),
    )

test_invalid_negative_excess_data_gas(blockchain_test, env, pre, blocks, correct_excess_data_gas, header_excess_data_gas)

Test rejection of blocks where the excessDataGas changes to the two's complement equivalent of the negative value after subtracting target blobs.

Reasoning is that the excessDataGas is a uint64, so it cannot be negative, and we test for a potential underflow here.

Source code in tests/cancun/eip4844_blobs/test_excess_data_gas.py
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
@pytest.mark.parametrize(
    "header_excess_data_gas",
    [(2**64 + (x * DATA_GAS_PER_BLOB)) for x in range(-TARGET_BLOBS_PER_BLOCK, 0)],
)
@pytest.mark.parametrize("parent_blobs", range(TARGET_BLOBS_PER_BLOCK))
@pytest.mark.parametrize("new_blobs", [1])
@pytest.mark.parametrize("parent_excess_blobs", range(TARGET_BLOBS_PER_BLOCK))
def test_invalid_negative_excess_data_gas(
    blockchain_test: BlockchainTestFiller,
    env: Environment,
    pre: Mapping[str, Account],
    blocks: List[Block],
    correct_excess_data_gas: int,
    header_excess_data_gas: Optional[int],
):
    """
    Test rejection of blocks where the `excessDataGas` changes to the two's
    complement equivalent of the negative value after subtracting target blobs.

    Reasoning is that the `excessDataGas` is a `uint64`, so it cannot be negative, and
    we test for a potential underflow here.
    """
    if header_excess_data_gas is None:
        raise Exception("test case is badly formatted")

    if header_excess_data_gas == correct_excess_data_gas:
        raise Exception("invalid test case")

    blockchain_test(
        pre=pre,
        post={},
        blocks=blocks,
        genesis_environment=env,
        tag="-".join(
            [
                f"correct:{hex(correct_excess_data_gas)}",
                f"header:{hex(header_excess_data_gas)}",
            ]
        ),
    )

test_invalid_non_multiple_excess_data_gas(blockchain_test, env, pre, blocks, correct_excess_data_gas, header_excess_data_gas)

Test rejection of blocks where the excessDataGas changes to a value that is not a multiple of DATA_GAS_PER_BLOB:

  • Parent block contains TARGET_BLOBS_PER_BLOCK + 1 blobs, but excessDataGas is off by ±1
  • Parent block contains TARGET_BLOBS_PER_BLOCK - 1 blobs, but excessDataGas is off by ±1
Source code in tests/cancun/eip4844_blobs/test_excess_data_gas.py
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
@pytest.mark.parametrize(
    "parent_blobs,header_excess_data_gas_delta",
    [
        (TARGET_BLOBS_PER_BLOCK + 1, 1),
        (TARGET_BLOBS_PER_BLOCK + 1, DATA_GAS_PER_BLOB - 1),
        (TARGET_BLOBS_PER_BLOCK - 1, -1),
        (TARGET_BLOBS_PER_BLOCK - 1, -(DATA_GAS_PER_BLOB - 1)),
    ],
)
@pytest.mark.parametrize("new_blobs", [1])
@pytest.mark.parametrize("parent_excess_blobs", [TARGET_BLOBS_PER_BLOCK + 1])
def test_invalid_non_multiple_excess_data_gas(
    blockchain_test: BlockchainTestFiller,
    env: Environment,
    pre: Mapping[str, Account],
    blocks: List[Block],
    correct_excess_data_gas: int,
    header_excess_data_gas: Optional[int],
):
    """
    Test rejection of blocks where the `excessDataGas` changes to a value that
    is not a multiple of `DATA_GAS_PER_BLOB`:

    - Parent block contains `TARGET_BLOBS_PER_BLOCK + 1` blobs, but `excessDataGas` is off by +/-1
    - Parent block contains `TARGET_BLOBS_PER_BLOCK - 1` blobs, but `excessDataGas` is off by +/-1
    """
    if header_excess_data_gas is None:
        raise Exception("test case is badly formatted")

    if header_excess_data_gas == correct_excess_data_gas:
        raise Exception("invalid test case")

    blockchain_test(
        pre=pre,
        post={},
        blocks=blocks,
        genesis_environment=env,
        tag="-".join(
            [
                f"correct:{hex(correct_excess_data_gas)}",
                f"header:{hex(header_excess_data_gas)}",
            ]
        ),
    )