Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update EIP-4844: Rename "data gas" to "blob gas" #225

Merged
merged 7 commits into from
Jul 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/writing_tests/adding_a_new_test.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ All test cases are located underneath the `tests` directory, which are then orga
│ | └── 📁 eip4844_blobs/
| | ├── 📄 __init__.py
| | ├── 📄 test_blobhash_opcode.py
| | ├── 📄 test_excess_data_gas.py
| | ├── 📄 test_excess_blob_gas.py
| | └── 📄 ...
| ├── 📁 shanghai
| | ├── 📁 eip3651_warm_coinbase
Expand Down
8 changes: 4 additions & 4 deletions src/ethereum_test_forks/base_fork.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,17 @@ def header_withdrawals_required(cls, block_number: int = 0, timestamp: int = 0)

@classmethod
@abstractmethod
def header_excess_data_gas_required(cls, block_number: int = 0, timestamp: int = 0) -> bool:
def header_excess_blob_gas_required(cls, block_number: int = 0, timestamp: int = 0) -> bool:
"""
Returns true if the header must contain excess data gas
Returns true if the header must contain excess blob gas
"""
pass

@classmethod
@abstractmethod
def header_data_gas_used_required(cls, block_number: int = 0, timestamp: int = 0) -> bool:
def header_blob_gas_used_required(cls, block_number: int = 0, timestamp: int = 0) -> bool:
"""
Returns true if the header must contain data gas used
Returns true if the header must contain blob gas used
"""
pass

Expand Down
16 changes: 8 additions & 8 deletions src/ethereum_test_forks/forks/forks.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,16 @@ def header_withdrawals_required(cls, block_number: int = 0, timestamp: int = 0)
return False

@classmethod
def header_excess_data_gas_required(cls, block_number: int = 0, timestamp: int = 0) -> bool:
def header_excess_blob_gas_required(cls, block_number: int = 0, timestamp: int = 0) -> bool:
"""
At genesis, header must not contain excess data gas
At genesis, header must not contain excess blob gas
"""
return False

@classmethod
def header_data_gas_used_required(cls, block_number: int = 0, timestamp: int = 0) -> bool:
def header_blob_gas_used_required(cls, block_number: int = 0, timestamp: int = 0) -> bool:
"""
At genesis, header must not contain data gas used
At genesis, header must not contain blob gas used
"""
return False

Expand Down Expand Up @@ -257,16 +257,16 @@ def is_deployed(cls):
return False

@classmethod
def header_excess_data_gas_required(cls, block_number: int = 0, timestamp: int = 0) -> bool:
def header_excess_blob_gas_required(cls, block_number: int = 0, timestamp: int = 0) -> bool:
"""
Excess data gas is required starting from Cancun.
Excess blob gas is required starting from Cancun.
"""
return True

@classmethod
def header_data_gas_used_required(cls, block_number: int = 0, timestamp: int = 0) -> bool:
def header_blob_gas_used_required(cls, block_number: int = 0, timestamp: int = 0) -> bool:
"""
Data gas used is required starting from Cancun.
Blob gas used is required starting from Cancun.
"""
return True

Expand Down
112 changes: 56 additions & 56 deletions src/ethereum_test_tools/common/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -920,31 +920,31 @@ class Environment:
cast_type=Hash,
),
)
parent_data_gas_used: Optional[NumberConvertible] = field(
parent_blob_gas_used: Optional[NumberConvertible] = field(
default=None,
json_encoder=JSONEncoder.Field(
name="parentDataGasUsed",
name="parentBlobGasUsed",
cast_type=Number,
),
)
parent_excess_data_gas: Optional[NumberConvertible] = field(
parent_excess_blob_gas: Optional[NumberConvertible] = field(
default=None,
json_encoder=JSONEncoder.Field(
name="parentExcessDataGas",
name="parentExcessBlobGas",
cast_type=Number,
),
)
data_gas_used: Optional[NumberConvertible] = field(
blob_gas_used: Optional[NumberConvertible] = field(
default=None,
json_encoder=JSONEncoder.Field(
name="currentDataGasUsed",
name="currentBlobGasUsed",
cast_type=Number,
),
)
excess_data_gas: Optional[NumberConvertible] = field(
excess_blob_gas: Optional[NumberConvertible] = field(
default=None,
json_encoder=JSONEncoder.Field(
name="currentExcessDataGas",
name="currentExcessBlobGas",
cast_type=Number,
),
)
Expand All @@ -964,8 +964,8 @@ def from_parent_header(parent: "FixtureHeader") -> "Environment":
parent_difficulty=parent.difficulty,
parent_timestamp=parent.timestamp,
parent_base_fee=parent.base_fee,
parent_data_gas_used=parent.data_gas_used,
parent_excess_data_gas=parent.excess_data_gas,
parent_blob_gas_used=parent.blob_gas_used,
parent_excess_blob_gas=parent.excess_blob_gas,
parent_gas_used=parent.gas_used,
parent_gas_limit=parent.gas_limit,
parent_ommers_hash=parent.ommers_hash,
Expand All @@ -991,8 +991,8 @@ def apply_new_parent(self, new_parent: "FixtureHeader") -> "Environment":
env.parent_difficulty = new_parent.difficulty
env.parent_timestamp = new_parent.timestamp
env.parent_base_fee = new_parent.base_fee
env.parent_data_gas_used = new_parent.data_gas_used
env.parent_excess_data_gas = new_parent.excess_data_gas
env.parent_blob_gas_used = new_parent.blob_gas_used
env.parent_excess_blob_gas = new_parent.excess_blob_gas
env.parent_gas_used = new_parent.gas_used
env.parent_gas_limit = new_parent.gas_limit
env.parent_ommers_hash = new_parent.ommers_hash
Expand Down Expand Up @@ -1023,18 +1023,18 @@ def set_fork_requirements(self, fork: Fork) -> "Environment":
res.difficulty = 0

if (
fork.header_excess_data_gas_required(number, timestamp)
and res.excess_data_gas is None
and res.parent_excess_data_gas is None
fork.header_excess_blob_gas_required(number, timestamp)
and res.excess_blob_gas is None
and res.parent_excess_blob_gas is None
):
res.excess_data_gas = 0
res.excess_blob_gas = 0

if (
fork.header_data_gas_used_required(number, timestamp)
and res.data_gas_used is None
and res.parent_data_gas_used is None
fork.header_blob_gas_used_required(number, timestamp)
and res.blob_gas_used is None
and res.parent_blob_gas_used is None
):
res.data_gas_used = 0
res.blob_gas_used = 0

return res

Expand Down Expand Up @@ -1149,10 +1149,10 @@ class Transaction:
to_json=True,
),
)
max_fee_per_data_gas: Optional[int] = field(
max_fee_per_blob_gas: Optional[int] = field(
default=None,
json_encoder=JSONEncoder.Field(
name="maxFeePerDataGas",
name="maxFeePerBlobGas",
cast_type=HexNumber,
),
)
Expand Down Expand Up @@ -1258,15 +1258,15 @@ def __post_init__(self) -> None:
if self.gas_price is not None and (
self.max_fee_per_gas is not None
or self.max_priority_fee_per_gas is not None
or self.max_fee_per_data_gas is not None
or self.max_fee_per_blob_gas is not None
):
raise Transaction.InvalidFeePayment()

if (
self.gas_price is None
and self.max_fee_per_gas is None
and self.max_priority_fee_per_gas is None
and self.max_fee_per_data_gas is None
and self.max_fee_per_blob_gas is None
):
self.gas_price = 10

Expand All @@ -1278,7 +1278,7 @@ def __post_init__(self) -> None:

if self.ty is None:
# Try to deduce transaction type from included fields
if self.max_fee_per_data_gas is not None:
if self.max_fee_per_blob_gas is not None:
self.ty = 3
elif self.max_fee_per_gas is not None:
self.ty = 2
Expand Down Expand Up @@ -1339,8 +1339,8 @@ def payload_body(self) -> List[Any]:
raise ValueError("max_priority_fee_per_gas must be set for type 3 tx")
if self.max_fee_per_gas is None:
raise ValueError("max_fee_per_gas must be set for type 3 tx")
if self.max_fee_per_data_gas is None:
raise ValueError("max_fee_per_data_gas must be set for type 3 tx")
if self.max_fee_per_blob_gas is None:
raise ValueError("max_fee_per_blob_gas must be set for type 3 tx")
if self.blob_versioned_hashes is None:
raise ValueError("blob_versioned_hashes must be set for type 3 tx")
if self.access_list is None:
Expand Down Expand Up @@ -1369,7 +1369,7 @@ def payload_body(self) -> List[Any]:
Uint(self.value),
Bytes(self.data),
[a.to_list() for a in self.access_list],
Uint(self.max_fee_per_data_gas),
Uint(self.max_fee_per_blob_gas),
[Hash(h) for h in self.blob_versioned_hashes],
Uint(self.v),
Uint(self.r),
Expand All @@ -1390,7 +1390,7 @@ def payload_body(self) -> List[Any]:
Uint(self.value),
Bytes(self.data),
[a.to_list() for a in self.access_list],
Uint(self.max_fee_per_data_gas),
Uint(self.max_fee_per_blob_gas),
[Hash(h) for h in self.blob_versioned_hashes],
Uint(self.v),
Uint(self.r),
Expand Down Expand Up @@ -1483,8 +1483,8 @@ def signing_envelope(self) -> List[Any]:
raise ValueError("max_priority_fee_per_gas must be set for type 3 tx")
if self.max_fee_per_gas is None:
raise ValueError("max_fee_per_gas must be set for type 3 tx")
if self.max_fee_per_data_gas is None:
raise ValueError("max_fee_per_data_gas must be set for type 3 tx")
if self.max_fee_per_blob_gas is None:
raise ValueError("max_fee_per_blob_gas must be set for type 3 tx")
if self.blob_versioned_hashes is None:
raise ValueError("blob_versioned_hashes must be set for type 3 tx")
return [
Expand All @@ -1497,7 +1497,7 @@ def signing_envelope(self) -> List[Any]:
Uint(self.value),
Bytes(self.data),
[a.to_list() for a in self.access_list] if self.access_list is not None else [],
Uint(self.max_fee_per_data_gas),
Uint(self.max_fee_per_blob_gas),
[Hash(h) for h in self.blob_versioned_hashes],
]
elif self.ty == 2:
Expand Down Expand Up @@ -1738,10 +1738,10 @@ class FixtureTransaction(Transaction):
cast_type=Bytes,
),
)
max_fee_per_data_gas: Optional[int] = field(
max_fee_per_blob_gas: Optional[int] = field(
default=None,
json_encoder=JSONEncoder.Field(
name="maxFeePerDataGas",
name="maxFeePerBlobGas",
cast_type=ZeroPaddedHexNumber,
),
)
Expand Down Expand Up @@ -1796,8 +1796,8 @@ class Header:
nonce: Optional[FixedSizeBytesConvertible] = None
base_fee: Optional[NumberConvertible | Removable] = None
withdrawals_root: Optional[FixedSizeBytesConvertible | Removable] = None
data_gas_used: Optional[NumberConvertible | Removable] = None
excess_data_gas: Optional[NumberConvertible | Removable] = None
blob_gas_used: Optional[NumberConvertible | Removable] = None
excess_blob_gas: Optional[NumberConvertible | Removable] = None
hash: Optional[FixedSizeBytesConvertible] = None

REMOVE_FIELD: ClassVar[Removable] = Removable()
Expand Down Expand Up @@ -2055,24 +2055,24 @@ class FixtureHeader:
json_encoder=JSONEncoder.Field(name="withdrawalsRoot"),
)

data_gas_used: Optional[int] = header_field(
blob_gas_used: Optional[int] = header_field(
default=None,
source=HeaderFieldSource(
parse_type=Number,
fork_requirement_check="header_data_gas_used_required",
source_transition_tool="dataGasUsed",
fork_requirement_check="header_blob_gas_used_required",
source_transition_tool="blobGasUsed",
),
json_encoder=JSONEncoder.Field(name="dataGasUsed", cast_type=ZeroPaddedHexNumber),
json_encoder=JSONEncoder.Field(name="blobGasUsed", cast_type=ZeroPaddedHexNumber),
)

excess_data_gas: Optional[int] = header_field(
excess_blob_gas: Optional[int] = header_field(
default=None,
source=HeaderFieldSource(
parse_type=Number,
fork_requirement_check="header_excess_data_gas_required",
source_transition_tool="currentExcessDataGas",
fork_requirement_check="header_excess_blob_gas_required",
source_transition_tool="currentExcessBlobGas",
),
json_encoder=JSONEncoder.Field(name="excessDataGas", cast_type=ZeroPaddedHexNumber),
json_encoder=JSONEncoder.Field(name="excessBlobGas", cast_type=ZeroPaddedHexNumber),
)

hash: Optional[Hash] = header_field(
Expand Down Expand Up @@ -2168,10 +2168,10 @@ def build(
header.append(Uint(int(self.base_fee)))
if self.withdrawals_root is not None:
header.append(self.withdrawals_root)
if self.data_gas_used is not None:
header.append(Uint(int(self.data_gas_used)))
if self.excess_data_gas is not None:
header.append(Uint(self.excess_data_gas))
if self.blob_gas_used is not None:
header.append(Uint(int(self.blob_gas_used)))
if self.excess_blob_gas is not None:
header.append(Uint(self.excess_blob_gas))

block = [
header,
Expand Down Expand Up @@ -2249,10 +2249,10 @@ def set_environment(self, env: Environment) -> Environment:
if not isinstance(self.base_fee, Removable):
new_env.base_fee = self.base_fee
new_env.withdrawals = self.withdrawals
if not isinstance(self.excess_data_gas, Removable):
new_env.excess_data_gas = self.excess_data_gas
if not isinstance(self.data_gas_used, Removable):
new_env.data_gas_used = self.data_gas_used
if not isinstance(self.excess_blob_gas, Removable):
new_env.excess_blob_gas = self.excess_blob_gas
if not isinstance(self.blob_gas_used, Removable):
new_env.blob_gas_used = self.blob_gas_used
"""
These values are required, but they depend on the previous environment,
so they can be calculated here.
Expand Down Expand Up @@ -2359,13 +2359,13 @@ class FixtureExecutionPayload(FixtureHeader):
default=None,
json_encoder=JSONEncoder.Field(name="baseFeePerGas", cast_type=HexNumber),
)
data_gas_used: Optional[int] = field(
blob_gas_used: Optional[int] = field(
default=None,
json_encoder=JSONEncoder.Field(name="dataGasUsed", cast_type=HexNumber),
json_encoder=JSONEncoder.Field(name="blobGasUsed", cast_type=HexNumber),
)
excess_data_gas: Optional[int] = field(
excess_blob_gas: Optional[int] = field(
default=None,
json_encoder=JSONEncoder.Field(name="excessDataGas", cast_type=HexNumber),
json_encoder=JSONEncoder.Field(name="excessBlobGas", cast_type=HexNumber),
)

# Fields only used in the Engine API
Expand Down
4 changes: 2 additions & 2 deletions src/ethereum_test_tools/spec/blockchain_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ def make_genesis(
mix_digest=Hash(0),
nonce=HeaderNonce(0),
base_fee=ZeroPaddedHexNumber.or_none(env.base_fee),
data_gas_used=ZeroPaddedHexNumber.or_none(env.data_gas_used),
excess_data_gas=ZeroPaddedHexNumber.or_none(env.excess_data_gas),
blob_gas_used=ZeroPaddedHexNumber.or_none(env.blob_gas_used),
excess_blob_gas=ZeroPaddedHexNumber.or_none(env.excess_blob_gas),
withdrawals_root=Hash.or_none(
t8n.calc_withdrawals_root(
withdrawals=env.withdrawals,
Expand Down
4 changes: 2 additions & 2 deletions src/ethereum_test_tools/spec/state_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ def make_genesis(
mix_digest=Hash(0),
nonce=HeaderNonce(0),
base_fee=ZeroPaddedHexNumber.or_none(env.base_fee),
data_gas_used=ZeroPaddedHexNumber.or_none(env.data_gas_used),
excess_data_gas=ZeroPaddedHexNumber.or_none(env.excess_data_gas),
blob_gas_used=ZeroPaddedHexNumber.or_none(env.blob_gas_used),
excess_blob_gas=ZeroPaddedHexNumber.or_none(env.excess_blob_gas),
withdrawals_root=Hash.or_none(
t8n.calc_withdrawals_root(
withdrawals=env.withdrawals,
Expand Down
4 changes: 2 additions & 2 deletions src/ethereum_test_tools/tests/test_transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@
access_list=[AccessList(address="0x123", storage_keys=["0x456", "0x789"])],
max_fee_per_gas=10,
max_priority_fee_per_gas=5,
max_fee_per_data_gas=100,
max_fee_per_blob_gas=100,
blob_versioned_hashes=[],
),
(
Expand All @@ -211,7 +211,7 @@
access_list=[AccessList(address="0x123", storage_keys=["0x456", "0x789"])],
max_fee_per_gas=10,
max_priority_fee_per_gas=5,
max_fee_per_data_gas=100,
max_fee_per_blob_gas=100,
blob_versioned_hashes=[bytes(), bytes([0x01])],
),
(
Expand Down
Loading
Loading