|
13 | 13 |
|
14 | 14 | from ethereum.crypto.elliptic_curve import SECP256K1N, secp256k1_recover |
15 | 15 | from ethereum.crypto.hash import Hash32, keccak256 |
16 | | -from ethereum.exceptions import InvalidSignatureError, InvalidTransaction |
| 16 | +from ethereum.exceptions import ( |
| 17 | + InsufficientTransactionGasError, |
| 18 | + InvalidSignatureError, |
| 19 | + NonceOverflowError, |
| 20 | +) |
17 | 21 |
|
18 | | -from .exceptions import TransactionTypeError |
| 22 | +from .exceptions import InitCodeTooLargeError, TransactionTypeError |
19 | 23 | from .fork_types import Address, VersionedHash |
20 | 24 |
|
21 | 25 | TX_BASE_COST = Uint(21000) |
@@ -439,19 +443,23 @@ def validate_transaction(tx: Transaction) -> Uint: |
439 | 443 |
|
440 | 444 | This function takes a transaction as a parameter and returns the intrinsic |
441 | 445 | gas cost of the transaction after validation. It throws an |
442 | | - `InvalidTransaction` exception if the transaction is invalid. |
| 446 | + `InsufficientTransactionGasError` exception if the transaction does not |
| 447 | + provide enough gas to cover the intrinsic cost, and a `NonceOverflowError` |
| 448 | + exception if the nonce is greater than `2**64 - 2`. It also raises an |
| 449 | + `InitCodeTooLargeError` if the code size of a contract creation transaction |
| 450 | + exceeds the maximum allowed size. |
443 | 451 |
|
444 | 452 | [EIP-2681]: https://eips.ethereum.org/EIPS/eip-2681 |
445 | 453 | """ |
446 | 454 | from .vm.interpreter import MAX_INIT_CODE_SIZE |
447 | 455 |
|
448 | 456 | intrinsic_gas = calculate_intrinsic_cost(tx) |
449 | 457 | if intrinsic_gas > tx.gas: |
450 | | - raise InvalidTransaction("Insufficient gas") |
| 458 | + raise InsufficientTransactionGasError("Insufficient gas") |
451 | 459 | if U256(tx.nonce) >= U256(U64.MAX_VALUE): |
452 | | - raise InvalidTransaction("Nonce too high") |
| 460 | + raise NonceOverflowError("Nonce too high") |
453 | 461 | if tx.to == Bytes0(b"") and len(tx.data) > MAX_INIT_CODE_SIZE: |
454 | | - raise InvalidTransaction("Code size too large") |
| 462 | + raise InitCodeTooLargeError("Code size too large") |
455 | 463 |
|
456 | 464 | return intrinsic_gas |
457 | 465 |
|
|
0 commit comments