Skip to content

Commit

Permalink
chore(fw|evm): fix witness check during fill.
Browse files Browse the repository at this point in the history
  • Loading branch information
spencer-tb committed Aug 27, 2024
1 parent 76eff11 commit cd047c0
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 17 deletions.
20 changes: 13 additions & 7 deletions src/evm_transition_tool/geth.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -191,22 +191,24 @@ 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.
"""
args = [str(address)]
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
Expand All @@ -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
8 changes: 5 additions & 3 deletions src/evm_transition_tool/transition_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
"""
Expand All @@ -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.
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit cd047c0

Please sign in to comment.