|
13 | 13 | Block, |
14 | 14 | BlockchainTestFiller, |
15 | 15 | Bytecode, |
| 16 | + Create2PreimageLayout, |
16 | 17 | Fork, |
17 | 18 | Op, |
18 | 19 | Transaction, |
@@ -175,31 +176,25 @@ def test_bloatnet_balance_extcodesize( |
175 | 176 | # Load results from memory |
176 | 177 | # Memory[96:128] = num_deployed_contracts |
177 | 178 | # Memory[128:160] = init_code_hash |
178 | | - + Op.MLOAD(96) # Load num_deployed_contracts |
179 | | - + Op.MLOAD(128) # Load init_code_hash |
180 | | - # Setup memory for CREATE2 address generation |
181 | | - # Memory layout at 0: 0xFF + factory_addr(20) + salt(32) + hash(32) |
182 | | - + Op.MSTORE( |
183 | | - 0, factory_address |
184 | | - ) # Store factory address at memory position 0 |
185 | | - + Op.MSTORE8(11, 0xFF) # Store 0xFF prefix at position (32 - 20 - 1) |
186 | | - + Op.MSTORE(32, 0) # Store salt at position 32 |
187 | | - # Stack now has: [num_contracts, init_code_hash] |
188 | | - + Op.PUSH1(64) # Push memory position |
189 | | - + Op.MSTORE # Store init_code_hash at memory[64] |
190 | | - # Stack now has: [num_contracts] |
| 179 | + + Op.MLOAD(96) # Load num_deployed_contracts to stack |
| 180 | + + ( |
| 181 | + create2_preimage := Create2PreimageLayout( |
| 182 | + factory_address=factory_address, |
| 183 | + salt=0, |
| 184 | + init_code_hash=Op.MLOAD(128), |
| 185 | + ) |
| 186 | + ) |
191 | 187 | # Main attack loop - iterate through all deployed contracts |
192 | 188 | + While( |
193 | 189 | body=( |
194 | 190 | # Generate CREATE2 addr: keccak256(0xFF+factory+salt+hash) |
195 | | - Op.SHA3(11, 85) # Generate CREATE2 address from memory[11:96] |
| 191 | + # Hash CREATE2 address from memory |
| 192 | + create2_preimage.address_op() |
196 | 193 | # The address is now on the stack |
197 | 194 | + Op.DUP1 # Duplicate for second operation |
198 | 195 | + benchmark_ops # Execute operations in specified order |
199 | 196 | # Increment salt for next iteration |
200 | | - + Op.MSTORE( |
201 | | - 32, Op.ADD(Op.MLOAD(32), 1) |
202 | | - ) # Increment and store salt |
| 197 | + + create2_preimage.increment_salt_op() |
203 | 198 | ), |
204 | 199 | # Continue while we haven't reached the limit |
205 | 200 | condition=Op.DUP1 |
@@ -372,31 +367,24 @@ def test_bloatnet_balance_extcodecopy( |
372 | 367 | # Load results from memory |
373 | 368 | # Memory[96:128] = num_deployed_contracts |
374 | 369 | # Memory[128:160] = init_code_hash |
375 | | - + Op.MLOAD(96) # Load num_deployed_contracts |
376 | | - + Op.MLOAD(128) # Load init_code_hash |
377 | | - # Setup memory for CREATE2 address generation |
378 | | - # Memory layout at 0: 0xFF + factory_addr(20) + salt(32) + hash(32) |
379 | | - + Op.MSTORE( |
380 | | - 0, factory_address |
381 | | - ) # Store factory address at memory position 0 |
382 | | - + Op.MSTORE8(11, 0xFF) # Store 0xFF prefix at position (32 - 20 - 1) |
383 | | - + Op.MSTORE(32, 0) # Store salt at position 32 |
384 | | - # Stack now has: [num_contracts, init_code_hash] |
385 | | - + Op.PUSH1(64) # Push memory position |
386 | | - + Op.MSTORE # Store init_code_hash at memory[64] |
387 | | - # Stack now has: [num_contracts] |
| 370 | + + Op.MLOAD(96) # Load num_deployed_contracts to stack |
| 371 | + + ( |
| 372 | + create2_preimage := Create2PreimageLayout( |
| 373 | + factory_address=factory_address, |
| 374 | + salt=0, |
| 375 | + init_code_hash=Op.MLOAD(128), |
| 376 | + ) |
| 377 | + ) |
388 | 378 | # Main attack loop - iterate through all deployed contracts |
389 | 379 | + While( |
390 | 380 | body=( |
391 | | - # Generate CREATE2 address |
392 | | - Op.SHA3(11, 85) # Generate CREATE2 address from memory[11:96] |
| 381 | + # Hash CREATE2 address |
| 382 | + create2_preimage.address_op() |
393 | 383 | # The address is now on the stack |
394 | 384 | + Op.DUP1 # Duplicate for later operations |
395 | 385 | + benchmark_ops # Execute operations in specified order |
396 | 386 | # Increment salt for next iteration |
397 | | - + Op.MSTORE( |
398 | | - 32, Op.ADD(Op.MLOAD(32), 1) |
399 | | - ) # Increment and store salt |
| 387 | + + create2_preimage.increment_salt_op() |
400 | 388 | ), |
401 | 389 | # Continue while counter > 0 |
402 | 390 | condition=Op.DUP1 |
@@ -554,23 +542,23 @@ def test_bloatnet_balance_extcodehash( |
554 | 542 | + Op.PUSH2(0x1000) # Jump to error handler if failed |
555 | 543 | + Op.JUMPI |
556 | 544 | # Load results from memory |
557 | | - + Op.MLOAD(96) # Load num_deployed_contracts |
558 | | - + Op.MLOAD(128) # Load init_code_hash |
559 | | - # Setup memory for CREATE2 address generation |
560 | | - + Op.MSTORE(0, factory_address) |
561 | | - + Op.MSTORE8(11, 0xFF) |
562 | | - + Op.MSTORE(32, 0) # Initial salt |
563 | | - + Op.PUSH1(64) |
564 | | - + Op.MSTORE # Store init_code_hash |
| 545 | + + Op.MLOAD(96) # Load num_deployed_contracts to stack |
| 546 | + + ( |
| 547 | + create2_preimage := Create2PreimageLayout( |
| 548 | + factory_address=factory_address, |
| 549 | + salt=0, |
| 550 | + init_code_hash=Op.MLOAD(128), |
| 551 | + ) |
| 552 | + ) |
565 | 553 | # Main attack loop |
566 | 554 | + While( |
567 | 555 | body=( |
568 | | - # Generate CREATE2 address |
569 | | - Op.SHA3(11, 85) |
| 556 | + # Hash CREATE2 address |
| 557 | + create2_preimage.address_op() |
570 | 558 | + Op.DUP1 # Duplicate for second operation |
571 | 559 | + benchmark_ops # Execute operations in specified order |
572 | 560 | # Increment salt |
573 | | - + Op.MSTORE(32, Op.ADD(Op.MLOAD(32), 1)) |
| 561 | + + create2_preimage.increment_salt_op() |
574 | 562 | ), |
575 | 563 | condition=Op.DUP1 |
576 | 564 | + Op.PUSH1(1) |
|
0 commit comments