Review report

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] · Empty redeem or witness scripts are dropped from the new fields

For valid P2SH or P2WSH spends with empty scripts and available undo data, the new decoded field is omitted because serialization checks script contents rather than extraction success.

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

Details and suggested fix

GetRedeemAndWitnessScripts uses an empty CScript for both successful extraction of an empty script and absence of a script. A P2SH output committing to HASH160("") can be spent with scriptSig OP_1 OP_0: removing the empty redeem script leaves one true item, which evaluating the empty script preserves. Likewise, a P2WSH output committing to SHA256("") can be spent with witness [01, ""]; the commitment matches and the remaining true item satisfies witness cleanstack. For confirmed spends with undo data, extraction therefore succeeds, but these .empty() guards suppress the corresponding decoded object. The raw scriptSig or witness remains available, so the consequence is limited to the new informational field. Track extraction success separately, for example with std::optional<CScript>, and emit the object whenever extraction succeeds. Add confirmed empty-script regression cases for P2SH and P2WSH. No current mainnet spend of an empty redeem or witness script was identified, so production impact is unconfirmed.


Coverage details

Earlier concerns

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