Skip to content

test_bal_call_no_delegation_and_oog_before_target_access()

Documentation for tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists_opcodes.py::test_bal_call_no_delegation_and_oog_before_target_access@c74f1a67.

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_and_oog_before_target_access --fork Amsterdam

CALL without 7702 delegation - test SUCCESS and OOG before target access.

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

Memory expansion is parametrized independently for args (insize) and ret (outsize) per #1910, surfacing client-impl asymmetry bugs in the memory-cost calculator.

Source code in tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists_opcodes.py
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
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
@pytest.mark.parametrize(
    "oog_boundary",
    [OutOfGasBoundary.SUCCESS, OutOfGasBoundary.OOG_BEFORE_TARGET_ACCESS],
    ids=lambda x: x.value,
)
@pytest.mark.parametrize(
    "target_is_warm", [False, True], ids=["cold_target", "warm_target"]
)
@pytest.mark.parametrize(
    "target_is_empty", [False, True], ids=["existing_target", "empty_target"]
)
@pytest.mark.parametrize("value", [0, 1], ids=["no_value", "with_value"])
@pytest.mark.parametrize(
    "args_size,ret_size",
    [
        pytest.param(0, 0, id="no_memory"),
        pytest.param(4096, 0, id="args_large"),
        pytest.param(0, 4096, id="ret_large"),
        pytest.param(32, 32, id="both_small"),
    ],
)
def test_bal_call_no_delegation_and_oog_before_target_access(
    pre: Alloc,
    blockchain_test: BlockchainTestFiller,
    fork: Fork,
    oog_boundary: OutOfGasBoundary,
    target_is_warm: bool,
    target_is_empty: bool,
    value: int,
    args_size: int,
    ret_size: int,
) -> None:
    """
    CALL without 7702 delegation - test SUCCESS and OOG before target access.

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

    Memory expansion is parametrized independently for args (insize) and
    ret (outsize) per #1910, surfacing client-impl asymmetry bugs in the
    memory-cost calculator.
    """
    alice = pre.fund_eoa()

    target = (
        pre.nonexistent_account()
        if target_is_empty
        else pre.deploy_contract(code=Op.STOP)
    )

    new_memory_size = max(args_size, ret_size)

    # Full gas metadata: includes create_cost when applicable
    call_code = Op.CALL(
        gas=0,
        address=target,
        value=value,
        args_size=args_size,
        args_offset=0,
        ret_size=ret_size,
        ret_offset=0,
        address_warm=target_is_warm,
        value_transfer=value > 0,
        account_new=value > 0 and target_is_empty,
        new_memory_size=new_memory_size,
    )
    caller = pre.deploy_contract(code=call_code, balance=value)

    access_list = (
        [AccessList(address=target, storage_keys=[])]
        if target_is_warm
        else None
    )

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

    if oog_boundary == OutOfGasBoundary.OOG_BEFORE_TARGET_ACCESS:
        # Static gas (before state access): no create_cost
        call_static = Op.CALL(
            gas=0,
            address=target,
            value=value,
            args_size=args_size,
            args_offset=0,
            ret_size=ret_size,
            ret_offset=0,
            address_warm=target_is_warm,
            value_transfer=value > 0,
            account_new=False,
            new_memory_size=new_memory_size,
        )
        gas_limit = intrinsic_cost + call_static.gas_cost(fork) - 1
    else:  # SUCCESS
        gas_limit = intrinsic_cost + call_code.gas_cost(fork)

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

    # BAL expectations
    account_expectations: Dict[Address, BalAccountExpectation | None]
    if oog_boundary == OutOfGasBoundary.OOG_BEFORE_TARGET_ACCESS:
        # Target NOT in BAL - we OOG before state access
        account_expectations = {
            caller: BalAccountExpectation.empty(),
            target: None,
        }
    elif value > 0:
        account_expectations = {
            caller: BalAccountExpectation(
                balance_changes=[
                    BalBalanceChange(block_access_index=1, post_balance=0)
                ]
            ),
            target: BalAccountExpectation(
                balance_changes=[
                    BalBalanceChange(block_access_index=1, post_balance=value)
                ]
            ),
        }
    else:
        account_expectations = {
            caller: BalAccountExpectation.empty(),
            target: BalAccountExpectation.empty(),
        }

    value_transferred = value > 0 and oog_boundary == OutOfGasBoundary.SUCCESS

    post_state: Dict[Address, Account | None] = {alice: Account(nonce=1)}

    if value_transferred:
        post_state[target] = Account(balance=value)
        post_state[caller] = Account(balance=0)
    else:
        post_state[caller] = Account(balance=value)
        post_state[target] = (
            Account.NONEXISTENT
            if target_is_empty
            else Account(balance=0, code=Op.STOP)
        )

    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 64 parametrized test cases across 1 fork.