What Is SegWit (Segregated Witness)?-banner-imageAcademy

What Is SegWit (Segregated Witness)?

Bitcoin and Scalability

The main reason for the emergence of Bitcoin was the desire to create a digital, decentralized payment method that can be used as an independent alternative to traditional currencies. The growing interest in the crypto industry and the resulting increased transaction volume lead to one of the biggest weaknesses of the Bitcoin protocol: Scalability.

In short, the scalability problem refers to delayed transactions and high transaction fees due to transactions exceeding network capacity. The Bitcoin protocol’s block size and the block creation conditions limit the average block creation time to 10 minutes and the maximum block size to 1MB. That is why Bitcoin is limited to an average of 7 transactions per second (TPS). Many methods have been proposed to solve the scalability problem.


Solution Methods on the Bitcoin Protocol

The Lightning Network, put forward by Joseph Poon and Thaddeus Dryja in 2015, is the first method applied to solve the scalability problem. The Lightning Network is an application running on the Bitcoin blockchain. In the 2nd layer of this application, payment channels are created between parties, and only the initial balances uploaded to the network and the final balances resulting from all transactions are processed into the blockchain network. The transactions performed on the Lightning Network payment channel during the contact period are not processed into the blockchain network, which decreases the density of the network and ensures its smooth operation.

For more information on the Lightning Network, you can click here to read our article.

The Bitcoin Cash Hard Fork, which was carried out on Aug. 1, 2017, was another method. Bitcoin Cash, which allowed more transactions per block to be included in the process compared to Bitcoin, increased the block sizes to 8-32MB. In addition, 61 transactions can be made per second.

In Aug. 2017, only three weeks after the Bitcoin Cash Hard Fork, SegWit (Segregated Witness) emerged as a result of a Soft Fork within the Bitcoin protocol. SegWit was introduced by Pieter Wuille, a Bitcoin Core developer.


What Is SegWit (Segregated Witness)?

Segregated Witness, or SegWit for short, is a protocol upgrade developed in 2015 and released in 2017. It was introduced as a solution to the scalability problem in blockchain networks. The main idea of SegWit is to reorganize block data so that witness data (digital signatures) can no longer be placed with transaction data. In other words, the SegWit upgrade enables witness data (digital signatures) to be separated from transaction data. And this allows more transactions to be stored in a single block, increasing the transaction volume of the network.

SegWit, which is used by some cryptocurrency projects including Bitcoin and Litecoin, provides many benefits such as improved transaction speed and block capacity. As of the time of this writing, May 15, 2021, the percentage of SegWit transactions is 77 on the Litecoin network and 57 on the Bitcoin network.


Screenshot_2_e0d14743d7.png

Source: Blockchair

How Does SegWit Work? What Is the Purpose of SegWit?

  • Each Bitcoin transaction includes:

  • The recipient’s (output) Public Key,

  • The sender’s (input) Public Key,

  • The sender’s digital signature, which is used to perform the transaction (Private Key).

A digital signature is used to sign and confirm transactions; thus, it is also called a “witness”. Witnesses:

  • Verify the validity of the transaction.

  • Must be used in the cryptographic hash formula for the Proof of Work mining algorithm.

Digital signatures, which are very important for transactions, take up most of the file size of a transaction. In short, before SegWit was introduced, the digital signature was in the middle of the transaction data structure. SegWit removes the digital signature from a central structure and places it at the end of the data structure. This creates unique transaction IDs with no witness data, which are verified by different validators.

Why SegWit Separates Witness Data (Digital Signatures)?

It turns out that on the Bitcoin blockchain, it is possible to change digital signatures before a transaction is verified. The digital signature change is valid by the network when you run a mathematical check on it, but it gives a different result when you run a hash algorithm on it.

For example, let’s say that the digital signature value is “3”, but we replace “3” with “03” or “3 + 7-7”. It is a valid signature since it still has the same value mathematically, but if we apply the hash algorithm to these different versions, we will get different results. Because the hash value depends on the way you write the value, not the value itself.


Goersel1_9fe624c3b1.jpg


Since the hash value is the transaction ID on the blockchain, it means that a transaction ID can be changed to a different ID effectively and will still be valid. Therefore, creating a new transaction ID for an existing transaction can be problematic.

To simplify it further, let’s look at an example of how someone can take advantage of this problem. Let’s suppose that Person A pays Person B in transaction X, which has not been verified yet. Person B then uses this unverified payment to buy an item from Person C (transaction Y). Person C sends the item to Person B without waiting for transaction Y to be verified.


Goersel2_f3a618fdc9.jpg


Now let’s suppose that Person B confirms the transaction from Person A with a different transaction ID. Transaction Y is now invalid since it is based on the non-original transaction ID of transaction X. Thus, Person C has not been paid, but has already delivered the item.


Goersel3_3b8138b32e.jpg


So, Person B can trick the system in this way if he has control over even one node on the network. Person B initiates the same transaction on the network with the help of this node, but with a different transaction ID. If Person B is lucky, the network records the transaction first, thus making it valid. The money is sent to Person B’s other wallet, which Person A has no idea about. If Person B complains that he never received the money and Person A checks the blockchain to see the original transaction ID, Person A will not be able to find it and will send the money once again. Therefore, while Person A and the rest of the network are unaware, Person B will have made twice as much profit and will also have the item Person C sent.

How Does SegWit Prevent This Situation?

SegWit is a proposed change to the block structure. Old blocks, also known as the Legacy Blocks, have a total of 1MB of space for all block data. On the other hand, SegWit Blocks are larger blocks, which consist of a base transaction block and an extended block and have up to 4MB of space.

The first part of a transaction contains the Public Keys of the sender (input) and receiver (output), and the second part contains the witness data that includes their digital signatures (Private Keys). SegWit Blocks move digital signatures out of the base transaction block. Digital signatures will still be transmitted but placed inside the extended block. The base transaction block contains information about the sender and receiver. The extended block (additional 3MB) contains all witness data that is not mandatory in the base transaction block. Therefore, SegWit achieves these two main goals with its new block format:

  • It moves digital signatures out of the base transaction block. Therefore, the transaction ID is not affected if someone changes the signature on the transaction. And this resolves the transaction malleability issue.

  • It shrinks base transaction data size. Since witness data takes up 65% of the transaction size, by moving it out of the base transaction block, it allows more transactions to be fit inside a 1MB block.


goersel_4_6f6f38563c.jpg


What Are the Advantages of SegWit?

Scalability

  • Capacity Increase: One of the biggest advantages of SegWit is the increase in block capacity. By moving signature data out of the base transaction block, it can fit more transactions in a single block. With that, the effective block size increases from 1MB to approximately 4MB. However, it should be noted that SegWit does not provide a “real” block size increase. Instead, it is an engineering solution to increase effective block size without having to increase the block size limit, and thus, it differs from the Bitcoin Cash Hard Fork. To be more precise, the actual block size is still 1MB, but the effective block size limit is 4MB.

  • Transaction Speed Increase: Since with a block that can store more transactions there can be more transactions on the blockchain, SegWit also has the ability to increase transaction speed. Although mining a block takes the same amount of time, more transactions are processed in it, thus the TPS (transaction per second) rate is higher. The increased transaction speed has also helped reduce transaction costs on the Bitcoin network.

Transaction Malleability

Another major problem Bitcoin has is that digital signatures can be changed. When a digital signature is changed, the transaction between two parties can be disrupted. Since the data stored on blockchain is almost immutable, invalid transactions are permanently stored on the blockchain. With SegWit, digital signatures are no longer part of the transaction data, and this eliminates the probability of altering data. This fix has also allowed for further innovation for the blockchain community, including Layer 2 protocols and smart contracts.