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 or state_test
  • pre
  • env
  • block or txs

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

test_valid_blob_tx_combinations(blockchain_test, pre, env, 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.

Source code in tests/cancun/eip4844_blobs/test_blob_txs.py
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
@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,
    block: 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=[block],
        genesis_environment=env,
    )

test_invalid_tx_max_fee_per_blob_gas(blockchain_test, pre, env, block, non_zero_blob_gas_used_genesis_block)

Reject blocks with invalid blob txs due to:

  • tx max_fee_per_blob_gas is barely not enough
  • tx max_fee_per_blob_gas is zero
Source code in tests/cancun/eip4844_blobs/test_blob_txs.py
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
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
@pytest.mark.parametrize(
    "parent_excess_blobs,parent_blobs,tx_max_fee_per_blob_gas,tx_error",
    [
        # tx max_blob_gas_cost of the transaction is not enough
        pytest.param(
            SpecHelpers.get_min_excess_blobs_for_blob_gas_price(2) - 1,  # blob gas price is 1
            SpecHelpers.target_blobs_per_block() + 1,  # blob gas cost increases to 2
            1,  # tx max_blob_gas_cost is 1
            TransactionException.INSUFFICIENT_MAX_FEE_PER_BLOB_GAS,
            id="insufficient_max_fee_per_blob_gas",
        ),
        # tx max_blob_gas_cost of the transaction is zero, which is invalid
        pytest.param(
            0,  # blob gas price is 1
            0,  # blob gas cost stays put at 1
            0,  # tx max_blob_gas_cost is 0
            TransactionException.INSUFFICIENT_MAX_FEE_PER_BLOB_GAS,
            id="invalid_max_fee_per_blob_gas",
        ),
    ],
)
@pytest.mark.parametrize(
    "account_balance_modifier",
    [1_000_000_000],
)  # Extra balance to cover block blob gas cost
@pytest.mark.valid_from("Cancun")
def test_invalid_tx_max_fee_per_blob_gas(
    blockchain_test: BlockchainTestFiller,
    pre: Dict,
    env: Environment,
    block: Block,
    non_zero_blob_gas_used_genesis_block: Optional[Block],
):
    """
    Reject blocks with invalid blob txs due to:

    - tx max_fee_per_blob_gas is barely not enough
    - tx max_fee_per_blob_gas is zero
    """
    blocks = [block]
    if non_zero_blob_gas_used_genesis_block is not None:
        pre[TestAddress2] = Account(balance=10**9)
        blocks = [non_zero_blob_gas_used_genesis_block, block]
    blockchain_test(
        pre=pre,
        post={},
        blocks=blocks,
        genesis_environment=env,
    )

test_invalid_tx_max_fee_per_blob_gas_state(state_test_only, state_env, pre, txs)

Reject an invalid blob transaction due to:

  • tx max_fee_per_blob_gas is barely not enough
  • tx max_fee_per_blob_gas is zero
Source code in tests/cancun/eip4844_blobs/test_blob_txs.py
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
682
683
684
685
@pytest.mark.parametrize(
    "parent_excess_blobs,parent_blobs,tx_max_fee_per_blob_gas,tx_error",
    [
        # tx max_blob_gas_cost of the transaction is not enough
        pytest.param(
            SpecHelpers.get_min_excess_blobs_for_blob_gas_price(2) - 1,  # blob gas price is 1
            SpecHelpers.target_blobs_per_block() + 1,  # blob gas cost increases to 2
            1,  # tx max_blob_gas_cost is 1
            TransactionException.INSUFFICIENT_MAX_FEE_PER_BLOB_GAS,
            id="insufficient_max_fee_per_blob_gas",
        ),
        # tx max_blob_gas_cost of the transaction is zero, which is invalid
        pytest.param(
            0,  # blob gas price is 1
            0,  # blob gas cost stays put at 1
            0,  # tx max_blob_gas_cost is 0
            TransactionException.INSUFFICIENT_MAX_FEE_PER_BLOB_GAS,
            id="invalid_max_fee_per_blob_gas",
        ),
    ],
)
@pytest.mark.valid_from("Cancun")
def test_invalid_tx_max_fee_per_blob_gas_state(
    state_test_only: StateTestFiller,
    state_env: Environment,
    pre: Dict,
    txs: List[Transaction],
):
    """
    Reject an invalid blob transaction due to:

    - tx max_fee_per_blob_gas is barely not enough
    - tx max_fee_per_blob_gas is zero
    """
    assert len(txs) == 1
    state_test_only(
        pre=pre,
        post={},
        tx=txs[0],
        env=state_env,
    )

test_invalid_normal_gas(state_test, state_env, pre, txs, header_verify, rlp_modifier)

Reject an invalid blob transaction due to:

  • Sufficient max fee per blob gas, but insufficient max fee per gas
Source code in tests/cancun/eip4844_blobs/test_blob_txs.py
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
@pytest.mark.parametrize(
    "tx_max_fee_per_gas,tx_error",
    [
        # max blob gas is ok, but max fee per gas is less than base fee per gas
        (
            6,
            TransactionException.INSUFFICIENT_MAX_FEE_PER_GAS,
        ),
    ],
    ids=["insufficient_max_fee_per_gas"],
)
@pytest.mark.valid_from("Cancun")
def test_invalid_normal_gas(
    state_test: StateTestFiller,
    state_env: Environment,
    pre: Dict,
    txs: List[Transaction],
    header_verify: Optional[Header],
    rlp_modifier: Optional[Header],
):
    """
    Reject an invalid blob transaction due to:

    - Sufficient max fee per blob gas, but insufficient max fee per gas
    """
    assert len(txs) == 1
    state_test(
        pre=pre,
        post={},
        tx=txs[0],
        env=state_env,
        blockchain_test_header_verify=header_verify,
        blockchain_test_rlp_modifier=rlp_modifier,
    )

test_invalid_block_blob_count(blockchain_test, pre, env, 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.

Source code in tests/cancun/eip4844_blobs/test_blob_txs.py
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
@pytest.mark.parametrize(
    "blobs_per_tx",
    invalid_blob_combinations(),
)
@pytest.mark.parametrize(
    "tx_error", [TransactionException.TYPE_3_TX_MAX_BLOB_GAS_ALLOWANCE_EXCEEDED], ids=[""]
)
@pytest.mark.valid_from("Cancun")
def test_invalid_block_blob_count(
    blockchain_test: BlockchainTestFiller,
    pre: Dict,
    env: Environment,
    block: 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=[block],
        genesis_environment=env,
    )

test_insufficient_balance_blob_tx(state_test, state_env, pre, txs)

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

  • Transactions with max fee equal or higher than current block base fee
  • Transactions with and without priority fee
  • Transactions with and without value
  • Transactions with and without calldata
  • Transactions with max fee per blob gas lower or higher than the priority fee
Source code in tests/cancun/eip4844_blobs/test_blob_txs.py
754
755
756
757
758
759
760
761
762
763
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
@pytest.mark.parametrize(
    "tx_access_list",
    [[], [AccessList(address=100, storage_keys=[100, 200])]],
    ids=["no_access_list", "access_list"],
)
@pytest.mark.parametrize("tx_max_fee_per_gas", [7, 14])
@pytest.mark.parametrize("tx_max_priority_fee_per_gas", [0, 7])
@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_blob_gas", [1, 100, 10000])
@pytest.mark.parametrize("account_balance_modifier", [-1], ids=["exact_balance_minus_1"])
@pytest.mark.parametrize("tx_error", [TransactionException.INSUFFICIENT_ACCOUNT_FUNDS], ids=[""])
@pytest.mark.valid_from("Cancun")
def test_insufficient_balance_blob_tx(
    state_test: StateTestFiller,
    state_env: Environment,
    pre: Dict,
    txs: List[Transaction],
):
    """
    Reject blocks where user cannot afford the blob gas specified (but
    max_fee_per_gas would be enough for current block), including:

    - Transactions with max fee equal or higher than current block base fee
    - Transactions with and without priority fee
    - Transactions with and without value
    - Transactions with and without calldata
    - Transactions with max fee per blob gas lower or higher than the priority fee
    """
    assert len(txs) == 1
    state_test(
        pre=pre,
        post={},
        tx=txs[0],
        env=state_env,
    )

test_sufficient_balance_blob_tx(state_test, state_env, pre, txs)

Check that transaction is accepted when user can exactly afford the blob gas specified (and max_fee_per_gas would be enough for current block), including:

  • Transactions with max fee equal or higher than current block base fee
  • Transactions with and without priority fee
  • Transactions with and without value
  • Transactions with and without calldata
  • Transactions with max fee per blob gas lower or higher than the priority fee
Source code in tests/cancun/eip4844_blobs/test_blob_txs.py
796
797
798
799
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
830
831
832
833
@pytest.mark.parametrize(
    "tx_access_list",
    [[], [AccessList(address=100, storage_keys=[100, 200])]],
    ids=["no_access_list", "access_list"],
)
@pytest.mark.parametrize("tx_max_fee_per_gas", [7, 14])
@pytest.mark.parametrize("tx_max_priority_fee_per_gas", [0, 7])
@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_blob_gas", [1, 100, 10000])
@pytest.mark.valid_from("Cancun")
def test_sufficient_balance_blob_tx(
    state_test: StateTestFiller,
    state_env: Environment,
    pre: Dict,
    txs: List[Transaction],
):
    """
    Check that transaction is accepted when user can exactly afford the blob gas specified (and
    max_fee_per_gas would be enough for current block), including:

    - Transactions with max fee equal or higher than current block base fee
    - Transactions with and without priority fee
    - Transactions with and without value
    - Transactions with and without calldata
    - Transactions with max fee per blob gas lower or higher than the priority fee
    """
    assert len(txs) == 1
    state_test(
        pre=pre,
        post={},
        tx=txs[0],
        env=state_env,
    )

test_sufficient_balance_blob_tx_pre_fund_tx(blockchain_test, total_account_minimum_balance, env, pre, txs, header_verify)

Check that transaction is accepted when user can exactly afford the blob gas specified (and max_fee_per_gas would be enough for current block) because a funding transaction is prepended in the same block, including:

  • Transactions with max fee equal or higher than current block base fee
  • Transactions with and without priority fee
  • Transactions with and without value
  • Transactions with and without calldata
  • Transactions with max fee per blob gas lower or higher than the priority fee
Source code in tests/cancun/eip4844_blobs/test_blob_txs.py
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
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
@pytest.mark.parametrize(
    "tx_access_list",
    [[], [AccessList(address=100, storage_keys=[100, 200])]],
    ids=["no_access_list", "access_list"],
)
@pytest.mark.parametrize("tx_max_fee_per_gas", [7, 14])
@pytest.mark.parametrize("tx_max_priority_fee_per_gas", [0, 7])
@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_blob_gas", [1, 100, 10000])
@pytest.mark.valid_from("Cancun")
def test_sufficient_balance_blob_tx_pre_fund_tx(
    blockchain_test: BlockchainTestFiller,
    total_account_minimum_balance: int,
    env: Environment,
    pre: Dict,
    txs: List[Transaction],
    header_verify: Optional[Header],
):
    """
    Check that transaction is accepted when user can exactly afford the blob gas specified (and
    max_fee_per_gas would be enough for current block) because a funding transaction is
    prepended in the same block, including:

    - Transactions with max fee equal or higher than current block base fee
    - Transactions with and without priority fee
    - Transactions with and without value
    - Transactions with and without calldata
    - Transactions with max fee per blob gas lower or higher than the priority fee
    """
    pre = {
        TestPreFundingAddress: Account(balance=(21_000 * 100) + total_account_minimum_balance),
    }
    txs = [
        Transaction(
            ty=2,
            nonce=0,
            to=TestAddress,
            value=total_account_minimum_balance,
            gas_limit=21_000,
            max_fee_per_gas=100,
            max_priority_fee_per_gas=0,
            access_list=[],
            secret_key=TestPreFundingKey,
        )
    ] + txs
    blockchain_test(
        pre=pre,
        post={},
        blocks=[
            Block(
                txs=txs,
                header_verify=header_verify,
            )
        ],
        genesis_environment=env,
    )

test_insufficient_balance_blob_tx_combinations(blockchain_test, pre, env, 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
Source code in tests/cancun/eip4844_blobs/test_blob_txs.py
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
@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", [TransactionException.INSUFFICIENT_ACCOUNT_FUNDS], ids=[""])
@pytest.mark.valid_from("Cancun")
def test_insufficient_balance_blob_tx_combinations(
    blockchain_test: BlockchainTestFiller,
    pre: Dict,
    env: Environment,
    block: 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=[block],
        genesis_environment=env,
    )

test_invalid_tx_blob_count(state_test, state_env, pre, txs, header_verify, rlp_modifier)

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
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
@pytest.mark.parametrize(
    "blobs_per_tx,tx_error",
    [
        ([0], TransactionException.TYPE_3_TX_ZERO_BLOBS),
        (
            [SpecHelpers.max_blobs_per_block() + 1],
            TransactionException.TYPE_3_TX_BLOB_COUNT_EXCEEDED,
        ),
    ],
    ids=["too_few_blobs", "too_many_blobs"],
)
@pytest.mark.valid_from("Cancun")
def test_invalid_tx_blob_count(
    state_test: StateTestFiller,
    state_env: Environment,
    pre: Dict,
    txs: List[Transaction],
    header_verify: Optional[Header],
    rlp_modifier: Optional[Header],
):
    """
    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
    """
    assert len(txs) == 1
    state_test(
        pre=pre,
        post={},
        tx=txs[0],
        env=state_env,
        blockchain_test_header_verify=header_verify,
        blockchain_test_rlp_modifier=rlp_modifier,
    )

test_invalid_blob_hash_versioning_single_tx(state_test, state_env, pre, txs, header_verify, rlp_modifier)

Reject blob transactions with invalid blob hash version, including:

  • Transaction with single blob with invalid version
  • Transaction with multiple blobs all with invalid version
  • Transaction with multiple blobs either with invalid version
Source code in tests/cancun/eip4844_blobs/test_blob_txs.py
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
@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)
        ],
    ],
    ids=[
        "single_blob",
        "multiple_blobs",
        "multiple_blobs_single_bad_hash_1",
        "multiple_blobs_single_bad_hash_2",
    ],
)
@pytest.mark.parametrize(
    "tx_error", [TransactionException.TYPE_3_TX_INVALID_BLOB_VERSIONED_HASH], ids=[""]
)
@pytest.mark.valid_from("Cancun")
def test_invalid_blob_hash_versioning_single_tx(
    state_test: StateTestFiller,
    state_env: Environment,
    pre: Dict,
    txs: List[Transaction],
    header_verify: Optional[Header],
    rlp_modifier: Optional[Header],
):
    """
    Reject blob transactions with invalid blob hash version, including:

    - Transaction with single blob with invalid version
    - Transaction with multiple blobs all with invalid version
    - Transaction with multiple blobs either with invalid version
    """
    assert len(txs) == 1
    state_test(
        pre=pre,
        post={},
        tx=txs[0],
        env=state_env,
        blockchain_test_header_verify=header_verify,
        blockchain_test_rlp_modifier=rlp_modifier,
    )

test_invalid_blob_hash_versioning_multiple_txs(blockchain_test, pre, env, block)

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

  • 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
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
@pytest.mark.parametrize(
    "blob_hashes_per_tx",
    [
        [
            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_blob",
        "multiple_blobs",
        "multiple_blobs_single_bad_hash_1",
        "multiple_blobs_single_bad_hash_2",
    ],
)
@pytest.mark.parametrize(
    "tx_error", [TransactionException.TYPE_3_TX_INVALID_BLOB_VERSIONED_HASH], ids=[""]
)
@pytest.mark.valid_from("Cancun")
def test_invalid_blob_hash_versioning_multiple_txs(
    blockchain_test: BlockchainTestFiller,
    pre: Dict,
    env: Environment,
    block: Block,
):
    """
    Reject blocks that include blob transactions with invalid blob hash
    version, including:

    - 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=[block],
        genesis_environment=env,
    )

test_invalid_blob_tx_contract_creation(blockchain_test, pre, env, txs, header_verify)

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

Source code in tests/cancun/eip4844_blobs/test_blob_txs.py
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
@pytest.mark.parametrize(
    "tx_gas", [500_000], ids=[""]
)  # Increase gas to account for contract creation
@pytest.mark.valid_from("Cancun")
def test_invalid_blob_tx_contract_creation(
    blockchain_test: BlockchainTestFiller,
    pre: Dict,
    env: Environment,
    txs: List[Transaction],
    header_verify: Optional[Header],
):
    """
    Reject blocks that include blob transactions that have nil to value (contract creating).
    """
    assert len(txs) == 1
    assert txs[0].blob_versioned_hashes is not None and len(txs[0].blob_versioned_hashes) == 1
    # Replace the transaction with a contract creating one, only in the RLP version
    contract_creating_tx = replace(txs[0], to=None).with_signature_and_sender()
    txs[0] = replace(txs[0], rlp=contract_creating_tx.serialized_bytes())
    blockchain_test(
        pre=pre,
        post={},
        blocks=[
            Block(
                txs=txs,
                exception=TransactionException.TYPE_3_TX_CONTRACT_CREATION,
                header_verify=header_verify,
            )
        ],
        genesis_environment=env,
    )

test_blob_tx_attribute_opcodes(state_test, pre, opcode, state_env, txs, 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
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
@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(
    state_test: StateTestFiller,
    pre: Dict,
    opcode: Tuple[bytes, Storage.StorageDictType],
    state_env: Environment,
    txs: List[Transaction],
    destination_account: str,
):
    """
    Test opcodes that read transaction attributes work properly for blob type transactions:

    - ORIGIN
    - CALLER
    """
    assert len(txs) == 1
    code, storage = opcode
    pre[destination_account] = Account(code=code)
    post = {
        destination_account: Account(
            storage=storage,
        )
    }
    state_test(
        pre=pre,
        post=post,
        tx=txs[0],
        env=state_env,
    )

test_blob_tx_attribute_value_opcode(state_test, pre, opcode, state_env, txs, 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
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
@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(
    state_test: StateTestFiller,
    pre: Dict,
    opcode: Tuple[bytes, Storage.StorageDictType],
    state_env: Environment,
    txs: List[Transaction],
    tx_value: int,
    destination_account: str,
):
    """
    Test the VALUE opcode with different blob type transaction value amounts.
    """
    assert len(txs) == 1
    code, storage = opcode
    pre[destination_account] = Account(code=code)
    post = {
        destination_account: Account(
            storage=storage,
            balance=tx_value,
        )
    }
    state_test(
        pre=pre,
        post=post,
        tx=txs[0],
        env=state_env,
    )

test_blob_tx_attribute_calldata_opcodes(state_test, pre, opcode, state_env, txs, 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
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
@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(
    state_test: StateTestFiller,
    pre: Dict,
    opcode: Tuple[bytes, Storage.StorageDictType],
    state_env: Environment,
    txs: List[Transaction],
    destination_account: str,
):
    """
    Test calldata related opcodes to verify their behavior is not affected by blobs:

    - CALLDATALOAD
    - CALLDATASIZE
    - CALLDATACOPY
    """
    assert len(txs) == 1
    code, storage = opcode
    pre[destination_account] = Account(code=code)
    post = {
        destination_account: Account(
            storage=storage,
        )
    }
    state_test(
        pre=pre,
        post=post,
        tx=txs[0],
        env=state_env,
    )

test_blob_tx_attribute_gasprice_opcode(state_test, pre, opcode, state_env, txs, destination_account)

Test GASPRICE opcode to sanity check that the blob gas fee 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
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
@pytest.mark.parametrize("tx_max_priority_fee_per_gas", [0, 2])  # always below data fee
@pytest.mark.parametrize("tx_max_fee_per_blob_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(
    state_test: StateTestFiller,
    pre: Dict,
    opcode: Tuple[bytes, Storage.StorageDictType],
    state_env: Environment,
    txs: List[Transaction],
    destination_account: str,
):
    """
    Test GASPRICE opcode to sanity check that the blob gas fee does not affect
    its calculation:

    - No priority fee
    - Priority fee below data fee
    - Priority fee above data fee
    """
    assert len(txs) == 1
    code, storage = opcode
    pre[destination_account] = Account(code=code)
    post = {
        destination_account: Account(
            storage=storage,
        )
    }
    state_test(
        pre=pre,
        post=post,
        tx=txs[0],
        env=state_env,
    )

test_blob_type_tx_pre_fork(state_test, pre, txs)

Reject blocks with blob type transactions before Cancun fork.

Blocks sent by NewPayloadV2 (Shanghai) that contain blob type transactions, furthermore blobs field within NewPayloadV2 method must be computed as INVALID, due to an invalid block hash.

Source code in tests/cancun/eip4844_blobs/test_blob_txs.py
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
@pytest.mark.parametrize(
    [
        "blobs_per_tx",
        "parent_excess_blobs",
        "tx_max_fee_per_blob_gas",
        "tx_error",
    ],
    [
        (
            [0],
            None,
            1,
            TransactionException.TYPE_3_TX_PRE_FORK | TransactionException.TYPE_3_TX_ZERO_BLOBS,
        ),
        ([1], None, 1, TransactionException.TYPE_3_TX_PRE_FORK),
    ],
    ids=["no_blob_tx", "one_blob_tx"],
)
@pytest.mark.valid_at_transition_to("Cancun")
def test_blob_type_tx_pre_fork(
    state_test: StateTestFiller,
    pre: Dict,
    txs: List[Transaction],
):
    """
    Reject blocks with blob type transactions before Cancun fork.

    Blocks sent by NewPayloadV2 (Shanghai) that contain blob type transactions, furthermore blobs
    field within NewPayloadV2 method must be computed as INVALID, due to an invalid block hash.
    """
    assert len(txs) == 1
    state_test(
        pre=pre,
        post={},
        tx=txs[0],
        env=Environment(),  # `env` fixture has blob fields
    )