@@ -769,6 +769,7 @@ def test_gas_cost(
769769 )
770770
771771
772+ @pytest .mark .parametrize ("check_delegated_account_first" , [True , False ])
772773@pytest .mark .parametrize (** gas_test_parameter_args (include_many = False , include_data = False ))
773774def test_account_warming (
774775 state_test : StateTestFiller ,
@@ -777,49 +778,80 @@ def test_account_warming(
777778 authorization_list : List [AuthorizationTuple ],
778779 access_list_case : AccessListType ,
779780 access_list : List [AccessList ],
780- authorize_to_address : Address ,
781781 data : bytes ,
782782 sender : EOA ,
783+ check_delegated_account_first : bool ,
783784):
784785 """
785786 Test warming of the authority and authorized accounts for set-code transactions.
786787 """
787- overhead_cost = 3
788+ OVERHEAD_COST = 3
789+ COLD_ACCOUNT_COST = 2600
790+ WARM_ACCOUNT_COST = 100
788791
789- # Dictionary to keep track of the addresses to check for warming, with a boolean value to
790- # indicate whether the address should already be warm or not .
791- addresses_to_check : Dict [Address , bool ] = {}
792+ # Dictionary to keep track of the addresses to check for warming, and the expected cost of
793+ # accessing such account .
794+ addresses_to_check : Dict [Address , int ] = {}
792795
793796 for authorization_with_properties in authorization_list_with_properties :
794797 authority = authorization_with_properties .tuple .signer
795798 assert authority is not None , "authority address is not set"
796- if authority not in addresses_to_check :
797- warm = False
798- if not authorization_with_properties .skip and (
799- authorization_with_properties .invalidity_type is None
800- or (
801- authorization_with_properties .invalidity_type
802- != AuthorizationInvalidityType .INVALID_CHAIN_ID
799+ delegated_account = authorization_with_properties .tuple .address
800+
801+ if check_delegated_account_first :
802+ if delegated_account not in addresses_to_check :
803+ addresses_to_check [delegated_account ] = (
804+ WARM_ACCOUNT_COST
805+ if access_list_case .contains_authority ()
806+ else COLD_ACCOUNT_COST
803807 )
804- or access_list_case .contains_authority ()
805- ):
806- warm = True
807- addresses_to_check [authority ] = warm
808-
809- if authorize_to_address not in addresses_to_check :
810- addresses_to_check [authorize_to_address ] = access_list_case .contains_set_code_address ()
808+ if authority not in addresses_to_check :
809+ access_cost = (
810+ COLD_ACCOUNT_COST + WARM_ACCOUNT_COST
811+ ) # Delegated-to account is unconditionally warm at this point
812+ if not authorization_with_properties .skip and (
813+ authorization_with_properties .invalidity_type is None
814+ or (
815+ authorization_with_properties .invalidity_type
816+ != AuthorizationInvalidityType .INVALID_CHAIN_ID
817+ )
818+ or access_list_case .contains_authority ()
819+ ):
820+ access_cost = WARM_ACCOUNT_COST * 2
821+
822+ addresses_to_check [authority ] = access_cost
823+ else :
824+ if authority not in addresses_to_check :
825+ access_cost = COLD_ACCOUNT_COST
826+ if not authorization_with_properties .skip and (
827+ authorization_with_properties .invalidity_type is None
828+ or (
829+ authorization_with_properties .invalidity_type
830+ != AuthorizationInvalidityType .INVALID_CHAIN_ID
831+ )
832+ or access_list_case .contains_authority ()
833+ ):
834+ access_cost = WARM_ACCOUNT_COST
835+ if (
836+ delegated_account in addresses_to_check
837+ or access_list_case .contains_set_code_address ()
838+ ):
839+ access_cost += WARM_ACCOUNT_COST
840+ else :
841+ access_cost += COLD_ACCOUNT_COST
842+ addresses_to_check [authority ] = access_cost
811843
812844 callee_storage = Storage ()
813845 callee_code : Bytecode = sum ( # type: ignore
814846 (
815847 CodeGasMeasure (
816848 code = Op .EXTCODESIZE (check_address ),
817- overhead_cost = overhead_cost ,
849+ overhead_cost = OVERHEAD_COST ,
818850 extra_stack_items = 1 ,
819- sstore_key = callee_storage .store_next (100 if warm else 2600 ),
851+ sstore_key = callee_storage .store_next (access_cost ),
820852 stop = False ,
821853 )
822- for check_address , warm in addresses_to_check .items ()
854+ for check_address , access_cost in addresses_to_check .items ()
823855 )
824856 )
825857 callee_code += Op .STOP
0 commit comments