Transaction Malleability
Changing a transaction's identifier without invalidating it, which broke pre-SegWit Lightning designs.
Basically
In plain words, the ability to modify a Bitcoin transaction's ID without invalidating it, a critical bug that SegWit fixed to enable Lightning.
Key Takeaways
- Transaction malleability allowed anyone to change a Bitcoin transaction's ID (txid) without invalidating it, because the txid was computed over signature data that could be altered after signing.
- This broke any protocol that referenced unconfirmed transactions by txid, making payment channels and the Lightning Network unsafe to deploy before the fix.
- SegWit resolved the problem in 2017 by moving witness data out of the txid calculation, enabling the entire Layer 2 ecosystem that exists today.
What Is Transaction Malleability?
Transaction malleability is a property of Bitcoin's original transaction format that allowed the transaction ID to be changed without invalidating the transaction itself. Because the txid was computed as a hash over the entire serialized transaction (including signatures), anyone who could modify the signature encoding could produce a different txid for the same economic transfer.
The core issue was a circular dependency: a transaction's signature cannot sign over itself. The signature must exist inside the transaction data that gets hashed into the txid, yet the signature is created before being placed there. This gap meant that alternative representations of the same valid signature produced entirely different txids while moving the same funds between the same addresses.
For simple payments, malleability was mostly a bookkeeping nuisance: wallets and exchanges tracking transactions by txid could lose track of confirmed payments. But for protocols that built chains of dependent transactions referencing unconfirmed txids, it was catastrophic.
How It Works
A Bitcoin txid is the double SHA-256 hash of the serialized transaction. In the original format, that serialization includes the version, inputs (each containing the previous txid, output index, scriptSig, and sequence number), outputs, and locktime. The scriptSig contains the unlocking script: typically an ECDSA signature and a public key.
Sources of Malleability
BIP 62 cataloged nine distinct sources of malleability. The most significant ones:
A Concrete Example
Consider a transaction with txid ABC123 broadcast to the network. An attacker (or any relay node) intercepts it, flips the S value in the ECDSA signature, and rebroadcasts the modified version with txid DEF456. Both versions are valid. Whichever reaches miners first gets confirmed. If DEF456 wins, any child transaction referencing ABC123 becomes permanently invalid.
Why It Matters
Breaking Payment Channels
The most consequential impact of transaction malleability was on payment channels. A bidirectional payment channel requires two transactions:
The commitment transaction must be created and signed before the funding transaction is broadcast. This is essential: once funds enter the multisig, both parties must cooperate to spend them. Without a pre-signed refund path, a malicious counterparty could refuse to cooperate, trapping funds permanently.
The commitment transaction references the funding transaction by its txid. If a third party malleates the funding transaction before it confirms, the txid changes and the commitment transaction becomes invalid. The party who funded the channel loses their safety net and their funds are stuck.
This single issue made the Lightning Network's payment channel architecture fundamentally unsafe. The entire design depends on chains of transactions that reference each other by txid: HTLCs, revocation keys, and justice transactions all require stable txids to function.
Mt. Gox and Real-World Impact
In February 2014, Mt. Gox, then the world's largest Bitcoin exchange, halted withdrawals and cited transaction malleability attacks. The exchange eventually filed for bankruptcy, claiming losses of approximately 850,000 BTC.
Subsequent research by Christian Decker and Roger Wattenhofer analyzed over a year of network data. They found 35,202 malleability attack instances but concluded that at most 386 BTC could have been stolen via this technique: a tiny fraction of Mt. Gox's claimed losses. Malleability was likely a contributing factor to bookkeeping confusion rather than the primary cause of the exchange's collapse.
The incident did trigger a surge in malleability attacks: 25,752 attacks occurred in the first two days after the public announcement, compared to only 421 in the entire preceding year. The publicity effectively taught attackers the technique. Silk Road 2.0 reported losing $2.7 million in Bitcoin to a similar attack shortly after.
How SegWit Fixed It
Segregated Witness (BIP 141), activated on August 24, 2017 at block 481,824, restructured the transaction format to eliminate malleability. The core idea: move witness data (signatures and redeem scripts) out of the data used to compute the txid.
The New Transaction Format
SegWit transactions use a new serialization with separate fields for witness data:
In SegWit transactions, the scriptSig is empty. Signatures are placed in the witness field instead. Since the txid is computed from [version][inputs][outputs][locktime] only, no malleable signature data enters the calculation.
A separate identifier, the wtxid, hashes the full serialization including witness data. Miners commit to a Merkle root of all wtxids in the coinbase transaction, ensuring witness data cannot be altered after block inclusion either.
Enabling the Lightning Network
With stable txids, payment channels became safe. A commitment transaction referencing a SegWit funding transaction's txid is guaranteed to remain valid regardless of what happens to the funding transaction's witness data. This one fix unlocked the entire Lightning Network scaling architecture: multi-hop payments, channel factories, submarine swaps, and every protocol built on chains of dependent transactions.
Layer 2 protocols like Spark also benefit from this foundation. By guaranteeing that transaction references remain stable, SegWit made it possible to build entire off-chain transaction graphs that settle back to Bitcoin's base layer with full security guarantees.
Third-Party vs. Self-Malleability
An important distinction exists between two types of malleability:
Schnorr signatures, introduced with Taproot (BIP 340) in November 2021, provide an additional layer of protection. Unlike ECDSA, Schnorr signatures are provably non-malleable: there is exactly one valid signature for a given message and key pair, eliminating even the ECDSA complement attack vector.
Use Cases and Legacy
While transaction malleability is largely a historical problem, its legacy shapes Bitcoin development to this day:
Risks and Considerations
Transaction malleability is effectively solved for SegWit transactions, but some considerations remain:
This glossary entry is for informational purposes only and does not constitute financial or investment advice. Always do your own research before using any protocol or technology.