rpc: print P2WSH and P2SH redem Script in getrawtransaction and getblock

bitcoin/bitcoin: PR #31252

2 minor findings · 1 suggestion

Earlier concerns neither republished nor resolved: 1 suggestion. See the Run archive for their assessments.

Findings

Link

[minor] · Multisig desc values with more than three keys are not parseable

The new redeemScript and witnessScript fields inherit decodescript's limitation: multisigs with more than three keys produce a bare multi(...) descriptor that the descriptor parser rejects.

Location: src/core_io.cpp:485 (head).

Details and suggested fix

When undo data is available, TxToUniv passes the extracted scripts to ScriptToUniv, which calls InferDescriptor at ParseScriptContext::TOP. A normal 3-of-5 multisig therefore produces a checksummed bare multi(...), but parsing it with getdescriptorinfo fails because top-level multisig descriptors allow at most three keys. The asm and type fields remain correct. Omit desc when its inferred value is not valid at top level, and mark that field optional in the result documentation.


Link

[minor] · Empty redeem and witness scripts are omitted after successful extraction

With undo data available, valid empty-script spends still omit redeemScript or witnessScript because emptiness also means extraction failed; no mainnet instance was identified.

Location: src/core_io.cpp:483 (head).

Details and suggested fix

GetRedeemAndWitnessScripts copies the final stack item into a CScript, but TxToUniv emits the corresponding field only when that script is nonempty. A P2SH output committing to HASH160("") can validly be spent with scriptSig equal to OP_1 OP_0: verification removes the empty redeem script and accepts the remaining truthy item. Likewise, P2WSH committing to SHA256("") accepts witness ["01", ""]. Return each extracted script as std::optional<CScript> and emit the object whenever the optional has a value, including an empty script.


Optional improvements

Link

[suggestion] · RPC help hides the new redeemScript and witnessScript fields

Help elision hides both fields in getrawtransaction verbosity 2 and getblock verbosity 2/3, leaving users without their documentation and making “Same vin fields as verbosity = 1” inaccurate.

Location: src/rpc/rawtransaction.cpp:252 (head).

Details and suggested fix

TxDoc adds both script objects before calling ElideGroup, which marks them HelpElisionSkip. The visibility-restoration loop handles only prevout, so neither script object reaches rendered help. getblock verbosity 2 summarizes the transaction documentation, while verbosity 3 points back to that result and also elides the script fields. Keep redeemScript and witnessScript visible alongside prevout in the elided input documentation so users can discover the fields and their undo-data requirement.


Coverage details

Earlier concerns

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