From 47863f73c00ccf37538eab5ddb999cd46642b781 Mon Sep 17 00:00:00 2001 From: Sam Wilson Date: Thu, 17 Oct 2024 12:05:48 -0400 Subject: [PATCH] Create TYPE_NOT_SUPPORTED error (#1021) --- src/ethereum/arrow_glacier/exceptions.py | 24 ++++++++++++++++++++++ src/ethereum/arrow_glacier/transactions.py | 4 ++-- src/ethereum/berlin/exceptions.py | 24 ++++++++++++++++++++++ src/ethereum/berlin/transactions.py | 4 ++-- src/ethereum/cancun/exceptions.py | 24 ++++++++++++++++++++++ src/ethereum/cancun/transactions.py | 4 ++-- src/ethereum/exceptions.py | 6 ++++++ src/ethereum/gray_glacier/exceptions.py | 24 ++++++++++++++++++++++ src/ethereum/gray_glacier/transactions.py | 4 ++-- src/ethereum/london/exceptions.py | 24 ++++++++++++++++++++++ src/ethereum/london/transactions.py | 4 ++-- src/ethereum/paris/exceptions.py | 24 ++++++++++++++++++++++ src/ethereum/paris/transactions.py | 4 ++-- src/ethereum/shanghai/exceptions.py | 24 ++++++++++++++++++++++ src/ethereum/shanghai/transactions.py | 4 ++-- 15 files changed, 188 insertions(+), 14 deletions(-) create mode 100644 src/ethereum/arrow_glacier/exceptions.py create mode 100644 src/ethereum/berlin/exceptions.py create mode 100644 src/ethereum/cancun/exceptions.py create mode 100644 src/ethereum/gray_glacier/exceptions.py create mode 100644 src/ethereum/london/exceptions.py create mode 100644 src/ethereum/paris/exceptions.py create mode 100644 src/ethereum/shanghai/exceptions.py diff --git a/src/ethereum/arrow_glacier/exceptions.py b/src/ethereum/arrow_glacier/exceptions.py new file mode 100644 index 0000000000..5781a2c1c3 --- /dev/null +++ b/src/ethereum/arrow_glacier/exceptions.py @@ -0,0 +1,24 @@ +""" +Exceptions specific to this fork. +""" + +from typing import Final + +from ethereum.exceptions import InvalidTransaction + + +class TransactionTypeError(InvalidTransaction): + """ + Unknown [EIP-2718] transaction type byte. + + [EIP-2718]: https://eips.ethereum.org/EIPS/eip-2718 + """ + + transaction_type: Final[int] + """ + The type byte of the transaction that caused the error. + """ + + def __init__(self, transaction_type: int): + super().__init__(f"unknown transaction type `{transaction_type}`") + self.transaction_type = transaction_type diff --git a/src/ethereum/arrow_glacier/transactions.py b/src/ethereum/arrow_glacier/transactions.py index 2a3cbd211c..9f1180f5c6 100644 --- a/src/ethereum/arrow_glacier/transactions.py +++ b/src/ethereum/arrow_glacier/transactions.py @@ -11,7 +11,7 @@ from ethereum_types.numeric import U64, U256, Uint from .. import rlp -from ..exceptions import InvalidBlock +from .exceptions import TransactionTypeError from .fork_types import Address TX_BASE_COST = 21000 @@ -110,6 +110,6 @@ def decode_transaction(tx: Union[LegacyTransaction, Bytes]) -> Transaction: elif tx[0] == 2: return rlp.decode_to(FeeMarketTransaction, tx[1:]) else: - raise InvalidBlock + raise TransactionTypeError(tx[0]) else: return tx diff --git a/src/ethereum/berlin/exceptions.py b/src/ethereum/berlin/exceptions.py new file mode 100644 index 0000000000..5781a2c1c3 --- /dev/null +++ b/src/ethereum/berlin/exceptions.py @@ -0,0 +1,24 @@ +""" +Exceptions specific to this fork. +""" + +from typing import Final + +from ethereum.exceptions import InvalidTransaction + + +class TransactionTypeError(InvalidTransaction): + """ + Unknown [EIP-2718] transaction type byte. + + [EIP-2718]: https://eips.ethereum.org/EIPS/eip-2718 + """ + + transaction_type: Final[int] + """ + The type byte of the transaction that caused the error. + """ + + def __init__(self, transaction_type: int): + super().__init__(f"unknown transaction type `{transaction_type}`") + self.transaction_type = transaction_type diff --git a/src/ethereum/berlin/transactions.py b/src/ethereum/berlin/transactions.py index fb53de628a..7215321be2 100644 --- a/src/ethereum/berlin/transactions.py +++ b/src/ethereum/berlin/transactions.py @@ -11,7 +11,7 @@ from ethereum_types.numeric import U64, U256, Uint from .. import rlp -from ..exceptions import InvalidBlock +from .exceptions import TransactionTypeError from .fork_types import Address TX_BASE_COST = 21000 @@ -81,7 +81,7 @@ def decode_transaction(tx: Union[LegacyTransaction, Bytes]) -> Transaction: """ if isinstance(tx, Bytes): if tx[0] != 1: - raise InvalidBlock + raise TransactionTypeError(tx[0]) return rlp.decode_to(AccessListTransaction, tx[1:]) else: return tx diff --git a/src/ethereum/cancun/exceptions.py b/src/ethereum/cancun/exceptions.py new file mode 100644 index 0000000000..5781a2c1c3 --- /dev/null +++ b/src/ethereum/cancun/exceptions.py @@ -0,0 +1,24 @@ +""" +Exceptions specific to this fork. +""" + +from typing import Final + +from ethereum.exceptions import InvalidTransaction + + +class TransactionTypeError(InvalidTransaction): + """ + Unknown [EIP-2718] transaction type byte. + + [EIP-2718]: https://eips.ethereum.org/EIPS/eip-2718 + """ + + transaction_type: Final[int] + """ + The type byte of the transaction that caused the error. + """ + + def __init__(self, transaction_type: int): + super().__init__(f"unknown transaction type `{transaction_type}`") + self.transaction_type = transaction_type diff --git a/src/ethereum/cancun/transactions.py b/src/ethereum/cancun/transactions.py index 70e0fc8286..13f04b3037 100644 --- a/src/ethereum/cancun/transactions.py +++ b/src/ethereum/cancun/transactions.py @@ -11,7 +11,7 @@ from ethereum_types.numeric import U64, U256, Uint from .. import rlp -from ..exceptions import InvalidBlock +from .exceptions import TransactionTypeError from .fork_types import Address, VersionedHash TX_BASE_COST = 21000 @@ -140,6 +140,6 @@ def decode_transaction(tx: Union[LegacyTransaction, Bytes]) -> Transaction: elif tx[0] == 3: return rlp.decode_to(BlobTransaction, tx[1:]) else: - raise InvalidBlock + raise TransactionTypeError(tx[0]) else: return tx diff --git a/src/ethereum/exceptions.py b/src/ethereum/exceptions.py index 4b2e787b73..1b2398538c 100644 --- a/src/ethereum/exceptions.py +++ b/src/ethereum/exceptions.py @@ -16,6 +16,12 @@ class InvalidBlock(EthereumException): """ +class InvalidTransaction(EthereumException): + """ + Thrown when a transaction being processed is found to be invalid. + """ + + class RLPDecodingError(InvalidBlock): """ Indicates that RLP decoding failed. diff --git a/src/ethereum/gray_glacier/exceptions.py b/src/ethereum/gray_glacier/exceptions.py new file mode 100644 index 0000000000..5781a2c1c3 --- /dev/null +++ b/src/ethereum/gray_glacier/exceptions.py @@ -0,0 +1,24 @@ +""" +Exceptions specific to this fork. +""" + +from typing import Final + +from ethereum.exceptions import InvalidTransaction + + +class TransactionTypeError(InvalidTransaction): + """ + Unknown [EIP-2718] transaction type byte. + + [EIP-2718]: https://eips.ethereum.org/EIPS/eip-2718 + """ + + transaction_type: Final[int] + """ + The type byte of the transaction that caused the error. + """ + + def __init__(self, transaction_type: int): + super().__init__(f"unknown transaction type `{transaction_type}`") + self.transaction_type = transaction_type diff --git a/src/ethereum/gray_glacier/transactions.py b/src/ethereum/gray_glacier/transactions.py index 2a3cbd211c..9f1180f5c6 100644 --- a/src/ethereum/gray_glacier/transactions.py +++ b/src/ethereum/gray_glacier/transactions.py @@ -11,7 +11,7 @@ from ethereum_types.numeric import U64, U256, Uint from .. import rlp -from ..exceptions import InvalidBlock +from .exceptions import TransactionTypeError from .fork_types import Address TX_BASE_COST = 21000 @@ -110,6 +110,6 @@ def decode_transaction(tx: Union[LegacyTransaction, Bytes]) -> Transaction: elif tx[0] == 2: return rlp.decode_to(FeeMarketTransaction, tx[1:]) else: - raise InvalidBlock + raise TransactionTypeError(tx[0]) else: return tx diff --git a/src/ethereum/london/exceptions.py b/src/ethereum/london/exceptions.py new file mode 100644 index 0000000000..5781a2c1c3 --- /dev/null +++ b/src/ethereum/london/exceptions.py @@ -0,0 +1,24 @@ +""" +Exceptions specific to this fork. +""" + +from typing import Final + +from ethereum.exceptions import InvalidTransaction + + +class TransactionTypeError(InvalidTransaction): + """ + Unknown [EIP-2718] transaction type byte. + + [EIP-2718]: https://eips.ethereum.org/EIPS/eip-2718 + """ + + transaction_type: Final[int] + """ + The type byte of the transaction that caused the error. + """ + + def __init__(self, transaction_type: int): + super().__init__(f"unknown transaction type `{transaction_type}`") + self.transaction_type = transaction_type diff --git a/src/ethereum/london/transactions.py b/src/ethereum/london/transactions.py index 2a3cbd211c..9f1180f5c6 100644 --- a/src/ethereum/london/transactions.py +++ b/src/ethereum/london/transactions.py @@ -11,7 +11,7 @@ from ethereum_types.numeric import U64, U256, Uint from .. import rlp -from ..exceptions import InvalidBlock +from .exceptions import TransactionTypeError from .fork_types import Address TX_BASE_COST = 21000 @@ -110,6 +110,6 @@ def decode_transaction(tx: Union[LegacyTransaction, Bytes]) -> Transaction: elif tx[0] == 2: return rlp.decode_to(FeeMarketTransaction, tx[1:]) else: - raise InvalidBlock + raise TransactionTypeError(tx[0]) else: return tx diff --git a/src/ethereum/paris/exceptions.py b/src/ethereum/paris/exceptions.py new file mode 100644 index 0000000000..5781a2c1c3 --- /dev/null +++ b/src/ethereum/paris/exceptions.py @@ -0,0 +1,24 @@ +""" +Exceptions specific to this fork. +""" + +from typing import Final + +from ethereum.exceptions import InvalidTransaction + + +class TransactionTypeError(InvalidTransaction): + """ + Unknown [EIP-2718] transaction type byte. + + [EIP-2718]: https://eips.ethereum.org/EIPS/eip-2718 + """ + + transaction_type: Final[int] + """ + The type byte of the transaction that caused the error. + """ + + def __init__(self, transaction_type: int): + super().__init__(f"unknown transaction type `{transaction_type}`") + self.transaction_type = transaction_type diff --git a/src/ethereum/paris/transactions.py b/src/ethereum/paris/transactions.py index 2a3cbd211c..9f1180f5c6 100644 --- a/src/ethereum/paris/transactions.py +++ b/src/ethereum/paris/transactions.py @@ -11,7 +11,7 @@ from ethereum_types.numeric import U64, U256, Uint from .. import rlp -from ..exceptions import InvalidBlock +from .exceptions import TransactionTypeError from .fork_types import Address TX_BASE_COST = 21000 @@ -110,6 +110,6 @@ def decode_transaction(tx: Union[LegacyTransaction, Bytes]) -> Transaction: elif tx[0] == 2: return rlp.decode_to(FeeMarketTransaction, tx[1:]) else: - raise InvalidBlock + raise TransactionTypeError(tx[0]) else: return tx diff --git a/src/ethereum/shanghai/exceptions.py b/src/ethereum/shanghai/exceptions.py new file mode 100644 index 0000000000..5781a2c1c3 --- /dev/null +++ b/src/ethereum/shanghai/exceptions.py @@ -0,0 +1,24 @@ +""" +Exceptions specific to this fork. +""" + +from typing import Final + +from ethereum.exceptions import InvalidTransaction + + +class TransactionTypeError(InvalidTransaction): + """ + Unknown [EIP-2718] transaction type byte. + + [EIP-2718]: https://eips.ethereum.org/EIPS/eip-2718 + """ + + transaction_type: Final[int] + """ + The type byte of the transaction that caused the error. + """ + + def __init__(self, transaction_type: int): + super().__init__(f"unknown transaction type `{transaction_type}`") + self.transaction_type = transaction_type diff --git a/src/ethereum/shanghai/transactions.py b/src/ethereum/shanghai/transactions.py index 2a3cbd211c..9f1180f5c6 100644 --- a/src/ethereum/shanghai/transactions.py +++ b/src/ethereum/shanghai/transactions.py @@ -11,7 +11,7 @@ from ethereum_types.numeric import U64, U256, Uint from .. import rlp -from ..exceptions import InvalidBlock +from .exceptions import TransactionTypeError from .fork_types import Address TX_BASE_COST = 21000 @@ -110,6 +110,6 @@ def decode_transaction(tx: Union[LegacyTransaction, Bytes]) -> Transaction: elif tx[0] == 2: return rlp.decode_to(FeeMarketTransaction, tx[1:]) else: - raise InvalidBlock + raise TransactionTypeError(tx[0]) else: return tx