1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747 | @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(
"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_staticcall_7702_delegation_and_oog(
pre: Alloc,
blockchain_test: BlockchainTestFiller,
fork: Fork,
oog_boundary: OutOfGasBoundary,
target_is_warm: bool,
delegation_is_warm: bool,
args_size: int,
ret_size: int,
) -> 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)
new_memory_size = max(args_size, ret_size)
staticcall_code = Op.STATICCALL(
gas=0,
address=target,
args_size=args_size,
args_offset=0,
ret_size=ret_size,
ret_offset=0,
address_warm=target_is_warm,
new_memory_size=new_memory_size,
delegated_address=True,
delegated_address_warm=delegation_is_warm,
)
caller = pre.deploy_contract(code=staticcall_code)
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
)
staticcall_static = Op.STATICCALL(
gas=0,
address=target,
args_size=args_size,
args_offset=0,
ret_size=ret_size,
ret_offset=0,
address_warm=target_is_warm,
new_memory_size=new_memory_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)},
)
|