test: fix MiniWallet script-path spend (missing parity bit in leaf version)

This commit fixes a dormant bug in MiniWallet that exists since
support for P2TR was initially added in #23371 (see commit
041abfebe4).

In the course of spending the output, the leaf version byte of the
control block in the witness stack doesn't set the parity bit, i.e.
we were so far just lucky that the used combinations of relevant
data (internal pubkey, leaf script / version) didn't result in a
tweaked pubkey with odd y-parity. If that was the case, we'd get the
following validation error:

`mandatory-script-verify-flag-failed (Witness program hash mismatch) (-26)`

Since MiniWallets can now optionally be tagged (#29939), resulting
in different internal pubkeys, the issue is more prevalent now.
Fix it by passing the parity bit, as specified in BIP341.
This commit is contained in:
Sebastian Falbesoner 2024-05-09 19:17:57 +02:00
parent 7774c314fb
commit c9f7364ab2

View file

@ -198,7 +198,7 @@ class MiniWallet:
leaf_info = list(self._taproot_info.leaves.values())[0]
i.scriptWitness.stack = [
leaf_info.script,
bytes([leaf_info.version]) + self._taproot_info.internal_pubkey,
bytes([leaf_info.version | self._taproot_info.negflag]) + self._taproot_info.internal_pubkey,
]
else:
assert False