OP_CHECKMULTISIG

The older multisignature check, awkward to use and replaced in Tapscript.

Basically

OP_CHECKMULTISIG checks that enough approved people have signed a Bitcoin payment. Tapscript uses OP_CHECKSIGADD instead.

Key Takeaways

  • OP_CHECKMULTISIG is the original Bitcoin Script opcode for m-of-n multisignature verification. It checks that at least m out of n provided public keys have valid corresponding signatures.
  • The opcode has a well-known off-by-one bug that consumes an extra stack element beyond what the algorithm uses. BIP 147 later required this dummy element to be OP_0 to close a malleability vector.
  • Tapscript (BIP 342) disables OP_CHECKMULTISIG entirely and replaces it with OP_CHECKSIGADD for scripted multisig. MuSig2 key aggregation also enables n-of-n schemes that look like single-signature spends on chain.

What Is OP_CHECKMULTISIG?

OP_CHECKMULTISIG is a Bitcoin Script opcode that verifies multiple digital signatures against multiple public keys in a single operation. Given m required signatures and n total public keys, it confirms that at least m of the n keys have produced valid signatures over the transaction. The opcode is the foundation of all on-chain multisignature wallets in legacy and SegWit v0 scripts.

OP_CHECKMULTISIG appeared in Bitcoin's earliest versions and enabled spending policies like "2-of-3", where any two out of three keyholders can spend, or "3-of-5", where three out of five are required. These policies power shared custody arrangements, corporate treasury controls and escrow services. BIP 11 formalised the m-of-n transaction type as a standard output, and BIP 16 (P2SH) later made multisig practical by hashing the full script into a compact address.

OP_CHECKMULTISIG carries a legacy bug, imposes sigops overhead and requires all signatures and keys to appear on chain despite its utility. Modern alternatives in Taproot address each of these shortcomings.

How It Works

OP_CHECKMULTISIG operates on values placed on the script stack. A standard multisig scriptPubKey contains the required public keys and signature threshold.

The scriptSig or witness provides the corresponding signatures to spend the output. These signatures match the public keys in the script.

The leading OP_0 is the dummy element required by the off-by-one bug explained below. The script interpreter pops values from the stack in the required order when it reaches OP_CHECKMULTISIG.

The total number of elements consumed is m + n + 3. After verification, the opcode pushes true (1) on success or false (0) on failure.

The Verification Algorithm

The algorithm uses two pointers that iterate linearly through the signatures and keys. Signatures must appear in the same order as their corresponding public keys in the script.

The ordering requirement means that for a 2-of-3 with keys A, B, C, a witness containing signatures from C then A would be invalid. They must appear in A-then-C order. BIP 67 addresses this by specifying deterministic lexicographic key ordering so that all implementations produce consistent multisig scripts.

The Off-by-One Bug

Satoshi's original implementation of OP_CHECKMULTISIG pops one more element from the stack than the algorithm actually needs. This extra element is consumed and discarded without any validation. The bug has persisted since Bitcoin's launch because fixing it would change consensus rules and require a hard fork.

Every OP_CHECKMULTISIG input must therefore push a dummy value, typically OP_0, before the signatures. Any value was accepted at first, so a third party could replace the dummy with a different value and change the transaction's ID without invalidating the signatures. BIP 147 (NULLDUMMY), activated alongside SegWit in 2017, requires the dummy element to be an empty byte array and makes any other value fail the script immediately.

Sigops Counting

Bitcoin limits the number of signature operations (sigops) per block to prevent denial of service. OP_CHECKMULTISIG counts as 20 sigops when it appears in a raw scriptPubKey, regardless of the actual m or n values, so a simple 2-of-3 multisig consumes the same sigops budget as a hypothetical 20-of-20. P2SH scripts use the actual n value instead, but the overhead remains significant compared to single-signature alternatives.

OP_CHECKMULTISIGVERIFY

OP_CHECKMULTISIGVERIFY is a companion opcode that behaves identically to OP_CHECKMULTISIG followed by OP_VERIFY. Instead of pushing true or false onto the stack, it fails the script immediately on invalid signatures and leaves nothing on the stack on success. This variant is used when multisig verification is one step in a larger script and the result does not need to remain on the stack.

Use Cases

OP_CHECKMULTISIG has been the backbone of on-chain multisignature wallets since Bitcoin's early years. Common configurations include shared custody arrangements, corporate treasury controls and escrow services.

These patterns are typically wrapped in P2SH (BIP 16) or P2WSH (SegWit) for practical use, keeping the full multisig script out of the output until spending time. The multisig wallets guide provides a deeper comparison of multisig wallet implementations.

Why Tapscript Replaced It

Taproot activated in November 2021 and introduced Tapscript, defined in BIP 342, as the new script validation rules for SegWit v1 outputs. Tapscript disables OP_CHECKMULTISIG and OP_CHECKMULTISIGVERIFY entirely, so executing either opcode in a Tapscript causes immediate script failure, similar to OP_RETURN.

OP_CHECKSIGADD (opcode 0xba) is the replacement and takes a fundamentally different approach to multisig verification. Instead of processing all signatures in a single opcode, OP_CHECKSIGADD checks one signature at a time and accumulates a counter.

Each OP_CHECKSIGADD pops three values from the stack: a public key, a running counter n and a signature. If the signature is a valid Schnorr signature for that key, it pushes n + 1. If the signature is an empty byte array, indicating this key is not signing, it pushes n unchanged, and the final OP_NUMEQUAL checks that exactly m valid signatures were provided.

OP_CHECKSIGADD offers several advantages over OP_CHECKMULTISIG. These advantages come from checking signatures individually and accumulating a counter rather than processing every signature in one opcode.

The Taproot and Schnorr signatures explainer covers how Taproot and Schnorr change Bitcoin's signature model. Read it for a comprehensive look at both technologies.

MuSig2 and the End of On-Chain n-of-n

MuSig2 eliminates the need for any on-chain multisig opcode altogether for the common case of n-of-n multisig, where all keyholders must sign. MuSig2 is a Schnorr-based key aggregation protocol defined in BIP 327 that combines multiple public keys into a single aggregate key. The resulting signature is indistinguishable from a standard single-key Schnorr signature on chain.

A 3-of-3 OP_CHECKMULTISIG transaction exposes three public keys and three signatures in the witness data, while a MuSig2 spend reveals only one public key and one signature. MuSig2 therefore reveals less witness data and fewer public keys and signatures.

MuSig2 requires a two-round signing protocol among all participants and is strictly n-of-n. Threshold signature protocols like FROST provide similar on-chain efficiency for threshold schemes where m-of-n has m < n. Layer 2 protocols like Spark leverage these cryptographic advances to enable efficient multi-party signing without the overhead of legacy multisig opcodes.

Legacy Script Limitations

OP_CHECKMULTISIG remains valid in legacy and SegWit v0 scripts, but new wallet implementations should prefer Taproot alternatives. Legacy multisig transactions are larger, more expensive and reveal the full spending policy on chain. A 2-of-3 P2WSH multisig spend requires roughly 260 bytes of witness data, compared to 65 bytes for a Taproot key-path spend using MuSig2.

Key Ordering Requirement

Signatures in OP_CHECKMULTISIG must match the order of their corresponding public keys in the script, and providing valid signatures in the wrong order causes the transaction to be rejected. BIP 67 specifies deterministic lexicographic ordering of keys to produce reproducible scripts, but implementations must still ensure the signing order matches. This requirement is a frequent source of bugs in multisig wallet software.

Address Reuse and Privacy

Spending a multisig UTXO reveals the full script on chain, including all public keys and the m-of-n policy. This exposure shows how many parties control the wallet and the quorum requirement, while Taproot key-path spends reveal nothing about the underlying spending policy. Migrating to Taproot-based multisig is strongly recommended for privacy-sensitive applications.

Sigops Budget Impact

OP_CHECKMULTISIG in raw scriptPubKey outputs always counts as 20 sigops against the block limit, regardless of how many keys are actually involved. This conservative accounting reduces the number of multisig transactions that can fit in a block. Tapscript's OP_CHECKSIGADD counts each key check individually, making more efficient use of the sigops budget.

The glossary entry is for informational purposes only and does not constitute financial or investment advice. Always do your own research before using any protocol or technology.

0

← All 1876 glossary terms