52
52
TX_ACCESS_LIST_STORAGE_KEY_COST ,
53
53
TX_BASE_COST ,
54
54
TX_CREATE_COST ,
55
- TX_DATA_COST_PER_NON_ZERO ,
56
- TX_DATA_COST_PER_ZERO ,
55
+ LEGACY_CALLDATA_TOKEN_COST ,
56
+ COST_FLOOR_PER_CALLDATA_TOKEN ,
57
57
AccessListTransaction ,
58
58
BlobTransaction ,
59
59
FeeMarketTransaction ,
@@ -369,7 +369,7 @@ def check_transaction(
369
369
InvalidBlock :
370
370
If the transaction is not includable.
371
371
"""
372
- if calculate_intrinsic_cost (tx ) > tx .gas :
372
+ if calculate_intrinsic_cost (tx )[ 0 ] > tx .gas :
373
373
raise InvalidBlock
374
374
if tx .nonce >= 2 ** 64 - 1 :
375
375
raise InvalidBlock
@@ -754,7 +754,8 @@ def process_transaction(
754
754
755
755
effective_gas_fee = tx .gas * env .gas_price
756
756
757
- gas = tx .gas - calculate_intrinsic_cost (tx )
757
+ intrinsic_gas , tokens_in_calldata = calculate_intrinsic_cost (tx )
758
+ gas = tx .gas - intrinsic_gas
758
759
increment_nonce (env .state , sender )
759
760
760
761
sender_balance_after_gas_fee = (
@@ -785,8 +786,17 @@ def process_transaction(
785
786
)
786
787
787
788
output = process_message_call (message , env )
788
-
789
- gas_used = tx .gas - output .gas_left
789
+
790
+ floor = Uint (tokens_in_calldata * COST_FLOOR_PER_CALLDATA_TOKEN + TX_BASE_COST )
791
+
792
+ legacy_cost = Uint (gas_used + tokens_in_calldata * LEGACY_TOKEN_COST )
793
+
794
+ if legacy_cost < floor :
795
+ output .gas_left -= floor - gas_used
796
+ gas_used = floor
797
+ else :
798
+ gas_used = tx .gas - output .gas_left
799
+
790
800
gas_refund = min (gas_used // 5 , output .refund_counter )
791
801
gas_refund_amount = (output .gas_left + gas_refund ) * env .gas_price
792
802
@@ -823,7 +833,7 @@ def process_transaction(
823
833
return total_gas_used , output .logs , output .error
824
834
825
835
826
- def calculate_intrinsic_cost (tx : Transaction ) -> Uint :
836
+ def calculate_intrinsic_cost (tx : Transaction ) -> Tuple [ Uint , Uint ] :
827
837
"""
828
838
Calculates the gas that is charged before execution is started.
829
839
@@ -845,14 +855,19 @@ def calculate_intrinsic_cost(tx: Transaction) -> Uint:
845
855
-------
846
856
verified : `ethereum.base_types.Uint`
847
857
The intrinsic cost of the transaction.
858
+ verified : `ethereum.base_types.Uint`
859
+ The eip-7623 calldata tokens used by the transaction.
848
860
"""
849
861
data_cost = 0
850
-
862
+
863
+ zerobytes = 0
851
864
for byte in tx .data :
852
865
if byte == 0 :
853
- data_cost += TX_DATA_COST_PER_ZERO
854
- else :
855
- data_cost += TX_DATA_COST_PER_NON_ZERO
866
+ zerobytes += 1
867
+
868
+ tokens_in_calldata = zerobytes + (len (tx .data ) - zerobytes ) * 4
869
+
870
+ data_cost = tokens_in_calldata * COST_FLOOR_PER_CALLDATA_TOKEN
856
871
857
872
if tx .to == Bytes0 (b"" ):
858
873
create_cost = TX_CREATE_COST + int (init_code_cost (Uint (len (tx .data ))))
@@ -867,7 +882,9 @@ def calculate_intrinsic_cost(tx: Transaction) -> Uint:
867
882
access_list_cost += TX_ACCESS_LIST_ADDRESS_COST
868
883
access_list_cost += len (keys ) * TX_ACCESS_LIST_STORAGE_KEY_COST
869
884
870
- return Uint (TX_BASE_COST + data_cost + create_cost + access_list_cost )
885
+ return Uint (TX_BASE_COST +
886
+ data_cost +
887
+ create_cost + access_list_cost ), tokens_in_calldata
871
888
872
889
873
890
def recover_sender (chain_id : U64 , tx : Transaction ) -> Address :
0 commit comments