The Segregated Witness (SegWit) soft fork has been one of the most significant updates in the history of the Bitcoin protocol.
Despite being considered a major innovation for several years, the Bitcoin blockchain is not a versatile technology. It is essential for distributing network governance and making attacks on Bitcoin uneconomical, but it is inefficient in processing transactions. This is because every payment must be verified and stored by the entire network. For example, a coffee payment in Milan must be recorded and verified by someone operating a node in Melbourne.
In a distributed network, the most well-known trade-off is known as the Trilemma because it involves three variables: decentralization, scalability, and security. It is not possible to achieve the maximum level in all three aspects because improving one directly leads to the deterioration of another.
The trade-off between decentralization and scalability led to a significant split within the Bitcoin community during the period known as the Blocksize War, from August 2015 to November 2017. The path to the activation of SegWit was long and complex. The discussion around the size of the blockchain blocks led, among other things, to the creation of the Bitcoin Cash fork.
The block size
In Bitcoin, a transaction is essentially text. When making a payment, the wallet software generates code that communicates to the network that party A is sending a certain amount to party B.
The texts containing different transactions are aggregated into data packets (and therefore bytes), which, along with other information, make up the blocks of the blockchain. When there are numerous transactions, some are excluded from the block, remaining in a limbo area called the mempool, waiting to be included in subsequent blocks.
The more complex a transaction is, the more text needs to be written, and the more space it will occupy within the block. Contrary to what one might think, fees do not depend on the amount transferred but on the size (in bytes) of the transaction.
Why a block size limit?
Removing the limit on the block size could include all transactions, and the confirmation times would decrease, making the Bitcoin network more scalable. However, such a change would jeopardize the decentralization of the network.
To manage a Bitcoin full node, it is necessary to download the entire blockchain, which is currently less than 1 TB in size. This means that anyone can build their own node with few resources, thus contributing to the decentralization of the network.
If blocks were larger, the weight of the entire blockchain would increase significantly, and the cost of managing a full node would become prohibitive for many people.
The improvements introduced by SegWit
Segregated Witness is a soft fork developed in 2015 and proposed through BIP 141 by the developer Pieter Wuille. It was implemented in Bitcoin Core in August 2017.
Through the SegWit soft fork, the Bitcoin network managed to introduce two significant improvements to the protocol.
In the structure of a transaction, the heaviest part in terms of bytes is the signature, which verifies that the sender has the necessary funds to make a payment.
SegWit has separated the transaction into two sections: the first part of the transaction contains the addresses of the sender and recipient, while the second part contains the “witness data” field that includes the transaction signature. Essentially, SegWit has separated the signature from the transaction data. By removing the “witness” field from the main block, SegWit has significantly reduced the size of transactions, allowing more transactions per block and improving the scalability of the Bitcoin network.
SegWit introduced a 75% discount on the “witness data” field containing the signature, effectively increasing the size of a block from 1 to about 4 MB.
As a side effect, SegWit has solved the problem of transaction malleability. This issue allowed an external actor to alter the unique identifier, known as the hash, of a transaction before it was confirmed in the blockchain. SegWit addresses this problem by moving the signature parts into a separate field outside the data flow that generates the transaction hash. This means that even if the signature parts were somehow altered, the transaction hash would remain unchanged.
With the introduction of SegWit, transaction malleability is no longer a problem because the information that could be altered is no longer included in the transaction hash calculation.
The improvements introduced by the SegWit soft fork lay the foundation for layer-2 solutions like the Lightning Network.