June 04, 2023
If you have been transacting Bitcoin for a while, you might be confused with two networks that often pop up while sending or receiving the coins.
You might be wondering what are the implications of using the SegWit network over the BTC Network. Let's start the discussion by first understanding what SegWit is and what challenges it solved that used to occur in our vanilla network.
Segwit is derived from Segregated Witness and is an upgrade to the Bitcoin network that aims to solve several issues, such as scalability, transaction malleability, and block size.
It was implemented as a soft fork in August 2017 and was first introduced by the Developer Pieter Wiulle at the Scaling Bitcoin conference in December 2015.
Let's dive deep into how it solves the above-mentioned issues:
SegWit increases the number of transactions that can fit into a single block by separating the transaction signatures (witness data) from the transaction data. This allows more transactions to be processed in each block, improving the overall transaction throughput of the network.
You might ask, why not simply increase the block size? That would be convenient, wouldn't it?
Yes, and you would be correct to think that way, and you might also be surprised to know that there was a hard fork of the Bitcoin network that increased the block size limit to 8 megabytes (MB) from the 4 MB. This hard fork resulted in the creation of a new cryptocurrency called Bitcoin Cash (BCH), which was launched on August 1, 2017.
However, the hard fork was controversial, and not all members of the Bitcoin community supported it. Some argued that increasing the block size limit would compromise the decentralization and security of the network, as larger blocks would require more storage and processing power, making it more difficult for individual users to participate in the network.
The maximum block size of Bitcoin is currently 4 megabytes (MB) in principle, but in practice, it is limited to 2 MB due to the way the block size is defined. This limit was introduced as a temporary measure by Satoshi Nakamoto, the creator of Bitcoin, to prevent spam attacks on the network.Okay, but how does SegWit separate the signature or witness data?
Alright, first, let's understand what the signature data is.
Here is how the whole thing sits in the big picture. When a miner validates a transaction, they first check the transaction data to ensure that it is valid and meets the network's rules. If the transaction is valid, the miner then checks the witness block to verify the digital signatures contained in the witness data.
Transaction malleability is a term used to describe the ability of a third party to modify the transaction ID of a Bitcoin transaction without changing the underlying transaction data before it is confirmed by the network. This can happen because the transaction ID is calculated based on the transaction data and the digital signatures contained in the witness data.
For example, let's say Alice sends 1 BTC to Bob and gets a TX ID of 123456. An attacker can intercept this transaction and change the signature data slightly, creating a new TX ID of 654321. The attacker then broadcasts this modified transaction to the network. If the modified transaction gets confirmed before the original one, Alice's wallet will show that her transaction is unconfirmed, even though Bob has received the payment. This can confuse Alice and make her think that she needs to resend the payment.
Note: The signature data is not immutable because it can be encoded differently without changing its meaning. For example, the signature data consists of two values, r, and s, which are numbers. However, these numbers can be represented in different formats, such as hexadecimal or decimal. The signature data also has a SIGHASH flag, which can be appended or prepended to the signature. These variations do not affect the validity of the signature, but they do change the TX ID that is generated by hashing the transaction data.
Another example of how transaction malleability can be exploited is by double-spending. Let's say Charlie sends 1 BTC to Dave and gets a TX ID of 789012. Charlie then creates another transaction that spends the same input as the first one but sends it to himself instead of Dave. He modifies the signature data of this second transaction to get a different TX ID of 210987. He then broadcasts both transactions to different parts of the network, hoping that one of them will get confirmed and the other will be rejected. If he succeeds, he can trick Dave into thinking that he has received the payment while actually keeping the coins for himself.
You'll be surprised to know that the Transaction malleability was one of the reasons behind the collapse of Mt Gox, a famous Bitcoin exchange that lost hundreds of thousands of bitcoins in 2014. The attackers used transaction malleability to withdraw bitcoins from Mt Gox multiple times while making it appear that their withdrawals were unsuccessful.
The Segregated Witness (SegWit) upgrade to the Bitcoin protocol addressed this issue by removing the digital signatures from the transaction ID calculation. This means that the transaction ID is now calculated based only on the transaction data, which makes it much harder to modify the transaction ID without changing the underlying transaction data.
In addition to compressing the transaction data, SegWit also includes other features that improve the efficiency and scalability of the Bitcoin network, such as the ability to process more transactions per block and the ability to implement second-layer solutions like the Lightning Network.
Let's see what those are:
SegWit addresses use a different format compared to normal addresses. The most common SegWit address format is the bech32format that starts with "bc1". For example:
Whereas the legacy addresses use the base58 encoding and can start with either "1" (Pay-to-Pubkey Hash or P2PKH) or "3" (Pay-to-Script Hash or P2SH). For example:
In conclusion, SegWit has had a significant impact on the Bitcoin network by addressing scalability issues, fixing transaction malleability, and enabling the development of second-layer solutions like the Lightning Network. While there are some disadvantages, such as complexity and partial adoption, the overall benefits of SegWit have made it an essential upgrade for the Bitcoin ecosystem.
Subscribe to the newsletter to learn more about the decentralized web, AI and technology.