Skip to content

Test Blob Txs

Documentation for tests/cancun/eip4844_blobs/test_blob_txs.py.

Generate fixtures for these test cases for Cancun with:

Cancun only:

fill -v tests/cancun/eip4844_blobs/test_blob_txs.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_blob_txs.py --until=Cancun --evm-bin=/path/to/evm-tool-dev-version

Tests blob type transactions for EIP-4844: Shard Blob Transactions

Test blob type transactions 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
  • pre
  • env
  • blocks

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

Spec dataclass

Parameters from the EIP-4844 specifications as defined at https://eips.ethereum.org/EIPS/eip-4844#parameters

If the parameter is not currently used within the tests, it is commented out.

Source code in tests/cancun/eip4844_blobs/spec.py
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
@dataclass(frozen=True)
class Spec:
    """
    Parameters from the EIP-4844 specifications as defined at
    https://eips.ethereum.org/EIPS/eip-4844#parameters

    If the parameter is not currently used within the tests, it is commented
    out.
    """

    BLOB_TX_TYPE = 0x03
    FIELD_ELEMENTS_PER_BLOB = 4096
    BLS_MODULUS = 0x73EDA753299D7D483339D80809A1D80553BDA402FFFE5BFEFFFFFFFF00000001
    BLOB_COMMITMENT_VERSION_KZG = 1
    POINT_EVALUATION_PRECOMPILE_ADDRESS = 20
    POINT_EVALUATION_PRECOMPILE_GAS = 50_000
    MAX_DATA_GAS_PER_BLOCK = 786432
    TARGET_DATA_GAS_PER_BLOCK = 393216
    MIN_DATA_GASPRICE = 1
    DATA_GASPRICE_UPDATE_FRACTION = 3338477
    # MAX_VERSIONED_HASHES_LIST_SIZE = 2**24
    # MAX_CALLDATA_SIZE = 2**24
    # MAX_ACCESS_LIST_SIZE = 2**24
    # MAX_ACCESS_LIST_STORAGE_KEYS = 2**24
    # MAX_TX_WRAP_COMMITMENTS = 2**12
    # LIMIT_BLOBS_PER_TX = 2**12
    DATA_GAS_PER_BLOB = 2**17
    HASH_OPCODE_BYTE = 0x49
    HASH_GAS_COST = 3

    @classmethod
    def kzg_to_versioned_hash(
        cls,
        kzg_commitment: bytes | int,  # 48 bytes
        blob_commitment_version_kzg: Optional[bytes | int] = None,
    ) -> bytes:
        """
        Calculates the versioned hash for a given KZG commitment.
        """
        if blob_commitment_version_kzg is None:
            blob_commitment_version_kzg = cls.BLOB_COMMITMENT_VERSION_KZG
        if isinstance(kzg_commitment, int):
            kzg_commitment = kzg_commitment.to_bytes(48, "big")
        if isinstance(blob_commitment_version_kzg, int):
            blob_commitment_version_kzg = blob_commitment_version_kzg.to_bytes(1, "big")
        return blob_commitment_version_kzg + sha256(kzg_commitment).digest()[1:]

    @classmethod
    def fake_exponential(cls, factor: int, numerator: int, denominator: int) -> int:
        """
        Used to calculate the data gas cost.
        """
        i = 1
        output = 0
        numerator_accumulator = factor * denominator
        while numerator_accumulator > 0:
            output += numerator_accumulator
            numerator_accumulator = (numerator_accumulator * numerator) // (denominator * i)
            i += 1
        return output // denominator

    @classmethod
    def calc_excess_data_gas(cls, parent: BlockHeaderDataGasFields) -> int:
        """
        Calculate the excess data gas for a block given the excess data gas
        and data gas used from the parent block header.
        """
        if parent.excess_data_gas + parent.data_gas_used < cls.TARGET_DATA_GAS_PER_BLOCK:
            return 0
        else:
            return parent.excess_data_gas + parent.data_gas_used - cls.TARGET_DATA_GAS_PER_BLOCK

    # Note: Currently unused.
    # @classmethod
    # def get_total_data_gas(cls, tx: Transaction) -> int:
    #     """
    #     Calculate the total data gas for a transaction.
    #     """
    #     if tx.blob_versioned_hashes is None:
    #         return 0
    #     return cls.DATA_GAS_PER_BLOB * len(tx.blob_versioned_hashes)

    @classmethod
    def get_data_gasprice(cls, *, excess_data_gas: int) -> int:
        """
        Calculate the data gas price from the excess.
        """
        return cls.fake_exponential(
            cls.MIN_DATA_GASPRICE,
            excess_data_gas,
            cls.DATA_GASPRICE_UPDATE_FRACTION,
        )

SpecHelpers dataclass

Define parameters and helper functions that are tightly coupled to the 4844 spec but not strictly part of it.

Source code in tests/cancun/eip4844_blobs/spec.py
127
128
129
130
131
132
133
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
@dataclass(frozen=True)
class SpecHelpers:
    """
    Define parameters and helper functions that are tightly coupled to the 4844
    spec but not strictly part of it.
    """

    BYTES_PER_FIELD_ELEMENT = 32

    @classmethod
    def max_blobs_per_block(cls) -> int:  # MAX_BLOBS_PER_BLOCK =
        """
        Returns the maximum number of blobs per block.
        """
        return Spec.MAX_DATA_GAS_PER_BLOCK // Spec.DATA_GAS_PER_BLOB

    @classmethod
    def target_blobs_per_block(cls) -> int:
        """
        Returns the target number of blobs per block.
        """
        return Spec.TARGET_DATA_GAS_PER_BLOCK // Spec.DATA_GAS_PER_BLOB

    @classmethod
    def calc_excess_data_gas_from_blob_count(
        cls, parent_excess_data_gas: int, parent_blob_count: int
    ) -> int:
        """
        Calculate the excess data gas for a block given the parent excess data gas
        and the number of blobs in the block.
        """
        parent_consumed_data_gas = parent_blob_count * Spec.DATA_GAS_PER_BLOB
        return Spec.calc_excess_data_gas(
            BlockHeaderDataGasFields(parent_excess_data_gas, parent_consumed_data_gas)
        )

    @classmethod
    def get_min_excess_data_gas_for_data_gas_price(cls, data_gas_price: int) -> int:
        """
        Gets the minimum required excess data gas value to get a given data gas cost in a block
        """
        current_excess_data_gas = 0
        current_data_gas_price = 1
        while current_data_gas_price < data_gas_price:
            current_excess_data_gas += Spec.DATA_GAS_PER_BLOB
            current_data_gas_price = Spec.get_data_gasprice(
                excess_data_gas=current_excess_data_gas
            )
        return current_excess_data_gas

    @classmethod
    def get_min_excess_data_blobs_for_data_gas_price(cls, data_gas_price: int) -> int:
        """
        Gets the minimum required excess data blobs to get a given data gas cost in a block
        """
        return (
            cls.get_min_excess_data_gas_for_data_gas_price(data_gas_price)
            // Spec.DATA_GAS_PER_BLOB
        )

test_valid_blob_tx_combinations(blockchain_test, pre, env, blocks)

Test all valid blob combinations in a single block, assuming a given value of MAX_BLOBS_PER_BLOCK.

This assumes a block can include from 1 and up to MAX_BLOBS_PER_BLOCK transactions where all transactions contain at least 1 blob, and the sum of all blobs in a block is at most MAX_BLOBS_PER_BLOCK.

This test is parametrized with all valid blob transaction combinations for a given block, and therefore if value of MAX_BLOBS_PER_BLOCK changes, this test is automatically updated.

Source code in tests/cancun/eip4844_blobs/test_blob_txs.py
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
@pytest.mark.parametrize(
    "blobs_per_tx",
    all_valid_blob_combinations(),
)
@pytest.mark.valid_from("Cancun")
def test_valid_blob_tx_combinations(
    blockchain_test: BlockchainTestFiller,
    pre: Dict,
    env: Environment,
    blocks: List[Block],
):
    """
    Test all valid blob combinations in a single block, assuming a given value of
    `MAX_BLOBS_PER_BLOCK`.

    This assumes a block can include from 1 and up to `MAX_BLOBS_PER_BLOCK` transactions where all
    transactions contain at least 1 blob, and the sum of all blobs in a block is at
    most `MAX_BLOBS_PER_BLOCK`.

    This test is parametrized with all valid blob transaction combinations for a given block, and
    therefore if value of `MAX_BLOBS_PER_BLOCK` changes, this test is automatically updated.
    """
    blockchain_test(
        pre=pre,
        post={},
        blocks=blocks,
        genesis_environment=env,
    )

test_invalid_tx_max_fee_per_data_gas(blockchain_test, pre, env, blocks, parent_blobs, block_intermediate)

Reject blocks with invalid blob txs due to:

  • tx max_fee_per_data_gas is barely not enough
  • tx max_fee_per_data_gas is zero
Source code in tests/cancun/eip4844_blobs/test_blob_txs.py
417
418
419
420
421
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
455
456
457
458
459
460
461
462
@pytest.mark.parametrize(
    "parent_excess_blobs,parent_blobs,tx_max_fee_per_data_gas,tx_error",
    [
        # tx max_data_gas_cost of the transaction is not enough
        (
            SpecHelpers.get_min_excess_data_blobs_for_data_gas_price(2) - 1,  # data gas price is 1
            SpecHelpers.target_blobs_per_block() + 1,  # data gas cost increases to 2
            1,  # tx max_data_gas_cost is 1
            "insufficient max fee per data gas",
        ),
        # tx max_data_gas_cost of the transaction is zero, which is invalid
        (
            0,  # data gas price is 1
            0,  # data gas cost stays put at 1
            0,  # tx max_data_gas_cost is 0
            "invalid max fee per data gas",
        ),
    ],
    ids=["insufficient_max_fee_per_data_gas", "invalid_max_fee_per_data_gas"],
)
@pytest.mark.valid_from("Cancun")
def test_invalid_tx_max_fee_per_data_gas(
    blockchain_test: BlockchainTestFiller,
    pre: Dict,
    env: Environment,
    blocks: List[Block],
    parent_blobs: int,
    block_intermediate: Block,
):
    """
    Reject blocks with invalid blob txs due to:

    - tx max_fee_per_data_gas is barely not enough
    - tx max_fee_per_data_gas is zero
    """
    if parent_blobs:
        pre[TestAddress2] = Account(balance=10**9)
        blocks.insert(0, block_intermediate)
        if env.excess_data_gas is not None:
            env.excess_data_gas += Spec.TARGET_DATA_GAS_PER_BLOCK
    blockchain_test(
        pre=pre,
        post={},
        blocks=blocks,
        genesis_environment=env,
    )

test_invalid_normal_gas(blockchain_test, pre, env, blocks)

Reject blocks with invalid blob txs due to:

  • Sufficient max fee per data gas, but insufficient max fee per gas
Source code in tests/cancun/eip4844_blobs/test_blob_txs.py
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
@pytest.mark.parametrize(
    "tx_max_fee_per_gas,tx_error",
    [
        # max data gas is ok, but max fee per gas is less than base fee per gas
        (
            6,
            "insufficient max fee per gas",
        ),
    ],
    ids=["insufficient_max_fee_per_gas"],
)
@pytest.mark.valid_from("Cancun")
def test_invalid_normal_gas(
    blockchain_test: BlockchainTestFiller,
    pre: Dict,
    env: Environment,
    blocks: List[Block],
):
    """
    Reject blocks with invalid blob txs due to:

    - Sufficient max fee per data gas, but insufficient max fee per gas
    """
    blockchain_test(
        pre=pre,
        post={},
        blocks=blocks,
        genesis_environment=env,
    )

test_invalid_block_blob_count(blockchain_test, pre, env, blocks)

Test all invalid blob combinations in a single block, where the sum of all blobs in a block is at MAX_BLOBS_PER_BLOCK + 1.

This test is parametrized with all blob transaction combinations exceeding MAX_BLOBS_PER_BLOCK by one for a given block, and therefore if value of MAX_BLOBS_PER_BLOCK changes, this test is automatically updated.

Source code in tests/cancun/eip4844_blobs/test_blob_txs.py
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
@pytest.mark.parametrize(
    "blobs_per_tx",
    invalid_blob_combinations(),
)
@pytest.mark.parametrize("tx_error", ["invalid_blob_count"])
@pytest.mark.valid_from("Cancun")
def test_invalid_block_blob_count(
    blockchain_test: BlockchainTestFiller,
    pre: Dict,
    env: Environment,
    blocks: List[Block],
):
    """
    Test all invalid blob combinations in a single block, where the sum of all blobs in a block is
    at `MAX_BLOBS_PER_BLOCK + 1`.

    This test is parametrized with all blob transaction combinations exceeding
    `MAX_BLOBS_PER_BLOCK` by one for a given block, and
    therefore if value of `MAX_BLOBS_PER_BLOCK` changes, this test is automatically updated.
    """
    blockchain_test(
        pre=pre,
        post={},
        blocks=blocks,
        genesis_environment=env,
    )

test_insufficient_balance_blob_tx(blockchain_test, pre, env, blocks)

Reject blocks where user cannot afford the data gas specified (but max_fee_per_gas would be enough for current block), including:

  • Transactions with and without priority fee
  • Transactions with and without value
  • Transactions with and without calldata
  • Transactions with max fee per data gas lower or higher than the priority fee
Source code in tests/cancun/eip4844_blobs/test_blob_txs.py
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
@pytest.mark.parametrize("tx_max_priority_fee_per_gas", [0, 8])
@pytest.mark.parametrize("tx_value", [0, 1])
@pytest.mark.parametrize(
    "tx_calldata",
    [b"", b"\x00", b"\x01"],
    ids=["no_calldata", "single_zero_calldata", "single_one_calldata"],
)
@pytest.mark.parametrize("tx_max_fee_per_data_gas", [1, 100, 10000])
@pytest.mark.parametrize("account_balance_modifier", [-1], ids=["exact_balance_minus_1"])
@pytest.mark.parametrize("tx_error", ["insufficient_account_balance"], ids=[""])
@pytest.mark.valid_from("Cancun")
def test_insufficient_balance_blob_tx(
    blockchain_test: BlockchainTestFiller,
    pre: Dict,
    env: Environment,
    blocks: List[Block],
):
    """
    Reject blocks where user cannot afford the data gas specified (but
    max_fee_per_gas would be enough for current block), including:

    - Transactions with and without priority fee
    - Transactions with and without value
    - Transactions with and without calldata
    - Transactions with max fee per data gas lower or higher than the priority fee
    """
    blockchain_test(
        pre=pre,
        post={},
        blocks=blocks,
        genesis_environment=env,
    )

test_insufficient_balance_blob_tx_combinations(blockchain_test, pre, env, blocks)

Reject all valid blob transaction combinations in a block, but block is invalid due to:

  • The amount of blobs is correct but the user cannot afford the transaction total cost
Source code in tests/cancun/eip4844_blobs/test_blob_txs.py
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
@pytest.mark.parametrize(
    "blobs_per_tx",
    all_valid_blob_combinations(),
)
@pytest.mark.parametrize("account_balance_modifier", [-1], ids=["exact_balance_minus_1"])
@pytest.mark.parametrize("tx_error", ["insufficient_account_balance"], ids=[""])
@pytest.mark.valid_from("Cancun")
def test_insufficient_balance_blob_tx_combinations(
    blockchain_test: BlockchainTestFiller,
    pre: Dict,
    env: Environment,
    blocks: List[Block],
):
    """
    Reject all valid blob transaction combinations in a block, but block is invalid due to:

    - The amount of blobs is correct but the user cannot afford the
            transaction total cost
    """
    blockchain_test(
        pre=pre,
        post={},
        blocks=blocks,
        genesis_environment=env,
    )

test_invalid_tx_blob_count(blockchain_test, pre, env, blocks)

Reject blocks that include blob transactions with invalid blob counts:

  • blob count == 0 in type 3 transaction
  • blob count > MAX_BLOBS_PER_BLOCK in type 3 transaction
Source code in tests/cancun/eip4844_blobs/test_blob_txs.py
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(
    "blobs_per_tx,tx_error",
    [
        ([0], "zero_blob_tx"),
        ([SpecHelpers.max_blobs_per_block() + 1], "too_many_blobs_tx"),
    ],
    ids=["too_few_blobs", "too_many_blobs"],
)
@pytest.mark.valid_from("Cancun")
def test_invalid_tx_blob_count(
    blockchain_test: BlockchainTestFiller,
    pre: Dict,
    env: Environment,
    blocks: List[Block],
):
    """
    Reject blocks that include blob transactions with invalid blob counts:

    - `blob count == 0` in type 3 transaction
    - `blob count > MAX_BLOBS_PER_BLOCK` in type 3 transaction
    """
    blockchain_test(
        pre=pre,
        post={},
        blocks=blocks,
        genesis_environment=env,
    )

test_invalid_blob_hash_versioning(blockchain_test, pre, env, blocks)

Reject blocks that include blob transactions with invalid blob hash version, including:

  • Single blob transaction with single blob with invalid version
  • Single blob transaction with multiple blobs all with invalid version
  • Single blob transaction with multiple blobs either with invalid version
  • Multiple blob transactions with single blob all with invalid version
  • Multiple blob transactions with multiple blobs all with invalid version
  • Multiple blob transactions with multiple blobs only one with invalid version
Source code in tests/cancun/eip4844_blobs/test_blob_txs.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
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
@pytest.mark.parametrize(
    "blob_hashes_per_tx",
    [
        [[to_hash_bytes(1)]],
        [[to_hash_bytes(x) for x in range(2)]],
        [
            add_kzg_version([to_hash_bytes(1)], Spec.BLOB_COMMITMENT_VERSION_KZG)
            + [to_hash_bytes(2)]
        ],
        [
            [to_hash_bytes(1)]
            + add_kzg_version([to_hash_bytes(2)], Spec.BLOB_COMMITMENT_VERSION_KZG)
        ],
        [
            add_kzg_version([to_hash_bytes(1)], Spec.BLOB_COMMITMENT_VERSION_KZG),
            [to_hash_bytes(2)],
        ],
        [
            add_kzg_version([to_hash_bytes(1)], Spec.BLOB_COMMITMENT_VERSION_KZG),
            [to_hash_bytes(x) for x in range(1, 3)],
        ],
        [
            add_kzg_version([to_hash_bytes(1)], Spec.BLOB_COMMITMENT_VERSION_KZG),
            [to_hash_bytes(2)]
            + add_kzg_version([to_hash_bytes(3)], Spec.BLOB_COMMITMENT_VERSION_KZG),
        ],
        [
            add_kzg_version([to_hash_bytes(1)], Spec.BLOB_COMMITMENT_VERSION_KZG),
            add_kzg_version([to_hash_bytes(2)], Spec.BLOB_COMMITMENT_VERSION_KZG),
            [to_hash_bytes(3)],
        ],
    ],
    ids=[
        "single_tx_single_blob",
        "single_tx_multiple_blobs",
        "single_tx_multiple_blobs_single_bad_hash_1",
        "single_tx_multiple_blobs_single_bad_hash_2",
        "multiple_txs_single_blob",
        "multiple_txs_multiple_blobs",
        "multiple_txs_multiple_blobs_single_bad_hash_1",
        "multiple_txs_multiple_blobs_single_bad_hash_2",
    ],
)
@pytest.mark.parametrize("tx_error", ["invalid_versioned_hash"], ids=[""])
@pytest.mark.valid_from("Cancun")
def test_invalid_blob_hash_versioning(
    blockchain_test: BlockchainTestFiller,
    pre: Dict,
    env: Environment,
    blocks: List[Block],
):
    """
    Reject blocks that include blob transactions with invalid blob hash
    version, including:

    - Single blob transaction with single blob with invalid version
    - Single blob transaction with multiple blobs all with invalid version
    - Single blob transaction with multiple blobs either with invalid version
    - Multiple blob transactions with single blob all with invalid version
    - Multiple blob transactions with multiple blobs all with invalid version
    - Multiple blob transactions with multiple blobs only one with invalid version
    """
    blockchain_test(
        pre=pre,
        post={},
        blocks=blocks,
        genesis_environment=env,
    )

test_invalid_blob_tx_contract_creation(blockchain_test, pre, env, blocks)

Reject blocks that include blob transactions that have nil to value (contract creating).

Source code in tests/cancun/eip4844_blobs/test_blob_txs.py
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
@pytest.mark.parametrize(
    "destination_account,tx_error", [(None, "no_contract_creating_blob_txs")], ids=[""]
)
@pytest.mark.valid_from("Cancun")
def test_invalid_blob_tx_contract_creation(
    blockchain_test: BlockchainTestFiller,
    pre: Dict,
    env: Environment,
    blocks: List[Block],
):
    """
    Reject blocks that include blob transactions that have nil to value (contract creating).
    """
    blockchain_test(
        pre=pre,
        post={},
        blocks=blocks,
        genesis_environment=env,
    )

test_blob_tx_attribute_opcodes(blockchain_test, pre, opcode, env, blocks, destination_account)

Test opcodes that read transaction attributes work properly for blob type transactions:

  • ORIGIN
  • CALLER
Source code in tests/cancun/eip4844_blobs/test_blob_txs.py
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
@pytest.mark.parametrize(
    "opcode",
    [Op.ORIGIN, Op.CALLER],
    indirect=["opcode"],
)
@pytest.mark.parametrize("tx_gas", [500_000])
@pytest.mark.valid_from("Cancun")
def test_blob_tx_attribute_opcodes(
    blockchain_test: BlockchainTestFiller,
    pre: Dict,
    opcode: Tuple[bytes, Storage.StorageDictType],
    env: Environment,
    blocks: List[Block],
    destination_account: str,
):
    """
    Test opcodes that read transaction attributes work properly for blob type transactions:

    - ORIGIN
    - CALLER
    """
    code, storage = opcode
    pre[destination_account] = Account(code=code)
    post = {
        destination_account: Account(
            storage=storage,
        )
    }
    blockchain_test(
        pre=pre,
        post=post,
        blocks=blocks,
        genesis_environment=env,
    )

test_blob_tx_attribute_value_opcode(blockchain_test, pre, opcode, env, blocks, tx_value, destination_account)

Test the VALUE opcode with different blob type transaction value amounts.

Source code in tests/cancun/eip4844_blobs/test_blob_txs.py
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
@pytest.mark.parametrize("opcode", [Op.CALLVALUE], indirect=["opcode"])
@pytest.mark.parametrize("tx_value", [0, 1, int(1e18)])
@pytest.mark.parametrize("tx_gas", [500_000])
@pytest.mark.valid_from("Cancun")
def test_blob_tx_attribute_value_opcode(
    blockchain_test: BlockchainTestFiller,
    pre: Dict,
    opcode: Tuple[bytes, Storage.StorageDictType],
    env: Environment,
    blocks: List[Block],
    tx_value: int,
    destination_account: str,
):
    """
    Test the VALUE opcode with different blob type transaction value amounts.
    """
    code, storage = opcode
    pre[destination_account] = Account(code=code)
    post = {
        destination_account: Account(
            storage=storage,
            balance=tx_value,
        )
    }
    blockchain_test(
        pre=pre,
        post=post,
        blocks=blocks,
        genesis_environment=env,
    )

test_blob_tx_attribute_calldata_opcodes(blockchain_test, pre, opcode, env, blocks, destination_account)

Test calldata related opcodes to verify their behavior is not affected by blobs:

  • CALLDATALOAD
  • CALLDATASIZE
  • CALLDATACOPY
Source code in tests/cancun/eip4844_blobs/test_blob_txs.py
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
@pytest.mark.parametrize(
    "opcode",
    [
        Op.CALLDATALOAD,
        Op.CALLDATASIZE,
        Op.CALLDATACOPY,
    ],
    indirect=True,
)
@pytest.mark.parametrize(
    "tx_calldata",
    [
        b"",
        b"\x01",
        b"\x00\x01" * 16,
    ],
    ids=["empty", "single_byte", "word"],
)
@pytest.mark.parametrize("tx_gas", [500_000])
@pytest.mark.valid_from("Cancun")
def test_blob_tx_attribute_calldata_opcodes(
    blockchain_test: BlockchainTestFiller,
    pre: Dict,
    opcode: Tuple[bytes, Storage.StorageDictType],
    env: Environment,
    blocks: List[Block],
    destination_account: str,
):
    """
    Test calldata related opcodes to verify their behavior is not affected by blobs:

    - CALLDATALOAD
    - CALLDATASIZE
    - CALLDATACOPY
    """
    code, storage = opcode
    pre[destination_account] = Account(code=code)
    post = {
        destination_account: Account(
            storage=storage,
        )
    }
    blockchain_test(
        pre=pre,
        post=post,
        blocks=blocks,
        genesis_environment=env,
    )

test_blob_tx_attribute_gasprice_opcode(blockchain_test, pre, opcode, env, blocks, destination_account)

Test GASPRICE opcode to sanity check that the data fee per gas does not affect its calculation:

  • No priority fee
  • Priority fee below data fee
  • Priority fee above data fee
Source code in tests/cancun/eip4844_blobs/test_blob_txs.py
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
@pytest.mark.parametrize("tx_max_priority_fee_per_gas", [0, 2])  # always below data fee
@pytest.mark.parametrize("tx_max_fee_per_data_gas", [1, 3])  # normal and above priority fee
@pytest.mark.parametrize("tx_max_fee_per_gas", [100])  # always above priority fee
@pytest.mark.parametrize("opcode", [Op.GASPRICE], indirect=True)
@pytest.mark.parametrize("tx_gas", [500_000])
@pytest.mark.valid_from("Cancun")
def test_blob_tx_attribute_gasprice_opcode(
    blockchain_test: BlockchainTestFiller,
    pre: Dict,
    opcode: Tuple[bytes, Storage.StorageDictType],
    env: Environment,
    blocks: List[Block],
    destination_account: str,
):
    """
    Test GASPRICE opcode to sanity check that the data fee per gas does not affect
    its calculation:

    - No priority fee
    - Priority fee below data fee
    - Priority fee above data fee
    """
    code, storage = opcode
    pre[destination_account] = Account(code=code)
    post = {
        destination_account: Account(
            storage=storage,
        )
    }
    blockchain_test(
        pre=pre,
        post=post,
        blocks=blocks,
        genesis_environment=env,
    )

test_blob_type_tx_pre_fork(blockchain_test, pre, blocks)

Reject blocks with blob type transactions before Cancun fork

Source code in tests/cancun/eip4844_blobs/test_blob_txs.py
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
@pytest.mark.parametrize(
    [
        "blobs_per_tx",
        "parent_excess_blobs",
        "tx_max_fee_per_data_gas",
        "tx_error",
    ],
    [
        ([0], None, 1, "tx_type_3_not_allowed_yet"),
        ([1], None, 1, "tx_type_3_not_allowed_yet"),
    ],
    ids=["no_blob_tx", "one_blob_tx"],
)
@pytest.mark.valid_at_transition_to("Cancun")
def test_blob_type_tx_pre_fork(
    blockchain_test: BlockchainTestFiller,
    pre: Dict,
    blocks: List[Block],
):
    """
    Reject blocks with blob type transactions before Cancun fork
    """
    blockchain_test(
        pre=pre,
        post={},
        blocks=blocks,
        genesis_environment=Environment(),  # `env` fixture has blob fields
    )