Module 08
Multisig
OP_CHECKMULTISIG validates M-of-N signatures: M keys must sign, out of a set of N. It's the foundation of shared custody, exchange cold storage, and the Lightning Network's funding transactions.
What you'll learn
- →Read and write M-of-N OP_CHECKMULTISIG scripts
- →Explain the historical off-by-one bug and why OP_0 is required
- →Understand signature/pubkey ordering constraints
- →Describe real-world multisig use cases: exchange cold storage, shared custody, Lightning
01
OP_CHECKMULTISIG
OP_CHECKMULTISIG reads its parameters from the stack in a specific order, from top to bottom:
NNumber of public keys<pubkey_N> … <pubkey_1>N public keysMNumber of required signatures<sig_M> … <sig_1>M signaturesOP_0Dummy element (historical bug)1-of-1 multisigThe simplest multisig: 1 sig required out of 1 key. Functionally equivalent to OP_CHECKSIG but more expensive.
↑ top of stack
nothing here yet
press Step or Run to push an item
02
The dummy bug
There's a bug in the original Bitcoin implementation of OP_CHECKMULTISIG: it pops one extra element from the stack after reading all the signatures. This was never fixed — changing it would break consensus.
To work around it, every multisig script must begin with a dummy value. By convention this is OP_0. BIP 147 later mandated that this dummy must specifically be an empty array, closing a malleability vector.
Without the dummy — broken
↑ top of stack
nothing here yet
press Step or Run to push an item
With OP_0 dummy — correct
↑ top of stack
nothing here yet
press Step or Run to push an item
Multisig on mainnet
03
2-of-3 multisig
The most common real-world multisig is 2-of-3: three parties hold keys, any two can authorise a spend. This is used by exchanges for cold storage and by users who want a backup key.
In this simulator we only have one valid key pair, so we'll demonstrate with 2-of-2: two separate entries of the same test-vector signature. In production each signature would come from a different private key.
↑ top of stack
nothing here yet
press Step or Run to push an item
04
Your turn
1-of-1 multisig from scratch
OP_CHECKMULTISIG script from scratch: OP_0, then the test-vector signature, then OP_1, then the pubkey, then OP_1, then OP_CHECKMULTISIG. Leave 1 (true) on the stack.Ctrl+Enter to check