22
22
Block ,
23
23
BlockchainTestFiller ,
24
24
Bytecode ,
25
+ Environment ,
25
26
StateTestFiller ,
26
27
Transaction ,
27
28
add_kzg_version ,
@@ -2727,12 +2728,14 @@ def test_worst_return_revert(
2727
2728
2728
2729
@pytest .mark .valid_from ("Osaka" )
2729
2730
def test_worst_clz_same_input (
2730
- state_test : StateTestFiller , blockchain_test : BlockchainTestFiller , pre : Alloc , fork : Fork
2731
+ blockchain_test : BlockchainTestFiller ,
2732
+ pre : Alloc ,
2733
+ fork : Fork ,
2734
+ gas_benchmark_value : int ,
2735
+ env : Environment ,
2731
2736
):
2732
2737
"""Test running a block with as many CLZ with same input as possible."""
2733
- env = Environment ()
2734
- attack_gas_limit = env .gas_limit
2735
- tx_gas_limit = fork .transaction_gas_limit_cap ()
2738
+ tx_gas_limit = fork .transaction_gas_limit_cap () or env .gas_limit
2736
2739
2737
2740
magic_value = 248 # CLZ(248) = 248
2738
2741
@@ -2743,42 +2746,38 @@ def test_worst_clz_same_input(
2743
2746
2744
2747
code_address = pre .deploy_contract (code = code )
2745
2748
2746
- tx = Transaction (
2747
- to = code_address ,
2748
- gas_limit = tx_gas_limit if tx_gas_limit else attack_gas_limit ,
2749
- sender = pre .fund_eoa (),
2750
- )
2749
+ sender = pre .fund_eoa ()
2750
+ tx_count = gas_benchmark_value // tx_gas_limit
2751
+ remainder_gas = gas_benchmark_value % tx_gas_limit
2751
2752
2752
- if (tx_gas_limit is None ) or (tx_gas_limit > attack_gas_limit ):
2753
- state_test (
2754
- env = env ,
2755
- pre = pre ,
2756
- post = {},
2757
- tx = tx ,
2758
- )
2759
- else :
2760
- tx_count = attack_gas_limit // tx_gas_limit
2761
- txs = [tx for _ in range (tx_count )]
2762
-
2763
- blockchain_test (
2764
- genesis_environment = Environment (),
2765
- pre = pre ,
2766
- post = {},
2767
- blocks = [Block (txs = txs )],
2753
+ txs = [
2754
+ Transaction (
2755
+ to = code_address ,
2756
+ gas_limit = tx_gas_limit if i < tx_count else remainder_gas ,
2757
+ nonce = i ,
2758
+ sender = sender ,
2768
2759
)
2760
+ for i in range (tx_count + 1 )
2761
+ ]
2762
+
2763
+ blockchain_test (
2764
+ genesis_environment = env ,
2765
+ pre = pre ,
2766
+ post = {},
2767
+ blocks = [Block (txs = txs )],
2768
+ )
2769
2769
2770
2770
2771
2771
@pytest .mark .valid_from ("Osaka" )
2772
2772
def test_worst_clz_diff_input (
2773
- state_test : StateTestFiller ,
2774
2773
blockchain_test : BlockchainTestFiller ,
2775
2774
pre : Alloc ,
2776
2775
fork : Fork ,
2776
+ gas_benchmark_value : int ,
2777
+ env : Environment ,
2777
2778
):
2778
2779
"""Test running a block with as many CLZ with different input as possible."""
2779
- env = Environment ()
2780
- attack_gas_limit = env .gas_limit
2781
- tx_gas_limit = fork .transaction_gas_limit_cap ()
2780
+ tx_gas_limit = fork .transaction_gas_limit_cap () or env .gas_limit
2782
2781
max_code_size = fork .max_code_size ()
2783
2782
2784
2783
code_prefix = Op .JUMPDEST
@@ -2800,26 +2799,22 @@ def test_worst_clz_diff_input(
2800
2799
2801
2800
code_address = pre .deploy_contract (code = attack_code )
2802
2801
2803
- tx = Transaction (
2804
- to = code_address ,
2805
- gas_limit = env .gas_limit ,
2806
- sender = pre .fund_eoa (),
2807
- )
2808
-
2809
- if (tx_gas_limit is None ) or (tx_gas_limit > attack_gas_limit ):
2810
- state_test (
2811
- env = env ,
2812
- pre = pre ,
2813
- post = {},
2814
- tx = tx ,
2815
- )
2816
- else :
2817
- tx_count = attack_gas_limit // tx_gas_limit
2818
- txs = [tx for _ in range (tx_count )]
2819
-
2820
- blockchain_test (
2821
- genesis_environment = Environment (),
2822
- pre = pre ,
2823
- post = {},
2824
- blocks = [Block (txs = txs )],
2802
+ sender = pre .fund_eoa ()
2803
+ tx_count = gas_benchmark_value // tx_gas_limit
2804
+ remainder_gas = gas_benchmark_value % tx_gas_limit
2805
+ txs = [
2806
+ Transaction (
2807
+ to = code_address ,
2808
+ gas_limit = tx_gas_limit if i < tx_count else remainder_gas ,
2809
+ nonce = i ,
2810
+ sender = sender ,
2825
2811
)
2812
+ for i in range (tx_count + 1 )
2813
+ ]
2814
+
2815
+ blockchain_test (
2816
+ genesis_environment = env ,
2817
+ pre = pre ,
2818
+ post = {},
2819
+ blocks = [Block (txs = txs )],
2820
+ )
0 commit comments