From c9f7364ab2bccad56a4473dbd18d9c80eaf651d4 Mon Sep 17 00:00:00 2001 From: Sebastian Falbesoner Date: Thu, 9 May 2024 19:17:57 +0200 Subject: [PATCH] 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 041abfebe49ae5e3e882c00cc5caea1365a27a49). 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. --- test/functional/test_framework/wallet.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/functional/test_framework/wallet.py b/test/functional/test_framework/wallet.py index 82553c6fc4..e816f6fedd 100644 --- a/test/functional/test_framework/wallet.py +++ b/test/functional/test_framework/wallet.py @@ -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