- Регистрация
- 9 Май 2015
- Сообщения
- 1,483
- Баллы
- 155


- 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.

- Keys: One private key → one public key.
- Addresses:
- Legacy (P2PKH): starts with 1...
- SegWit (P2WPKH): starts with bc1q...
- 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].

- Keys: N people, each with their own private key.
- Addresses:
- Legacy P2SH: starts with 3...
- SegWit P2WSH: starts with bc1q...
- 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

// 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.

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? | ![]() | ![]() | No (SegWit) |

- 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.

- Single-sig SegWit: Everyday wallet, low fees.
- Multisig SegWit: Treasury, cold storage, shared accounts — but with cost savings and malleability protection.

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.
Источник: