Skip to content

Commit

Permalink
add prints for trie construction
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeSpa committed Jul 2, 2022
1 parent e284bea commit d289384
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,6 @@ It will be your job to implement the Merkle proof functionality and to verify it

# Merkle Patricia Trie and RLP

A trie is used in two key places: to encode transaction lists in a block, and to encode the state of a block. For transactions, the keys are big-endian integers representing the transaction count in the current block. For the state trie, the keys are ethereum addresses. It is essential for any full node to maintain the state trie, as it must be used to verify new transactions (since contract data must be referenced). Unlike bitcoin, however, there is no need to store old transactions for verification purposes, since there is a state database. So technically the transaction tries don’t need to be stored. Of course, if no one keeps them around, then no one will ever be able to verify from the genesis block up to the current state again, so it makes sense to hang on to them.

Repo supporting blog post at http://easythereentropy.wordpress.com/2014/06/04/understanding-the-ethereum-trie/
11 changes: 10 additions & 1 deletion merkle-patricia-trie/exercise.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,17 @@

print("\n")
print(
"- Let’s do it again but with a key equal to the first few nibbles of our original ke"
"- Let’s do it again but with a key equal to the first few nibbles of our original key"
)
key = utils.to_string("\x01\x01")
state.update(key, rlp.encode(["hellothere"]))

print("Root hash:", encode(state.root_hash, "hex"))
print("Root node:", state.root_node)
print("new Branch node: ", state._decode_to_node(state.root_node[1]))
print(
"- The branch node corresponds to the key ‘\x01\x01’, but there is also a value with that key (‘hellothere’). Hence, that value is placed in the final (17th) position of the branch node. "
)


## EX2 - D
Expand All @@ -105,12 +108,18 @@

print("\n")

print(
"- we add a new entry with a key that is identical to the original key, but has an additional two nibbles"
)
key = utils.to_string("\x01\x01\x02\x57")
state.update(key, rlp.encode(["hellothere"]))

print("Root hash:", encode(state.root_hash, "hex"))
print("Root node:", state.root_node)
print("Branch node: ", state._decode_to_node(state.root_node[1]))
print(
"- Now the original entry’s value is stored at the final position of the branch node, where the key for the branch node is the key for that value (‘\x01\x01\x02’). The second entry is stored at the position of it’s next nibble (5), with a key equal to the remaining nibbles (just 7)"
)


## EX3
Expand Down

0 comments on commit d289384

Please sign in to comment.