|
14 | 14 |
|
15 | 15 | from ethereum_test_base_types.base_types import Bytes |
16 | 16 | from ethereum_test_forks import Fork |
| 17 | +from ethereum_test_specs.tests.test_fixtures import TransactionType |
17 | 18 | from ethereum_test_tools import ( |
18 | 19 | Address, |
19 | 20 | Alloc, |
|
23 | 24 | Environment, |
24 | 25 | StateTestFiller, |
25 | 26 | Transaction, |
| 27 | + add_kzg_version, |
26 | 28 | ) |
27 | 29 | from ethereum_test_tools.code.generators import While |
28 | 30 | from ethereum_test_tools.vm.opcode import Opcodes as Op |
@@ -823,6 +825,62 @@ def select_shift_amount(shift_fn, v): |
823 | 825 | ) |
824 | 826 |
|
825 | 827 |
|
| 828 | +@pytest.mark.valid_from("Cancun") |
| 829 | +@pytest.mark.parametrize( |
| 830 | + "blob_index, blobs_present", |
| 831 | + [ |
| 832 | + pytest.param(0, 0, id="no blobs"), |
| 833 | + pytest.param(0, 1, id="one blob and accessed"), |
| 834 | + pytest.param(1, 1, id="one blob but access non-existent index"), |
| 835 | + pytest.param(5, 6, id="six blobs, access latest"), |
| 836 | + ], |
| 837 | +) |
| 838 | +def test_worst_blobhash( |
| 839 | + fork: Fork, |
| 840 | + state_test: StateTestFiller, |
| 841 | + pre: Alloc, |
| 842 | + blob_index: int, |
| 843 | + blobs_present: bool, |
| 844 | +): |
| 845 | + """Test running a block with as many BLOBHASH instructions as possible.""" |
| 846 | + env = Environment() |
| 847 | + |
| 848 | + code_prefix = Op.PUSH1(blob_index) + Op.JUMPDEST |
| 849 | + code_suffix = Op.JUMP(len(code_prefix) - 1) |
| 850 | + loop_iter = Op.POP(Op.BLOBHASH(Op.DUP1)) |
| 851 | + code_body_len = (MAX_CODE_SIZE - len(code_prefix) - len(code_suffix)) // len(loop_iter) |
| 852 | + code_body = loop_iter * code_body_len |
| 853 | + code = code_prefix + code_body + code_suffix |
| 854 | + assert len(code) <= MAX_CODE_SIZE |
| 855 | + |
| 856 | + tx_type = TransactionType.LEGACY |
| 857 | + blob_versioned_hashes = None |
| 858 | + max_fee_per_blob_gas = None |
| 859 | + if blobs_present > 0: |
| 860 | + tx_type = TransactionType.BLOB_TRANSACTION |
| 861 | + max_fee_per_blob_gas = fork.min_base_fee_per_blob_gas() |
| 862 | + blob_versioned_hashes = add_kzg_version( |
| 863 | + [i.to_bytes() * 32 for i in range(blobs_present)], |
| 864 | + BlobsSpec.BLOB_COMMITMENT_VERSION_KZG, |
| 865 | + ) |
| 866 | + |
| 867 | + tx = Transaction( |
| 868 | + ty=tx_type, |
| 869 | + to=pre.deploy_contract(code=code), |
| 870 | + gas_limit=env.gas_limit, |
| 871 | + max_fee_per_blob_gas=max_fee_per_blob_gas, |
| 872 | + blob_versioned_hashes=blob_versioned_hashes, |
| 873 | + sender=pre.fund_eoa(), |
| 874 | + ) |
| 875 | + |
| 876 | + state_test( |
| 877 | + env=env, |
| 878 | + pre=pre, |
| 879 | + post={}, |
| 880 | + tx=tx, |
| 881 | + ) |
| 882 | + |
| 883 | + |
826 | 884 | @pytest.mark.valid_from("Cancun") |
827 | 885 | @pytest.mark.parametrize("mod_bits", [255, 191, 127, 63]) |
828 | 886 | @pytest.mark.parametrize("op", [Op.MOD, Op.SMOD]) |
|
0 commit comments