0

I am writing some code implementing taproot address creation where a script path is present and I have a quick question surrounding the reference code.

The BIP-341 reference method taproot_tree_helper(script_tree) will recursively call itself if the parameter is not a tuple (leaf node). When it calls itself, it passes in it's child nodes by:

left, left_h = taproot_tree_helper(script_tree[0])
right, right_h = taproot_tree_helper(script_tree[1])

What should happen if a node only contains a single child (where script_tree[1] does not exist)? Should it pass in the same node twice for both left and right or should the tree be constructed in a way that this cannot happen?

Thanks

1
2

Unlike transaction Merkle trees, the taproot script tree does not need to be balanced; i.e., not every leaf needs to be at the same distance from the root.

So there is no need for a "node" with just a single child, and such nodes are in fact not possible. Instead, just construct a tree where the would-be single child is placed one level higher in the tree.

1
  • I see, I was working under the assumption that the tree was balanced and arbitrary data was used to fill in left over leaves but this makes more sense. Thanks
    – Keijyu
    Oct 30 '21 at 13:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.