Skip to content

Commit e637b8e

Browse files
committed
Move tip v burn validation to Frontier to dedup
1 parent 083cc4a commit e637b8e

File tree

3 files changed

+15
-44
lines changed

3 files changed

+15
-44
lines changed

eth/vm/forks/frontier/validation.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,22 @@
1212

1313
def validate_frontier_transaction(state: StateAPI,
1414
transaction: SignedTransactionAPI) -> None:
15-
gas_cost = transaction.gas * transaction.gas_price
15+
max_gas_cost = transaction.gas * state.get_gas_price(transaction)
1616
sender_balance = state.get_balance(transaction.sender)
1717

18-
if sender_balance < gas_cost:
18+
if sender_balance < max_gas_cost:
1919
raise ValidationError(
2020
f"Sender {transaction.sender!r} cannot afford txn gas "
21-
f"{gas_cost} with account balance {sender_balance}"
21+
f"{max_gas_cost} with account balance {sender_balance}"
2222
)
2323

24-
total_cost = transaction.value + gas_cost
24+
total_cost = transaction.value + max_gas_cost
2525

2626
if sender_balance < total_cost:
27-
raise ValidationError("Sender account balance cannot afford txn")
27+
raise ValidationError(
28+
f"Sender does not have enough balance to cover transaction value and gas "
29+
f" (has {sender_balance}, needs {total_cost})"
30+
)
2831

2932
sender_nonce = state.get_nonce(transaction.sender)
3033
if sender_nonce != transaction.nonce:

eth/vm/forks/london/state.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from typing import Type
22

33
from eth_hash.auto import keccak
4-
from eth_utils.exceptions import ValidationError
54
from eth_utils import (
65
encode_hex,
76
)
@@ -16,7 +15,6 @@
1615
)
1716
from eth.constants import (
1817
CREATE_CONTRACT_ADDRESS,
19-
SECPK1_N,
2018
)
2119
from eth.db.account import (
2220
AccountDB
@@ -110,21 +108,9 @@ def validate_transaction(
110108
self,
111109
transaction: SignedTransactionAPI
112110
) -> None:
113-
# frontier validation (without the gas price checks)
114-
sender_nonce = self.get_nonce(transaction.sender)
115-
if sender_nonce != transaction.nonce:
116-
raise ValidationError(
117-
f"Invalid transaction nonce: Expected {sender_nonce}, but got {transaction.nonce}"
118-
)
119-
120-
# homestead validation
121-
if transaction.s > SECPK1_N // 2 or transaction.s == 0:
122-
raise ValidationError("Invalid signature S value")
123-
124111
validate_london_normalized_transaction(
125112
state=self,
126113
transaction=transaction,
127-
base_fee_per_gas=self.execution_context.base_fee_per_gas
128114
)
129115

130116
def get_transaction_context(self: StateAPI,

eth/vm/forks/london/validation.py

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,29 @@
1+
from eth_utils.exceptions import ValidationError
2+
13
from eth.abc import (
24
SignedTransactionAPI,
35
StateAPI
46
)
5-
6-
from eth_utils.exceptions import ValidationError
7+
from eth.vm.forks.homestead.validation import (
8+
validate_homestead_transaction,
9+
)
710

811

912
def validate_london_normalized_transaction(
1013
state: StateAPI,
1114
transaction: SignedTransactionAPI,
12-
base_fee_per_gas: int
1315
) -> None:
1416
"""
1517
Validates a London normalized transaction.
1618
1719
Raise `eth.exceptions.ValidationError` if the sender cannot
1820
afford to send this transaction.
1921
"""
22+
base_fee_per_gas = state.execution_context.base_fee_per_gas
2023
if transaction.max_fee_per_gas < base_fee_per_gas:
2124
raise ValidationError(
2225
f"Sender's max fee per gas ({transaction.max_fee_per_gas}) is "
2326
f"lower than block's base fee per gas ({base_fee_per_gas})"
2427
)
2528

26-
sender_balance = state.get_balance(transaction.sender)
27-
if sender_balance < transaction.value:
28-
# This check is redundant to the later total_transaction_cost check,
29-
# but is helpful for clear error messages.
30-
raise ValidationError(
31-
f"Sender {transaction.sender!r} cannot afford txn value"
32-
f"{transaction.value} with account balance {sender_balance}"
33-
)
34-
35-
priority_fee_per_gas = min(
36-
transaction.max_priority_fee_per_gas,
37-
transaction.max_fee_per_gas - base_fee_per_gas,
38-
)
39-
40-
effective_gas_price = priority_fee_per_gas + base_fee_per_gas
41-
total_transaction_cost = transaction.value + effective_gas_price * transaction.gas
42-
43-
if sender_balance < total_transaction_cost:
44-
raise ValidationError(
45-
f"Sender does not have enough balance to cover transaction value and gas "
46-
f" (has {sender_balance}, needs {total_transaction_cost})"
47-
)
29+
validate_homestead_transaction(state, transaction)

0 commit comments

Comments
 (0)