4

I would like to learn the difference, explained as simple as possible, between OP_CHECKMULTISIG / OP_CHECKMULTISIGVERIFY and OP_CHECKSIG / OP_CHECKSIGVERIFY. The only explanation I found is: Same as OP_CHECKMULTISIG (or same as OP_CHECKSIG) except OP_VERIFY is executed afterward.

For OP_VERIFY: Mark a transaction as invalid if top stack value is not true.

Can this be better explained? How does OP_CHECKMULTISIGVERIFY and OP_CHECKMULTISIG differ in practice and in logic of creating scripts? What are the effects (pros and cons) of OP_VERIFY being executed afterward or before? Examples would be highly appreciated.

1 Answer 1

3

OP_CHECKMULTISIG, OP_CHECKSIG, OP_EQUAL all put true or false on the stack. This means you could use them with an OP_IF or similar, it doesn't have to immediately end execution if its false. OP_VERIFY will, as you quoted, mark the transaction as invalid of the top stack element isn't true, but you may not want to, you may want to perform some additional logic before that.

6
  • This means that every script that has advanced logics and multiple OP_IF and OP_ENDIF has to end with an OP_VERIFY in case between if and endifs we only have OP_CHECKSIG and OP_CHECKMULTISIG?
    – skydanc3r
    Commented Jul 27, 2017 at 11:43
  • This means the following script is invalid: IF 2 <Alice key> <Bob key> 2 CHECKMULTISIGVERIFY ELSE <Bob key> CHECKSIGVERIFY SHA256 <hash_of_secret> EQUALVERIFY ENDIF
    – skydanc3r
    Commented Jul 27, 2017 at 11:47
  • You used VERIFY in that script, did you mean to? You don't need to end with OP_VERIFY, the script will still be valid at the end if a non-zero (true) value is on the stack. The VERIFY versions are mostly used to mark it as invalid early on rather than evaluating the whole script, like you might use "return false;" in Java or C++ Commented Jul 27, 2017 at 12:37
  • Thanks. In my example the second condition after else (providing the secret) will not even be checked in case first condition is not met, because checkmultisigverify will end the script immediately. Got it right?
    – skydanc3r
    Commented Jul 27, 2017 at 13:05
  • Yep, correct :) Commented Jul 27, 2017 at 19:21

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.