Skip to content

Commit 00d4b59

Browse files
committed
Disallow configuring an invalid base fee on header
1 parent 396ec8a commit 00d4b59

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

eth/vm/forks/london/headers.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
Optional,
66
)
77

8+
from eth_utils import (
9+
ValidationError,
10+
)
811
from toolz.functoolz import curry
912

1013
from eth._utils.headers import (
@@ -104,10 +107,14 @@ def create_header_from_parent(difficulty_fn: Callable[[BlockHeaderAPI, int], int
104107
all_fields = fill_header_params_from_parent(parent_header, **header_params)
105108

106109
# must add the new field *after* filling, because the general fill function doesn't recognize it
107-
if 'base_fee_per_gas' in header_params:
108-
all_fields['base_fee_per_gas'] = header_params['base_fee_per_gas']
110+
base_fee_per_gas = calculate_expected_base_fee_per_gas(parent_header)
111+
if 'base_fee_per_gas' in header_params and all_fields['base_fee_per_gas'] != base_fee_per_gas:
112+
raise ValidationError(
113+
f"Cannot select an invalid base_fee_per_gas of:"
114+
f" {all_fields['base_fee_per_gas']!r}, expected: {base_fee_per_gas}"
115+
)
109116
else:
110-
all_fields['base_fee_per_gas'] = calculate_expected_base_fee_per_gas(parent_header)
117+
all_fields['base_fee_per_gas'] = base_fee_per_gas
111118

112119
new_header = LondonBlockHeader(**all_fields) # type:ignore
113120
return new_header

0 commit comments

Comments
 (0)