1313
1414from ethereum .crypto .elliptic_curve import SECP256K1N , secp256k1_recover
1515from ethereum .crypto .hash import Hash32 , keccak256
16- from ethereum .exceptions import InvalidSignatureError
16+ from ethereum .exceptions import InvalidBlock , InvalidSignatureError
1717
1818from .exceptions import TransactionTypeError
1919from .fork_types import Address , Authorization , VersionedHash
@@ -176,7 +176,7 @@ def decode_transaction(tx: Union[LegacyTransaction, Bytes]) -> Transaction:
176176 return tx
177177
178178
179- def validate_transaction (tx : Transaction ) -> bool :
179+ def validate_transaction (tx : Transaction ) -> Tuple [ Uint , Uint ] :
180180 """
181181 Verifies a transaction.
182182
@@ -198,21 +198,28 @@ def validate_transaction(tx: Transaction) -> bool:
198198
199199 Returns
200200 -------
201- verified : `bool`
202- True if the transaction can be executed, or False otherwise.
201+ intrinsic_gas : `ethereum.base_types.Uint`
202+ The intrinsic cost of the transaction.
203+ calldata_floor_gas_cost : `ethereum.base_types.Uint`
204+ The eip-7623 minimum gas cost charged to the transaction
205+ based on the calldata size.
206+
207+ Raises
208+ ------
209+ InvalidBlock :
210+ If the transaction is not valid.
203211 """
204212 from .vm .interpreter import MAX_CODE_SIZE
205213
206- intrinsic_gas , tokens_in_calldata = calculate_intrinsic_cost (tx )
207- gas_floor = Uint (tokens_in_calldata * FLOOR_CALLDATA_COST + TX_BASE_COST )
208- if max (intrinsic_gas , gas_floor ) > tx .gas :
209- return False
214+ intrinsic_gas , calldata_floor_gas_cost = calculate_intrinsic_cost (tx )
215+ if max (intrinsic_gas , calldata_floor_gas_cost ) > tx .gas :
216+ raise InvalidBlock
210217 if U256 (tx .nonce ) >= U256 (U64 .MAX_VALUE ):
211- return False
218+ raise InvalidBlock
212219 if tx .to == Bytes0 (b"" ) and len (tx .data ) > 2 * MAX_CODE_SIZE :
213- return False
220+ raise InvalidBlock
214221
215- return True
222+ return intrinsic_gas , calldata_floor_gas_cost
216223
217224
218225def calculate_intrinsic_cost (tx : Transaction ) -> Tuple [Uint , Uint ]:
@@ -235,10 +242,11 @@ def calculate_intrinsic_cost(tx: Transaction) -> Tuple[Uint, Uint]:
235242
236243 Returns
237244 -------
238- verified : `ethereum.base_types.Uint`
245+ intrinsic_gas : `ethereum.base_types.Uint`
239246 The intrinsic cost of the transaction.
240- tokens_in_calldata : `ethereum.base_types.Uint`
241- The eip-7623 calldata tokens used by the transaction.
247+ calldata_floor_gas_cost : `ethereum.base_types.Uint`
248+ The eip-7623 minimum gas cost used by the transaction
249+ based on the calldata size.
242250 """
243251 from .vm .eoa_delegation import PER_EMPTY_ACCOUNT_COST
244252 from .vm .gas import init_code_cost
@@ -248,9 +256,13 @@ def calculate_intrinsic_cost(tx: Transaction) -> Tuple[Uint, Uint]:
248256 if byte == 0 :
249257 zero_bytes += 1
250258
251- tokens_in_calldata = zero_bytes + (len (tx .data ) - zero_bytes ) * 4
259+ tokens_in_calldata = Uint (zero_bytes + (len (tx .data ) - zero_bytes ) * 4 )
260+ # EIP-7623 floor price (note: no EVM costs)
261+ calldata_floor_gas_cost = (
262+ tokens_in_calldata * FLOOR_CALLDATA_COST + TX_BASE_COST
263+ )
252264
253- data_cost = Uint ( tokens_in_calldata ) * STANDARD_CALLDATA_TOKEN_COST
265+ data_cost = tokens_in_calldata * STANDARD_CALLDATA_TOKEN_COST
254266
255267 if tx .to == Bytes0 (b"" ):
256268 create_cost = TX_CREATE_COST + init_code_cost (ulen (tx .data ))
@@ -283,7 +295,7 @@ def calculate_intrinsic_cost(tx: Transaction) -> Tuple[Uint, Uint]:
283295 + access_list_cost
284296 + auth_cost
285297 ),
286- Uint ( tokens_in_calldata ) ,
298+ calldata_floor_gas_cost ,
287299 )
288300
289301
0 commit comments