Skip to content

Instantly share code, notes, and snippets.

@hyperevo
Created August 15, 2019 00:09
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save hyperevo/1fca647cbe6207c207730a65fd281836 to your computer and use it in GitHub Desktop.
showing a bug in py-trie
import rlp
from trie import HexaryTrie
ZERO_HASH32 = 32 * b'\x00'
BLANK_ROOT_HASH = b'V\xe8\x1f\x17\x1b\xccU\xa6\xff\x83E\xe6\x92\xc0\xf8n\x5bH\xe0\x1b\x99l\xad\xc0\x01b/\xb5\xe3c\xb4!'
def make_trie_root_and_nodes( items):
return _make_trie_root_and_nodes(tuple(rlp.encode(item) for item in items))
def _make_trie_root_and_nodes(items):
kv_store = {} # type: Dict[bytes, bytes]
trie = HexaryTrie(kv_store, BLANK_ROOT_HASH, prune=True)
memory_trie = trie
for index, item in enumerate(items):
index_key = rlp.encode(index, sedes=rlp.sedes.big_endian_int)
print('ZZZZZZZZZZZZZ')
print(index)
print(index_key)
print(item)
memory_trie[index_key] = item
return trie.root_hash, kv_store
def test_trie_root():
from secrets import token_bytes
list_of_bytes = []
for i in range(129):
#random_bytes = token_bytes(1)*999
random_bytes = ZERO_HASH32
list_of_bytes.append(random_bytes)
#print(list_of_bytes)
print(_make_trie_root_and_nodes(list_of_bytes))
test_trie_root()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment