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
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760 | @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 capped_intrinsic_cost(auth_count: int) -> int:
"""Return the intrinsic gas that counts toward the cap."""
cost = intrinsic_cost(
access_list=make_access_list(auth_count),
authorization_list_or_count=auth_count,
)
return cost
auth_list_length = max_count_with_intrinsic_cost_at_most(
capped_intrinsic_cost, 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
)
correct_capped_cost = capped_intrinsic_cost(auth_list_length)
if exceed_tx_gas_limit:
assert correct_capped_cost > tx_gas_limit_cap, (
"Correct capped intrinsic cost should exceed the tx gas limit cap"
)
else:
assert correct_capped_cost <= tx_gas_limit_cap, (
"Correct capped 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,
# EIP-8037 reports a cap overflow as INTRINSIC_GAS_TOO_LOW.
error=(
TransactionException.INTRINSIC_GAS_TOO_LOW
if fork.is_eip_enabled(8037)
else 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,
)
env = Environment()
if fork.is_eip_enabled(8037):
# Size the block so it fits the state reservoir.
env = Environment(gas_limit=correct_intrinsic_cost)
state_test(
env=env,
pre=pre,
post={},
tx=tx,
)
|