Skip to content

Commit 87e8be0

Browse files
authored
feat(tests): EIP-7918 - Blob base fee bounded by execution cost (#1685)
* feat(forks|tests): eip-7918 initial tests plus eip-4844 adjustments. * chore(tests): extra param and docstring tweak.
1 parent c3cd74a commit 87e8be0

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

ethereum_test_forks/base_fork.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ def __call__(
9696
parent_excess_blobs: int | None = None,
9797
parent_blob_gas_used: int | None = None,
9898
parent_blob_count: int | None = None,
99+
parent_base_fee_per_gas: int,
99100
) -> int:
100101
"""Return the excess blob gas given the parent's excess blob gas and blob gas used."""
101102
pass

ethereum_test_forks/forks/forks.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -960,6 +960,7 @@ def fn(
960960
parent_excess_blobs: int | None = None,
961961
parent_blob_gas_used: int | None = None,
962962
parent_blob_count: int | None = None,
963+
parent_base_fee_per_gas: int, # Required for Osaka as using this as base
963964
) -> int:
964965
if parent_excess_blob_gas is None:
965966
assert parent_excess_blobs is not None, "Parent excess blobs are required"
@@ -1388,6 +1389,55 @@ def precompiles(cls, block_number: int = 0, timestamp: int = 0) -> List[Address]
13881389
"""
13891390
return [Address(0x100)] + super(Osaka, cls).precompiles(block_number, timestamp)
13901391

1392+
@classmethod
1393+
def excess_blob_gas_calculator(
1394+
cls, block_number: int = 0, timestamp: int = 0
1395+
) -> ExcessBlobGasCalculator:
1396+
"""Return a callable that calculates the excess blob gas for a block."""
1397+
target_blobs_per_block = cls.target_blobs_per_block(block_number, timestamp)
1398+
blob_gas_per_blob = cls.blob_gas_per_blob(block_number, timestamp)
1399+
target_blob_gas_per_block = target_blobs_per_block * blob_gas_per_blob
1400+
max_blobs_per_block = cls.max_blobs_per_block(block_number, timestamp)
1401+
blob_base_cost = 2**14 # EIP-7918 new parameter
1402+
1403+
def fn(
1404+
*,
1405+
parent_excess_blob_gas: int | None = None,
1406+
parent_excess_blobs: int | None = None,
1407+
parent_blob_gas_used: int | None = None,
1408+
parent_blob_count: int | None = None,
1409+
parent_base_fee_per_gas: int, # EIP-7918 additional parameter
1410+
) -> int:
1411+
if parent_excess_blob_gas is None:
1412+
assert parent_excess_blobs is not None, "Parent excess blobs are required"
1413+
parent_excess_blob_gas = parent_excess_blobs * blob_gas_per_blob
1414+
if parent_blob_gas_used is None:
1415+
assert parent_blob_count is not None, "Parent blob count is required"
1416+
parent_blob_gas_used = parent_blob_count * blob_gas_per_blob
1417+
if parent_excess_blob_gas + parent_blob_gas_used < target_blob_gas_per_block:
1418+
return 0
1419+
1420+
# EIP-7918: Apply reserve price when execution costs dominate blob costs
1421+
current_blob_base_fee = cls.blob_gas_price_calculator()(
1422+
excess_blob_gas=parent_excess_blob_gas
1423+
)
1424+
reserve_price_active = (
1425+
blob_base_cost * parent_base_fee_per_gas
1426+
> blob_gas_per_blob * current_blob_base_fee
1427+
)
1428+
if reserve_price_active:
1429+
blob_excess_adjustment = (
1430+
parent_blob_gas_used
1431+
* (max_blobs_per_block - target_blobs_per_block)
1432+
// max_blobs_per_block
1433+
)
1434+
return parent_excess_blob_gas + blob_excess_adjustment
1435+
1436+
# Original EIP-4844 calculation
1437+
return parent_excess_blob_gas + parent_blob_gas_used - target_blob_gas_per_block
1438+
1439+
return fn
1440+
13911441

13921442
class EOFv1(Prague, solc_name="cancun"):
13931443
"""EOF fork."""

0 commit comments

Comments
 (0)