MSTR Cat

Blockchain/Level IV · Protocol depth/4.1 Script/Lesson 7

Segregated Witness and transaction malleability

The unstable ID, the split signature, and the fix that unlocked Lightning

MaterialsA block explorer with JSON output capabilityA pre-SegWit P2PKH transaction hex string (from 2016 or earlier)A post-SegWit P2WPKH transaction hex string

Wonder

  1. Why could a stranger change a transaction’s identity without breaking its validity?
  2. How does moving signatures out of the hash fix malleability while keeping them consensus-protected?
  3. What is block weight, and why did discounting witness data increase capacity?

Explore

  1. Before SegWit, a transaction ID (txid) was the double SHA-256 of the whole transaction, signatures included. A third party could re-encode a signature, for example by negating its s value or changing how it was pushed, without invalidating it, producing a new txid for the same payment. This malleability broke unconfirmed chains: if Alice’s child transaction referenced her parent by ID, a malleated parent would orphan it, confusing wallets and exchanges tracking payments.
  2. Mt. Gox cited this mechanism in February 2014 to explain internal chaos during its collapse, though later analysis showed it accounted for little of the reported losses. The vulnerability persisted because ECDSA signatures are inherently mutable in their byte representation; third parties, and after the BIP66 and low-S rules mainly miners, could rewrite them. This instability made it unsafe to build two-way payment channels such as Lightning, where channel states depend on specific, predictable transaction IDs before confirmation.
  3. Segregated Witness (BIP141), activated August 24, 2017, at block 481,824, resolved this by separating witness data from the transaction body. The txid now hashes only the non-witness fields, rendering it immutable to signature encoding changes. Witnesses remain in a distinct structure within the raw transaction but are excluded from the identity hash. Third parties can no longer change the txid, while the signatures remain fully checked by consensus.
  4. Witness data is committed via a Merkle tree referenced in each block’s coinbase transaction, ensuring it cannot be dropped or modified without invalidating the block. Although segregated from the txid, witnesses still count toward block size limits under a new ‘weight’ metric: 4,000,000 weight units per block. Each non-witness byte counts as 4 weight units and each witness byte as 1, so signature-heavy transactions fit more easily.
  5. BIP143 introduced a new signature-hashing scheme that removed quadratic hashing costs for transactions with many inputs. BIP141 defined version 0 witness programs, P2WPKH and P2WSH, which became the standard for new addresses, and BIP144 specified how witness data travels between peers. These changes not only fixed malleability but also laid the groundwork for future upgrades like Taproot by establishing a versioned witness program framework that allows script evolution without breaking existing consensus rules.
  6. Open a block explorer and locate a recent P2WPKH transaction. Inspect it: the signatures appear in a separate ‘witness’ field rather than in the input’s scriptSig, and the txid is computed without them. Compare this to a pre-SegWit P2PKH transaction from 2016, where signatures sit in the scriptSig and so feed into the txid. The visual separation confirms that witness data no longer influences the transaction’s identity.

Key facts

  • Segregated Witness activated on August 24, 2017, at block 481,824.
  • Transaction malleability allowed third parties to change a txid by modifying ECDSA signature encoding without invalidating the transaction.
  • BIP141 moved signatures into a separate witness structure excluded from the txid calculation.
  • Block weight is capped at 4,000,000 units, with witness data discounted by a factor of four relative to non-witness data.
  • BIP143 introduced a signature-hashing scheme that removed quadratic hashing costs for transactions with many inputs.
  • BIP141 introduced version-numbered witness programs (version 0: P2WPKH and P2WSH), leaving room for later versions such as Taproot.

Exercise nine, six, three, one

9CollectList 9 technical or economic consequences of transaction malleability pre-2017. Note which affected users, wallets, exchanges, or protocol developers.
6ClusterGroup the 9 into 6 categories: ID instability, unconfirmed chain breaks, exchange confusion, channel impossibility, signature encoding mutability, and consensus protection gaps.
3DistillReduce the 6 to 3 core reasons why malleability prevented scalable payment channels before SegWit.
1CrystallizeWrite 1 sentence on how separating witness data from the txid hash simultaneously fixes ID stability and enables future script upgrades.

Fact check

Dates, figures and claims checked against the published sources listed below.

Open in the interactive academy →

PT ES ZH JA KO RU DE FR MS