Skip to content

Commit a956eb2

Browse files
marioevzpetertdavies
authored andcommitted
EIP-7742: Use parent.target_blob_gas_per_block in excess blob gas calculation
1 parent ed930de commit a956eb2

File tree

3 files changed

+17
-14
lines changed

3 files changed

+17
-14
lines changed

src/ethereum/prague/fork.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ def state_transition(chain: BlockChain, block: Block) -> None:
200200
Block to apply to `chain`.
201201
"""
202202
parent_header = chain.blocks[-1].header
203-
excess_blob_gas = calculate_excess_blob_gas(block.header, parent_header)
203+
excess_blob_gas = calculate_excess_blob_gas(parent_header)
204204
if block.header.excess_blob_gas != excess_blob_gas:
205205
raise InvalidBlock
206206

src/ethereum/prague/vm/gas.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -273,16 +273,14 @@ def init_code_cost(init_code_length: Uint) -> Uint:
273273
return GAS_INIT_CODE_WORD_COST * ceil32(init_code_length) // 32
274274

275275

276-
def calculate_excess_blob_gas(header: Header, parent_header: Header) -> U64:
276+
def calculate_excess_blob_gas(parent_header: Header) -> U64:
277277
"""
278278
Calculated the excess blob gas for the current block based
279279
on the gas used in the parent block and the gas target set
280280
in the current block.
281281
282282
Parameters
283283
----------
284-
header :
285-
The header of the current block.
286284
parent_header :
287285
The parent block of the current block.
288286
@@ -294,7 +292,7 @@ def calculate_excess_blob_gas(header: Header, parent_header: Header) -> U64:
294292
parent_blob_gas = (
295293
parent_header.excess_blob_gas + parent_header.blob_gas_used
296294
)
297-
blob_gas = GAS_PER_BLOB * header.target_blobs_per_block
295+
blob_gas = GAS_PER_BLOB * parent_header.target_blobs_per_block
298296
if parent_blob_gas < blob_gas:
299297
return U64(0)
300298
else:

src/ethereum_spec_tools/evm_tools/t8n/env.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ class Env:
5252
excess_blob_gas: Optional[U64]
5353
requests: Any
5454
target_blobs_per_block: Optional[U64]
55+
parent_target_blobs_per_block: Optional[U64]
5556

5657
def __init__(self, t8n: "T8N", stdin: Optional[Dict] = None):
5758
if t8n.options.input_env == "stdin":
@@ -91,7 +92,7 @@ def read_excess_blob_gas(self, data: Any, t8n: "T8N") -> None:
9192
self.parent_blob_gas_used = U64(0)
9293
self.parent_excess_blob_gas = U64(0)
9394
self.excess_blob_gas = None
94-
self.target_blobs_per_block = None
95+
self.parent_target_blobs_per_block = None
9596

9697
if not t8n.fork.is_after_fork("ethereum.cancun"):
9798
return
@@ -116,19 +117,23 @@ def read_excess_blob_gas(self, data: Any, t8n: "T8N") -> None:
116117
self.parent_excess_blob_gas + self.parent_blob_gas_used
117118
)
118119

119-
if "currentTargetBlobsPerBlock" in data:
120-
self.target_blobs_per_block = parse_hex_or_int(
121-
data["currentTargetBlobsPerBlock"], U64
120+
if "parentTargetBlobsPerBlock" in data:
121+
self.parent_target_blobs_per_block = parse_hex_or_int(
122+
data["parentTargetBlobsPerBlock"], U64
122123
)
123-
target_blob_gas_per_block = (
124-
self.target_blobs_per_block * t8n.fork.GAS_PER_BLOB
124+
parent_target_blob_gas_per_block = (
125+
self.parent_target_blobs_per_block * t8n.fork.GAS_PER_BLOB
125126
)
126127
else:
127-
target_blob_gas_per_block = t8n.fork.TARGET_BLOB_GAS_PER_BLOCK
128+
parent_target_blob_gas_per_block = (
129+
t8n.fork.TARGET_BLOB_GAS_PER_BLOCK
130+
)
128131

129132
self.excess_blob_gas = U64(0)
130-
if excess_blob_gas >= target_blob_gas_per_block:
131-
self.excess_blob_gas = excess_blob_gas - target_blob_gas_per_block
133+
if excess_blob_gas >= parent_target_blob_gas_per_block:
134+
self.excess_blob_gas = (
135+
excess_blob_gas - parent_target_blob_gas_per_block
136+
)
132137

133138
if "currentTargetBlobsPerBlock" in data:
134139
self.target_blobs_per_block = parse_hex_or_int(

0 commit comments

Comments
 (0)