test: cover scantxoutset scan-object validation errors

bitcoin/bitcoin: PR #36877

The review is inconclusive; no findings were published.

Coverage details

Background

Ralph's summary of historical context for the behaviour affected by this change. The historical record reviewed here is incomplete.

Documented decisions

UTXO scanning was intended to find currently spendable funds without importing a wallet and reconstructing its entire transaction history, including on pruned nodes. Separating discovery from signing also supported preparing sweeps online and signing them in cold storage or a hardware wallet.

The scan objects identify which output scripts to search for; they are not wallet-import instructions. In the pinned implementation, valid objects are expanded into scripts and matched against the UTXO database. Requiring a descriptor gives this wallet-independent operation its search target.

Source 1 · Source 2 · Source 3 · Source 4

Descriptors were introduced as a unified interface for specifying output scripts, combining script types, multisig, extended keys, and chains of derived keys rather than treating each scanning use case separately.

This explains why both accepted scan-object forms ultimately supply a descriptor string, while the object form can additionally provide derivation bounds. The new tests exercise malformed containers and range syntax, not whether a descriptor expresses a valid script.

Source 1

The original implementation deliberately accepted the cost of scanning the UTXO set instead of requiring a scriptPubKey index. Its author cited implementation simplicity and immediate recovery needs, while noting extra-index storage costs and concern that changing database ordering could slow verification.

The pinned RPC still builds a set of target scripts before traversing the UTXO database. Scan-object validation precedes that traversal, so malformed requests are rejected before the expensive database scan. These historical arguments explain the surrounding cost tradeoff, not a claim that the current validation is a complete resource-protection mechanism.

Source 1 · Source 2

Ralph's inferences

The three errors distinguish an unusable scan request from a legitimate search that happens to find no matching coins. Rejecting malformed structure rather than treating it as an empty search avoids giving callers a misleading successful result.

At both pinned base and head, EvalDescriptorStringOrObject rejects non-string/non-object elements and objects without desc; range syntax is checked before descriptor parsing. The added tests preserve this existing application-level input contract. This explanation is an inference; the inspected historical sources do not state why these cases specifically use -8.

Source 1

Explicit finite ranges make wildcard key searches operationally bounded: they trade search completeness against derivation work and memory. An integer endpoint is shorthand for starting at zero, while a begin/end pair permits a selected interval.

The pinned parser accepts an integer or a two-number array, applies bounds checks, and expands the resulting inclusive interval into scripts. Rejecting a string such as "foo" ensures there is a usable interval before expansion. Historically, the descriptor author explicitly changed range semantics to a maximum index rather than a count; the resource-control explanation is inferred from the pinned expansion behavior.

Source 1 · Source 2