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

Minor Prague t8n fixes #1013

Merged
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
15 changes: 8 additions & 7 deletions src/ethereum_spec_tools/evm_tools/loaders/transaction_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
hex_to_u256,
hex_to_uint,
)
from ethereum_spec_tools.evm_tools.utils import parse_hex_or_int


class UnsupportedTx(Exception):
Expand Down Expand Up @@ -160,24 +161,24 @@ def get_legacy_transaction(self) -> Any:
def read(self) -> Any:
"""Convert json transaction data to a transaction object"""
if "type" in self.raw:
tx_type = hex_to_bytes(self.raw.get("type"))
if tx_type == b"\x04":
tx_type = parse_hex_or_int(self.raw.get("type"), Uint)
if tx_type == Uint(4):
tx_cls = self.fork.SetCodeTransaction
tx_byte_prefix = b"\x04"
elif tx_type == b"\x03":
elif tx_type == Uint(3):
tx_cls = self.fork.BlobTransaction
tx_byte_prefix = b"\x03"
elif tx_type == b"\x02":
elif tx_type == Uint(2):
tx_cls = self.fork.FeeMarketTransaction
tx_byte_prefix = b"\x02"
elif tx_type == b"\x01":
elif tx_type == Uint(1):
tx_cls = self.fork.AccessListTransaction
tx_byte_prefix = b"\x01"
elif tx_type == b"\x00":
elif tx_type == Uint(0):
tx_cls = self.get_legacy_transaction()
tx_byte_prefix = b""
else:
raise ValueError(f"Unknown transaction type: {tx_type.hex()}")
raise ValueError(f"Unknown transaction type: {tx_type}")
else:
if "authorizationList" in self.raw:
tx_cls = self.fork.SetCodeTransaction
Expand Down
20 changes: 5 additions & 15 deletions src/ethereum_spec_tools/evm_tools/t8n/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from ethereum import rlp
from ethereum.base_types import U64, U256, Bytes32, Uint
from ethereum.crypto.hash import Hash32, keccak256
from ethereum.utils.byte import left_pad_zero_bytes
from ethereum.utils.hexadecimal import hex_to_bytes

from ..utils import parse_hex_or_int
Expand Down Expand Up @@ -168,20 +167,11 @@ def read_randao(self, data: Any, t8n: "T8N") -> None:
"""
self.prev_randao = None
if t8n.fork.is_after_fork("ethereum.paris"):
# tf tool might not always provide an
# even number of nibbles in the randao
# This could create issues in the
# hex_to_bytes function
current_random = data["currentRandom"]
if current_random.startswith("0x"):
current_random = current_random[2:]

if len(current_random) % 2 == 1:
current_random = "0" + current_random

self.prev_randao = Bytes32(
left_pad_zero_bytes(hex_to_bytes(current_random), 32)
)
# Some tooling sends prev_randao as an int, parse it as an int to
# support that tooling
self.prev_randao = parse_hex_or_int(
data["currentRandom"], U256
).to_be_bytes32()

def read_withdrawals(self, data: Any, t8n: "T8N") -> None:
"""
Expand Down
16 changes: 16 additions & 0 deletions src/ethereum_spec_tools/evm_tools/t8n/t8n_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,22 @@ def generic_request_to_json(self, request: Any) -> Any:
for attr in request.__annotations__:
data[attr] = encode_to_hex(getattr(request, attr))

if "public_key" in data:
data["pubkey"] = data["public_key"]
del data["public_key"]

if "validator_public_key" in data:
data["validator_pubkey"] = data["validator_public_key"]
del data["validator_public_key"]

if "target_public_key" in data:
data["target_pubkey"] = data["target_public_key"]
del data["target_public_key"]

if "source_public_key" in data:
data["source_pubkey"] = data["source_public_key"]
del data["source_public_key"]

return data

def to_json(self) -> Any:
Expand Down
Loading