Skip to content

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

Open
Eunovo wants to merge 4 commits into
bitcoin:masterfrom
Eunovo:2026-fix-inferpubkey
Open

Eunovo wants to merge 4 commits into
bitcoin:masterfrom
Eunovo:2026-fix-inferpubkey

Conversation

@Eunovo

@Eunovo Eunovo commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

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

The inferred descriptors are incorrect and are rejected by `getdescriptorinfo`.
This happens because the inference process does not check that the pubkey is on the curve.

Future commits will fix the problem.
Descriptors inferred from scripts with invalid pubkeys were rejected by the parser. Fix by validating pubkeys during the inference process.
@DrahtBot

DrahtBot commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

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

This desc will be used calculate the maximum size in AvailableCoins in this series of commits.
InferDescriptor was updated to perform curve point check for any
pubkeys in the script. This forced AvailableCoins to perform
this curve point check for all txos in the wallet.

Use the descriptor provided by the txo to avoid InferDescriptor calls.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants