Fix taproot hash computation
When hashing two branches in the taproot tree, the one containing the script that is going to be executed should always go first (we cannot just concatenate the two branches in order). Then, the current implementation for the example [ [A, B], C ] works for A and B. The problem is that for a huge tree with an arbitrary amount of leaves, the implementation only works for the two most leftmost leaves. The tests were correct since they checked spending from the first leaves. They'd failed when spending from C.
Hi @ramonamela , I will check this when I am back from holidays. Thanks for the contribution.
Just an update here. I've tested with a taproot tree with more than 500 scripts and it seems to work on testnet. Enjoy you holidays :)
I was solving two problems in the same PR but I think one has been solved by an other PR. I rebased my master so there is no longer conflicts. The key is in this piece of code: if len(level) == 1: return traverse_level(level[0]) if len(level) == 2: a, a1 = traverse_level(level[0]) b, b1 = traverse_level(level[1]) if a1: return (a + b), True if b1: return (b + a), True return tapbranch_tagged_hash(a, b), False As explained in this issue: https://github.com/karask/python-bitcoin-utils/issues/105