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 @@ -2296,3 +2296,54 @@ def test_worst_clz_same_input(
2296
2296
post = {},
2297
2297
blocks = [Block (txs = txs )],
2298
2298
)
2299
+
2300
+
2301
+ @pytest .mark .valid_from ("Osaka" )
2302
+ def test_worst_clz_diff_input (
2303
+ state_test : StateTestFiller ,
2304
+ blockchain_test : BlockchainTestFiller ,
2305
+ pre : Alloc ,
2306
+ fork : Fork ,
2307
+ ):
2308
+ """Test running a block with as many CLZ with different input as possible."""
2309
+ env = Environment ()
2310
+ attack_gas_limit = env .gas_limit
2311
+ tx_gas_limit = fork .transaction_gas_limit_cap ()
2312
+ max_code_size = fork .max_code_size ()
2313
+
2314
+ code_prefix = Op .JUMPDEST
2315
+ code_suffix = Op .PUSH0 + Op .JUMP
2316
+
2317
+ iteration = (max_code_size - len (code_prefix ) - len (code_suffix )) // 2
2318
+
2319
+ code_seq = Bytecode ()
2320
+
2321
+ for i in range (2 * iteration ):
2322
+ value = i if i % 2 else 2 ** 256 - 1 - i
2323
+ code_seq += Op .CLZ (value ) + Op .POP
2324
+
2325
+ code_address = pre .deploy_contract (code = code_prefix + code_seq + code_suffix )
2326
+
2327
+ tx = Transaction (
2328
+ to = code_address ,
2329
+ gas_limit = env .gas_limit ,
2330
+ sender = pre .fund_eoa (),
2331
+ )
2332
+
2333
+ if (tx_gas_limit is None ) or (tx_gas_limit > attack_gas_limit ):
2334
+ state_test (
2335
+ env = env ,
2336
+ pre = pre ,
2337
+ post = {},
2338
+ tx = tx ,
2339
+ )
2340
+ else :
2341
+ tx_count = attack_gas_limit // tx_gas_limit
2342
+ txs = [tx for _ in range (tx_count )]
2343
+
2344
+ blockchain_test (
2345
+ genesis_environment = Environment (),
2346
+ pre = pre ,
2347
+ post = {},
2348
+ blocks = [Block (txs = txs )],
2349
+ )
You can’t perform that action at this time.
0 commit comments