Skip to content

Commit

Permalink
Merge pull request #11 from kcalvinalvin/2024-08-26-fix-root-idx
Browse files Browse the repository at this point in the history
Fix root_idx when the leaf is not at the bottom
  • Loading branch information
kcalvinalvin authored Aug 26, 2024
2 parents 28d6e3d + a4e4f6b commit a0d0713
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pytreexo.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def root_idx(numleaves: int, position: int) -> int:
if not root_present(numleaves, row):
continue
pos = position
for _ in range(row): pos = parent(pos, tree_rows(numleaves))
for _ in range(detect_row(position, tree_rows(numleaves)), row): pos = parent(pos, tree_rows(numleaves))
if isroot(pos, numleaves, tree_rows(numleaves)):
return idx
idx += 1
Expand Down
11 changes: 11 additions & 0 deletions tests/test_cases.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,17 @@
"proofhashes": [],
"expected": true
},
{
"numleaves": 6,
"roots": [
"2b77298feac78ab51bc5079099a074c6d789bd350442f5079fcba2b3402694e5",
"9eec588c41d87b16b0ee226cb38da3864f9537632321d8be855a73d5616dcc73"
],
"targets": [8],
"target_preimages": [1],
"proofhashes": ["9576f4ade6e9bc3a6458b506ce3e4e890df29cb14cb5d3d887672aef55647a2b"],
"expected": true
},
{
"numleaves": 8,
"roots": [
Expand Down

0 comments on commit a0d0713

Please sign in to comment.