Segregated Witness
Segregated Witness (SegWit)¶
Segregated Witness (SegWit) is a soft fork described by multiple BIPs (141, 142, 143, 144, and 145). Its primary purpose is to optimize the structure of Bitcoin transactions and blocks by moving the transaction signature (also called "scriptSig," "witness," or "unlocking script") from the transaction into a separate structure. It not only reduces the data size of Bitcoin transactions (thus allowing a block to fit more transactions), but also solves the "transaction malleability" problem (a defect that hindered the implementation of the Lightning Network). This is critically important for technologies like payment channels and the Lightning Network that are built on Bitcoin's transaction structure.
SegWit was officially activated on August 24, 2017, becoming part of the Bitcoin network.
SegWit Improvements¶
Improved Scalability¶
By separating witness data, the number of transactions each block can accommodate is increased, thereby improving the processing capacity of the Bitcoin network.
This includes two main parts: inputs and outputs. Without Segregated Witness, signature data could take up to 65% of a block. With SegWit, signature data is removed from transaction inputs. This increases the effective block size from 1 MB to approximately 4 MB.
Additionally, SegWit introduced the concept of block weight. Think of block weight as a replacement for the concept of block size. Essentially, block weight is a unit of measurement that includes all block data: transaction data (1 MB) and signature data (up to 3 MB).
Transaction Malleability Fix¶
The Transaction Malleability problem occurs when, after a Bitcoin transaction A is sent but before it is confirmed, an attacker uses new signature data to change the transaction's unique identifier - the transaction hash - thereby creating a new transaction B. If transaction B is recorded on the Bitcoin ledger first, transaction A will be rejected as invalid due to the double-spending problem.
With Segregated Witness, signatures are no longer part of the transaction data, eliminating the possibility of modifying this data. This fix enables further innovation within the blockchain community, including Layer 2 protocols and smart contracts.