What is Segregated Witness (Segwit)?

what is segwit

SegWit (Segregated Witness) was a major upgrade for Bitcoin. The code was released in 2015, and Segwit finally went live on Bitcoin on August 24, 2017.

Segwit Benefits

SegWit improves Bitcoin and fixes a number of bugs. The main features of Segwit are described in detail below.

Capacity Increase

Segwit doubled the capacity of the Bitcoin network.

A lot of people are claiming that SegWit did not increase the block size. It’s very easy to see that, yes, SegWit was a block size increase!

Here, for example, we can see a 2,177 KB (2.17 MB) Bitcoin block mined in January 2018.

Segwit Fixes Transaction Malleability

In addition to increasing Bitcoin’s ability to process transactions, SegWit fixes a fatal flaw in Bitcoin’s protocol that allowed users to tamper with transaction identities.

Before SegWit, the Transaction ID of a transaction could have been changed by manipulating the unlocking code of the transaction (your digital signature). After you digitally sign a transaction, it is sent through Bitcoin’s cryptographic hash function which results in a unique transaction ID.

If one character is changed in the digital signature, it will result in an entirely different transaction ID. SegWit moves the signature to the end of the transaction data, so the Transaction ID is created from everything but the digital signature.

In effect, this change renders it impossible to change the Transaction ID – if malicious nodes were able to tamper with Transaction IDs, the Lightning Network wouldn’t be possible.

Segwit Adoption

Segwit adoption is increasing. Nearly 40% of all Bitcoin transactions use SegWit addresses.

Why Segwit is Important

Bitcoin is by far the largest cryptocurrency by market cap, and for good reason. However, many in the crypto space have criticized Bitcoin because it is having trouble scaling to its ever-expanding user base.

Bitcoin is only capable of processing a mere 7-10 transactions per second on the base layer. Bitcoin’s underlying technology, although revolutionary, has also become one of Bitcoin’s most significant challenges.

Nevertheless, prominent developers in the Bitcoin community are working to develop a solution to the problem. SegWit and the Lightning Network together will allow Bitcoin to process millions (or more) transactions per second.

How Bitcoin Works

Before you can understand SegWit, you must first understand how Bitcoin transactions are processed.

This video may help give you some background before reading on:

You can think of the Bitcoin network like a chain, and each link in the chain is a block. For the sake of simplicity, let’s picture a block that only contains one transaction. If Mike sends 1 BTC to Bob, he’d add important data to the block:

Mike’s public key and digital signature must be included in the block to prove that the transaction is legitimate and really did come from him. The digital signature is included in the block as script (you can think of script as code). Just like people sign checks to authorize them, users of the BTC network must sign transactions to authorize them.

Despite being necessary to authenticate transactions, digital signatures fill up a lot of space that could otherwise be used for transaction data.

When thousands of transactions are initiated at once, there is not enough room for all of them to enter the same block. Users must pay a transaction fee which incentivizes miners to include their transaction in the block before others’. The more you pay, the faster your transaction will go through.

Unfortunately, transaction fees can get quite pricey. In December of 2017, it wasn’t unheard of to pay $20 per transaction if you wanted it to be validated within 10-20 minutes. Bitcoin’s scalability issue is one of its most significant obstacles prior to mainstream adoption. Nobody in today’s society wants to pay $20 for a cup of coffee while waiting around for their payment to clear.

Evidently, something must change. Some believe the best way to solve the problem is expanding Bitcoin’s block size – however, that solution would require Bitcoin to hard fork. Rather than forking into a completely new cryptocurrency, SegWit has been implemented to significantly increase Bitcoin’s ability to process transactions.

How Segwit Works

As mentioned previously, every block is composed of transaction data (public key, amount of BTC, etc.) and script (the sender’s public key and their digital signature). Although it is imperative that digital signatures are included in the validation process, they use a lot of space in blocks that could otherwise be used for more transactions.

Digital signatures, also known as witnesses, take up 60% of transaction data and usually the witness data exists in the middle of the transaction data. Segregated Witness is a way to remove the witness (signature) from the transaction – instead, SegWit transactions move the witness data to the end of the transaction.

When a SegWit transaction is being validated by a Legacy node (one that hasn’t upgraded), the witness data is stripped from the transaction. By removing signatures from the main block of transactions, transaction size is notably smaller, thus allowing far more transactions per block.

It is important to note that prior to SegWit, Bitcoin’s maximum block size was 1,000,000 bytes (1MB) – that is, once that data limit was reached, the block was no longer able to accept more transactions and any other transactions that weren’t included in the block had to wait.

SegWit, contrary to popular belief, is indeed a block size increase. SegWit has implemented a new way to measure the size of transactions. Instead of relying on a 1,000,000-byte block size, SegWit measures blocks using something known as block weight.

Here’s the formula used to calculate block weight:

(tx size with witness data stripped) * 3 + (tx size)

Legacy transactions don’t have any witness data because it was stripped. So, the weight of a legacy transaction is effectively four times larger. SegWit transactions do have witness data, but i’s at the end of the transaction rather than being in the middle, so they are less than four times the size.

Since Segwit transactions are broadcasted to all nodes with the witness data stripped, the legacy nodes will never have to validate a block greater than 1,000,000 bytes, therefore adhering to Bitcoin’s original protocol.

Conversely, SegWit nodes can receive blocks that are very close to, but not quite 4MB in size. In order for a block to be (near) 4MB, it would have to consist of primarily witness data rather than transaction data. It would be incredibly close to 4MB with the witness data, but still, less than 1,000,000 bytes when stripped of the witness data.

Although SegWit nodes are capable of validating a 4MB (4,000,000 bytes) block, in practice, that block size is ridiculously large. In most cases, a SegWit block will not exceed 2MB.

What’s The Bottom Line on SegWit?

Before After
Max Block Size 1 MB 4 MB
Transactions per Second 3 TX/s 7 TX/s
Transaction Malleability Bug
Broken Fixed

SegWit is the foundation for the Lightning Network. By eliminating the possibility for transaction malleability, secure payment channels can be created that will eventually allow the Bitcoin network to process millions of transactions per second. Lastly, SegWit is a way to help Bitcoin scale to accommodate its ever-expanding user base, without forcing a hard-fork.

Is Segwit Activated On Litecoin?

Yes, congrats Litecoin! :)