Segregated Witness, or SegWit, is an upgrade implemented in Bitcoin Core in 2017. SegWit bolstered the working of the Bitcoin network on many levels and opened the door to future upgrades, including Taproot.
First and foremost, SegWit fixed transaction malleability. This was a critical issue. It also increased Bitcoin’s block size limit. This allowed more transactions to be included in each block. Also, SegWit enabled two new script types, ways of sending and receiving bitcoin, and a new encoding scheme called Bech32.
The SegWit upgrade was contentious. Its implementation created polarization within the Bitcoin community. However, Bitcoin evolved stronger and more scalable. It also established that its decentralization could resist an attempted takeover by miners and community leaders.
Transaction Malleability and Why it’s a Problem
Transaction malleability is a transaction having multiple valid txids. This happens when a part of a transaction changes after the transaction has been committed without invalidating the signature. As a txid is a hash of the transaction, any modification to the transaction will affect the txid. Modifications that alter the txid and invalidate the signatures are not a concern. However, the changes which alter the txid but do not invalidate the signature raise malleability concerns.
Malleability is trouble for developers and users needing to reference a prior transaction in a new spending transaction before the previous transaction has been committed on the blockchain. This problem arises in the scenario that spends bitcoin created by a previous transaction. Now, the spending transaction must reference the txid of the previous transaction. However, should this txid change, the reference fails, and the spending transaction is rendered invalid.
Transaction malleability, specifically, was a problem in the way of the adoption of the Lightning Network, which is dependent on the exchange of unconfirmed Bitcoin transactions.
Also Read: Russia To Accept Bitcoins For Oil and Gas
The SegWit Fix to Transaction Malleability
A transaction is malleated in two ways. First, post transaction signing, additional data may be added to a ScriptSig. ScriptSig is the part of the transaction which contains the signature and other data used to unlock the bitcoin. Secondly, the signature held within the ScriptSig, can be altered. Both these options are possible as a signature cannot sign itself, and thus cannot render itself immutable. As the ScriptSig and its content signatures are part of the txid preimage, changing them would mean changing the txid.
SegWit removes this possibility by erasing all data from the ScriptSig. This is achieved by moving the ScriptSig data, comprising of signatures and public keys,to the Witness. Witness is a new part of SegWit transactions that is not hashed to calculate the txid. The ScriptSig corresponding to SegWit inputs is thus rendered immutable post the signing. Further, the data needed to unlock bitcoin, which is not immutable, are held in the Witness. This implies that the ScriptSig cannot be altered, and therefore, the txid cannot be changed either without invalidating the entire transaction.
Enabling the Lightning Network
The implementation of SegWit paved the way for the launch of the Lightning Network as a second layer atop the Bitcoin network. Before SegWit was enabled, the Lightning Network was unworkable since it relied heavily on unconfirmed bitcoin transactions. Hence was susceptible to attack so long as transaction malleability was possible.
Increase in Block Size
Being technically a soft fork, SegWit altered one of Bitcoin’s important consensus regulations in a backward-compatible way to increase the number of transactions that could be included in each block.
Before SegWit came into play, each block size was restricted to 1MB of data, equating to roughly 1650 transactions in a full block. SegWit introduced block weight, replacing block size as the limiting factor for a block. Nowadays, full blocks comprise of about 2700 transactions.
Enabling SegWit has been a major upgrade for Bitcoin. However, the next challenge for Bitcoin lies in its proof-of-work validating mechanism which is turning out to be inordinately energy-expensive.
A section of the Bitcoin community speaks of Bitcoin transitioning from its proof-of-work mechanism to something more like Ethereum’s prro-of-stake validation mechanism in the future.