user127204: 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

user208: 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.

127204: <p>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.</p>
<p>The BIP-341 reference method <code>taproot_tree_helper(script_tree)</code> 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:</p>
<pre><code>left, left_h = taproot_tree_helper(script_tree[0])
right, right_h = taproot_tree_helper(script_tree[1])
</code></pre>
<p>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?</p>
<p>Thanks</p>
 208: <p>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.</p>
<p>So there is no need for a &quot;node&quot; 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.</p>
