767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971 | @pytest.mark.parametrize(
"failure_point",
["set_delegation_oog", "dispatch_charge_oog", "execution_halt"],
)
def test_reservoir_settlement_with_value_to_empty_recipient(
fork: Fork,
pre: Alloc,
state_test: StateTestFiller,
failure_point: str,
) -> None:
"""
The many-authorization reservoir transaction, now moving value to an
empty recipient, carries both classes of state charge at once --
and a failure settles each class by whether its state survives.
The value transfer adds the recipient's ``NEW_ACCOUNT`` dispatch
charge alongside the authorizations' ``NEW_ACCOUNT`` + ``AUTH_BASE``
charges. The recipient is a precompile (here the bn254 pairing) --
an empty account that still executes, so an execution-phase failure
is reachable (a 1-byte input makes the pairing exceptionally halt
after the value has moved). An empty recipient runs no code of its
own, so there is no revert scenario here; the delegated-recipient
variant above covers it.
- ``set_delegation_oog``: the last authorization's closing
``AUTH_BASE`` is starved by one gas. Everything rolls back and
the whole reservoir returns: ``gas_used == cap``.
- ``dispatch_charge_oog``: every authorization applies, then the
recipient's ``NEW_ACCOUNT`` state charge is starved by one gas.
It shares the preparation snapshot: ``gas_used == cap``.
- ``execution_halt``: the reservoir is sized *above* the
authorizations' total state gas, so it survives the preparation
and the settlement can distinguish the two charge classes. The
precompile halts after the transfer: the recipient's leaf rolls
back, so its ``NEW_ACCOUNT`` refills and returns with the
reservoir remainder, while the persisting delegations keep their
state gas consumed -- ``gas_used == cap + auth_state_total``
exactly. (With a small reservoir the refill would be burned with
``gas_left`` and be unobservable, which is why the sizes differ
per scenario.)
In every scenario the transfer never sticks: the recipient's leaf
is absent from the post state and the sender keeps the value,
paying only the gas.
"""
cap = fork.transaction_gas_limit_cap()
assert cap is not None, "EIP-7825 cap expected on this fork"
gas_costs = fork.gas_costs()
value = 1
sender = pre.fund_eoa()
recipient = Address(0x08)
delegation_target = pre.deploy_contract(code=Op.STOP)
def creation_authorization(authority: EOA) -> AuthorizationTuple:
"""Authorization creating a fresh authority's account leaf."""
return AuthorizationTuple(
address=delegation_target,
nonce=0,
signer=authority,
creates_account=True,
)
probe_authority = pre.fund_eoa(amount=0)
probe = creation_authorization(probe_authority)
base_intrinsic = _intrinsic_execution(
fork,
[],
recipient_type=RecipientType.EMPTY_ACCOUNT,
sends_value=True,
)
per_auth_intrinsic = (
_intrinsic_execution(
fork,
[probe],
recipient_type=RecipientType.EMPTY_ACCOUNT,
sends_value=True,
)
- base_intrinsic
)
per_auth_charges = _auth_top_frame_charges(fork, [probe])
per_auth_total = per_auth_intrinsic + per_auth_charges
# The smallest authorization count whose starved-by-one gas limit
# exceeds the cap, plus one more so the starved scenarios' reservoir
# exceeds a full authorization's preparation charge.
min_count = (cap + 1 - base_intrinsic) // per_auth_total + 1
auth_count = min_count + 1
authorities = [probe_authority] + [
pre.fund_eoa(amount=0) for _ in range(auth_count - 1)
]
authorization_list = [probe] + [
creation_authorization(authority) for authority in authorities[1:]
]
intrinsic_execution = base_intrinsic + auth_count * per_auth_intrinsic
auth_charges = auth_count * per_auth_charges
auth_state_total = fork.transaction_top_frame_state_gas(
recipient_type=RecipientType.CONTRACT,
authorizations=authorization_list,
)
data = b""
if failure_point == "set_delegation_oog":
# The final authorization's closing AUTH_BASE is starved by one.
gas_limit = intrinsic_execution + auth_charges - 1
expected_gas_used = cap
delegations_persist = False
elif failure_point == "dispatch_charge_oog":
# All authorizations apply; the recipient's NEW_ACCOUNT state
# charge is starved by one.
gas_limit = (
intrinsic_execution + auth_charges + gas_costs.NEW_ACCOUNT - 1
)
expected_gas_used = cap
delegations_persist = False
else: # execution_halt
# One byte: not a multiple of 192, so the pairing precompile
# exceptionally halts after the value has moved. The reservoir
# covers the authorizations' state gas and the recipient's
# NEW_ACCOUNT with headroom, so no preparation charge spills
# into gas_left and the refill is observable in the settlement.
data = b"\x00"
gas_limit = cap + auth_state_total + gas_costs.NEW_ACCOUNT + 100_000
expected_gas_used = cap + auth_state_total
delegations_persist = True
reservoir = gas_limit - cap
if delegations_persist:
assert reservoir > auth_state_total, (
"the reservoir must survive the persisted auth state gas"
)
else:
assert reservoir > per_auth_charges, (
"the reservoir must exceed one authorization's charges"
)
tx = Transaction(
sender=sender,
to=recipient,
value=value,
data=data,
authorization_list=authorization_list,
gas_limit=gas_limit,
expected_receipt=TransactionReceipt(
cumulative_gas_used=expected_gas_used,
),
)
applied_authority = Account(
nonce=1,
balance=0,
code=Spec7702.delegation_designation(delegation_target),
)
post: dict[Address, Account | None] = {
# The transfer never sticks; the recipient's leaf stays absent.
recipient: None,
**(
dict.fromkeys(authorities, applied_authority)
if delegations_persist
else dict.fromkeys(authorities)
),
}
# The recipient is first loaded for its NEW_ACCOUNT alive-check, so
# it is absent from the block access list only when the halt lands
# inside set_delegation; afterwards it appears with no net change
# (the transfer, if any, rolled back). The authorities' delegation
# target is never read at all: writing a designation does not
# access the designated account.
if delegations_persist:
authority_bal = BalAccountExpectation(
nonce_changes=[BalNonceChange(block_access_index=1, post_nonce=1)],
code_changes=[
BalCodeChange(
block_access_index=1,
new_code=Spec7702.delegation_designation(
delegation_target
),
)
],
)
else:
authority_bal = BalAccountExpectation.empty()
recipient_bal = (
None
if failure_point == "set_delegation_oog"
else BalAccountExpectation.empty()
)
expected_block_access_list = BlockAccessListExpectation(
account_expectations={
recipient: recipient_bal,
delegation_target: None,
**dict.fromkeys(authorities, authority_bal),
}
)
state_test(
pre=pre,
tx=tx,
post=post,
expected_block_access_list=expected_block_access_list,
)
|