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

bitcoin/bitcoin: PR #31252

1 minor finding

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

Findings

Link

[minor] · Successfully extracted empty scripts are omitted from RPC/REST output

Valid empty redeem and witness scripts are omitted from the new RPC/REST decoding fields even with undo data; no specific mainnet transaction triggering this omission was identified.

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

Details and suggested fix

GetRedeemAndWitnessScripts() rejects an empty stack, but successfully extracts an empty final item. For example, P2SH committing to HASH160("") can be spent with scriptSig OP_1 OP_0, and P2WSH committing to SHA256("") can be spent with witness [01, ""]. Both execute an empty script with one truthy item remaining and satisfy cleanstack. The .empty() checks here then hide the extracted script in getrawtransaction verbosity 2, getblock verbosity 2/3, and REST block JSON with transaction details. This also affects an empty witness script inside P2SH-P2WSH. Represent presence separately, for example with std::optional<CScript>, and emit the decoded field whenever extraction succeeds, preserving the existing no-extraction paths.


Coverage details

Earlier concerns

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