From 05f76ba508c55fbb1a7abd47947cd96c9ded6760 Mon Sep 17 00:00:00 2001 From: Richard Gregory Date: Thu, 22 Feb 2024 14:54:37 +0100 Subject: [PATCH 01/15] Refactor includability check in homestead --- src/ethereum/homestead/fork.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/ethereum/homestead/fork.py b/src/ethereum/homestead/fork.py index 1037b340df..b36bf8b0c7 100644 --- a/src/ethereum/homestead/fork.py +++ b/src/ethereum/homestead/fork.py @@ -302,6 +302,7 @@ def validate_proof_of_work(header: Header) -> None: def check_transaction( + env: vm.Environment, tx: Transaction, gas_available: Uint, ) -> Address: @@ -310,6 +311,8 @@ def check_transaction( Parameters ---------- + env : + Environment for the Ethereum Virtual Machine. tx : The transaction. gas_available : @@ -325,6 +328,13 @@ def check_transaction( InvalidBlock : If the transaction is not includable. """ + sender = env.origin + sender_account = get_account(env.state, sender) + gas_fee = tx.gas * tx.gas_price + ensure(sender_account.nonce == tx.nonce, InvalidBlock) + ensure(sender_account.balance >= gas_fee + tx.value, InvalidBlock) + ensure(sender_account.code == bytearray(), InvalidBlock) + ensure(tx.gas <= gas_available, InvalidBlock) sender_address = recover_sender(tx) @@ -656,9 +666,6 @@ def process_transaction( sender = env.origin sender_account = get_account(env.state, sender) gas_fee = tx.gas * tx.gas_price - ensure(sender_account.nonce == tx.nonce, InvalidBlock) - ensure(sender_account.balance >= gas_fee + tx.value, InvalidBlock) - ensure(sender_account.code == bytearray(), InvalidBlock) gas = tx.gas - calculate_intrinsic_cost(tx) increment_nonce(env.state, sender) From 50a7b1aabb88ac9d6aeaed66067ed9df102e5393 Mon Sep 17 00:00:00 2001 From: Richard Gregory Date: Wed, 28 Feb 2024 12:37:12 +0100 Subject: [PATCH 02/15] Refactor includability check in constantinople --- src/ethereum/constantinople/fork.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/ethereum/constantinople/fork.py b/src/ethereum/constantinople/fork.py index f52b17d890..6f7d1bdb0d 100644 --- a/src/ethereum/constantinople/fork.py +++ b/src/ethereum/constantinople/fork.py @@ -308,6 +308,7 @@ def validate_proof_of_work(header: Header) -> None: def check_transaction( + env: vm.Environment, tx: Transaction, gas_available: Uint, chain_id: U64, @@ -317,6 +318,8 @@ def check_transaction( Parameters ---------- + env : + Environment for the Ethereum Virtual Machine. tx : The transaction. gas_available : @@ -334,6 +337,14 @@ def check_transaction( InvalidBlock : If the transaction is not includable. """ + sender = env.origin + sender_account = get_account(env.state, sender) + gas_fee = tx.gas * tx.gas_price + + ensure(sender_account.nonce == tx.nonce, InvalidBlock) + ensure(sender_account.balance >= gas_fee + tx.value, InvalidBlock) + ensure(sender_account.code == bytearray(), InvalidBlock) + ensure(tx.gas <= gas_available, InvalidBlock) sender_address = recover_sender(chain_id, tx) @@ -668,9 +679,6 @@ def process_transaction( sender = env.origin sender_account = get_account(env.state, sender) gas_fee = tx.gas * tx.gas_price - ensure(sender_account.nonce == tx.nonce, InvalidBlock) - ensure(sender_account.balance >= gas_fee + tx.value, InvalidBlock) - ensure(sender_account.code == bytearray(), InvalidBlock) gas = tx.gas - calculate_intrinsic_cost(tx) increment_nonce(env.state, sender) From 7f6a1210499cc1ba2f5045aeb312d08b32ffe8d5 Mon Sep 17 00:00:00 2001 From: Richard Gregory Date: Wed, 28 Feb 2024 12:58:45 +0100 Subject: [PATCH 03/15] Refactor includability check in Arrow Glacier. --- src/ethereum/arrow_glacier/fork.py | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/ethereum/arrow_glacier/fork.py b/src/ethereum/arrow_glacier/fork.py index 82f452daf3..954204fee0 100644 --- a/src/ethereum/arrow_glacier/fork.py +++ b/src/ethereum/arrow_glacier/fork.py @@ -391,6 +391,7 @@ def validate_proof_of_work(header: Header) -> None: def check_transaction( + env: vm.Environment, tx: Transaction, base_fee_per_gas: Uint, gas_available: Uint, @@ -401,6 +402,8 @@ def check_transaction( Parameters ---------- + env : + Environment for the Ethereum Virtual Machine. tx : The transaction. base_fee_per_gas : @@ -422,6 +425,18 @@ def check_transaction( InvalidBlock : If the transaction is not includable. """ + sender = env.origin + sender_account = get_account(env.state, sender) + + if isinstance(tx, FeeMarketTransaction): + gas_fee = tx.gas * tx.max_fee_per_gas + else: + gas_fee = tx.gas * tx.gas_price + + ensure(sender_account.nonce == tx.nonce, InvalidBlock) + ensure(sender_account.balance >= gas_fee + tx.value, InvalidBlock) + ensure(sender_account.code == bytearray(), InvalidBlock) + ensure(tx.gas <= gas_available, InvalidBlock) sender_address = recover_sender(chain_id, tx) @@ -783,15 +798,6 @@ def process_transaction( sender = env.origin sender_account = get_account(env.state, sender) - if isinstance(tx, FeeMarketTransaction): - max_gas_fee = tx.gas * tx.max_fee_per_gas - else: - max_gas_fee = tx.gas * tx.gas_price - - ensure(sender_account.nonce == tx.nonce, InvalidBlock) - ensure(sender_account.balance >= max_gas_fee + tx.value, InvalidBlock) - ensure(sender_account.code == bytearray(), InvalidBlock) - effective_gas_fee = tx.gas * env.gas_price gas = tx.gas - calculate_intrinsic_cost(tx) From 7ed3cd4ad39f0593223d7cd12ffa16037fb29170 Mon Sep 17 00:00:00 2001 From: Richard Gregory Date: Wed, 28 Feb 2024 14:33:36 +0100 Subject: [PATCH 04/15] Refactor includability check for Berlin --- src/ethereum/berlin/fork.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/ethereum/berlin/fork.py b/src/ethereum/berlin/fork.py index 9c64bd85c0..36cd44b685 100644 --- a/src/ethereum/berlin/fork.py +++ b/src/ethereum/berlin/fork.py @@ -314,6 +314,7 @@ def validate_proof_of_work(header: Header) -> None: def check_transaction( + env: vm.Environment, tx: Transaction, gas_available: Uint, chain_id: U64, @@ -323,6 +324,8 @@ def check_transaction( Parameters ---------- + env : + Environment for the Ethereum Virtual Machine. tx : The transaction. gas_available : @@ -340,6 +343,13 @@ def check_transaction( InvalidBlock : If the transaction is not includable. """ + sender = env.origin + sender_account = get_account(env.state, sender) + gas_fee = tx.gas * tx.gas_price + ensure(sender_account.nonce == tx.nonce, InvalidBlock) + ensure(sender_account.balance >= gas_fee + tx.value, InvalidBlock) + ensure(sender_account.code == bytearray(), InvalidBlock) + ensure(tx.gas <= gas_available, InvalidBlock) sender_address = recover_sender(chain_id, tx) @@ -680,9 +690,6 @@ def process_transaction( sender = env.origin sender_account = get_account(env.state, sender) gas_fee = tx.gas * tx.gas_price - ensure(sender_account.nonce == tx.nonce, InvalidBlock) - ensure(sender_account.balance >= gas_fee + tx.value, InvalidBlock) - ensure(sender_account.code == bytearray(), InvalidBlock) gas = tx.gas - calculate_intrinsic_cost(tx) increment_nonce(env.state, sender) From 3bdab60fc950f359777b8363c80bcbebca8879c0 Mon Sep 17 00:00:00 2001 From: Richard Gregory Date: Wed, 28 Feb 2024 14:45:51 +0100 Subject: [PATCH 05/15] Refactor includability check for Byzantium --- src/ethereum/byzantium/fork.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/ethereum/byzantium/fork.py b/src/ethereum/byzantium/fork.py index 31b745aabe..58f296a16f 100644 --- a/src/ethereum/byzantium/fork.py +++ b/src/ethereum/byzantium/fork.py @@ -308,6 +308,7 @@ def validate_proof_of_work(header: Header) -> None: def check_transaction( + env: vm.Environment, tx: Transaction, gas_available: Uint, chain_id: U64, @@ -317,6 +318,8 @@ def check_transaction( Parameters ---------- + env : + Environment for the Ethereum Virtual Machine. tx : The transaction. gas_available : @@ -334,6 +337,13 @@ def check_transaction( InvalidBlock : If the transaction is not includable. """ + sender = env.origin + sender_account = get_account(env.state, sender) + gas_fee = tx.gas * tx.gas_price + ensure(sender_account.nonce == tx.nonce, InvalidBlock) + ensure(sender_account.balance >= gas_fee + tx.value, InvalidBlock) + ensure(sender_account.code == bytearray(), InvalidBlock) + ensure(tx.gas <= gas_available, InvalidBlock) sender_address = recover_sender(chain_id, tx) @@ -668,9 +678,6 @@ def process_transaction( sender = env.origin sender_account = get_account(env.state, sender) gas_fee = tx.gas * tx.gas_price - ensure(sender_account.nonce == tx.nonce, InvalidBlock) - ensure(sender_account.balance >= gas_fee + tx.value, InvalidBlock) - ensure(sender_account.code == bytearray(), InvalidBlock) gas = tx.gas - calculate_intrinsic_cost(tx) increment_nonce(env.state, sender) From 6fef4ebd3c91604edf25da52e434f020ca5d3db2 Mon Sep 17 00:00:00 2001 From: Richard Gregory Date: Wed, 28 Feb 2024 14:53:12 +0100 Subject: [PATCH 06/15] Refactor includability check for DAO Fork --- src/ethereum/constantinople/fork.py | 2 +- src/ethereum/dao_fork/fork.py | 13 ++++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/ethereum/constantinople/fork.py b/src/ethereum/constantinople/fork.py index 6f7d1bdb0d..208152d7ea 100644 --- a/src/ethereum/constantinople/fork.py +++ b/src/ethereum/constantinople/fork.py @@ -340,7 +340,7 @@ def check_transaction( sender = env.origin sender_account = get_account(env.state, sender) gas_fee = tx.gas * tx.gas_price - + ensure(sender_account.nonce == tx.nonce, InvalidBlock) ensure(sender_account.balance >= gas_fee + tx.value, InvalidBlock) ensure(sender_account.code == bytearray(), InvalidBlock) diff --git a/src/ethereum/dao_fork/fork.py b/src/ethereum/dao_fork/fork.py index fb453598c8..afd59edf0c 100644 --- a/src/ethereum/dao_fork/fork.py +++ b/src/ethereum/dao_fork/fork.py @@ -319,6 +319,7 @@ def validate_proof_of_work(header: Header) -> None: def check_transaction( + env: vm.Environment, tx: Transaction, gas_available: Uint, ) -> Address: @@ -327,6 +328,8 @@ def check_transaction( Parameters ---------- + env : + Environment for the Ethereum Virtual Machine. tx : The transaction. gas_available : @@ -342,6 +345,13 @@ def check_transaction( InvalidBlock : If the transaction is not includable. """ + sender = env.origin + sender_account = get_account(env.state, sender) + gas_fee = tx.gas * tx.gas_price + ensure(sender_account.nonce == tx.nonce, InvalidBlock) + ensure(sender_account.balance >= gas_fee + tx.value, InvalidBlock) + ensure(sender_account.code == bytearray(), InvalidBlock) + ensure(tx.gas <= gas_available, InvalidBlock) sender_address = recover_sender(tx) @@ -673,9 +683,6 @@ def process_transaction( sender = env.origin sender_account = get_account(env.state, sender) gas_fee = tx.gas * tx.gas_price - ensure(sender_account.nonce == tx.nonce, InvalidBlock) - ensure(sender_account.balance >= gas_fee + tx.value, InvalidBlock) - ensure(sender_account.code == bytearray(), InvalidBlock) gas = tx.gas - calculate_intrinsic_cost(tx) increment_nonce(env.state, sender) From 72c60048c6598bc0dca7ff9cc25b8442772def6e Mon Sep 17 00:00:00 2001 From: Richard Gregory Date: Wed, 28 Feb 2024 15:08:00 +0100 Subject: [PATCH 07/15] Refactor includability check for Frontier --- src/ethereum/frontier/fork.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/ethereum/frontier/fork.py b/src/ethereum/frontier/fork.py index 897fdb4e21..9228b190ae 100644 --- a/src/ethereum/frontier/fork.py +++ b/src/ethereum/frontier/fork.py @@ -300,6 +300,7 @@ def validate_proof_of_work(header: Header) -> None: def check_transaction( + env: vm.Environment, tx: Transaction, gas_available: Uint, ) -> Address: @@ -308,6 +309,8 @@ def check_transaction( Parameters ---------- + env : + Environment for the Ethereum Virtual Machine. tx : The transaction. gas_available : @@ -323,6 +326,13 @@ def check_transaction( InvalidBlock : If the transaction is not includable. """ + sender = env.origin + sender_account = get_account(env.state, sender) + gas_fee = tx.gas * tx.gas_price + ensure(sender_account.nonce == tx.nonce, InvalidBlock) + ensure(sender_account.balance >= gas_fee + tx.value, InvalidBlock) + ensure(sender_account.code == bytearray(), InvalidBlock) + ensure(tx.gas <= gas_available, InvalidBlock) sender_address = recover_sender(tx) @@ -654,9 +664,6 @@ def process_transaction( sender = env.origin sender_account = get_account(env.state, sender) gas_fee = tx.gas * tx.gas_price - ensure(sender_account.nonce == tx.nonce, InvalidBlock) - ensure(sender_account.balance >= gas_fee + tx.value, InvalidBlock) - ensure(sender_account.code == bytearray(), InvalidBlock) gas = tx.gas - calculate_intrinsic_cost(tx) increment_nonce(env.state, sender) From 1ef6434989cab204f49a0c78e487ceded4d4a076 Mon Sep 17 00:00:00 2001 From: Richard Gregory Date: Wed, 28 Feb 2024 15:40:22 +0100 Subject: [PATCH 08/15] Refactor includability check for Instanbul --- src/ethereum/istanbul/fork.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/ethereum/istanbul/fork.py b/src/ethereum/istanbul/fork.py index f98937d8e8..1f9a1d6087 100644 --- a/src/ethereum/istanbul/fork.py +++ b/src/ethereum/istanbul/fork.py @@ -308,6 +308,7 @@ def validate_proof_of_work(header: Header) -> None: def check_transaction( + env: vm.Environment, tx: Transaction, gas_available: Uint, chain_id: U64, @@ -317,6 +318,8 @@ def check_transaction( Parameters ---------- + env : + Environment for the Ethereum Virtual Machine. tx : The transaction. gas_available : @@ -334,6 +337,13 @@ def check_transaction( InvalidBlock : If the transaction is not includable. """ + sender = env.origin + sender_account = get_account(env.state, sender) + gas_fee = tx.gas * tx.gas_price + ensure(sender_account.nonce == tx.nonce, InvalidBlock) + ensure(sender_account.balance >= gas_fee + tx.value, InvalidBlock) + ensure(sender_account.code == bytearray(), InvalidBlock) + ensure(tx.gas <= gas_available, InvalidBlock) sender_address = recover_sender(chain_id, tx) @@ -669,9 +679,6 @@ def process_transaction( sender = env.origin sender_account = get_account(env.state, sender) gas_fee = tx.gas * tx.gas_price - ensure(sender_account.nonce == tx.nonce, InvalidBlock) - ensure(sender_account.balance >= gas_fee + tx.value, InvalidBlock) - ensure(sender_account.code == bytearray(), InvalidBlock) gas = tx.gas - calculate_intrinsic_cost(tx) increment_nonce(env.state, sender) From 2d88f288bf9eca0da200dea051b86d077b5c1edc Mon Sep 17 00:00:00 2001 From: Richard Gregory Date: Sat, 27 Apr 2024 12:50:07 +0100 Subject: [PATCH 09/15] Refactor includability check for Gray Glacier --- src/ethereum/gray_glacier/fork.py | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/ethereum/gray_glacier/fork.py b/src/ethereum/gray_glacier/fork.py index c13d043518..a1512e0506 100644 --- a/src/ethereum/gray_glacier/fork.py +++ b/src/ethereum/gray_glacier/fork.py @@ -391,6 +391,7 @@ def validate_proof_of_work(header: Header) -> None: def check_transaction( + env: vm.Environment, tx: Transaction, base_fee_per_gas: Uint, gas_available: Uint, @@ -401,6 +402,8 @@ def check_transaction( Parameters ---------- + env : + Environment for the Ethereum Virtual Machine. tx : The transaction. base_fee_per_gas : @@ -422,6 +425,18 @@ def check_transaction( InvalidBlock : If the transaction is not includable. """ + sender = env.origin + sender_account = get_account(env.state, sender) + + if isinstance(tx, FeeMarketTransaction): + gas_fee = tx.gas * tx.max_fee_per_gas + else: + gas_fee = tx.gas * tx.gas_price + + ensure(sender_account.nonce == tx.nonce, InvalidBlock) + ensure(sender_account.balance >= gas_fee + tx.value, InvalidBlock) + ensure(sender_account.code == bytearray(), InvalidBlock) + ensure(tx.gas <= gas_available, InvalidBlock) sender_address = recover_sender(chain_id, tx) @@ -783,15 +798,6 @@ def process_transaction( sender = env.origin sender_account = get_account(env.state, sender) - if isinstance(tx, FeeMarketTransaction): - max_gas_fee = tx.gas * tx.max_fee_per_gas - else: - max_gas_fee = tx.gas * tx.gas_price - - ensure(sender_account.nonce == tx.nonce, InvalidBlock) - ensure(sender_account.balance >= max_gas_fee + tx.value, InvalidBlock) - ensure(sender_account.code == bytearray(), InvalidBlock) - effective_gas_fee = tx.gas * env.gas_price gas = tx.gas - calculate_intrinsic_cost(tx) From 84e6d6899633bba10751bbeaee425e36f5d8f7c8 Mon Sep 17 00:00:00 2001 From: Richard Gregory Date: Sat, 27 Apr 2024 12:50:56 +0100 Subject: [PATCH 10/15] Refactor includability check for London --- src/ethereum/london/fork.py | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/ethereum/london/fork.py b/src/ethereum/london/fork.py index 9f13fd4251..32437fd8a1 100644 --- a/src/ethereum/london/fork.py +++ b/src/ethereum/london/fork.py @@ -399,6 +399,7 @@ def validate_proof_of_work(header: Header) -> None: def check_transaction( + env: vm.Environment, tx: Transaction, base_fee_per_gas: Uint, gas_available: Uint, @@ -409,6 +410,8 @@ def check_transaction( Parameters ---------- + env : + Environment for the Ethereum Virtual Machine. tx : The transaction. base_fee_per_gas : @@ -430,6 +433,18 @@ def check_transaction( InvalidBlock : If the transaction is not includable. """ + sender = env.origin + sender_account = get_account(env.state, sender) + + if isinstance(tx, FeeMarketTransaction): + gas_fee = tx.gas * tx.max_fee_per_gas + else: + gas_fee = tx.gas * tx.gas_price + + ensure(sender_account.nonce == tx.nonce, InvalidBlock) + ensure(sender_account.balance >= gas_fee + tx.value, InvalidBlock) + ensure(sender_account.code == bytearray(), InvalidBlock) + ensure(tx.gas <= gas_available, InvalidBlock) sender_address = recover_sender(chain_id, tx) @@ -791,15 +806,6 @@ def process_transaction( sender = env.origin sender_account = get_account(env.state, sender) - if isinstance(tx, FeeMarketTransaction): - max_gas_fee = tx.gas * tx.max_fee_per_gas - else: - max_gas_fee = tx.gas * tx.gas_price - - ensure(sender_account.nonce == tx.nonce, InvalidBlock) - ensure(sender_account.balance >= max_gas_fee + tx.value, InvalidBlock) - ensure(sender_account.code == bytearray(), InvalidBlock) - effective_gas_fee = tx.gas * env.gas_price gas = tx.gas - calculate_intrinsic_cost(tx) From d3c750d4076bc8c2deb05fc8b784e3671bba4d65 Mon Sep 17 00:00:00 2001 From: Richard Gregory Date: Wed, 28 Feb 2024 16:20:37 +0100 Subject: [PATCH 11/15] Refactor includability check for Muir Glacier. --- src/ethereum/muir_glacier/fork.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/ethereum/muir_glacier/fork.py b/src/ethereum/muir_glacier/fork.py index b8c786a26a..42cc51baf9 100644 --- a/src/ethereum/muir_glacier/fork.py +++ b/src/ethereum/muir_glacier/fork.py @@ -308,6 +308,7 @@ def validate_proof_of_work(header: Header) -> None: def check_transaction( + env: vm.Environment, tx: Transaction, gas_available: Uint, chain_id: U64, @@ -317,6 +318,8 @@ def check_transaction( Parameters ---------- + env : + Environment for the Ethereum Virtual Machine. tx : The transaction. gas_available : @@ -334,6 +337,13 @@ def check_transaction( InvalidBlock : If the transaction is not includable. """ + sender = env.origin + sender_account = get_account(env.state, sender) + gas_fee = tx.gas * tx.gas_price + ensure(sender_account.nonce == tx.nonce, InvalidBlock) + ensure(sender_account.balance >= gas_fee + tx.value, InvalidBlock) + ensure(sender_account.code == bytearray(), InvalidBlock) + ensure(tx.gas <= gas_available, InvalidBlock) sender_address = recover_sender(chain_id, tx) @@ -669,9 +679,6 @@ def process_transaction( sender = env.origin sender_account = get_account(env.state, sender) gas_fee = tx.gas * tx.gas_price - ensure(sender_account.nonce == tx.nonce, InvalidBlock) - ensure(sender_account.balance >= gas_fee + tx.value, InvalidBlock) - ensure(sender_account.code == bytearray(), InvalidBlock) gas = tx.gas - calculate_intrinsic_cost(tx) increment_nonce(env.state, sender) From bf2d38757efe8cdfaeeffc7e84843f4368abd99e Mon Sep 17 00:00:00 2001 From: Richard Gregory Date: Sat, 27 Apr 2024 12:51:37 +0100 Subject: [PATCH 12/15] Refactor includability check for Paris. --- src/ethereum/paris/fork.py | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/ethereum/paris/fork.py b/src/ethereum/paris/fork.py index 95d2ab85eb..45c89a28af 100644 --- a/src/ethereum/paris/fork.py +++ b/src/ethereum/paris/fork.py @@ -303,6 +303,7 @@ def validate_header(header: Header, parent_header: Header) -> None: def check_transaction( + env: vm.Environment, tx: Transaction, base_fee_per_gas: Uint, gas_available: Uint, @@ -313,6 +314,8 @@ def check_transaction( Parameters ---------- + env : + Environment for the Ethereum Virtual Machine. tx : The transaction. base_fee_per_gas : @@ -334,6 +337,17 @@ def check_transaction( InvalidBlock : If the transaction is not includable. """ + sender = env.origin + sender_account = get_account(env.state, sender) + + if isinstance(tx, FeeMarketTransaction): + gas_fee = tx.gas * tx.max_fee_per_gas + else: + gas_fee = tx.gas * tx.gas_price + + ensure(sender_account.nonce == tx.nonce, InvalidBlock) + ensure(sender_account.balance >= gas_fee + tx.value, InvalidBlock) + ensure(sender_account.code == bytearray(), InvalidBlock) ensure(tx.gas <= gas_available, InvalidBlock) sender_address = recover_sender(chain_id, tx) @@ -571,15 +585,6 @@ def process_transaction( sender = env.origin sender_account = get_account(env.state, sender) - if isinstance(tx, FeeMarketTransaction): - max_gas_fee = tx.gas * tx.max_fee_per_gas - else: - max_gas_fee = tx.gas * tx.gas_price - - ensure(sender_account.nonce == tx.nonce, InvalidBlock) - ensure(sender_account.balance >= max_gas_fee + tx.value, InvalidBlock) - ensure(sender_account.code == bytearray(), InvalidBlock) - effective_gas_fee = tx.gas * env.gas_price gas = tx.gas - calculate_intrinsic_cost(tx) From 34863d6bde054d6f93e1e76269d91ddcbdfd03bb Mon Sep 17 00:00:00 2001 From: Richard Gregory Date: Sat, 27 Apr 2024 12:52:24 +0100 Subject: [PATCH 13/15] Refactor includability check for Shanghai. --- src/ethereum/shanghai/fork.py | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/ethereum/shanghai/fork.py b/src/ethereum/shanghai/fork.py index 42b964e958..19bf5fbe0b 100644 --- a/src/ethereum/shanghai/fork.py +++ b/src/ethereum/shanghai/fork.py @@ -310,6 +310,7 @@ def validate_header(header: Header, parent_header: Header) -> None: def check_transaction( + env: vm.Environment, tx: Transaction, base_fee_per_gas: Uint, gas_available: Uint, @@ -320,6 +321,8 @@ def check_transaction( Parameters ---------- + env : + Environment for the Ethereum Virtual Machine. tx : The transaction. base_fee_per_gas : @@ -341,6 +344,18 @@ def check_transaction( InvalidBlock : If the transaction is not includable. """ + sender = env.origin + sender_account = get_account(env.state, sender) + + if isinstance(tx, FeeMarketTransaction): + gas_fee = tx.gas * tx.max_fee_per_gas + else: + gas_fee = tx.gas * tx.gas_price + + ensure(sender_account.nonce == tx.nonce, InvalidBlock) + ensure(sender_account.balance >= gas_fee + tx.value, InvalidBlock) + ensure(sender_account.code == bytearray(), InvalidBlock) + ensure(tx.gas <= gas_available, InvalidBlock) sender_address = recover_sender(chain_id, tx) @@ -596,15 +611,6 @@ def process_transaction( sender = env.origin sender_account = get_account(env.state, sender) - if isinstance(tx, FeeMarketTransaction): - max_gas_fee = tx.gas * tx.max_fee_per_gas - else: - max_gas_fee = tx.gas * tx.gas_price - - ensure(sender_account.nonce == tx.nonce, InvalidBlock) - ensure(sender_account.balance >= max_gas_fee + tx.value, InvalidBlock) - ensure(sender_account.code == bytearray(), InvalidBlock) - effective_gas_fee = tx.gas * env.gas_price gas = tx.gas - calculate_intrinsic_cost(tx) From 47f7e8a8e8c291c8b45a119500f768be37e2c7e8 Mon Sep 17 00:00:00 2001 From: Richard Gregory Date: Wed, 28 Feb 2024 16:49:17 +0100 Subject: [PATCH 14/15] Refactor includability check for Spurious Dragon. --- src/ethereum/spurious_dragon/fork.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/ethereum/spurious_dragon/fork.py b/src/ethereum/spurious_dragon/fork.py index 0598e23a03..695deca8ff 100644 --- a/src/ethereum/spurious_dragon/fork.py +++ b/src/ethereum/spurious_dragon/fork.py @@ -304,6 +304,7 @@ def validate_proof_of_work(header: Header) -> None: def check_transaction( + env: vm.Environment, tx: Transaction, gas_available: Uint, chain_id: U64, @@ -313,6 +314,8 @@ def check_transaction( Parameters ---------- + env : + Environment for the Ethereum Virtual Machine. tx : The transaction. gas_available : @@ -330,6 +333,13 @@ def check_transaction( InvalidBlock : If the transaction is not includable. """ + sender = env.origin + sender_account = get_account(env.state, sender) + gas_fee = tx.gas * tx.gas_price + ensure(sender_account.nonce == tx.nonce, InvalidBlock) + ensure(sender_account.balance >= gas_fee + tx.value, InvalidBlock) + ensure(sender_account.code == bytearray(), InvalidBlock) + ensure(tx.gas <= gas_available, InvalidBlock) sender_address = recover_sender(chain_id, tx) @@ -664,9 +674,6 @@ def process_transaction( sender = env.origin sender_account = get_account(env.state, sender) gas_fee = tx.gas * tx.gas_price - ensure(sender_account.nonce == tx.nonce, InvalidBlock) - ensure(sender_account.balance >= gas_fee + tx.value, InvalidBlock) - ensure(sender_account.code == bytearray(), InvalidBlock) gas = tx.gas - calculate_intrinsic_cost(tx) increment_nonce(env.state, sender) From b80eb0c63f0ece915ccc6255c73d0be07d3309e4 Mon Sep 17 00:00:00 2001 From: Richard Gregory Date: Wed, 28 Feb 2024 16:53:36 +0100 Subject: [PATCH 15/15] Refactor includability check for Tangerine Whistle. --- src/ethereum/tangerine_whistle/fork.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/ethereum/tangerine_whistle/fork.py b/src/ethereum/tangerine_whistle/fork.py index 1037b340df..b36bf8b0c7 100644 --- a/src/ethereum/tangerine_whistle/fork.py +++ b/src/ethereum/tangerine_whistle/fork.py @@ -302,6 +302,7 @@ def validate_proof_of_work(header: Header) -> None: def check_transaction( + env: vm.Environment, tx: Transaction, gas_available: Uint, ) -> Address: @@ -310,6 +311,8 @@ def check_transaction( Parameters ---------- + env : + Environment for the Ethereum Virtual Machine. tx : The transaction. gas_available : @@ -325,6 +328,13 @@ def check_transaction( InvalidBlock : If the transaction is not includable. """ + sender = env.origin + sender_account = get_account(env.state, sender) + gas_fee = tx.gas * tx.gas_price + ensure(sender_account.nonce == tx.nonce, InvalidBlock) + ensure(sender_account.balance >= gas_fee + tx.value, InvalidBlock) + ensure(sender_account.code == bytearray(), InvalidBlock) + ensure(tx.gas <= gas_available, InvalidBlock) sender_address = recover_sender(tx) @@ -656,9 +666,6 @@ def process_transaction( sender = env.origin sender_account = get_account(env.state, sender) gas_fee = tx.gas * tx.gas_price - ensure(sender_account.nonce == tx.nonce, InvalidBlock) - ensure(sender_account.balance >= gas_fee + tx.value, InvalidBlock) - ensure(sender_account.code == bytearray(), InvalidBlock) gas = tx.gas - calculate_intrinsic_cost(tx) increment_nonce(env.state, sender)