|
39 | 39 | from ethereum_test_tools import Macros as Om |
40 | 40 | from ethereum_test_tools import Opcodes as Op |
41 | 41 | from ethereum_test_tools.eof.v1 import Container, Section |
| 42 | +from ethereum_test_types import TransactionReceipt |
42 | 43 |
|
43 | 44 | from ...cancun.eip4844_blobs.spec import Spec as Spec4844 |
44 | 45 | from ..eip6110_deposits.helpers import DepositRequest |
@@ -2514,32 +2515,31 @@ def test_set_code_to_log( |
2514 | 2515 | ) |
2515 | 2516 |
|
2516 | 2517 |
|
2517 | | -@pytest.mark.with_all_call_opcodes( |
2518 | | - selector=( |
2519 | | - lambda opcode: opcode |
2520 | | - not in [Op.STATICCALL, Op.CALLCODE, Op.DELEGATECALL, Op.EXTDELEGATECALL, Op.EXTSTATICCALL] |
2521 | | - ) |
2522 | | -) |
| 2518 | +@pytest.mark.with_all_call_opcodes |
2523 | 2519 | @pytest.mark.with_all_precompiles |
2524 | 2520 | def test_set_code_to_precompile( |
2525 | 2521 | state_test: StateTestFiller, |
2526 | 2522 | pre: Alloc, |
2527 | 2523 | precompile: int, |
2528 | 2524 | call_opcode: Op, |
2529 | 2525 | ): |
2530 | | - """Test setting the code of an account to a pre-compile address.""" |
| 2526 | + """ |
| 2527 | + Test setting the code of an account to a pre-compile address and executing all call |
| 2528 | + opcodes. |
| 2529 | + """ |
2531 | 2530 | auth_signer = pre.fund_eoa(auth_account_start_balance) |
2532 | 2531 |
|
| 2532 | + value = 1 if call_opcode in {Op.CALL, Op.CALLCODE, Op.EXTCALL} else 0 |
2533 | 2533 | caller_code_storage = Storage() |
2534 | 2534 | caller_code = ( |
2535 | 2535 | Op.SSTORE( |
2536 | 2536 | caller_code_storage.store_next(call_return_code(opcode=call_opcode, success=True)), |
2537 | | - call_opcode(address=auth_signer), |
| 2537 | + call_opcode(address=auth_signer, value=value, gas=0), |
2538 | 2538 | ) |
2539 | 2539 | + Op.SSTORE(caller_code_storage.store_next(0), Op.RETURNDATASIZE) |
2540 | 2540 | + Op.STOP |
2541 | 2541 | ) |
2542 | | - caller_code_address = pre.deploy_contract(caller_code) |
| 2542 | + caller_code_address = pre.deploy_contract(caller_code, balance=value) |
2543 | 2543 |
|
2544 | 2544 | tx = Transaction( |
2545 | 2545 | sender=pre.fund_eoa(), |
@@ -2570,6 +2570,52 @@ def test_set_code_to_precompile( |
2570 | 2570 | ) |
2571 | 2571 |
|
2572 | 2572 |
|
| 2573 | +@pytest.mark.with_all_precompiles |
| 2574 | +def test_set_code_to_precompile_not_enough_gas_for_precompile_execution( |
| 2575 | + state_test: StateTestFiller, |
| 2576 | + pre: Alloc, |
| 2577 | + fork: Fork, |
| 2578 | + precompile: int, |
| 2579 | +): |
| 2580 | + """ |
| 2581 | + Test set code to precompile and making direct call in same transaction with intrinsic gas |
| 2582 | + only, no extra gas for precompile execution. |
| 2583 | + """ |
| 2584 | + auth_signer = pre.fund_eoa(amount=1) |
| 2585 | + auth = AuthorizationTuple(address=Address(precompile), nonce=0, signer=auth_signer) |
| 2586 | + |
| 2587 | + intrinsic_gas = fork.transaction_intrinsic_cost_calculator()( |
| 2588 | + authorization_list_or_count=[auth], |
| 2589 | + ) |
| 2590 | + discount = min( |
| 2591 | + Spec.PER_EMPTY_ACCOUNT_COST - Spec.PER_AUTH_BASE_COST, |
| 2592 | + intrinsic_gas // 5, # max discount EIP-3529 |
| 2593 | + ) |
| 2594 | + |
| 2595 | + tx = Transaction( |
| 2596 | + sender=pre.fund_eoa(), |
| 2597 | + to=auth_signer, |
| 2598 | + gas_limit=intrinsic_gas, |
| 2599 | + value=1, |
| 2600 | + authorization_list=[auth], |
| 2601 | + # explicitly check expected gas, no precompile code executed |
| 2602 | + expected_receipt=TransactionReceipt(gas_used=intrinsic_gas - discount), |
| 2603 | + ) |
| 2604 | + |
| 2605 | + state_test( |
| 2606 | + pre=pre, |
| 2607 | + tx=tx, |
| 2608 | + post={ |
| 2609 | + auth_signer: Account( |
| 2610 | + # implicitly checks no OOG, successful tx transfers ``value=1`` |
| 2611 | + balance=2, |
| 2612 | + code=Spec.delegation_designation(Address(precompile)), |
| 2613 | + nonce=1, |
| 2614 | + ), |
| 2615 | + }, |
| 2616 | + ) |
| 2617 | + |
| 2618 | + |
2573 | 2619 | def deposit_contract_initial_storage() -> Storage: |
2574 | 2620 | """Return the initial storage of the deposit contract.""" |
2575 | 2621 | storage = Storage() |
|
0 commit comments