The control block length rule in Script Validation caps m at 128, but
compute_merkle_root and compute_control_block applied no depth bound, so a
129-deep tree produced a 4129-byte control block for an output consensus
must reject as unspendable.
Structural validation also used assert, which python -O strips: a malformed
3-child branch silently returned the root of its first two leaves rather
than raising, dropping a script leaf from the commitment.
Adds negative_structure_tests covering both, run from BIP360_tests.
Standardizes all P2MR-specific functions to use bytes uniformly for
input/output. Hex conversions are now confined to two boundaries:
reading `script` field out of ScriptTree input, and comparing against
hex-encoded test vector data in `run_single_test`.
bech32 functions and s2w are left unchanged.
This refactors `compute_control_block` to improve performance, and make
the function simpler to read (to me at least).
The previous version walked the entire script tree searching for the
first matching instance of the leaf node.
The new version expects the caller to pass in an explicit `path`
parameter, which tells us exactly where the leaf node lives, with
left/right steps encoded as bits in an integer. We walk down the
tree straight to that leaf node, and build the control block as we go.
This might not be the best DX for a real-world API or library, but this
is just reference code, so we can accept poor usage ergonomics if it makes
the code clearer and more explicit.