test: add BIP352 scanning to the functional test framework

bitcoin/bitcoin: PR #36835

1 minor finding · 2 suggestions

Findings

Link

[minor] · Empty witnesses crash the scanner or change input eligibility

Empty or malformed witnesses can make the BIP352 test helper raise IndexError or include an ineligible Taproot input; no current caller producing these inputs was found.

Location: test/functional/test_framework/bip352.py:31 (head).

Details and suggested fix

An empty witness reaches witness[-1] for native P2WPKH and for P2SH-P2WPKH with a single redeem-script push. A P2TR stack with multiple items ending in b'' instead fails at stack[-1][0]. An empty P2TR stack takes the unconditional public-key return, unlike C++ GetPubKeyFromInput, which rejects it. After resolving prevouts, scan_tx can pass these empty stacks from unsigned transactions because it deserializes rather than validates the spend. Consensus-valid spends do not trigger these cases. Return None for empty witness stacks in these branches and check that the final item is nonempty before reading its annex byte.


Optional improvements

Link

[suggestion] · scan_tx leaves its confirmed-transaction prerequisite undocumented

The unused, untested scan_tx adapter needs -txindex to resolve confirmed transactions' spent prevouts, but its docstring omits that prerequisite; no failure was observed.

Location: test/functional/test_framework/bip352.py:72 (head).

Details and suggested fix

For an ordinary transaction confirmed in the supplied node's active chain, gettxout(..., include_mempool=False) returns null for its spent prevouts. The fallback then requests each confirmed parent with getrawtransaction(txid, True) without a block hash, which fails without -txindex, off by default. Unconfirmed transactions can work without the index when their prevouts remain in chainstate or their parents are in the mempool. Document this requirement in the docstring. The receiving-vector unittest calls scan directly, so it does not exercise either RPC lookup path or the adapter's witness-to-input mapping.


Link

[suggestion] · Receiving vectors do not exercise the witness v2+ exclusion

None of the receiving vectors spends a witness v2+ output, so deleting scan's transaction-wide exclusion would leave the new assertions passing.

Location: test/functional/test_framework/bip352.py:51 (head).

Details and suggested fix

BIP352 v0 excludes the whole transaction when any input spends a future witness version, even if other inputs supply eligible keys. Add a case based on the label-free “Simple send: two inputs” receiving vector, append an input spending a v2 witness program, and assert that scan returns []. Choose the added outpoint so its serialization is lexicographically greater than the existing minimum. Without the guard, that input contributes no key and does not change the smallest outpoint, so the scanner would still find the original nonempty output set. This makes the assertion depend on the exclusion rather than an unrelated empty-result condition.


Coverage details