29
29
NonceMismatchError ,
30
30
)
31
31
32
- from . import vm
32
+ from . import FORK_CRITERIA , vm
33
33
from .blocks import Block , Header , Log , Receipt , Withdrawal , encode_receipt
34
34
from .bloom import logs_bloom
35
35
from .exceptions import (
81
81
from .vm import Message
82
82
from .vm .eoa_delegation import is_valid_delegation
83
83
from .vm .gas import (
84
+ MAX_BLOB_GAS_PER_BLOCK ,
84
85
calculate_blob_gas_price ,
85
86
calculate_data_fee ,
86
87
calculate_excess_blob_gas ,
87
88
calculate_total_blob_gas ,
88
89
)
89
90
from .vm .interpreter import MessageCallOutput , process_message_call
90
91
91
- BASE_FEE_MAX_CHANGE_DENOMINATOR = Uint (8 )
92
+ BASE_FEE_MAX_CHANGE_DENOMINATOR = Uint (16 ) # Doubled for EIP-7782 (was 8)
92
93
ELASTICITY_MULTIPLIER = Uint (2 )
93
- GAS_LIMIT_ADJUSTMENT_FACTOR = Uint (1024 )
94
- GAS_LIMIT_MINIMUM = Uint (5000 )
94
+ GAS_LIMIT_ADJUSTMENT_FACTOR = Uint (2048 ) # Doubled for EIP-7782 (was 1024)
95
+ GAS_LIMIT_MINIMUM = Uint (2500 ) # Halved for EIP-7782 (was 5000)
95
96
EMPTY_OMMER_HASH = keccak256 (rlp .encode ([]))
96
97
SYSTEM_ADDRESS = hex_to_address ("0xfffffffffffffffffffffffffffffffffffffffe" )
97
98
BEACON_ROOTS_ADDRESS = hex_to_address (
98
99
"0x000F3df6D732807Ef1319fB7B8bB8522d0Beac02"
99
100
)
100
101
SYSTEM_TRANSACTION_GAS = Uint (30000000 )
101
- MAX_BLOB_GAS_PER_BLOCK = U64 (1179648 )
102
102
VERSIONED_HASH_VERSION_KZG = b"\x01 "
103
103
104
104
WITHDRAWAL_REQUEST_PREDEPLOY_ADDRESS = hex_to_address (
110
110
HISTORY_STORAGE_ADDRESS = hex_to_address (
111
111
"0x0000F90827F1C53a10cb7A02335B175320002935"
112
112
)
113
- MAX_BLOCK_SIZE = 10_485_760
114
- SAFETY_MARGIN = 2_097_152
113
+ MAX_BLOCK_SIZE = 5_242_880 # Halved for EIP-7782 (was 10_485_760)
114
+ SAFETY_MARGIN = 1_048_576 # Halved for EIP-7782 (was 2_097_152)
115
115
MAX_RLP_BLOCK_SIZE = MAX_BLOCK_SIZE - SAFETY_MARGIN
116
- BLOB_COUNT_LIMIT = 6
117
-
116
+ BLOB_COUNT_LIMIT = 3 # Halved for EIP-7782 (was 6)
118
117
119
118
@dataclass
120
119
class BlockChain :
@@ -271,7 +270,6 @@ def state_transition(chain: BlockChain, block: Block) -> None:
271
270
272
271
273
272
def calculate_base_fee_per_gas (
274
- block_gas_limit : Uint ,
275
273
parent_gas_limit : Uint ,
276
274
parent_gas_used : Uint ,
277
275
parent_base_fee_per_gas : Uint ,
@@ -296,8 +294,6 @@ def calculate_base_fee_per_gas(
296
294
Base fee per gas for the block.
297
295
"""
298
296
parent_gas_target = parent_gas_limit // ELASTICITY_MULTIPLIER
299
- if not check_gas_limit (block_gas_limit , parent_gas_limit ):
300
- raise InvalidBlock
301
297
302
298
if parent_gas_used == parent_gas_target :
303
299
expected_base_fee_per_gas = parent_base_fee_per_gas
@@ -361,13 +357,11 @@ def validate_header(chain: BlockChain, header: Header) -> None:
361
357
362
358
if header .gas_used > header .gas_limit :
363
359
raise InvalidBlock
360
+
361
+ if not check_gas_limit (header .gas_limit , parent_header ):
362
+ raise InvalidBlock
364
363
365
- expected_base_fee_per_gas = calculate_base_fee_per_gas (
366
- header .gas_limit ,
367
- parent_header .gas_limit ,
368
- parent_header .gas_used ,
369
- parent_header .base_fee_per_gas ,
370
- )
364
+ expected_base_fee_per_gas = calculate_base_fee_per_gas (parent_header )
371
365
if expected_base_fee_per_gas != header .base_fee_per_gas :
372
366
raise InvalidBlock
373
367
if header .timestamp <= parent_header .timestamp :
@@ -1014,7 +1008,7 @@ def increase_recipient_balance(recipient: Account) -> None:
1014
1008
destroy_account (block_env .state , wd .address )
1015
1009
1016
1010
1017
- def check_gas_limit (gas_limit : Uint , parent_gas_limit : Uint ) -> bool :
1011
+ def check_gas_limit (gas_limit : Uint , parent : Header ) -> bool :
1018
1012
"""
1019
1013
Validates the gas limit for a block.
1020
1014
@@ -1034,14 +1028,20 @@ def check_gas_limit(gas_limit: Uint, parent_gas_limit: Uint) -> bool:
1034
1028
gas_limit :
1035
1029
Gas limit to validate.
1036
1030
1037
- parent_gas_limit :
1038
- Gas limit of the parent block.
1031
+ parent :
1032
+ The parent block of the current block.
1039
1033
1040
1034
Returns
1041
1035
-------
1042
1036
check : `bool`
1043
1037
True if gas limit constraints are satisfied, False otherwise.
1044
1038
"""
1039
+ parent_gas_limit = parent .gas_limit
1040
+
1041
+ # If this is a fork block, use half of parent's gas limit (EIP-7782)
1042
+ if not FORK_CRITERIA .check (parent .number , parent .timestamp ):
1043
+ parent_gas_limit /= 2
1044
+
1045
1045
max_adjustment_delta = parent_gas_limit // GAS_LIMIT_ADJUSTMENT_FACTOR
1046
1046
if gas_limit >= parent_gas_limit + max_adjustment_delta :
1047
1047
return False
0 commit comments