descriptor: fix InferScript creates invalid descriptors for invalid pubkeys #37018

Open
Eunovo wants to merge 4 commits from 2026-fix-inferpubkey into master AGit
Eunovo commented 2026-11-30 13:32:47 +00:00 (Migrated from github.com)

InferScript creates descriptors that are rejected by the descriptor parsing process when supplied with scripts containing invalid pubkeys. This PR fixes this by checking that pubkeys are on the curve during inference and adds a functional test.

Adding this curve point check to InferPubkey slows down AvailableCoins by 100% because it has to infer the descriptor for every txo in the wallet for size estimation. Fix this by creating the txo with the inferred descriptor and using that desc during size estimation; see wallet_create_tx benchmark results below:

Point ms/op
Pre InferPubkey fix 55.9
Post InferPubkey fix 125.3
Branch tip 52.7
`InferScript` creates descriptors that are rejected by the descriptor parsing process when supplied with scripts containing invalid pubkeys. This PR fixes this by checking that pubkeys are on the curve during inference and adds a functional test. Adding this curve point check to InferPubkey slows down AvailableCoins by 100% because it has to infer the descriptor for every txo in the wallet for size estimation. Fix this by creating the txo with the inferred descriptor and using that desc during size estimation; see `wallet_create_tx` benchmark results below: | Point | ms/op | |---|---:| | Pre InferPubkey fix | 55.9 | | Post InferPubkey fix | 125.3 | | Branch tip | 52.7 |
DrahtBot commented 2026-11-30 13:33:00 +00:00 (Migrated from github.com)

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

External sites

Reviews

See the guideline and AI policy for information on the review process.
A summary of reviews will appear here.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #36033 ([wip,nomerge,rfc] build: Require C++23 compiler by maflcko)
  • #34872 (wallet: fix mixed-input transaction accounting in history RPCs by w0xlt)
  • #27865 (wallet: Track no-longer-spendable TXOs separately by achow101)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

LLM Linter (✨ experimental)

Possible places where named args for integral literals may be used (e.g. func(x, /*named_arg=*/0) in C++, and func(x, named_arg=0) in Python):

  • src/wallet/spend.cpp: MaxInputWeight(desc, CTxIn{outpoint}, coin_control, true, can_grind_r)
  • src/wallet/spend.cpp: GetVirtualTransactionSize(*weight, 0, 0)

2026-12-02 06:57:14

<!--e57a25ab6845829454e8d69fc972939a--> The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. <!--006a51241073e994b41acfe9ec718e94--> ### External sites * Code coverage & benchmarks: https://corecheck.dev/bitcoin/bitcoin/pulls/37018 * Ralph review <img src=https://review.fish.foo/assets/bitcoin/bitcoin/37018.png alt="Ralph review status"> https://git.fish.foo/bitcoin/bitcoin/pulls/37018#author-ralph <!--021abf342d371248e50ceaed478a90ca--> ### Reviews See [the guideline](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#code-review) and [AI policy](https://github.com/bitcoin/bitcoin/blob/master/doc/AI_POLICY.md) for information on the review process. A summary of reviews will appear here. <!--174a7506f384e20aa4161008e828411d--> ### Conflicts Reviewers, this pull request conflicts with the following ones: * [#36033](https://github.com/bitcoin/bitcoin/pull/36033) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36033.svg"></sub> ([wip,nomerge,rfc] build: Require C++23 compiler by maflcko) * [#34872](https://github.com/bitcoin/bitcoin/pull/34872) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/34872.svg"></sub> (wallet: fix mixed-input transaction accounting in history RPCs by w0xlt) * [#27865](https://github.com/bitcoin/bitcoin/pull/27865) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/27865.svg"></sub> (wallet: Track no-longer-spendable TXOs separately by achow101) If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. <!--5faf32d7da4f0f540f40219e4f7537a3--> ### LLM Linter (✨ experimental) Possible places where named args for integral literals may be used (e.g. `func(x, /*named_arg=*/0)` in C++, and `func(x, named_arg=0)` in Python): - `src/wallet/spend.cpp`: `MaxInputWeight(desc, CTxIn{outpoint}, coin_control, true, can_grind_r)` - `src/wallet/spend.cpp`: `GetVirtualTransactionSize(*weight, 0, 0)` <sup>2026-12-02 06:57:14</sup>
First-time contributor

🟠 Minor · Off-curve keys make spendable mixed-key multisig inputs unsolvable for funding

Without input_weights, spendable mixed-key 1-of-2 multisig inputs now fail funding size estimation and wallet coins report solvable=false; no current production caller funding such scripts was found.

Location: src/script/descriptor.cpp:2273 (head).

🔵 Suggestion · Eager descriptor caching adds work and storage for spent wallet history

The cache avoids repeated inference in AvailableCoins, but eagerly computes and retains a separate descriptor for every owned historical output, including spent outputs that its only consumer skips.

Location: src/wallet/wallet.cpp:3746 (head).

🔵 Suggestion · AvailableCoins still copies solving providers for non-P2SH coins

Sizing now uses the descriptor cached on WalletTXO, so fetching a solving provider for every candidate adds unnecessary lookup and copy work outside the P2SH branch.

Location: src/wallet/spend.cpp:453 (head).

Review coverage was incomplete.


Reviewed: 274028917e90 · Review report · Previous reports

permalink

<!-- forgejo-review-bot:bitcoin/bitcoin --> <!-- ralph-engine:current:e1a29e5e677c47d383756f0fcf8f3760725c91d1104dd3ccb2f333b6217eba26:47880f5569fd2047d249266f337c4f2a509adf7d96c3ccb1c7644c2c2a650bff --> <!-- ralph-base:966e9800e84ee96bf4f23a4732ed30c275ef1db9 --> <!-- ralph-head:274028917e90d0d78beb2d0df7d263598ccea3ba --> <!-- ralph-case:0b1ee9f257a10a43ec6724bd1dbba7d773cb86fedc0a8cc517b43be167e99ada --> **🟠 Minor · Off-curve keys make spendable mixed-key multisig inputs unsolvable for funding** Without `input_weights`, spendable mixed-key `1-of-2` multisig inputs now fail funding size estimation and wallet coins report `solvable=false`; no current production caller funding such scripts was found. Location: [`src/script/descriptor.cpp:2273`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/274028917e90d0d78beb2d0df7d263598ccea3ba/src/script/descriptor.cpp#L2273>) (head). **🔵 Suggestion · Eager descriptor caching adds work and storage for spent wallet history** The cache avoids repeated inference in `AvailableCoins`, but eagerly computes and retains a separate descriptor for every owned historical output, including spent outputs that its only consumer skips. Location: [`src/wallet/wallet.cpp:3746`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/274028917e90d0d78beb2d0df7d263598ccea3ba/src/wallet/wallet.cpp#L3746>) (head). **🔵 Suggestion · `AvailableCoins` still copies solving providers for non-P2SH coins** Sizing now uses the descriptor cached on `WalletTXO`, so fetching a solving provider for every candidate adds unnecessary lookup and copy work outside the P2SH branch. Location: [`src/wallet/spend.cpp:453`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/274028917e90d0d78beb2d0df7d263598ccea3ba/src/wallet/spend.cpp#L453>) (head). Review coverage was incomplete. <!-- Review tier: sensitive --> --- Reviewed: [`274028917e90`](<https://git.fish.foo/bitcoin/bitcoin/commit/274028917e90d0d78beb2d0df7d263598ccea3ba>) · [Review report](<https://review.fish.foo/report/37018-274028917e90d0d78beb2d0df7d263598ccea3ba-3425-2.html>) · [Previous reports](<https://review.fish.foo/traces/37018/>) [permalink](<https://review.fish.foo/report/37018-274028917e90d0d78beb2d0df7d263598ccea3ba-3425-2.html>)
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
bitcoin/bitcoin!37018
No description provided.