@@ -402,6 +402,19 @@ def call(evm: Evm) -> None:
402402 evm ,
403403 access_gas_cost + transfer_gas_cost + extend_memory .cost ,
404404 )
405+ # Early balance check - before accessing target state.
406+ # This ensures target is NOT in BAL when call fails due to insufficient funds.
407+ sender_balance = get_account (
408+ evm .message .block_env .state , evm .message .current_target
409+ ).balance
410+ if sender_balance < value :
411+ # Only charge transfer + memory (not cold access, since we didn't access)
412+ charge_gas (evm , transfer_gas_cost + extend_memory .cost )
413+ evm .memory += b"\x00 " * extend_memory .expand_by
414+ push (evm .stack , U256 (0 ))
415+ evm .return_data = b""
416+ evm .pc += Uint (1 )
417+ return
405418
406419 # need to access account to check if account is alive, check gas before
407420 create_gas_cost = GAS_NEW_ACCOUNT
@@ -452,30 +465,23 @@ def call(evm: Evm) -> None:
452465 if evm .message .is_static and value != U256 (0 ):
453466 raise WriteInStaticContext
454467 evm .memory += b"\x00 " * extend_memory .expand_by
455- sender_balance = get_account (
456- evm .message .block_env .state , evm .message .current_target
457- ).balance
458- if sender_balance < value :
459- push (evm .stack , U256 (0 ))
460- evm .return_data = b""
461- evm .gas_left += message_call_gas .sub_call
462- else :
463- generic_call (
464- evm ,
465- message_call_gas .sub_call ,
466- value ,
467- evm .message .current_target ,
468- to ,
469- code_address ,
470- True ,
471- False ,
472- memory_input_start_position ,
473- memory_input_size ,
474- memory_output_start_position ,
475- memory_output_size ,
476- code ,
477- disable_precompiles ,
478- )
468+
469+ generic_call (
470+ evm ,
471+ message_call_gas .sub_call ,
472+ value ,
473+ evm .message .current_target ,
474+ to ,
475+ code_address ,
476+ True ,
477+ False ,
478+ memory_input_start_position ,
479+ memory_input_size ,
480+ memory_output_start_position ,
481+ memory_output_size ,
482+ code ,
483+ disable_precompiles ,
484+ )
479485
480486 # PROGRAM COUNTER
481487 evm .pc += Uint (1 )
0 commit comments