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

Nodes in trie lib use Bytes as a type for Nibble #1043

Open
ClementWalter opened this issue Dec 3, 2024 · 3 comments
Open

Nodes in trie lib use Bytes as a type for Nibble #1043

ClementWalter opened this issue Dec 3, 2024 · 3 comments
Labels
A-spec Area: specification C-bug Category: this is a bug, deviation, or other problem.

Comments

@ClementWalter
Copy link

Metadata

  • Hardfork: cancun

What was wrong?

https://github.com/ethereum/execution-specs/blob/master/src/ethereum/cancun/trie.py#L80-L95

@slotted_freezable
@dataclass
class LeafNode:
    """Leaf node in the Merkle Trie"""

    rest_of_key: Bytes
    value: rlp.Extended


@slotted_freezable
@dataclass
class ExtensionNode:
    """Extension node in the Merkle Trie"""

    key_segment: Bytes
    subnode: rlp.Extended

rest_of_key and key_segment should be Nibble (type to create) instead of Bytes, as it's not true that any bytes. can be in (see for example encode_internal_node where it crashes in nibble_list_to_compact(node.rest_of_key, True)

@ClementWalter ClementWalter added A-spec Area: specification C-bug Category: this is a bug, deviation, or other problem. labels Dec 3, 2024
@SamWilsn
Copy link
Collaborator

SamWilsn commented Dec 3, 2024

Is this similar to #241?

@ClementWalter
Copy link
Author

ClementWalter commented Dec 3, 2024

similar indeed, the idea is that one should be able to check nibble at "compile" time. But I'd go with what you have already with FixedUint and use a Nibble or Nibbles = List[Uint4]

@ClementWalter
Copy link
Author

same issue with patricialize defined as

def patricialize(
    obj: Mapping[Bytes, Bytes], level: Uint
) -> Optional[InternalNode]:

where keys should be nibble, as also stated in the docstring

    obj :
        Underlying trie key-value pairs, with keys in nibble-list format.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-spec Area: specification C-bug Category: this is a bug, deviation, or other problem.
Projects
None yet
Development

No branches or pull requests

2 participants