Skip to content

Commit

Permalink
Merge pull request #4 from marioevz/prague-eip-7742
Browse files Browse the repository at this point in the history
EIP-7742: Use `parent.target_blob_gas_per_block` in excess blob gas calculation
  • Loading branch information
petertdavies authored Dec 12, 2024
2 parents 4c4fe59 + ef2bbbf commit 1aa211a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/ethereum/prague/fork.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ def state_transition(chain: BlockChain, block: Block) -> None:
Block to apply to `chain`.
"""
parent_header = chain.blocks[-1].header
excess_blob_gas = calculate_excess_blob_gas(block.header, parent_header)
excess_blob_gas = calculate_excess_blob_gas(parent_header)
if block.header.excess_blob_gas != excess_blob_gas:
raise InvalidBlock

Expand Down
6 changes: 2 additions & 4 deletions src/ethereum/prague/vm/gas.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,16 +267,14 @@ def init_code_cost(init_code_length: Uint) -> Uint:
return GAS_INIT_CODE_WORD_COST * ceil32(init_code_length) // 32


def calculate_excess_blob_gas(header: Header, parent_header: Header) -> U64:
def calculate_excess_blob_gas(parent_header: Header) -> U64:
"""
Calculated the excess blob gas for the current block based
on the gas used in the parent block and the gas target set
in the current block.
Parameters
----------
header :
The header of the current block.
parent_header :
The parent block of the current block.
Expand All @@ -288,7 +286,7 @@ def calculate_excess_blob_gas(header: Header, parent_header: Header) -> U64:
parent_blob_gas = (
parent_header.excess_blob_gas + parent_header.blob_gas_used
)
blob_gas = GAS_PER_BLOB * header.target_blobs_per_block
blob_gas = GAS_PER_BLOB * parent_header.target_blobs_per_block
if parent_blob_gas < blob_gas:
return U64(0)
else:
Expand Down
23 changes: 14 additions & 9 deletions src/ethereum_spec_tools/evm_tools/t8n/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class Env:
excess_blob_gas: Optional[U64]
requests: Any
target_blobs_per_block: Optional[U64]
parent_target_blobs_per_block: Optional[U64]

def __init__(self, t8n: "T8N", stdin: Optional[Dict] = None):
if t8n.options.input_env == "stdin":
Expand Down Expand Up @@ -91,7 +92,7 @@ def read_excess_blob_gas(self, data: Any, t8n: "T8N") -> None:
self.parent_blob_gas_used = U64(0)
self.parent_excess_blob_gas = U64(0)
self.excess_blob_gas = None
self.target_blobs_per_block = None
self.parent_target_blobs_per_block = None

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

if "currentTargetBlobsPerBlock" in data:
self.target_blobs_per_block = parse_hex_or_int(
data["currentTargetBlobsPerBlock"], U64
if "parentTargetBlobsPerBlock" in data:
self.parent_target_blobs_per_block = parse_hex_or_int(
data["parentTargetBlobsPerBlock"], U64
)
target_blob_gas_per_block = (
self.target_blobs_per_block * t8n.fork.GAS_PER_BLOB
parent_target_blob_gas_per_block = (
self.parent_target_blobs_per_block * t8n.fork.GAS_PER_BLOB
)
else:
target_blob_gas_per_block = t8n.fork.TARGET_BLOB_GAS_PER_BLOCK
parent_target_blob_gas_per_block = (
t8n.fork.TARGET_BLOB_GAS_PER_BLOCK
)

self.excess_blob_gas = U64(0)
if excess_blob_gas >= target_blob_gas_per_block:
self.excess_blob_gas = excess_blob_gas - target_blob_gas_per_block
if excess_blob_gas >= parent_target_blob_gas_per_block:
self.excess_blob_gas = (
excess_blob_gas - parent_target_blob_gas_per_block
)

if "currentTargetBlobsPerBlock" in data:
self.target_blobs_per_block = parse_hex_or_int(
Expand Down

0 comments on commit 1aa211a

Please sign in to comment.