|
| 1 | +"""Test the CALL opcode after EIP-2929.""" |
| 2 | + |
| 3 | +import pytest |
| 4 | + |
| 5 | +from ethereum_test_forks import Fork |
| 6 | +from ethereum_test_tools import ( |
| 7 | + Account, |
| 8 | + Alloc, |
| 9 | + CodeGasMeasure, |
| 10 | + Environment, |
| 11 | + StateTestFiller, |
| 12 | + Transaction, |
| 13 | +) |
| 14 | +from ethereum_test_vm import Opcodes as Op |
| 15 | + |
| 16 | +REFERENCE_SPEC_GIT_PATH = "EIPS/eip-2929.md" |
| 17 | +REFERENCE_SPEC_VERSION = "0e11417265a623adb680c527b15d0cb6701b870b" |
| 18 | + |
| 19 | + |
| 20 | +@pytest.mark.valid_from("Berlin") |
| 21 | +def test_call_insufficient_balance( |
| 22 | + state_test: StateTestFiller, pre: Alloc, env: Environment, fork: Fork |
| 23 | +): |
| 24 | + """ |
| 25 | + Test a regular CALL to see if it warms the destination with insufficient |
| 26 | + balance. |
| 27 | + """ |
| 28 | + gas_costs = fork.gas_costs() |
| 29 | + destination = pre.fund_eoa(1) |
| 30 | + contract_address = pre.deploy_contract( |
| 31 | + # Perform the aborted external calls |
| 32 | + Op.SSTORE( |
| 33 | + 0, |
| 34 | + Op.CALL( |
| 35 | + gas=Op.GAS, |
| 36 | + address=destination, |
| 37 | + value=1, |
| 38 | + args_offset=0, |
| 39 | + args_size=0, |
| 40 | + ret_offset=0, |
| 41 | + ret_size=0, |
| 42 | + ), |
| 43 | + ) |
| 44 | + # Measure the gas cost for BALANCE operation |
| 45 | + + CodeGasMeasure( |
| 46 | + code=Op.BALANCE(destination), |
| 47 | + overhead_cost=gas_costs.G_VERY_LOW, # PUSH20 costs 3 gas |
| 48 | + extra_stack_items=1, # BALANCE puts balance on stack |
| 49 | + sstore_key=1, |
| 50 | + ), |
| 51 | + balance=0, |
| 52 | + ) |
| 53 | + |
| 54 | + tx = Transaction( |
| 55 | + to=contract_address, |
| 56 | + gas_limit=100_000, |
| 57 | + sender=pre.fund_eoa(), |
| 58 | + ) |
| 59 | + |
| 60 | + post = { |
| 61 | + destination: Account( |
| 62 | + balance=1, |
| 63 | + ), |
| 64 | + contract_address: Account( |
| 65 | + storage={ |
| 66 | + 0: 0, # The CALL is aborted |
| 67 | + 1: gas_costs.G_WARM_ACCOUNT_ACCESS, # Warm access cost |
| 68 | + }, |
| 69 | + ), |
| 70 | + } |
| 71 | + state_test(env=env, pre=pre, post=post, tx=tx) |
0 commit comments