SegWit Depth Overview

achinta das
Coinmonks

--

Introduction: In this article, I am going to give depth overview of SegWit. And how SegWit helps bitcoin to be scalable. Pieter Wuille first introduced the idea for SegWit at a Bitcoin conference in 2015.

SegWit(Segregated Witness) is a protocol upgrade that changes the structure of bitcoin transaction data. It was introduced on bitcoin on 23 August 2017 and characterized as a soft fork in the bitcoin chain, and then it has been widely accepted by bitcoin miners and users.

What is SegWit?

SegWit is how the block size limit on a blockchain is increased by removing signature data from bitcoin transactions. When some parts of a transaction are removed from blocks, this frees up space or capacity to add more transactions to the chain.

  • Firstly and most critically, SegWit fixed transaction malleability.
  • Increases Blocksize of bitcoin to add more transaction.
  • SegWit introduced two new script types — sending and receiving bitcoin — and a new encoding scheme called Bech32.

What Is Transaction Malleability?

Transaction malleability is the ability of a transaction to have multiple valid txids. For more information, view this link.

How Segwit Works?

  1. Block Size Increase: Segwit proposes how bitcoin blocks are structure. non-segwit block also known as legacy blocks has 1MB space. Inside 1MB block, data was input, output & signatures etc.
  • On the other side, Segwit block size up to 4MB. This is because it's consist base transaction block and an extended block. So Segwit, just like Bitcoin Cash, is indeed a block size increase.
Legacy vs SegWit Block

SegWit block structure achieves two primary goals.

  • Segwit block structure moves the digital signature outside of the base transaction block. So if someone changes the signature on the transaction, it will not affect the transaction id. This, in effect, solves the transaction malleability issue.
  • It's minimizing the base transaction data in the block. Since the witness data takes up to 65% of the transaction size, moving it outside the base transaction block allows more transactions to fit inside a 1MB block.

2. Segwit is a Soft Fork: So SegWit is just a block increase. So you may be thinking, then why not blocksize increase to 4 MB. In this case, developer just avoiding the hard fork.

Bitcoin specifically states that block size can't exceed 1MB. So the bitcoin developer finds the solution without hard fork. A solution of a 1MB block with an “extension” of another 3MB is still acceptable under the existing protocol.

So the legacy node can accept 1MB block and the Segwit node can accept 1 MB extended total of 4 MB blocks. This is called a soft fork.

3. Measuring Block :

Legacy Block measure by size, and SegWit block measure by weight.

A SegWit transaction was divided into two parts:

  • Segwit Part of Transaction: The witness of a transaction is classified as segwit part of a transaction.
  • Non-Segwit Part of Transaction: All the other parts of transactions except witness are classified as Non-Segwit part of a transaction.

A simple formula defines the weight of any transaction:

3*(non-segwit-part-of-transaction) + 1*(segwit-part-of-transaction)

But, first, let's see the mathematics equation block measure.

legacy_block_size = (size_of_non-segwit-data_of_each_transaction)segwit_block_size = legacy_block_size + (size_of_segwit-data_of_each_transaction)

For a block, non_segwit_weight and segwit_weight is defined as

non_segwit_weight = 3*(size_of_non-segwit-data_of_each_transaction)segwit_weight = 1*(size_of_segwit-data_of_each_transaction)block_weight = non_segwit_weight + segwit_weigh

For a block to be valid on the chain

legacy_block_size <= 1 MBblock_weight <= 4MBU

Pros & Cons of SegWit

Pros :

  1. Bitcoin transactions faster: SegWit makes the Bitcoin blockchain lighter. It allows more transactions to be processed without increasing the overall Bitcoin blockchain size.
  2. Bitcoin transactions cheaper. Higher transaction speed means lower transaction fees. However, bitcoin transaction fees can be incredibly high, so the community should welcome any changes that bring them down.
  3. Transaction malleability a thing of the past: SegWit is a simple and creative solution to a significant problem in the Bitcoin protocol.

Cons :

  1. SegWit has caused divisions in the Bitcoin community: The disagreements surrounding SegWit have caused several hard forks. The most well known of these is Bitcoin Cash (BCH).
  2. Enough nodes aren’t using it: A lot of miners don’t like SegWit. Lower fees affect their profits, and they also don’t appreciate having to support the witness-data sidechain, which doesn’t provide any fee revenue.

Conclusion

The implementation of SegWit marks a significant upgrade to the bitcoin blockchain network. It's introduced to the scalable bitcoin network for mass adoption. Furthermore, segregating the digital signature, or the witness, from the transaction block, achieves several advantages such as smaller transaction size, malleability fixes, and more. But at the same time, many manners not accepting SegWit because of deducted revenue. Bitcoin transaction scalability needs more R&D to fix several issues even though SegWit can be a short time of scalability fixed.

Reference

  1. https://www.bitpanda.com/academy/en/lessons/what-is-segwit-segregated-witness-and-how-does-it-work/
  2. https://www.econstor.eu/bitstream/10419/230576/1/1693601958.pdf
  3. https://river.com/learn/what-is-segwit/
  4. https://medium.com/@akshay_111meher/segwit-block-size-and-block-weights-f5864a6133fc

--

--