ethereum / ethereum-org-website

Ethereum.org is a primary online resource for the Ethereum community.
https://ethereum.org/
MIT License
5.08k stars 4.83k forks source link

HashE (node E) from the "Patricia Merkle Trie" example is embeddable #6860

Closed weipin closed 6 months ago

weipin commented 2 years ago

HashE (node E) from the "Patricia Merkle Trie" example is embeddable

The current trie example lists "hashE" as a standalone extension node. The node has a length of 31 in bytes in RLP encoding, making it actually "embeddable." In other words, "hashE" shouldn't exist as a standalone node but be embedded in "hashD".

To Reproduce Steps to reproduce the behavior:

Uses pyrlp to calculate the node length in bytes:

>>> import rlp
>>> len(rlp.encode([ 0x17, [ [], [], [], [], [], [], [ 0x35, "coin" ], [], [], [], [], [], [], [], [], [], "puppy" ] ]))
31

Uses py-trie to example the internal data of hashD:

>>> from trie import HexaryTrie

>>> t = HexaryTrie(db={})
>>> t.set(b'do', b'verb')
>>> t.set(b'dog', b'puppy')
>>> t.set(b'doge', b'coin')
>>> t.set(b'horse', b'stallion')

>>> t.traverse(t.root_node.sub_segments[0] + (0x4, 0x6, 0xf))
HexaryTrieNode(sub_segments=((0x6,),), value=b'verb', suffix=(), raw=[b'', b'', b'', b'', b'', b'', [b'\x17', [b'', b'', b'', b'', b'', b'', [b'5', b'coin'], b'', b'', b'', b'', b'', b'', b'', b'', b'', b'puppy']], b'', b'', b'', b'', b'', b'', b'', b'', b'', b'verb'], node_type=<NodeType.BRANCH: 3>)

Note: b'5' in the output above represents 0x35

>>> b'5'.hex()
'35'

Expected behavior

I am new to this concept. Hope this issue makes sense and I wasn't missing anything.

May I @jmcook1186 :)

minimalsm commented 2 years ago

Thanks for reporting @weipin,

@jmcook1186 could you have a look?

github-actions[bot] commented 2 years ago

This issue is stale because it has been open 45 days with no activity.