BEGINNER_DOC_015 // BEGINNERS / SEGWIT
SEGWIT
witness-segwit-bip-141/">Segregated Witness (SegWit) is a 2017 protocol upgrade that moved signature data out
of the transaction body into a separate witness field. This fixed transaction
malleability, enabled the Lightning Network, increased effective block capacity, and introduced
lower fees through a witness discount. It was activated via fork/">soft fork at block 481,824.
THE_PROBLEM — TRANSACTION_MALLEABILITY
BEFORE SEGWIT — THE MALLEABILITY BUG
Legacy transaction:
TxID = HASH(version + inputs + outputs + locktime)
↑ ScriptSig is INSIDE the hash
Problem: A third party could alter the ScriptSig (valid but different encoding)
→ different TxID, but same transaction
→ breaks any protocol relying on unconfirmed TxIDs
→ Lightning Network impossible to build safely
FIXED BY SEGWIT
AFTER SEGWIT — WITNESS SEPARATED
SegWit transaction:
TxID = HASH(version + inputs + outputs + locktime)
↑ witness data is NOT included — TxID is immutable
WTXID = HASH(full tx including witness)
Signatures live in the Witness field, outside TxID calculation.
TxID is now stable before confirmation. Lightning is possible.
SEGWIT_VERSIONS
The original SegWit upgrade. Addresses start with bc1q. Uses ECDSA signatures. Two output types: P2WPKH (single key) and P2WSH (script-hash/">script hash).
P2WPKH: OP_0 <20-byte-pubkey-hash> → bc1q... address
P2WSH: OP_0 <32-byte-script-hash> → bc1q... address (longer)
Witness discount: witness bytes count as 1/4 weight unit
Legacy input: ~148 bytes × 4 = 592 weight units
SegWit input: ~41 bytes × 4 + ~107 bytes × 1 = 271 weight units
Taproot uses schnorr-signatures/">Schnorr signatures instead of ECDSA, and introduces MAST for script privacy. Addresses start with bc1p. More efficient and private than v0.
P2TR: OP_1 <32-byte-tweaked-pubkey> → bc1p... address
Key-path spend: single Schnorr signature (most private)
Script-path spend: reveals only the executed branch of a script tree
Schnorr signatures: 64 bytes (vs 71–73 for ECDSA)
Batch verification: faster for validators to verify many signatures
BLOCK_WEIGHT_AND_VIRTUAL_BYTES
Weight Units & vBytes
FEE CALCULATION
SegWit replaced the block size limit with a block weight limit. Non-witness data costs 4 weight units per byte; witness data costs 1 weight unit per byte.
Block limit: 4,000,000 weight units
1 vbyte: 4 weight units
Non-witness bytes: 1 byte = 4 weight units
Witness bytes: 1 byte = 1 weight unit
virtual size (vsize) = ceil(weight / 4)
Fee = vsize × sat/vbyte
A typical P2WPKH tx (1-in 2-out):
Weight: ~561 wu → vsize: ~141 vbytes
TERMINOLOGY_INDEX
SegWit
Segregated Witness. The 2017 soft fork that moved signature data to a separate witness field.
Witness
The separate section of a SegWit transaction containing signatures and public keys.
Malleability
A pre-SegWit bug allowing third parties to alter a transaction's ID without invalidating it.
Weight Units
The post-SegWit measure of transaction size. Non-witness = 4 WU/byte, witness = 1 WU/byte.
vByte
Virtual byte. 1 vbyte = 4 weight units. Used to calculate fees (sat/vbyte).
Soft Fork
A backward-compatible protocol upgrade. Old nodes still see SegWit transactions as valid (anyone-can-spend outputs).