AI-generated analysisPublished automatically and not human-verified. Validated context appears in community notes below.
← Watch feed
Low 35 Bitcoin

txscript: refactor CalcScriptInfo for nested P2SH analysis

Public commit record

What the developer wrote

Authored by Olaoluwa Osuntokun

73/100 · Adequate
txscript: refactor CalcScriptInfo for nested P2SH analysis

Extract the nested P2SH analysis from CalcScriptInfo into a dedicated
calcP2SHScriptInfo helper, and switch it to use finalOpcodeData for
redeem-script extraction (matching the consolidation in NewEngine and
GetWitnessSigOpCount). The helper also threads the inner witness-script
expected-input contribution for nested P2WSH spends, which the previous
inline code did not account for.
✓ Specific, descriptive subject✓ Names a concrete action or component✓ Provides detailed explanatory context
The short version

What changed, and why it matters

This commit refactors how btcd counts expected inputs and signature operations for a specific kind of Bitcoin transaction: P2SH (pay-to-script-hash) that hides a SegWit (witness) program inside. The main change is that nested P2SH-P2WSH transactions now also account for the inner witness script's expected stack arguments, which the previous code ignored. The commit does not claim to fix a vulnerability, but the change corrects an analysis gap that could cause fee-estimation or policy checks to undercount required inputs for these transactions.

Recommended action

Review the new helper against all P2SH and nested-P2WSH test vectors, ensure expected-input counts match Bitcoin Core behavior, and add regression tests for nested P2SH-P2WSH expected-input counting if not already present. Treat this as a correctness improvement with potential fee/policy implications rather than an active consensus bug.

Security signals we found

01

Corrects under-counting of expected stack inputs for nested P2SH-P2WSH spends

02

Switches redeem-script extraction to finalOpcodeData, matching consensus-critical code elsewhere

03

Removes direct sigScript[1:] slicing that assumed a one-byte push opcode prefix

04

Refactors two separate P2SH cases into one helper to reduce divergence

Risk score

Why this scored 35/100

Our methodology →
Potential impact 8/30
Exploitability 5/25
Stealth signal 6/15
Affected reach 7/15
Confidence 6/10
Evidence quality 3/5
Human-validated context

Community notes

Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.

No validated notes yet.

The AI analysis stands alone for now. Submit a note if you can add evidence or important context.