Zeth - Zerocash on Ethereum  0.8
Reference implementation of the Zeth protocol by Clearmatics
Classes | Functions | Variables
zeth.core.merkle_tree Namespace Reference

Classes

class  ITreeHash
 
class  MerkleTree
 
class  MerkleTreeData
 
class  PersistentMerkleTree
 

Functions

List[str] compute_merkle_path (int address, MerkleTree mk_tree)
 

Variables

 ZERO_ENTRY
 

Function Documentation

◆ compute_merkle_path()

List[str] zeth.core.merkle_tree.compute_merkle_path ( int  address,
MerkleTree  mk_tree 
)
Given an "address" (index into leaves of a Merkle tree), compute the path to
the root.

Definition at line 188 of file merkle_tree.py.

188 def compute_merkle_path(address: int, mk_tree: MerkleTree) -> List[str]:
189  """
190  Given an "address" (index into leaves of a Merkle tree), compute the path to
191  the root.
192  """
193  merkle_path: List[str] = []
194  if address == -1:
195  return merkle_path
196 
197  # Check each bit of address in turn. If it is set, take the left node,
198  # otherwise take the right node.
199  for depth in range(mk_tree.depth):
200  address_bit = address & 0x1
201  if address_bit:
202  merkle_path.append(mk_tree.get_node(depth, address - 1).hex())
203  else:
204  merkle_path.append(mk_tree.get_node(depth, address + 1).hex())
205  address = address >> 1
206  return merkle_path
207 
208 
Here is the caller graph for this function:

Variable Documentation

◆ ZERO_ENTRY

zeth.core.merkle_tree.ZERO_ENTRY
Initial value:
1 = bytes.fromhex(
2  "0000000000000000000000000000000000000000000000000000000000000000")

Definition at line 13 of file merkle_tree.py.

zeth.core.merkle_tree.compute_merkle_path
List[str] compute_merkle_path(int address, MerkleTree mk_tree)
Definition: merkle_tree.py:188