Skip to content

test_bal_staticcall_7702_delegation_and_oog()

Documentation for tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists_opcodes.py::test_bal_staticcall_7702_delegation_and_oog@21507778.

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

STATICCALL with 7702 delegation - test all OOG boundaries.

When target_is_warm or delegation_is_warm, we use EIP-2930 tx access list. Access list warming does NOT add targets to BAL - only EVM access does.

For 7702 delegation, there's ALWAYS a gap between static gas and second check (delegation_cost) - all 3 scenarios produce distinct behaviors.

Source code in tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists_opcodes.py
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
@pytest.mark.parametrize(
    "oog_boundary",
    list(OutOfGasBoundary),
    ids=lambda x: x.value,
)
@pytest.mark.parametrize(
    "target_is_warm", [False, True], ids=["cold_target", "warm_target"]
)
@pytest.mark.parametrize(
    "delegation_is_warm",
    [False, True],
    ids=["cold_delegation", "warm_delegation"],
)
@pytest.mark.parametrize(
    "memory_expansion", [False, True], ids=["no_memory", "with_memory"]
)
def test_bal_staticcall_7702_delegation_and_oog(
    pre: Alloc,
    blockchain_test: BlockchainTestFiller,
    fork: Fork,
    oog_boundary: OutOfGasBoundary,
    target_is_warm: bool,
    delegation_is_warm: bool,
    memory_expansion: bool,
) -> None:
    """
    STATICCALL with 7702 delegation - test all OOG boundaries.

    When target_is_warm or delegation_is_warm, we use EIP-2930 tx access list.
    Access list warming does NOT add targets to BAL - only EVM access does.

    For 7702 delegation, there's ALWAYS a gap between static gas and
    second check (delegation_cost) - all 3 scenarios produce distinct
    behaviors.
    """
    alice = pre.fund_eoa()

    delegation_target = pre.deploy_contract(code=Op.STOP)
    target = pre.fund_eoa(amount=0, delegation=delegation_target)

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

    # Full gas metadata: includes delegation cost
    staticcall_code = Op.STATICCALL(
        gas=0,
        address=target,
        ret_size=ret_size,
        ret_offset=ret_offset,
        address_warm=target_is_warm,
        new_memory_size=ret_size,
        delegated_address=True,
        delegated_address_warm=delegation_is_warm,
    )

    caller = pre.deploy_contract(code=staticcall_code)

    # Build access list for warming
    access_list: list[AccessList] = []
    if target_is_warm:
        access_list.append(AccessList(address=target, storage_keys=[]))
    if delegation_is_warm:
        access_list.append(
            AccessList(address=delegation_target, storage_keys=[])
        )

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

    # Static gas (before state access): no delegation
    staticcall_static = Op.STATICCALL(
        gas=0,
        address=target,
        ret_size=ret_size,
        ret_offset=ret_offset,
        address_warm=target_is_warm,
        new_memory_size=ret_size,
    )

    if oog_boundary == OutOfGasBoundary.OOG_BEFORE_TARGET_ACCESS:
        gas_limit = intrinsic_cost + staticcall_static.gas_cost(fork) - 1
    elif oog_boundary == OutOfGasBoundary.OOG_AFTER_TARGET_ACCESS:
        # Enough for static_gas only - not enough for delegation_cost
        gas_limit = intrinsic_cost + staticcall_static.gas_cost(fork)
    elif oog_boundary == OutOfGasBoundary.OOG_SUCCESS_MINUS_1:
        # One less than full cost - not enough for full call
        gas_limit = intrinsic_cost + staticcall_code.gas_cost(fork) - 1
    else:
        gas_limit = intrinsic_cost + staticcall_code.gas_cost(fork)

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

    # Access list warming does NOT add to BAL - only EVM execution does
    if oog_boundary == OutOfGasBoundary.OOG_BEFORE_TARGET_ACCESS:
        target_in_bal = False
        delegation_in_bal = False
    elif oog_boundary in (
        OutOfGasBoundary.OOG_AFTER_TARGET_ACCESS,
        OutOfGasBoundary.OOG_SUCCESS_MINUS_1,
    ):
        # Both cases: target accessed but not enough gas for full call
        # so delegation is NOT read (static check optimization)
        target_in_bal = True
        delegation_in_bal = False
    else:
        target_in_bal = True
        delegation_in_bal = True

    account_expectations: Dict[Address, BalAccountExpectation | None] = {
        caller: BalAccountExpectation.empty(),
        delegation_target: (
            BalAccountExpectation.empty() if delegation_in_bal else None
        ),
    }

    if target_in_bal:
        account_expectations[target] = BalAccountExpectation.empty()
    else:
        account_expectations[target] = None

    blockchain_test(
        pre=pre,
        blocks=[
            Block(
                txs=[tx],
                expected_block_access_list=BlockAccessListExpectation(
                    account_expectations=account_expectations
                ),
            )
        ],
        post={alice: Account(nonce=1)},
    )

Parametrized Test Cases

This test generates 32 parametrized test cases across 1 fork.