2929 NonceMismatchError ,
3030)
3131
32- from . import vm
32+ from . import FORK_CRITERIA , vm
3333from .blocks import Block , Header , Log , Receipt , Withdrawal , encode_receipt
3434from .bloom import logs_bloom
3535from .exceptions import (
8181from .vm import Message
8282from .vm .eoa_delegation import is_valid_delegation
8383from .vm .gas import (
84+ MAX_BLOB_GAS_PER_BLOCK ,
8485 calculate_blob_gas_price ,
8586 calculate_data_fee ,
8687 calculate_excess_blob_gas ,
8788 calculate_total_blob_gas ,
8889)
8990from .vm .interpreter import MessageCallOutput , process_message_call
9091
91- BASE_FEE_MAX_CHANGE_DENOMINATOR = Uint (8 )
92+ BASE_FEE_MAX_CHANGE_DENOMINATOR = Uint (16 ) # Doubled for EIP-7782 (was 8)
9293ELASTICITY_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)
9596EMPTY_OMMER_HASH = keccak256 (rlp .encode ([]))
9697SYSTEM_ADDRESS = hex_to_address ("0xfffffffffffffffffffffffffffffffffffffffe" )
9798BEACON_ROOTS_ADDRESS = hex_to_address (
9899 "0x000F3df6D732807Ef1319fB7B8bB8522d0Beac02"
99100)
100101SYSTEM_TRANSACTION_GAS = Uint (30000000 )
101- MAX_BLOB_GAS_PER_BLOCK = U64 (1179648 )
102102VERSIONED_HASH_VERSION_KZG = b"\x01 "
103103
104104WITHDRAWAL_REQUEST_PREDEPLOY_ADDRESS = hex_to_address (
110110HISTORY_STORAGE_ADDRESS = hex_to_address (
111111 "0x0000F90827F1C53a10cb7A02335B175320002935"
112112)
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)
115115MAX_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)
118117
119118@dataclass
120119class BlockChain :
@@ -271,7 +270,6 @@ def state_transition(chain: BlockChain, block: Block) -> None:
271270
272271
273272def calculate_base_fee_per_gas (
274- block_gas_limit : Uint ,
275273 parent_gas_limit : Uint ,
276274 parent_gas_used : Uint ,
277275 parent_base_fee_per_gas : Uint ,
@@ -296,8 +294,6 @@ def calculate_base_fee_per_gas(
296294 Base fee per gas for the block.
297295 """
298296 parent_gas_target = parent_gas_limit // ELASTICITY_MULTIPLIER
299- if not check_gas_limit (block_gas_limit , parent_gas_limit ):
300- raise InvalidBlock
301297
302298 if parent_gas_used == parent_gas_target :
303299 expected_base_fee_per_gas = parent_base_fee_per_gas
@@ -361,13 +357,11 @@ def validate_header(chain: BlockChain, header: Header) -> None:
361357
362358 if header .gas_used > header .gas_limit :
363359 raise InvalidBlock
360+
361+ if not check_gas_limit (header .gas_limit , parent_header ):
362+ raise InvalidBlock
364363
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 )
371365 if expected_base_fee_per_gas != header .base_fee_per_gas :
372366 raise InvalidBlock
373367 if header .timestamp <= parent_header .timestamp :
@@ -1014,7 +1008,7 @@ def increase_recipient_balance(recipient: Account) -> None:
10141008 destroy_account (block_env .state , wd .address )
10151009
10161010
1017- def check_gas_limit (gas_limit : Uint , parent_gas_limit : Uint ) -> bool :
1011+ def check_gas_limit (gas_limit : Uint , parent : Header ) -> bool :
10181012 """
10191013 Validates the gas limit for a block.
10201014
@@ -1034,14 +1028,20 @@ def check_gas_limit(gas_limit: Uint, parent_gas_limit: Uint) -> bool:
10341028 gas_limit :
10351029 Gas limit to validate.
10361030
1037- parent_gas_limit :
1038- Gas limit of the parent block.
1031+ parent :
1032+ The parent block of the current block.
10391033
10401034 Returns
10411035 -------
10421036 check : `bool`
10431037 True if gas limit constraints are satisfied, False otherwise.
10441038 """
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+
10451045 max_adjustment_delta = parent_gas_limit // GAS_LIMIT_ADJUSTMENT_FACTOR
10461046 if gas_limit >= parent_gas_limit + max_adjustment_delta :
10471047 return False
0 commit comments