๐ TL;DR
- Normal: 1 input โ 1 signature.
- Multisig: 1 input โ M signatures (from N possible cosigners).
- SegWit moves signatures out of the txid calculation โ cheaper & no txid malleability.
- We collect partial signatures, sort them, and build the final script or witness per input.
1๏ธโฃ Normal Transactions (Single-Sig)
- Keys: One private key โ one public key.
-
Addresses:
- Legacy (P2PKH): starts with
1...
- SegWit (P2WPKH): starts with
bc1q...
- Legacy (P2PKH): starts with
-
Signing:
- Create a sighash for each input.
- Sign it once.
- Attach the signature and public key.
- Example (Legacy):
[Signature, PubKey]
-
Example (SegWit):
- scriptSig empty, witness carries
[Signature, PubKey]
.
- scriptSig empty, witness carries
2๏ธโฃ Multisig Transactions (M-of-N)
- Keys: N people, each with their own private key.
-
Addresses:
- Legacy P2SH: starts with
3...
- SegWit P2WSH: starts with
bc1q...
- Legacy P2SH: starts with
- Rule: Any M of these N signatures can spend the coins.
-
Signing:
- Each cosigner signs separately.
- Collect M valid signatures for each input.
- Build the final unlocking data:
- Legacy P2SH:
OP_0 + Sig1 + Sig2 + ... + RedeemScript
- SegWit P2WSH: Witness stack:
OP_0 (empty) + Sig1 + Sig2 + ... + WitnessScript
๐ป Example: Our Walletโs Finalization (P2SH & P2WSH)
// Group signatures by input index
for sig in partial_sigs {
signatures[input_index].push(sig);
}
// Sort by pubkey (BIP67)
sorted_sigs.sort_by(pubkey_order);
// Build final unlocking data
if is_p2sh {
// Legacy P2SH scriptSig
OP_0 + all_sigs + redeem_script
} else {
// SegWit P2WSH witness stack
[OP_0] + all_sigs + witness_script
}
SegWit version is cheaper in fees and immune to txid malleability.
โ Side-by-Side: Normal vs Multisig (With SegWit)
Feature | Normal | Multisig (Legacy) | Multisig (SegWit) |
---|---|---|---|
Keys | 1 keypair | N keypairs | N keypairs |
Signatures/input | 1 | M | M |
Unlocking data | [sig, pubkey] | OP_0 + sigs + redeem script | Witness stack: OP_0 + sigs + witness script |
Fee efficiency | Medium | High cost | Lower cost |
Txid malleable? | Yes (legacy) | Yes (legacy) | No (SegWit) |
๐ Why SegWit Multisig Rocks
- Lower fees: Witness data gets a weight discount.
- No txid malleability: Safer for complex protocols like Lightning.
- Future-ready: Works with Taproot for even more privacy.
- Same multisig benefits: More security, shared control, auditability.
๐ When to Use
- Single-sig SegWit: Everyday wallet, low fees.
- Multisig SegWit: Treasury, cold storage, shared accounts โ but with cost savings and malleability protection.
๐ก Key takeaway:
SegWit doesnโt change the rules of multisig โ it just makes them cheaper, faster, and safer.
If youโre setting up a new multisig today, use SegWit (P2WSH) unless you need legacy compatibility.
Top comments (0)