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
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739 | @pytest.mark.parametrize(
"exceed_tx_gas_limit,correct_intrinsic_cost_in_transaction_gas_limit",
[
pytest.param(True, False, marks=pytest.mark.exception_test),
pytest.param(True, True, marks=pytest.mark.exception_test),
pytest.param(False, True),
],
)
@pytest.mark.valid_from("Osaka")
def test_tx_gas_limit_cap_authorized_tx(
state_test: StateTestFiller,
pre: Alloc,
fork: Fork,
exceed_tx_gas_limit: bool,
correct_intrinsic_cost_in_transaction_gas_limit: bool,
) -> None:
"""Test a transaction limit cap with authorized tx."""
intrinsic_cost = fork.transaction_intrinsic_cost_calculator()
tx_gas_limit_cap = fork.transaction_gas_limit_cap()
assert tx_gas_limit_cap is not None, (
"Fork does not have a transaction gas limit cap"
)
def make_access_list(auth_count: int) -> List[AccessList]:
return [
AccessList(
address=Address(i + 1),
storage_keys=[],
)
for i in range(auth_count)
]
def intrinsic_cost_for_auth_list_length(auth_count: int) -> int:
return intrinsic_cost(
access_list=make_access_list(auth_count),
authorization_list_or_count=auth_count,
)
auth_list_length = max_count_with_intrinsic_cost_at_most(
intrinsic_cost_for_auth_list_length, tx_gas_limit_cap
) + int(exceed_tx_gas_limit)
# EIP-7702 authorization transaction cost:
# 21000 + 16 * non-zero calldata bytes + 4 * zero calldata bytes + 1900 *
# access list storage key count + 2400 * access list address count + access
# list data cost + AUTH_PER_EMPTY_ACCOUNT_COST * authorization list
# length
#
# There is no calldata and no storage keys in this test case.
# However, each access-list address includes data bytes that may contribute
# additional cost depending on fork repricing.
auth_address = pre.deploy_contract(code=Op.STOP)
access_list = make_access_list(auth_list_length)
auth_signers = [pre.fund_eoa() for _ in range(auth_list_length)]
auth_tuples = [
AuthorizationTuple(
signer=signer,
address=auth_address,
nonce=signer.nonce,
)
for signer in auth_signers
]
correct_intrinsic_cost = intrinsic_cost(
access_list=access_list, authorization_list_or_count=auth_list_length
)
if exceed_tx_gas_limit:
assert correct_intrinsic_cost > tx_gas_limit_cap, (
"Correct intrinsic cost should exceed the tx gas limit cap"
)
else:
assert correct_intrinsic_cost <= tx_gas_limit_cap, (
"Correct intrinsic cost should be less than or "
"equal to the tx gas limit cap"
)
tx_gas_limit = (
correct_intrinsic_cost
if correct_intrinsic_cost_in_transaction_gas_limit
else tx_gas_limit_cap
)
tx = Transaction(
to=pre.fund_eoa(),
gas_limit=tx_gas_limit,
sender=pre.fund_eoa(),
access_list=access_list,
authorization_list=auth_tuples,
error=TransactionException.GAS_LIMIT_EXCEEDS_MAXIMUM
if correct_intrinsic_cost_in_transaction_gas_limit
and exceed_tx_gas_limit
else TransactionException.INTRINSIC_GAS_TOO_LOW
if exceed_tx_gas_limit
else None,
)
state_test(
pre=pre,
post={},
tx=tx,
)
|