Skip to content

Commit

Permalink
Change add to only add 1 leaf since that's what's really going on
Browse files Browse the repository at this point in the history
anyways
  • Loading branch information
kcalvinalvin committed Aug 25, 2024
1 parent 8b4f6a3 commit 8177860
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
18 changes: 8 additions & 10 deletions pytreexo.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,14 @@ def __str__(self):
def __eq__(self, other):
return self.roots == other.roots and self.numleaves == other.numleaves

def add(self, adds: [bytes]):
for add in adds:
for row in range(tree_rows(self.numleaves)+1):
if not root_present(self.numleaves, row):
break
root = self.roots.pop()
add = parent_hash(root, add)

self.roots.append(add)
self.numleaves += 1
def add(self, add: bytes):
for row in range(tree_rows(self.numleaves)+1):
if not root_present(self.numleaves, row): break
root = self.roots.pop()
add = parent_hash(root, add)

self.roots.append(add)
self.numleaves += 1

def verify(self, dels: [bytes], proof: Proof):
if len(dels) != len(proof.targets):
Expand Down
6 changes: 4 additions & 2 deletions tests/test_stump.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ def test_add(self):
hashed_leaves = [hashlib.sha256(leaf).digest() for leaf in leaves]

s = pytreexo.Stump()
s.add(hashed_leaves)
for hashed_leaf in hashed_leaves:
s.add(hashed_leaf)

for i, expected_str in enumerate(test['expected_roots']):
expected = bytes.fromhex(expected_str)
Expand Down Expand Up @@ -50,7 +51,8 @@ def test_delete(self):
hashed_leaves = [hashlib.sha256(leaf).digest() for leaf in leaves]

s = pytreexo.Stump()
s.add(hashed_leaves)
for hashed_leaf in hashed_leaves:
s.add(hashed_leaf)

preimages = [preimage.to_bytes(1, byteorder='big') for preimage in test['target_values']]
del_hashes = [hashlib.sha256(preimage).digest() for preimage in preimages]
Expand Down

0 comments on commit 8177860

Please sign in to comment.