2222 Block ,
2323 BlockchainTestFiller ,
2424 Bytecode ,
25+ Environment ,
2526 StateTestFiller ,
2627 Transaction ,
2728 add_kzg_version ,
@@ -2727,12 +2728,14 @@ def test_worst_return_revert(
27272728
27282729@pytest .mark .valid_from ("Osaka" )
27292730def 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 ,
27312736):
27322737 """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
27362739
27372740 magic_value = 248 # CLZ(248) = 248
27382741
@@ -2743,42 +2746,38 @@ def test_worst_clz_same_input(
27432746
27442747 code_address = pre .deploy_contract (code = code )
27452748
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
27512752
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 ,
27682759 )
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+ )
27692769
27702770
27712771@pytest .mark .valid_from ("Osaka" )
27722772def test_worst_clz_diff_input (
2773- state_test : StateTestFiller ,
27742773 blockchain_test : BlockchainTestFiller ,
27752774 pre : Alloc ,
27762775 fork : Fork ,
2776+ gas_benchmark_value : int ,
2777+ env : Environment ,
27772778):
27782779 """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
27822781 max_code_size = fork .max_code_size ()
27832782
27842783 code_prefix = Op .JUMPDEST
@@ -2800,26 +2799,22 @@ def test_worst_clz_diff_input(
28002799
28012800 code_address = pre .deploy_contract (code = attack_code )
28022801
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 ,
28252811 )
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