Skip to content

Commit ce05f6c

Browse files
committed
feat: add support for EIP-7782 (6 sec slots)
1 parent 6b0f795 commit ce05f6c

File tree

2 files changed

+25
-24
lines changed

2 files changed

+25
-24
lines changed

src/ethereum/osaka/fork.py

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
NonceMismatchError,
3030
)
3131

32-
from . import vm
32+
from . import FORK_CRITERIA, vm
3333
from .blocks import Block, Header, Log, Receipt, Withdrawal, encode_receipt
3434
from .bloom import logs_bloom
3535
from .exceptions import (
@@ -81,24 +81,24 @@
8181
from .vm import Message
8282
from .vm.eoa_delegation import is_valid_delegation
8383
from .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
)
8990
from .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)
9293
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)
9596
EMPTY_OMMER_HASH = keccak256(rlp.encode([]))
9697
SYSTEM_ADDRESS = hex_to_address("0xfffffffffffffffffffffffffffffffffffffffe")
9798
BEACON_ROOTS_ADDRESS = hex_to_address(
9899
"0x000F3df6D732807Ef1319fB7B8bB8522d0Beac02"
99100
)
100101
SYSTEM_TRANSACTION_GAS = Uint(30000000)
101-
MAX_BLOB_GAS_PER_BLOCK = U64(1179648)
102102
VERSIONED_HASH_VERSION_KZG = b"\x01"
103103

104104
WITHDRAWAL_REQUEST_PREDEPLOY_ADDRESS = hex_to_address(
@@ -110,11 +110,10 @@
110110
HISTORY_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)
115115
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)
118117

119118
@dataclass
120119
class BlockChain:
@@ -271,7 +270,6 @@ def state_transition(chain: BlockChain, block: Block) -> None:
271270

272271

273272
def 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

src/ethereum/osaka/vm/gas.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,13 @@
7070
GAS_POINT_EVALUATION = Uint(50000)
7171

7272
GAS_PER_BLOB = U64(2**17)
73-
BLOB_SCHEDULE_TARGET = U64(6)
73+
BLOB_SCHEDULE_TARGET = U64(3) # Halved for EIP-7782 (was 6)
7474
TARGET_BLOB_GAS_PER_BLOCK = GAS_PER_BLOB * BLOB_SCHEDULE_TARGET
7575
BLOB_BASE_COST = Uint(2**13)
76-
BLOB_SCHEDULE_MAX = U64(9)
76+
BLOB_SCHEDULE_MAX = U64(4) # Halved for EIP-7782 (was 9)
77+
MAX_BLOB_GAS_PER_BLOCK = BLOB_SCHEDULE_MAX * GAS_PER_BLOB
7778
MIN_BLOB_GASPRICE = Uint(1)
78-
BLOB_BASE_FEE_UPDATE_FRACTION = Uint(5007716)
79+
BLOB_BASE_FEE_UPDATE_FRACTION = Uint(10015432) # Doubled for EIP-7782 (was 5007716)
7980

8081
GAS_BLS_G1_ADD = Uint(375)
8182
GAS_BLS_G1_MUL = Uint(12000)

0 commit comments

Comments
 (0)