|
18 | 18 | Environment,
|
19 | 19 | StateTestFiller,
|
20 | 20 | Transaction,
|
| 21 | + compute_create_address, |
21 | 22 | )
|
22 | 23 | from ethereum_test_tools.vm.opcode import Opcodes as Op
|
23 | 24 |
|
@@ -469,3 +470,74 @@ def test_clz_with_memory_operation(state_test: StateTestFiller, pre: Alloc, bits
|
469 | 470 | )
|
470 | 471 |
|
471 | 472 | state_test(pre=pre, post=post, tx=tx)
|
| 473 | + |
| 474 | + |
| 475 | +@pytest.mark.valid_from("Osaka") |
| 476 | +def test_clz_initcode_context(state_test: StateTestFiller, pre: Alloc): |
| 477 | + """Test CLZ opcode behavior when creating a contract.""" |
| 478 | + bits = [0, 1, 64, 128, 255] |
| 479 | + |
| 480 | + storage = Storage() |
| 481 | + |
| 482 | + init_code = Bytecode() |
| 483 | + for bit in bits: |
| 484 | + init_code += Op.SSTORE(storage.store_next(255 - bit), Op.CLZ(1 << bit)) |
| 485 | + |
| 486 | + sender_address = pre.fund_eoa() |
| 487 | + |
| 488 | + contract_address = compute_create_address(address=sender_address, nonce=0) |
| 489 | + |
| 490 | + tx = Transaction( |
| 491 | + to=None, |
| 492 | + gas_limit=6_000_000, |
| 493 | + data=init_code, |
| 494 | + sender=sender_address, |
| 495 | + ) |
| 496 | + |
| 497 | + post = { |
| 498 | + contract_address: Account(storage=storage), |
| 499 | + } |
| 500 | + |
| 501 | + state_test(pre=pre, post=post, tx=tx) |
| 502 | + |
| 503 | + |
| 504 | +@pytest.mark.valid_from("Osaka") |
| 505 | +@pytest.mark.parametrize("opcode", [Op.CREATE, Op.CREATE2]) |
| 506 | +def test_clz_initcode_create(state_test: StateTestFiller, pre: Alloc, opcode: Op): |
| 507 | + """Test CLZ opcode behavior when creating a contract.""" |
| 508 | + bits = [0, 1, 64, 128, 255] # expected values: [255, 254, 191, 127, 0] |
| 509 | + |
| 510 | + storage = Storage() |
| 511 | + ext_code = Bytecode() |
| 512 | + |
| 513 | + for bit in bits: |
| 514 | + ext_code += Op.SSTORE(storage.store_next(255 - bit), Op.CLZ(1 << bit)) |
| 515 | + |
| 516 | + sender_address = pre.fund_eoa() |
| 517 | + |
| 518 | + create_contract = ( |
| 519 | + Op.CALLDATACOPY(offset=0, size=len(ext_code)) |
| 520 | + + opcode(offset=0, size=len(ext_code)) |
| 521 | + + Op.STOP |
| 522 | + ) |
| 523 | + |
| 524 | + factory_contract_address = pre.deploy_contract(code=create_contract) |
| 525 | + |
| 526 | + created_contract_address = compute_create_address( |
| 527 | + address=factory_contract_address, nonce=1, initcode=ext_code, opcode=opcode |
| 528 | + ) |
| 529 | + |
| 530 | + tx = Transaction( |
| 531 | + to=factory_contract_address, |
| 532 | + gas_limit=200_000, |
| 533 | + data=ext_code, |
| 534 | + sender=sender_address, |
| 535 | + ) |
| 536 | + |
| 537 | + post = { |
| 538 | + created_contract_address: Account( |
| 539 | + storage=storage, |
| 540 | + ), |
| 541 | + } |
| 542 | + |
| 543 | + state_test(pre=pre, post=post, tx=tx) |
0 commit comments