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

primitives: split WitnessScript and WitnessScriptBuf from script

Public commit record

What the developer wrote

Authored by Andrew Poelstra

73/100 · Adequate
primitives: split WitnessScript and WitnessScriptBuf from script

Ok, after the previous huge/ugly commits, this one is pretty cathartic.
I introduced the new type, used it for every field named `witness_script`
and all the constructors for `WScriptHash`, chased through all the
compiler bugs, and everything "just worked".

There is one oddity: in BIP143 there is a special-cased scriptcode construction
used for P2SH-wrapped segwit. We have methods that compute this. To make the
types line up (without introducing new traits and generics) I simply typed
the special-case thing as a WitnessScript, since that's what it's pretending
to be. I added a doccomment to all the methods that compute this.

This is a mild abuse of the `WitnessScript` type, since this special-case
object really isn't a witness script (though you could use it as one, and
trick wallets in mostly-harmless ways by doing so ... but this is a bug
in Bitcoin, not in our library!). But only a mild one, and I think it does
a *way* better job of guiding the user through the script-mangling weirdness
around sighashes and p2sh/p2wsh wrapping.

The final tag is TapScript, which will be done in the next commit. Then I
can throw away the Whatever tag, delete `Script`/`ScriptBuf`, and finally
rename `GenericScript`/`GenericScriptBuf` to those names.
✓ Specific, descriptive subject✓ Names a concrete action or component✓ Provides detailed explanatory context
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, WitnessScript, for Segwit v0 witness scripts and uses it wherever the code previously used the generic Script type for that purpose. The change is primarily about making the type system guide users to the correct Bitcoin concepts. The commit message explicitly notes one deliberate design oddity: for BIP143 P2SH-wrapped-segwit sighash calculations, the returned object is typed as WitnessScript even though it is technically a special-case template, not a real witness script. The author calls this a 'mild abuse' and documents it. There is no bug fix for a runtime vulnerability in the diff; the security relevance is that stronger typing may help prevent future API misuse.

Recommended action

Treat as a normal API refactor. Review downstream code that constructs WScriptHash or calls p2wsh/p2shwsh/sighash APIs to ensure it uses the new WitnessScript/WitnessScriptBuf types. No urgent security patch is indicated by the diff itself.

Security signals we found

01

Type-system hardening: dedicated WitnessScript type reduces accidental misuse of script kinds

02

Author-documented 'mild abuse' of WitnessScript for BIP143 scriptCode template

03

No runtime validation or cryptographic logic changes observed

04

No memory-safety, overflow, or deserialization fixes present

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.