From 66f2dacdeb6aaf1e372fc624c00ddec1947e9e0c Mon Sep 17 00:00:00 2001 From: Sam Wilson Date: Wed, 30 Oct 2024 22:12:23 -0400 Subject: [PATCH] Introduce error type for txs originating from accounts with code (#1021) --- src/ethereum/arrow_glacier/fork.py | 4 ++-- src/ethereum/berlin/fork.py | 4 ++-- src/ethereum/byzantium/fork.py | 4 ++-- src/ethereum/cancun/fork.py | 4 ++-- src/ethereum/constantinople/fork.py | 4 ++-- src/ethereum/dao_fork/fork.py | 4 ++-- src/ethereum/exceptions.py | 7 +++++++ src/ethereum/frontier/fork.py | 4 ++-- src/ethereum/gray_glacier/fork.py | 4 ++-- src/ethereum/homestead/fork.py | 4 ++-- src/ethereum/istanbul/fork.py | 4 ++-- src/ethereum/london/fork.py | 4 ++-- src/ethereum/muir_glacier/fork.py | 4 ++-- src/ethereum/paris/fork.py | 4 ++-- src/ethereum/shanghai/fork.py | 4 ++-- src/ethereum/spurious_dragon/fork.py | 4 ++-- src/ethereum/tangerine_whistle/fork.py | 4 ++-- 17 files changed, 39 insertions(+), 32 deletions(-) diff --git a/src/ethereum/arrow_glacier/fork.py b/src/ethereum/arrow_glacier/fork.py index 7d6007af76..1cce622ecd 100644 --- a/src/ethereum/arrow_glacier/fork.py +++ b/src/ethereum/arrow_glacier/fork.py @@ -21,7 +21,7 @@ from ethereum.crypto.elliptic_curve import SECP256K1N, secp256k1_recover from ethereum.crypto.hash import Hash32, keccak256 from ethereum.ethash import dataset_size, generate_cache, hashimoto_light -from ethereum.exceptions import InvalidBlock +from ethereum.exceptions import InvalidBlock, InvalidSenderError from .. import rlp from . import vm @@ -794,7 +794,7 @@ def process_transaction( if Uint(sender_account.balance) < max_gas_fee + Uint(tx.value): raise InvalidBlock if sender_account.code != bytearray(): - raise InvalidBlock + raise InvalidSenderError("not EOA") effective_gas_fee = tx.gas * env.gas_price diff --git a/src/ethereum/berlin/fork.py b/src/ethereum/berlin/fork.py index 2b53207ced..b7764c2fad 100644 --- a/src/ethereum/berlin/fork.py +++ b/src/ethereum/berlin/fork.py @@ -21,7 +21,7 @@ from ethereum.crypto.elliptic_curve import SECP256K1N, secp256k1_recover from ethereum.crypto.hash import Hash32, keccak256 from ethereum.ethash import dataset_size, generate_cache, hashimoto_light -from ethereum.exceptions import InvalidBlock +from ethereum.exceptions import InvalidBlock, InvalidSenderError from .. import rlp from . import vm @@ -683,7 +683,7 @@ def process_transaction( if Uint(sender_account.balance) < gas_fee + Uint(tx.value): raise InvalidBlock if sender_account.code != bytearray(): - raise InvalidBlock + raise InvalidSenderError("not EOA") gas = tx.gas - calculate_intrinsic_cost(tx) increment_nonce(env.state, sender) diff --git a/src/ethereum/byzantium/fork.py b/src/ethereum/byzantium/fork.py index 4131c0ea1c..3e311e695f 100644 --- a/src/ethereum/byzantium/fork.py +++ b/src/ethereum/byzantium/fork.py @@ -21,7 +21,7 @@ from ethereum.crypto.elliptic_curve import SECP256K1N, secp256k1_recover from ethereum.crypto.hash import Hash32, keccak256 from ethereum.ethash import dataset_size, generate_cache, hashimoto_light -from ethereum.exceptions import InvalidBlock +from ethereum.exceptions import InvalidBlock, InvalidSenderError from .. import rlp from . import vm @@ -671,7 +671,7 @@ def process_transaction( if Uint(sender_account.balance) < gas_fee + Uint(tx.value): raise InvalidBlock if sender_account.code != bytearray(): - raise InvalidBlock + raise InvalidSenderError("not EOA") gas = tx.gas - calculate_intrinsic_cost(tx) increment_nonce(env.state, sender) diff --git a/src/ethereum/cancun/fork.py b/src/ethereum/cancun/fork.py index 04b2f04f43..454ded353a 100644 --- a/src/ethereum/cancun/fork.py +++ b/src/ethereum/cancun/fork.py @@ -20,7 +20,7 @@ from ethereum.crypto.elliptic_curve import SECP256K1N, secp256k1_recover from ethereum.crypto.hash import Hash32, keccak256 -from ethereum.exceptions import InvalidBlock +from ethereum.exceptions import InvalidBlock, InvalidSenderError from .. import rlp from . import vm @@ -427,7 +427,7 @@ def check_transaction( if Uint(sender_account.balance) < max_gas_fee + Uint(tx.value): raise InvalidBlock if sender_account.code != bytearray(): - raise InvalidBlock + raise InvalidSenderError("not EOA") return sender, effective_gas_price, blob_versioned_hashes diff --git a/src/ethereum/constantinople/fork.py b/src/ethereum/constantinople/fork.py index 50e51990d3..2cae7ad3fa 100644 --- a/src/ethereum/constantinople/fork.py +++ b/src/ethereum/constantinople/fork.py @@ -21,7 +21,7 @@ from ethereum.crypto.elliptic_curve import SECP256K1N, secp256k1_recover from ethereum.crypto.hash import Hash32, keccak256 from ethereum.ethash import dataset_size, generate_cache, hashimoto_light -from ethereum.exceptions import InvalidBlock +from ethereum.exceptions import InvalidBlock, InvalidSenderError from .. import rlp from . import vm @@ -671,7 +671,7 @@ def process_transaction( if Uint(sender_account.balance) < gas_fee + Uint(tx.value): raise InvalidBlock if sender_account.code != bytearray(): - raise InvalidBlock + raise InvalidSenderError("not EOA") gas = tx.gas - calculate_intrinsic_cost(tx) increment_nonce(env.state, sender) diff --git a/src/ethereum/dao_fork/fork.py b/src/ethereum/dao_fork/fork.py index d03e644174..8ebf877de1 100644 --- a/src/ethereum/dao_fork/fork.py +++ b/src/ethereum/dao_fork/fork.py @@ -23,7 +23,7 @@ from ethereum.crypto.elliptic_curve import SECP256K1N, secp256k1_recover from ethereum.crypto.hash import Hash32, keccak256 from ethereum.ethash import dataset_size, generate_cache, hashimoto_light -from ethereum.exceptions import InvalidBlock +from ethereum.exceptions import InvalidBlock, InvalidSenderError from .. import rlp from . import FORK_CRITERIA, vm @@ -677,7 +677,7 @@ def process_transaction( if Uint(sender_account.balance) < gas_fee + Uint(tx.value): raise InvalidBlock if sender_account.code != bytearray(): - raise InvalidBlock + raise InvalidSenderError("not EOA") gas = tx.gas - calculate_intrinsic_cost(tx) increment_nonce(env.state, sender) diff --git a/src/ethereum/exceptions.py b/src/ethereum/exceptions.py index 013dfae369..466778e924 100644 --- a/src/ethereum/exceptions.py +++ b/src/ethereum/exceptions.py @@ -32,3 +32,10 @@ class RLPEncodingError(EthereumException): """ Indicates that RLP encoding failed. """ + + +class InvalidSenderError(InvalidTransaction): + """ + Thrown when a transaction originates from an account that cannot send + transactions. + """ diff --git a/src/ethereum/frontier/fork.py b/src/ethereum/frontier/fork.py index 458ff46700..69e1cbeb21 100644 --- a/src/ethereum/frontier/fork.py +++ b/src/ethereum/frontier/fork.py @@ -21,7 +21,7 @@ from ethereum.crypto.elliptic_curve import SECP256K1N, secp256k1_recover from ethereum.crypto.hash import Hash32, keccak256 from ethereum.ethash import dataset_size, generate_cache, hashimoto_light -from ethereum.exceptions import InvalidBlock +from ethereum.exceptions import InvalidBlock, InvalidSenderError from .. import rlp from . import vm @@ -658,7 +658,7 @@ def process_transaction( if Uint(sender_account.balance) < gas_fee + Uint(tx.value): raise InvalidBlock if sender_account.code != bytearray(): - raise InvalidBlock + raise InvalidSenderError("not EOA") gas = tx.gas - calculate_intrinsic_cost(tx) increment_nonce(env.state, sender) diff --git a/src/ethereum/gray_glacier/fork.py b/src/ethereum/gray_glacier/fork.py index 63617e93bd..e92513a2b4 100644 --- a/src/ethereum/gray_glacier/fork.py +++ b/src/ethereum/gray_glacier/fork.py @@ -21,7 +21,7 @@ from ethereum.crypto.elliptic_curve import SECP256K1N, secp256k1_recover from ethereum.crypto.hash import Hash32, keccak256 from ethereum.ethash import dataset_size, generate_cache, hashimoto_light -from ethereum.exceptions import InvalidBlock +from ethereum.exceptions import InvalidBlock, InvalidSenderError from .. import rlp from . import vm @@ -794,7 +794,7 @@ def process_transaction( if Uint(sender_account.balance) < max_gas_fee + Uint(tx.value): raise InvalidBlock if sender_account.code != bytearray(): - raise InvalidBlock + raise InvalidSenderError("not EOA") effective_gas_fee = tx.gas * env.gas_price diff --git a/src/ethereum/homestead/fork.py b/src/ethereum/homestead/fork.py index 309310362e..bae77156b9 100644 --- a/src/ethereum/homestead/fork.py +++ b/src/ethereum/homestead/fork.py @@ -21,7 +21,7 @@ from ethereum.crypto.elliptic_curve import SECP256K1N, secp256k1_recover from ethereum.crypto.hash import Hash32, keccak256 from ethereum.ethash import dataset_size, generate_cache, hashimoto_light -from ethereum.exceptions import InvalidBlock +from ethereum.exceptions import InvalidBlock, InvalidSenderError from .. import rlp from . import vm @@ -659,7 +659,7 @@ def process_transaction( if Uint(sender_account.balance) < gas_fee + Uint(tx.value): raise InvalidBlock if sender_account.code != bytearray(): - raise InvalidBlock + raise InvalidSenderError("not EOA") gas = tx.gas - calculate_intrinsic_cost(tx) increment_nonce(env.state, sender) diff --git a/src/ethereum/istanbul/fork.py b/src/ethereum/istanbul/fork.py index 6665157072..a647f7193c 100644 --- a/src/ethereum/istanbul/fork.py +++ b/src/ethereum/istanbul/fork.py @@ -21,7 +21,7 @@ from ethereum.crypto.elliptic_curve import SECP256K1N, secp256k1_recover from ethereum.crypto.hash import Hash32, keccak256 from ethereum.ethash import dataset_size, generate_cache, hashimoto_light -from ethereum.exceptions import InvalidBlock +from ethereum.exceptions import InvalidBlock, InvalidSenderError from .. import rlp from . import vm @@ -672,7 +672,7 @@ def process_transaction( if Uint(sender_account.balance) < gas_fee + Uint(tx.value): raise InvalidBlock if sender_account.code != bytearray(): - raise InvalidBlock + raise InvalidSenderError("not EOA") gas = tx.gas - calculate_intrinsic_cost(tx) increment_nonce(env.state, sender) diff --git a/src/ethereum/london/fork.py b/src/ethereum/london/fork.py index 89819d6d30..2fa09d771a 100644 --- a/src/ethereum/london/fork.py +++ b/src/ethereum/london/fork.py @@ -21,7 +21,7 @@ from ethereum.crypto.elliptic_curve import SECP256K1N, secp256k1_recover from ethereum.crypto.hash import Hash32, keccak256 from ethereum.ethash import dataset_size, generate_cache, hashimoto_light -from ethereum.exceptions import InvalidBlock +from ethereum.exceptions import InvalidBlock, InvalidSenderError from .. import rlp from . import FORK_CRITERIA, vm @@ -800,7 +800,7 @@ def process_transaction( if Uint(sender_account.balance) < max_gas_fee + Uint(tx.value): raise InvalidBlock if sender_account.code != bytearray(): - raise InvalidBlock + raise InvalidSenderError("not EOA") effective_gas_fee = tx.gas * env.gas_price diff --git a/src/ethereum/muir_glacier/fork.py b/src/ethereum/muir_glacier/fork.py index 77910a2e0a..ba21a83202 100644 --- a/src/ethereum/muir_glacier/fork.py +++ b/src/ethereum/muir_glacier/fork.py @@ -21,7 +21,7 @@ from ethereum.crypto.elliptic_curve import SECP256K1N, secp256k1_recover from ethereum.crypto.hash import Hash32, keccak256 from ethereum.ethash import dataset_size, generate_cache, hashimoto_light -from ethereum.exceptions import InvalidBlock +from ethereum.exceptions import InvalidBlock, InvalidSenderError from .. import rlp from . import vm @@ -672,7 +672,7 @@ def process_transaction( if Uint(sender_account.balance) < gas_fee + Uint(tx.value): raise InvalidBlock if sender_account.code != bytearray(): - raise InvalidBlock + raise InvalidSenderError("not EOA") gas = tx.gas - calculate_intrinsic_cost(tx) increment_nonce(env.state, sender) diff --git a/src/ethereum/paris/fork.py b/src/ethereum/paris/fork.py index e38611d537..afeb620480 100644 --- a/src/ethereum/paris/fork.py +++ b/src/ethereum/paris/fork.py @@ -20,7 +20,7 @@ from ethereum.crypto.elliptic_curve import SECP256K1N, secp256k1_recover from ethereum.crypto.hash import Hash32, keccak256 -from ethereum.exceptions import InvalidBlock +from ethereum.exceptions import InvalidBlock, InvalidSenderError from .. import rlp from . import vm @@ -584,7 +584,7 @@ def process_transaction( if Uint(sender_account.balance) < max_gas_fee + Uint(tx.value): raise InvalidBlock if sender_account.code != bytearray(): - raise InvalidBlock + raise InvalidSenderError("not EOA") effective_gas_fee = tx.gas * env.gas_price diff --git a/src/ethereum/shanghai/fork.py b/src/ethereum/shanghai/fork.py index 1bfc2bd091..c969e3df2d 100644 --- a/src/ethereum/shanghai/fork.py +++ b/src/ethereum/shanghai/fork.py @@ -20,7 +20,7 @@ from ethereum.crypto.elliptic_curve import SECP256K1N, secp256k1_recover from ethereum.crypto.hash import Hash32, keccak256 -from ethereum.exceptions import InvalidBlock +from ethereum.exceptions import InvalidBlock, InvalidSenderError from .. import rlp from . import vm @@ -607,7 +607,7 @@ def process_transaction( if Uint(sender_account.balance) < max_gas_fee + Uint(tx.value): raise InvalidBlock if sender_account.code != bytearray(): - raise InvalidBlock + raise InvalidSenderError("not EOA") effective_gas_fee = tx.gas * env.gas_price diff --git a/src/ethereum/spurious_dragon/fork.py b/src/ethereum/spurious_dragon/fork.py index ec19a316ce..bb1c9bbbc1 100644 --- a/src/ethereum/spurious_dragon/fork.py +++ b/src/ethereum/spurious_dragon/fork.py @@ -21,7 +21,7 @@ from ethereum.crypto.elliptic_curve import SECP256K1N, secp256k1_recover from ethereum.crypto.hash import Hash32, keccak256 from ethereum.ethash import dataset_size, generate_cache, hashimoto_light -from ethereum.exceptions import InvalidBlock +from ethereum.exceptions import InvalidBlock, InvalidSenderError from .. import rlp from . import vm @@ -667,7 +667,7 @@ def process_transaction( if Uint(sender_account.balance) < gas_fee + Uint(tx.value): raise InvalidBlock if sender_account.code != bytearray(): - raise InvalidBlock + raise InvalidSenderError("not EOA") gas = tx.gas - calculate_intrinsic_cost(tx) increment_nonce(env.state, sender) diff --git a/src/ethereum/tangerine_whistle/fork.py b/src/ethereum/tangerine_whistle/fork.py index 309310362e..bae77156b9 100644 --- a/src/ethereum/tangerine_whistle/fork.py +++ b/src/ethereum/tangerine_whistle/fork.py @@ -21,7 +21,7 @@ from ethereum.crypto.elliptic_curve import SECP256K1N, secp256k1_recover from ethereum.crypto.hash import Hash32, keccak256 from ethereum.ethash import dataset_size, generate_cache, hashimoto_light -from ethereum.exceptions import InvalidBlock +from ethereum.exceptions import InvalidBlock, InvalidSenderError from .. import rlp from . import vm @@ -659,7 +659,7 @@ def process_transaction( if Uint(sender_account.balance) < gas_fee + Uint(tx.value): raise InvalidBlock if sender_account.code != bytearray(): - raise InvalidBlock + raise InvalidSenderError("not EOA") gas = tx.gas - calculate_intrinsic_cost(tx) increment_nonce(env.state, sender)