Introduction to SegWit

Deepkamal
4 min readDec 28, 2021

--

In this blog, we shall learn about the idea behind SegWit and its related topics. If you do regular transactions in Bitcoin, SegWit is a term you would want to be aware of.

What is SegWit?

A Bitcoin block consists of header and transaction data. It contains all the data necessary to validate a transaction and also keeps its record in a public ledger.

The two major components of a transaction are inputs and outputs which are the public addresses of the sender and receiver respectively. In a transaction, the majority of its space is occupied by a signature (a part of inputs) which validates whether or not the sender has the sufficient funds required to do the transaction.

SegWit (short for Segregated Witness) is a process that separates this signature data from the Bitcoin transactions. It thus helps to increase the size of a block in a particular blockchain by freeing up space thus allowing more transactions to be added to the block without clogging the network. It was presented by Pieter Wiulle in December of 2015 and activated in August of 2017.

Problems in Scalability and Malleability Of Bitcoin

We know that Bitcoin transactions are carried out on the blockchain and each block contains several transactions which are regularly added to the blockchain. On average, a new block is added every ten minutes on the blockchain. Prior to SegWit, the maximum size of a block was 1 Megabyte which could carry out 2700 transactions on average.

With the increase in the number of transactions in Bitcoin and the limited block size, the number of pending transactions also increased. The number of transactions and the time required to carry them out were nowhere near the ones operating in the traditional finance system. For the widespread acceptance of Bitcoin and its sustainability, this problem needed to be solved.

Bitcoin’s protocol allows the digital signature of a particular transaction to be altered before the transaction has been confirmed in such a way that is still valid if checked mathematically but different if checked via a hashing algorithm. Hence the id of the particular transaction could be changed without affecting its validity.

This creates problems in running the lighting network (second layer of Bitcoin) effectively as it depends on the immutability of the main network. Alteration in the transaction id can also cause problems if the unconfirmed funds are spent or accepted.

How Does SegWit Solve These Problems

SegWit separates the signature data from the transaction and stores it in an extended block thus freeing up space in the base transaction block. Moving the witness data out of the transaction block frees up about 65% of its space. This new space can now be used to accommodate more transactions. Hence it increases the average number of transactions per second per block thus tackling the problem of scalability effectively.

As the witness data is stored and transmitted on a separate block, no alteration can be done to the data thus making it truly immutable. So now, if anyone changes the digital signature of a transaction, it won’t affect the transaction id whatsoever thus solving the problems of malleability.

By using SegWit, developers can thus avoid a hard fork in the Bitcoin network.

Difference Between Legacy And SegWit Blocks

The blocks which do not use SegWit are called Legacy blocks. In these blocks, the witness data cannot be separated from the transaction data. As a result, the weight of a transaction in the Legacy block is much higher than that of one in a SegWit block.

Weight of a transaction is a new concept introduced in SegWit which can be calculated by the following formula

Transaction Weight = Size of Transaction (without witness data) * 3 + Size of Full Transaction

In the case of Legacy blocks, the weight of any transaction is 4 times the size of that transaction. In SegWit, the higher the size of the witness data of a transaction, the lower will be the weight of that transaction. As a result of this, SegWit transactions are cheaper and also consume less time to get confirmed.

Legacy addresses start with “1” whereas SegWit addresses start with “3” or “bc1”. The backward compatibility of SegWit allows its users to transfer funds from a SegWit wallet to a Legacy wallet and vice versa.

Conclusion

Now that you know about SegWit and how it works, you can choose which block to use to do your transactions in a cheaper and efficient way. We shall cover more topics like this in our upcoming blogs.

--

--

Deepkamal

Content writer specializing in blockchains and DeFi