0

How does the CHECKSIGADD opcode (defined in the Tapscript BIP) BIP342 work? How does it compare to its predecessor CHECKMULTISIG?

The design of CHECKSIGADD was discussed in this StackExchange question.

1 Answer 1

2

James Chiang explained how the CHECKSIGADD opcode works in this Bitcoin Optech workshop. (The code for CHECKSIGADD in the Bitcoin Core codebase is here.)

As you can see on the left we have an output script that uses CHECKSIGADD and CHECKSIG opcodes to express a n-of-n multisig output.

pk0
checksig
pk1
checksigadd
pk2
checksigadd
3
equal

This is our initial stack which is populated with 3 signatures:

sig0
sig1
sig2

In the first step we will push this public key (pk0) onto the stack and evaluate that against sig0 with the opcode CHECKSIG. Let’s assume this evaluates to TRUE. Since it evaluates to TRUE we will now have a 1 byte on the top of the stack:

1
sig1
sig2

We will use a counter.

2
sig2

As we evaluate the signatures against other public keys, if that script evaluates successfully we will then have a counter of 3 on the stack and that counter can then be compared to the one encoded in the output script. If they are equal we have successfully spent a 3-of-3 multisig output which uses CHECKSIGADD to encode that multisig.

3

How does it compare to its predecessor CHECKMULTISIG?

CHECKMULTISIG doesn't (it is still used for SegWit v0 spends) use an increasing counter. The equivalent locking script using CHECKMULTISIG would be:

3
pk0
pk1
pk2
3
checkmultisig

CHECKMULTISIG also contains a longstanding bug which means the unlocking script requires a 0 at the bottom to satisfy the locking script.

sig0
sig1
sig2
0

The operation of CHECKMULTISIG is explained in this StackExchange question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.