Review report

bitcoin/bitcoin: PR #35733

7 suggestions

Optional improvements

Link

[suggestion] · Oversized P2SH early refusal lacks a state regression test

A false-return assertion would pass even if the new guard were removed, because final verification already rejects oversized redeemScript pushes.

Location: src/script/sign.cpp:684 (head).

Details and suggested fix

Without this guard, ProduceSignature recurses into an otherwise signable oversized redeemScript and records signatures before final verification fails. The converted P2SH fixtures do not assert this distinction. Add a test using a FlatSigningProvider containing 16 compressed keys and fresh SignatureData: a 1-of-16 multisig redeemScript is 547 bytes and should return false with no signatures and an empty scriptSig. The same script as a P2WSH witnessScript should sign and verify with a supplied amount, because the witnessScript is removed before witness argument sizes are checked. A 1-of-15 P2SH control, at 513 bytes, should still sign. If testing the exact 520/521-byte boundary instead, use scripts that Solver recognizes so the negative case actually depends on this guard.


Link

[suggestion] · Oversized P2SH rejection produces a missing-key diagnostic

For an unsigned P2SH input, an oversized redeemScript can now produce a misleading missing-key diagnostic instead of the push-size error.

Location: src/script/sign.cpp:684 (head).

Details and suggested fix

ParsePrevouts accepts a matching oversized multisig redeemScript into its FlatSigningProvider. This guard then returns before adding the redeemScript to the signing result, leaving an empty scriptSig for an initially unsigned input. SignTransaction maps the resulting stack underflow at OP_HASH160 to "Unable to sign input, invalid stack size (possibly missing key)", even when all keys are supplied. Previously, final verification reported "Push value size limit exceeded". Report a specific size error for oversized traditional P2SH redeemScripts in ParsePrevouts, without applying that restriction to P2WSH witnessScripts. No current in-tree caller relying on the old message was found; the impact is user-facing diagnostics for an input that cannot be spent in either version.


Link

[suggestion] · bitcoin-tx loses its oversized P2SH redeemScript error

Supplying an oversized P2SH redeemScript to bitcoin-tx sign can now return an unsigned input with exit status 0 instead of failing explicitly.

Location: src/bitcoin-tx.cpp:669 (head).

Details and suggested fix

Replacing AddCScript with scripts.emplace removes the former size error for both P2SH and P2WSH prevouts. For an initially unsigned P2SH input with a matching oversized redeemScript, SignStep refuses the script, but MutateTxSign ignores the signing result and the command succeeds. Preserve an explicit insertion error when scriptPubKey.IsPayToScriptHash() and the supplied redeemScript exceeds 520 bytes. Keep accepting otherwise signable larger P2WSH witnessScripts when keys and an amount are supplied; that is a useful improvement over base. Document this behavior change and add utility vectors for both cases, since the current signing vectors supply no redeemScript. The compatibility impact is limited because bitcoin-tx already leaves other unsignable inputs, such as those missing keys, unsigned without an error.


Link

[suggestion] · Nested-witness signing lacks a bitcoin-tx regression vector

The existing native P2WPKH signing vectors do not exercise the P2WPKH script registration now inlined into bitcoin-tx.

Location: src/bitcoin-tx.cpp:607 (head).

Details and suggested fix

Signing P2SH-P2WPKH without a supplied redeemScript requires the outer SCRIPTHASH lookup to find the P2WPKH program registered here for compressed keys. The existing witness signing vectors use native 0014751e… outputs, which construct the P2PKH witness script directly and never consult the scripts map. Removing this registration would therefore leave those vectors unchanged while bitcoin-tx returned an unsigned nested-witness input, since it ignores ProduceSignature's result. Add a golden signing vector using the existing compressed key KwDiBf89…, a P2SH wrapper of that P2WPKH program, and an amount, without supplying redeemScript.


Link

[suggestion] · Inlining leaves stale names and drops script-map documentation

The LegacyDataSPKM comments reference removed names and no longer document how m_scripts differs from setWatchOnly.

Location: src/wallet/scriptpubkeyman.cpp:492 (head).

Details and suggested fix

The copied "This does not use AddCScript, as it may be overridden" sentence refers to an API that no longer exists, and GetCandidateScriptPubKeys still calls the renamed member mapScripts. Delete the obsolete override rationale and update the member name. Also carry the relevant map documentation onto m_scripts: it contains implicit memory-only P2WPKH programs, and membership does not by itself confer the ownership that setWatchOnly represents. The helper still explains implicit learning, but the map-level distinction from setWatchOnly was dropped. Leave references to removed persistence APIs out of the restored comment.


Link

[suggestion] · Dummy input-size fixture stores an unused private key

CalculateNestedKeyhashInputSize needs only its script and pubkey entries; the new private-key insertion has no consumer.

Location: src/wallet/test/wallet_tests.cpp:631 (head).

Details and suggested fix

FillableSigningProvider::GetPubKey previously derived the public key from the stored private key, but FlatSigningProvider reads the explicit pubkeys entry instead. This helper only uses dummy signature creators, which do not query private keys, and their checker accepts nonempty signatures without consulting the provider. Remove the keystore.keys.emplace while retaining the script and pubkey entries. The size calculation remains unchanged, and the fixture more clearly expresses that only public solving data is needed.


Link

[suggestion] · Multisig witness fixture adds an unused pubkey entry

All uses of keystore2 in test_witness obtain public keys from the multisig script, so its new pubkeys entry is unused.

Location: src/test/transaction_tests.cpp:618 (head).

Details and suggested fix

keystore2 signs only the 2-of-2 multisig script and its P2SH/P2WSH wrappers. Wrapper resolution reads scripts, the MULTISIG branch constructs public keys from the script, and the signature creator retrieves private keys from keys. Origin lookup uses origins, while signature combination uses DUMMY_SIGNING_PROVIDER. Remove keystore2.pubkeys.emplace while retaining the private key and two script entries; partial signing and witness behavior remain unchanged.


Coverage details