sign: Remove FillableSigningProvider

bitcoin/bitcoin: PR #35733

2 minor findings · 4 suggestions

Earlier concerns neither republished nor resolved: 2 suggestions. See the Run archive for their assessments.

Findings

Link

[minor] · bitcoin-tx loses the oversized P2SH redeemScript error

Although signing is best-effort, supplying a P2SH redeemScript over 520 bytes now leaves an input unsigned instead of raising the previous bitcoin-tx error.

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

Details and suggested fix

For an initially unsigned input whose P2SH prevout matches the supplied oversized redeemScript, the new SignStep check returns false and leaves scriptSig empty. MutateTxSign ignores the ProduceSignature result, so replacing the checked AddCScript call with unconditional insertion changes a CLI failure into normal transaction output without a diagnostic. Restore a P2SH-only size check and error in MutateTxSign, while keeping the new ability to supply P2WSH witness scripts over 520 bytes. Add utility vectors covering the P2SH error and successful signing of a valid large P2WSH script.


Link

[minor] · Oversized P2SH redeemScripts now produce a misleading missing-key diagnostic

For an unsigned input with a supplied P2SH redeemScript over 520 bytes, signrawtransactionwithkey now reports a possibly missing key instead of the previous push-size error.

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

Details and suggested fix

ParsePrevouts still inserts the matching oversized script into its FlatSigningProvider. The new early return preserves no refusal reason, so ProduceSignature leaves an empty scriptSig. SignTransaction then verifies that empty script, encounters SCRIPT_ERR_INVALID_STACK_OPERATION at OP_HASH160, and reports Unable to sign input, invalid stack size (possibly missing key) even when every key is present. Base instead pushed the oversized script and reported Push value size limit exceeded. Keep the signing guard, but record its size failure in SignatureData and propagate a size-specific error to the RPC result.


Optional improvements

Link

[suggestion] · Signing tests do not distinguish early P2SH size refusal from verification failure

A test checking only that ProduceSignature returns false would miss removal of the new guard, because final verification also rejects the oversized push after signatures have been created.

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

Details and suggested fix

CreateSig records signatures during redeem-script recursion, before the final VerifyScript call. The existing 513-byte fifteenSigops fixture does not exercise this path because it builds its scriptSig manually.

Add a boundary test using a FlatSigningProvider holding the keys and scripts: a compressed-key 1-of-15 multisig script, 513 bytes, should sign as P2SH; a 1-of-16 script, 547 bytes, should fail with a fresh SignatureData whose signatures and scriptSig remain empty. The same 547-byte script should sign and verify as native P2WSH and P2SH-P2WSH, supplying the 34-byte witness program for the nested case. This checks both early refusal and its restriction to the P2SH role.


Link

[suggestion] · The bitcoin-tx vectors miss implicit P2SH-P2WPKH script learning

Existing bitcoin-tx signing vectors use only P2PKH or native P2WPKH, so they do not exercise the witness-program insertion now performed explicitly for compressed keys.

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

Details and suggested fix

Native P2WPKH signing constructs its script code directly, whereas P2SH-P2WPKH must retrieve the witness program through GetCScript. Deleting or incorrectly keying this insertion would therefore leave nested inputs unsigned without changing any existing CLI vector. Add a vector using the compressed key from the native-witness case, a P2SH prevout committing to its P2WPKH program, an explicit amount, and no supplied redeemScript. Compare against a fixture whose scriptSig pushes that program and whose witness contains the signature and public key.


Link

[suggestion] · The relocated m_scripts loses its ownership and persistence documentation

The new m_scripts declaration omits the old distinction between solving material and watch-only ownership, while relocated comments still refer to removed AddCScript and renamed mapScripts.

Location: src/wallet/scriptpubkeyman.h:183 (head).

Details and suggested fix

Migration still filters candidate scripts through IsMine, where native witness recognition depends on HaveCScript; membership alone does not establish ownership. The deleted mapScripts comment explained that distinction from setWatchOnly and why key-derived witness programs remain memory-only. Move a concise version beside m_scripts, describing loaded redeem/witness scripts and reconstructed witness programs without carrying over obsolete persistence APIs. Also remove the AddCScript override remark and update the remaining mapScripts reference.


Link

[suggestion] · SetupDummyInputs retains an unused, incomplete provider output

The helper now omits the public keys needed to sign its P2PKH outputs, but none of its three callers consumes the provider, making that output parameter unnecessary.

Location: src/test/util/transaction_utils.cpp:50 (head).

Details and suggested fix

The P2PKH signing path calls GetPubKey, but FlatSigningProvider reads only pubkeys, which this helper never fills. Base derived public keys from the stored private keys. None of CCoinsCaching, test_Get, or test_IsStandard reads the provider after SetupDummyInputs; the helper builds its output scripts from the local key array. Remove keystoreRet and the three caller-local providers rather than maintaining an unused, partly populated signing result. This leaves the current transaction and coin fixtures unchanged.


Coverage details

Earlier concerns

Earlier reports raised these, with the titles and severities shown there. This review neither republished nor resolved them.

Background

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

Documented decisions

The 520-byte check was a safeguard against creating or retaining unusable P2SH redeemScripts, not an inherent limit on script storage. BIP16 explains that backward compatibility requires the serialized redeemScript to obey ordinary PUSHDATA rules: a script larger than 520 bytes cannot be pushed and therefore cannot redeem its P2SH output. PR #3843 explicitly proposed teaching multisig RPCs and the wallet to reject such scripts.

At the pinned base, FillableSigningProvider::AddCScript enforced this restriction before inserting a script. Moving enforcement into SignStep must preserve refusal to satisfy P2SH with a redeemScript larger than 520 bytes, regardless of which provider supplied it. The historical reason concerns how the script is spent, rather than whether arbitrary script bytes may exist in a provider.

Source 1 · Source 2

P2WSH deliberately has a different script-size boundary. Historical SegWit wallet documentation states that the 520-byte P2SH script limit does not constrain the P2WSH witnessScript, including for P2SH-P2WSH: the witnessScript instead has a 10,000-byte consensus limit and a 3,600-byte default policy limit. This does not remove size limits on ordinary stack elements.

For P2SH-P2WSH, the P2SH redeemScript is the small witness program, not the potentially much larger witnessScript. The head places the new check specifically in SignStep's SCRIPTHASH branch and leaves witness-script lookup separate. The pinned interpreter likewise removes the witnessScript from the witness stack before execution and applies the script-size limit. Thus the historical boundary is to reject oversized P2SH redeemScripts without imposing a blanket 520-byte restriction on witnessScripts.

Source 1

The legacy script map became both solving material and a gate on payment recognition. Its documented history distinguishes outputs the wallet intended to receive from outputs it could merely spend because it possessed keys. Before SegWit activation, recognizing arbitrary witness outputs was especially unsafe because those outputs could be spent without the wallet's signatures. Script-map membership is also distinct from watch-only membership: possessing a solving script does not by itself establish ownership.

Removing FillableSigningProvider does not make its script map semantically disposable. LegacyDataSPKM's retained IsMine logic still requires a corresponding witness program in the script map before accepting native P2WPKH or P2WSH, and then checks the underlying spending conditions. Migration therefore depends on script-map contents as well as keys; neither an empty replacement map nor treating every stored script as a watched payment represents the historical rules.

Source 1

Implicit witness-script learning reconciled backup recovery with compatibility and future flexibility. The original SegWit wallet proposal made existing and imported keys usable across address types, reconstructed witness programs in memory so old backups worked with new software, and explicitly persisted scripts for generated addresses and used keypool keys to support downgrades. Later documentation explains why implicitly derived scripts remain memory-only: persisting them all would constrain future wallets' ability to recognize a narrower set of payments. The original implementation derives P2WPKH programs only for compressed keys and bypasses virtual AddCScript.

The absence of a witness-program record on disk does not mean the legacy wallet lacked recognition of the corresponding output. LegacyDataSPKM reconstructs these programs when loading both plaintext and encrypted keys. Preserving that reconstruction is separate from writing scripts to the database; the memory-only entries are intentional behavior, not merely an incomplete write-through cache.

Source 1 · Source 2 · Source 3

Migration history explicitly relies on reconstructing legacy output coverage rather than copying only persisted scripts. PR #31452 describes combo() migration as equivalent to preserving P2PK, P2PKH, P2WPKH, and P2SH-P2WPKH coverage. Its discussion clarifies that key loading adds the P2WPKH witness program to the script map, while candidate enumeration derives P2PK and P2PKH directly from keys; those latter scripts need not appear in the map.

At the pinned head, GetCandidateScriptPubKeys derives candidates from keys, script-map entries, and watch-only scripts; GetScriptPubKeys filters them through legacy IsMine; MigrateToDescriptor consumes that result. Consequently, migration completeness depends on preserving both candidate generation and the implicitly reconstructed witness-program entries that allow the ownership filter to accept the appropriate candidates.

Source 1 · Source 2 · Source 3 · Source 4

Ralph's inferences

For bitcoin-tx, explicitly inserting a compressed key's P2WPKH program replaces a signing dependency formerly hidden inside AddKey; it does not reproduce wallet persistence policy. Native P2WPKH signing constructs its scriptCode directly, whereas P2SH-P2WPKH signing must retrieve the witness program as the P2SH redeemScript.

The base used FillableSigningProvider::AddKey and inherited implicit learning. The head explicitly inserts keys, public keys, and compressed-key witness programs into a temporary FlatSigningProvider. It also inserts user-supplied redeemScript bytes for P2SH or P2WSH without the former insertion-time rejection. Historical constraints therefore attach to the script's spending role: insertion alone neither establishes wallet ownership nor establishes that an oversized script is usable as a P2SH redeemScript.

Legacy wallet loading has a separate historical-data tolerance contract: an oversized stored redeemScript produces a warning and is omitted from the in-memory script map, but does not make loading fail.

Both pinned base and head LoadCScript return success after warning about scripts larger than 520 bytes. This loader behavior is distinct from the new signing-time check and from bitcoin-tx's temporary explicit insertion. Removing the provider therefore touches three separate operations—loading old records, supplying signing material, and satisfying an output—with different existing semantics.