Skip to content

test_bal_call_no_delegation_oog_after_target_access()

Documentation for tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists_opcodes.py::test_bal_call_no_delegation_oog_after_target_access@892e6d1e.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists_opcodes.py::test_bal_call_no_delegation_oog_after_target_access --fork Amsterdam

CALL without 7702 delegation - OOG after state access.

When target_is_warm=True, uses EIP-2930 tx access list to warm the target. Access list warming does NOT add targets to BAL - only EVM access does.

This test is only meaningful when there's a gap between gas check before state access and after state access. This only happens if create cost (empty target) and value transfer cost are both non-zero.

Note
  • target is always empty - required for create cost
  • value=1 (greater than 0) - required for create cost

The create_cost (NEW_ACCOUNT = 25000) is charged only for value transfers to empty accounts, creating the gap tested here.

Source code in tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists_opcodes.py
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
@pytest.mark.parametrize(
    "target_is_warm", [False, True], ids=["cold_target", "warm_target"]
)
@pytest.mark.parametrize(
    "memory_expansion", [False, True], ids=["no_memory", "with_memory"]
)
@pytest.mark.eels_base_coverage
def test_bal_call_no_delegation_oog_after_target_access(
    pre: Alloc,
    blockchain_test: BlockchainTestFiller,
    fork: Fork,
    target_is_warm: bool,
    memory_expansion: bool,
) -> None:
    """
    CALL without 7702 delegation - OOG after state access.

    When target_is_warm=True, uses EIP-2930 tx access list to warm the target.
    Access list warming does NOT add targets to BAL - only EVM access does.

    This test is only meaningful when there's a gap between gas check before
    state access and after state access. This only happens if create cost
    (empty target) and value transfer cost are both non-zero.

    Note:
        - target is always empty - required for create cost
        - value=1 (greater than 0) - required for create cost

    The create_cost (NEW_ACCOUNT = 25000) is charged only for value
    transfers to empty accounts, creating the gap tested here.

    """
    alice = pre.fund_eoa()

    # empty target required for create_cost gap
    target = pre.nonexistent_account()
    # value > 0 required for create_cost
    value = 1

    # memory expansion / no expansion
    ret_size = 32 if memory_expansion else 0

    # Static gas (before state access): no create_cost
    # Pass static check, fail at second check due to create cost
    call_code = Op.CALL(
        gas=0,
        address=target,
        value=value,
        ret_size=ret_size,
        ret_offset=0,
        address_warm=target_is_warm,
        value_transfer=True,
        account_new=False,
        new_memory_size=ret_size,
    )
    caller = pre.deploy_contract(code=call_code, balance=value)

    # Access list for warming target (if needed)
    access_list = (
        [AccessList(address=target, storage_keys=[])]
        if target_is_warm
        else None
    )

    intrinsic_cost = fork.transaction_intrinsic_cost_calculator()(
        access_list=access_list
    )

    gas_limit = intrinsic_cost + call_code.gas_cost(fork)

    tx = Transaction(
        sender=alice,
        to=caller,
        gas_limit=gas_limit,
        access_list=access_list,
    )

    # Target is always in BAL after state access but value transfer fails
    # (no balance changes)
    account_expectations: Dict[Address, BalAccountExpectation | None] = {
        caller: BalAccountExpectation.empty(),
        target: BalAccountExpectation.empty(),
    }

    post_state = {
        alice: Account(nonce=1),
        caller: Account(balance=value),
        target: Account.NONEXISTENT,
    }

    blockchain_test(
        pre=pre,
        blocks=[
            Block(
                txs=[tx],
                expected_block_access_list=BlockAccessListExpectation(
                    account_expectations=account_expectations
                ),
            )
        ],
        post=post_state,
    )

Parametrized Test Cases

This test generates 4 parametrized test cases across 1 fork.