What is SegWit?

What is SegWit?

Segregated Witness, commonly referred to as SegWit, represents a pivotal upgrade to the Bitcoin Core protocol, introduced in 2017. Originating as a means to address Bitcoin's scaling challenges and particular vulnerabilities, SegWit brought about a number of significant improvements. Among its foremost accomplishments, the protocol rectified transaction malleability issues and augmented Bitcoin's block size limit, thereby facilitating the inclusion of more transactions within each block. Moreover, this upgrade ushered in two innovative script types for Bitcoin transactions and presented a new encoding approach known as Bech32.

The path to SegWit's activation wasn't devoid of challenges, as it engendered considerable debate within the Bitcoin community. Such disputes underscored the inherent decentralized nature of Bitcoin — an ecosystem reliant on consensus among its global participants. While centralized systems can implement changes through authoritative decrees, Bitcoin demands a collective agreement for any protocol modifications. Despite the contention surrounding SegWit, Bitcoin demonstrated resilience and adaptability, highlighting its capacity to resist undue influence from miners and prominent community figures.

How Does SegWit Work?

Segregated Witness, more commonly known as SegWit, represents a transformative update to the Bitcoin transaction protocol. Its core intention is to enhance transaction efficiency and resolve non-intentional transaction malleability. By partitioning the transaction into two components, with the first encompassing the sender and receiver wallet addresses and the second holding the transaction signatures or witness data, SegWit alleviates block weight. This separation ensures that more transactions fit within a single Bitcoin block, thus fostering increased throughput and diminishing transaction fees.

Unlike a hard fork, which cleaves a blockchain into two distinct chains, SegWit was implemented as a soft fork. This means that there remained a unified Bitcoin blockchain accepting blocks from both SegWit-enabled and non-enabled users. By relocating signature data out of the primary transaction block but retaining its verification capabilities, Bitcoin's integrity is upheld, allowing more transactions within the standard 1 megabyte block. The outcome is a Bitcoin network that's both quicker and more secure.

Complementing SegWit is the Bech32 address standard. These 'native SegWit' addresses, identifiable by their "bc1" prefix, contrast with the traditional Legacy addresses that begin with "1". By adopting SegWit and the Bech32 standard, users stand to benefit from reduced transaction fees. It's essential to note that while Bitcoin stored in Legacy addresses remains there until transacted, any change from these addresses, when part of a transaction, will transition to a SegWit address. Over time, as users engage in transactions and receive funds to SegWit addresses, their Bitcoin balances will organically shift towards these more efficient addresses.

How Does SegWit Solve Transaction Malleability?

Segregated Witness, commonly known as SegWit, is a crucial upgrade in the Bitcoin protocol, primarily designed to address the issue of transaction malleability. This problem refers to the potential modification of transaction data before its confirmation on the blockchain.

Delving into Transaction Malleability

Imagine a scenario where John owes Steven 10 BTC. Steven, with malicious intent, alters John's witness data before the network confirms the transaction. The transaction ID changes, even though the content of the transaction remains unchanged. After the manipulated transaction gets confirmed, the original is canceled. If Steven falsely claims he didn't receive the 10 BTC, John might resend the BTC, becoming a victim of the scam without even realizing it. Such manipulations were invisible to the network, making them hard to prevent.

SegWit's Solution to the Problem

SegWit’s primary function is to segregate witness data from transaction data, ensuring that it can't be altered to change transaction IDs. By developing a sidechain to store this witness data separately from the main blockchain, SegWit removes the possibility of such malicious alterations.

Additionally, SegWit maintains backward compatibility, meaning nodes running on the SegWit protocol can still interact with older nodes. This kind of upgrade is a soft fork, unlike hard forks which aren't backward compatible and can split the blockchain. A unique aspect of SegWit is that while it encrypts all witness data on a sidechain, the root code remains on the main blockchain.

SegWit and Scalability: A Match Made for the Future

Beyond addressing transaction malleability, SegWit brings significant scalability benefits. Scalability is the network's capability to handle a surge in transactions without compromising speed. Although many blockchain networks slow down as they expand, SegWit enhances Bitcoin's efficiency.

The consensus process is the root cause of scalability challenges in many cryptocurrencies. A transaction must be verified by more than half of the Bitcoin nodes before being added to the blockchain. With an increasing number of nodes, reaching consensus takes longer. However, SegWit alleviates this concern. Previously, witness data consumed about 65% of a Bitcoin block's space. SegWit's approach of offloading witness data from the primary blockchain provides more room for transactions, optimizing the network's processing ability without enlarging Bitcoin's blockchain. In essence, SegWit streamlines the blockchain, making it more efficient.

Are there downsides to SegWit?

SegWit, or Segregated Witness, is closely tied to Bitcoin's evolution and sparks various perspectives on its efficacy and intent.

At its core, SegWit's design aims to optimize block capacity by selectively storing certain transaction data off the main blockchain, using the primary chain as a reference. This approach was developed to alleviate scalability issues inherent to the original Bitcoin design. Critics argue that offloading data compromises the integrity of the blockchain, suggesting that it's a workaround for an inherently flawed system.

This skepticism around SegWit led a faction of the community to diverge, initiating a hard fork that resulted in the creation of Bitcoin Cash in 2017. In essence, Bitcoin Cash mirrors the original Bitcoin model before the SegWit implementation. Its solution to scalability issues focuses on enlarging the block size, ensuring all transactional data remains on-chain. This approach starkly contrasts with the philosophy of the Bitcoin Core developers who view SegWit as a foundation for a multi-layered blockchain system.

Bitcoin's evolution and the rise of Bitcoin Cash exemplify the diverse perspectives on how to best scale and maintain decentralized blockchain networks. Various other cryptocurrencies and protocols have emerged, each bringing new solutions and innovations. While SegWit remains a significant milestone for Bitcoin's developer community, it also represents the broader, ever-evolving landscape of blockchain technology and its diverse approaches to solving inherent challenges.

SegWit Enables the Lightning Network

One of the most groundbreaking advancements made possible by SegWit was the integration of the Lightning Network, a second-layer solution designed to address Bitcoin's scalability challenges. The Lightning Network promises faster transaction speeds and reduced fees by creating off-chain payment channels between parties. This innovative approach allows for numerous transactions to be processed outside the main Bitcoin blockchain, with only the final account balances being recorded on-chain. The result is a more efficient and streamlined system, capable of handling a larger volume of transactions at a fraction of the time.

However, the full potential of the Lightning Network couldn’t be realized without the activation of SegWit. This is primarily because the Lightning Network's foundation relied heavily on unconfirmed bitcoin transactions. In the initial state of the Bitcoin network, these transactions were vulnerable to a type of attack called 'transaction malleability.' Essentially, attackers could alter the unique identification of a transaction before it got confirmed, creating discrepancies and potential double-spending scenarios.

By activating SegWit, the Bitcoin community addressed this transaction malleability issue. In doing so, it not only fortified the network's defenses but also paved the way for the safe deployment of the Lightning Network. Without the risk of transaction malleability, the Lightning Network can operate smoothly, ensuring that users can transact with more speed, security, and cost-effectiveness.

SegWit’s Block Size Increase

SegWit, although categorized as a soft fork, brought significant changes to one of Bitcoin's core consensus rules. This change was implemented in a manner that maintained backward compatibility and was aimed at increasing the capacity of transactions within each block.

Before the advent of SegWit, every block had a restriction of holding up to 1MB of data, translating to approximately 1650 transactions when the block was filled to its maximum capacity. However, SegWit ushered in the concept of block weight, which supplanted the block size as the primary constraint on block contents. In the present day, a fully loaded block houses close to 2700 transactions.

It's worth noting this distinction: Prior to SegWit's introduction, each block was constrained by a size of 1MB, which represents 1 million bytes of transaction data.

In contrast, block weight uses a more nuanced measurement system, relying on weight units. In this system, a byte of a transaction's non-Witness data is equivalent to 4 weight units, while a byte of Witness data is equivalent to just 1 weight unit. With a cap set at 4 million weight units for a block, a block filled solely with non-SegWit transactions would still observe the former 1 million byte restriction.

This innovative method of measurement ensures that the increment in block size remains consistent with the principles of a soft fork. Additionally, it presents both Bitcoin miners and users with financial motivations to adopt SegWit. Users transacting with SegWit can benefit from reduced transaction fees since the Witness data occupies a smaller portion of the block weight limit. Concurrently, miners processing SegWit transactions have the opportunity to include more transactions in their blocks, leading to an increase in fee revenue.

SegWit’s New Script Types

In the world of Bitcoin, script types represent distinct methods for transacting Bitcoin on the blockchain via its proprietary scripting language named "Script." With the advent of SegWit, two fresh script types were ushered in to harness the capabilities of the Witness field: namely, Pay-to-Witness-Pubkey-Hash (P2WPKH) and Pay-to-Witness-Script-Hash (P2WSH).

Essential Insight: Those script types, including P2PKH and P2SH, that existed prior to the SegWit era, are termed as "Legacy script types."

Pay-to-Witness-PubKey-Hash (P2WPKH)

Before SegWit's incorporation, the most predominantly utilized script was the Pay-to-Pubkey-Hash (P2PKH), a mechanism that effectively anchored bitcoin to a public key's hash. P2WPKH, an innovation of SegWit, mirrors the functionalities of P2PKH with a subtle variance. In the scenario of spending a P2WPKH output, the essential components — the signature and public key — are safely ensconced in the Witness. Meanwhile, the ScriptSig remains untouched. This strategic move aims to avert potential malleability in the transaction ID.

Pay-to-Witness-Script-Hash (P2WSH)

Following P2PKH, Pay-to-Script-Hash (P2SH) gained traction as a prominent legacy script type. It empowers users to dispatch bitcoin to a uniquely arbitrary script's hash, dubbed the redeemScript. Anyone equipped with this redeemScript, and meeting its stipulated criteria, can reclaim this bitcoin.

In its early days, P2SH primarily catered to multisig transactions, offering both enhanced space efficiency and discretion compared to its counterparts like bare multisig.

Enter SegWit's Pay-to-Witness-Script-Hash (P2WSH). Its modus operandi resonates closely with P2SH. P2WSH outputs get unlocked when presented with the Witness Script (SegWit's version of the redeemScript) alongside the requisite signatures and public keys. Mirroring the approach in P2WPKH, P2WSH inputs necessitate a vacant ScriptSig field, relegating the Script Witness — encompassing the vital signatures and public keys — to the witness territory.

Wrapped SegWit

Introducing novel script types to Bitcoin's protocol is no small feat, considering the plethora of wallets, apps, and services that interact with it. To smoothen the transition, facilitating a gradual adoption of SegWit, an intermediary termed "wrapped SegWit" was conceptualized.

In essence, wrapped SegWit functions as a traditional P2SH script variant. It seamlessly integrates a native SegWit script, be it P2WPKH or P2WSH, and casts it in the role of a P2SH script's redeemScript. Consequently, the resultant wrapped SegWit scripts get classified as either P2SH-P2WPKH or P2SH-P2WSH.

Such an arrangement ensures even those systems not updated for SegWit can transfer bitcoin to SegWit addresses. Beneficiaries of these wrapped SegWit transactions are empowered to utilize the bitcoin through a SegWit input, which can be a potential avenue for fee savings.

Please note that Plisio also offers you:

Create Crypto Invoices in 2 Clicks and Accept Crypto Donations

12 integrations

6 libraries for the most popular programming languages

19 cryptocurrencies and 12 blockchains

Ready to Get Started?

Create an account and start accepting payments – no contracts or KYC required. Or, contact us to design a custom package for your business.

Make first step

Always know what you pay

Integrated per-transaction pricing with no hidden fees

Start your integration

Set up Plisio swiftly in just 10 minutes.