diff --git a/src/ethereum_spec_tools/evm_tools/loaders/transaction_loader.py b/src/ethereum_spec_tools/evm_tools/loaders/transaction_loader.py index 7faf2a4784..6826b894f7 100644 --- a/src/ethereum_spec_tools/evm_tools/loaders/transaction_loader.py +++ b/src/ethereum_spec_tools/evm_tools/loaders/transaction_loader.py @@ -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): @@ -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 diff --git a/src/ethereum_spec_tools/evm_tools/t8n/env.py b/src/ethereum_spec_tools/evm_tools/t8n/env.py index aa158b6488..e09e5b7ce3 100644 --- a/src/ethereum_spec_tools/evm_tools/t8n/env.py +++ b/src/ethereum_spec_tools/evm_tools/t8n/env.py @@ -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 @@ -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: """ diff --git a/src/ethereum_spec_tools/evm_tools/t8n/t8n_types.py b/src/ethereum_spec_tools/evm_tools/t8n/t8n_types.py index d1ca55c9ec..b079e49000 100644 --- a/src/ethereum_spec_tools/evm_tools/t8n/t8n_types.py +++ b/src/ethereum_spec_tools/evm_tools/t8n/t8n_types.py @@ -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: