File tree Expand file tree Collapse file tree 1 file changed +51
-0
lines changed Expand file tree Collapse file tree 1 file changed +51
-0
lines changed Original file line number Diff line number Diff line change @@ -2358,3 +2358,54 @@ def test_worst_clz_same_input(
2358
2358
post = {},
2359
2359
blocks = [Block (txs = txs )],
2360
2360
)
2361
+
2362
+
2363
+ @pytest .mark .valid_from ("Osaka" )
2364
+ def test_worst_clz_diff_input (
2365
+ state_test : StateTestFiller ,
2366
+ blockchain_test : BlockchainTestFiller ,
2367
+ pre : Alloc ,
2368
+ fork : Fork ,
2369
+ ):
2370
+ """Test running a block with as many CLZ with different input as possible."""
2371
+ env = Environment ()
2372
+ attack_gas_limit = env .gas_limit
2373
+ tx_gas_limit = fork .transaction_gas_limit_cap ()
2374
+ max_code_size = fork .max_code_size ()
2375
+
2376
+ code_prefix = Op .JUMPDEST
2377
+ code_suffix = Op .PUSH0 + Op .JUMP
2378
+
2379
+ iteration = (max_code_size - len (code_prefix ) - len (code_suffix )) // 2
2380
+
2381
+ code_seq = Bytecode ()
2382
+
2383
+ for i in range (2 * iteration ):
2384
+ value = i if i % 2 else 2 ** 256 - 1 - i
2385
+ code_seq += Op .CLZ (value ) + Op .POP
2386
+
2387
+ code_address = pre .deploy_contract (code = code_prefix + code_seq + code_suffix )
2388
+
2389
+ tx = Transaction (
2390
+ to = code_address ,
2391
+ gas_limit = env .gas_limit ,
2392
+ sender = pre .fund_eoa (),
2393
+ )
2394
+
2395
+ if (tx_gas_limit is None ) or (tx_gas_limit > attack_gas_limit ):
2396
+ state_test (
2397
+ env = env ,
2398
+ pre = pre ,
2399
+ post = {},
2400
+ tx = tx ,
2401
+ )
2402
+ else :
2403
+ tx_count = attack_gas_limit // tx_gas_limit
2404
+ txs = [tx for _ in range (tx_count )]
2405
+
2406
+ blockchain_test (
2407
+ genesis_environment = Environment (),
2408
+ pre = pre ,
2409
+ post = {},
2410
+ blocks = [Block (txs = txs )],
2411
+ )
You can’t perform that action at this time.
0 commit comments