diff --git a/src/evm_transition_tool/geth.py b/src/evm_transition_tool/geth.py index 251b699d03..50a73aca2f 100644 --- a/src/evm_transition_tool/geth.py +++ b/src/evm_transition_tool/geth.py @@ -13,7 +13,7 @@ from re import compile from typing import Dict, Optional -from ethereum_test_base_types import Address, Alloc, to_json +from ethereum_test_base_types import Address, Alloc, ZeroPaddedHexNumber, to_json from ethereum_test_forks import Fork from ethereum_test_types.verkle import VerkleTree, WitnessCheck from ethereum_test_types.verkle.types import Hash as VerkleHash @@ -191,7 +191,9 @@ def get_verkle_state_root(self, mpt_alloc: Alloc) -> bytes: hex_string = self._run_verkle_command("state-root", "--input.alloc", alloc_path) return binascii.unhexlify(hex_string[2:]) - def get_verkle_single_key(self, address: Address, storage_slot: Optional[int] = None) -> str: + def get_verkle_single_key( + self, address: Address, storage_slot: Optional[ZeroPaddedHexNumber] = None + ) -> str: """ Returns the VKT key for an account address or storage slot. """ @@ -199,14 +201,14 @@ def get_verkle_single_key(self, address: Address, storage_slot: Optional[int] = if storage_slot is not None: args.append(str(storage_slot)) output = self._run_verkle_command("single-key", *args) - return str(json.loads(output)) + return output - def get_verkle_code_chunk_key(self, address: Address, code_chunk: int) -> str: + def get_verkle_code_chunk_key(self, address: Address, code_chunk: ZeroPaddedHexNumber) -> str: """ Returns the VKT key of a code chunk for an account address. """ output = self._run_verkle_command("code-chunk-key", str(address), str(code_chunk)) - return str(json.loads(output)) + return output def format_witness_check( self, witness_check: WitnessCheck @@ -228,13 +230,17 @@ def format_witness_check( # Format storage entries using `evm verkle single-key` if witness_check.storage_slots: for address, storage_slot, value in witness_check.storage_slots: - storage_tree_key = self.get_verkle_single_key(address, storage_slot) + storage_tree_key = self.get_verkle_single_key( + address, ZeroPaddedHexNumber(storage_slot) + ) witness_check_key_values[VerkleHash(storage_tree_key)] = value # Format code chunks using `evm verkle code-chunk-key` if witness_check.code_chunks: for address, code_chunk, value in witness_check.code_chunks: - code_chunk_tree_key = self.get_verkle_code_chunk_key(address, code_chunk) + code_chunk_tree_key = self.get_verkle_code_chunk_key( + address, ZeroPaddedHexNumber(code_chunk) + ) witness_check_key_values[VerkleHash(code_chunk_tree_key)] = value return witness_check_key_values diff --git a/src/evm_transition_tool/transition_tool.py b/src/evm_transition_tool/transition_tool.py index d00561e5d1..f8f0321d49 100644 --- a/src/evm_transition_tool/transition_tool.py +++ b/src/evm_transition_tool/transition_tool.py @@ -15,7 +15,7 @@ from re import Pattern from typing import Dict, List, Mapping, Optional, Type -from ethereum_test_base_types import Address, Alloc +from ethereum_test_base_types import Address, Alloc, ZeroPaddedHexNumber from ethereum_test_fixtures import FixtureFormats, FixtureVerifier from ethereum_test_forks import Fork from ethereum_test_types import Environment, Transaction @@ -594,7 +594,9 @@ def get_verkle_state_root(self, mpt_alloc: Alloc) -> bytes: " tool." ) - def get_verkle_single_key(self, address: Address, storage_slot: Optional[int] = None) -> str: + def get_verkle_single_key( + self, address: Address, storage_slot: Optional[ZeroPaddedHexNumber] = None + ) -> str: """ Returns the VKT key for an account address or storage slot. """ @@ -603,7 +605,7 @@ def get_verkle_single_key(self, address: Address, storage_slot: Optional[int] = " tool." ) - def get_verkle_code_chunk_key(self, address: Address, code_chunk: int) -> str: + def get_verkle_code_chunk_key(self, address: Address, code_chunk: ZeroPaddedHexNumber) -> str: """ Returns the VKT key of a code chunk for an account address. """ diff --git a/tests/verkle/eip7709_blockhash_witness/test_blockhash_instruction.py b/tests/verkle/eip7709_blockhash_witness/test_blockhash_instruction.py index 7287d0a100..d837b1eb0c 100644 --- a/tests/verkle/eip7709_blockhash_witness/test_blockhash_instruction.py +++ b/tests/verkle/eip7709_blockhash_witness/test_blockhash_instruction.py @@ -93,13 +93,14 @@ def _blockhash( ) witness_check = WitnessCheck() - witness_check.add_account_full(env.fee_recipient, None) - witness_check.add_account_full(TestAddress, pre[TestAddress]) - # witness_check.add_account_full(TestAddress2, pre[TestAddress2]) - # if not fail: - # storage_slot = block_num_target % HISTORY_STORAGE_ADDRESS - # value = None # TODO(verkle): TODO. - # witness_check.add_storage_slot(blockhash_system_contract_address, storage_slot, value) + for address in [env.fee_recipient, TestAddress, TestAddress2]: + witness_check.add_account_full( + address, None if address == env.fee_recipient else pre[address] + ) + if not fail: + storage_slot = block_num_target % HISTORY_STORAGE_ADDRESS + value = None # TODO: Process the value for Verkle storage slot + witness_check.add_storage_slot(blockhash_system_contract_address, storage_slot, value) blocks = [Block(txs=[tx], witness_check=witness_check)] blockchain_test(