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

primitives: split ScriptPubKey and ScriptPubKeyBuf from generic script

Public commit record

What the developer wrote

Authored by Andrew Poelstra

85/100 · Strong
primitives: split ScriptPubKey and ScriptPubKeyBuf from generic script

There are a couple places where (in Bitcoin, not just this crate) there
is confusion between scriptPubKeys and redeemScripts. Specifically, in
P2SH-wrapped segwit, we put a segwit scriptpubkey into a redeemScript
slot and then it must be treated as both.

The next commit will introduce the RedeemScript type and a trait that
covers both RedeemScript and ScriptPubKey.

Meanwhile, there are a couple methods that belong in this trait, which
in this commit I just implemented for GenericScript<T> for all T:

* in bitcoin/src/crypto/sighash.rs all the sighash methods
* in primitives/src/script/mod.rs the ScriptHash constructors
* in bitcoin/src/script/mod.rs for new_witness_program_unchecked
* in bitcoin/src/script/borrowed.rs for all the p2sh methods
* in bitcoin/src/script/owned.rs for the new_p2wpkh constructor

In the next commit we will tighten these so that they are only applicable
to the two types RedeemScript and ScriptPubKey. (Really, we want to
tighten them so that they're applicable only to RedeemScript and some
more-specific SegwitV0ScriptPubKey type. But I think that would be a
bridge too far: if we had multiple scriptpubkey types then what would
we put in TxOut::script_pubkey?)
✓ Specific, descriptive subject✓ Names a concrete action or component✓ Provides detailed explanatory context✓ Explains rationale or failure mode
The short version

What changed, and why it matters

This commit is a large internal refactoring in the rust-bitcoin library. It introduces a new dedicated type, ScriptPubKey, for the scripts that appear in transaction outputs, and updates many examples and internal functions to use it. The change is described by the author as a step toward preventing confusion between scriptPubKeys and redeemScripts. It is not a security patch for an exploitable bug; it is a type-system cleanup that may reduce future misuse but does not by itself fix any vulnerability.

Recommended action

Treat as a normal library refactoring commit. Review downstream code for API breakage due to the new ScriptPubKey/ScriptPubKeyBuf types. No urgent security action is required based on this commit alone.

Security signals we found

01

Large API refactor introducing ScriptPubKey/ScriptPubKeyBuf types

02

Author notes confusion between scriptPubKeys and redeemScripts as motivation

03

Several methods temporarily loosened to GenericScript<T> with intent to tighten later

04

No new bounds checks, no validation changes, no consensus rule changes

05

No mention of CVE, advisory, bug bounty, or external report

Risk score

Why this scored 19/100

Our methodology →
Potential impact 2/30
Exploitability 1/25
Stealth signal 1/15
Affected reach 3/15
Confidence 8/10
Evidence quality 4/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.