diff --git a/src/script/interpreter.cpp b/src/script/interpreter.cpp --- a/src/script/interpreter.cpp +++ b/src/script/interpreter.cpp @@ -1058,21 +1058,15 @@ } } - // Clean up stack of actual arguments - int i = idxDummy; - int ikey2 = idxSigCount; - while (i-- > 1) { - // If the operation failed, we require that all - // signatures must be empty vector - if (!fSuccess && (flags & SCRIPT_VERIFY_NULLFAIL) && - !ikey2 && stacktop(-1).size()) { - return set_error(serror, - SCRIPT_ERR_SIG_NULLFAIL); - } - if (ikey2 > 0) { - ikey2--; + // If the operation failed, we require that all + // signatures must be empty vector + if (!fSuccess && (flags & SCRIPT_VERIFY_NULLFAIL)) { + for (int i = 0; i < nSigsCount; i++) { + if (stacktop(-idxTopSig - i).size()) { + return set_error(serror, + SCRIPT_ERR_SIG_NULLFAIL); + } } - popstack(stack); } // A bug causes CHECKMULTISIG to consume one extra @@ -1082,10 +1076,14 @@ // mutability, so optionally verify it is exactly equal // to zero prior to removing it from the stack. if ((flags & SCRIPT_VERIFY_NULLDUMMY) && - stacktop(-1).size()) { + stacktop(-idxDummy).size()) { return set_error(serror, SCRIPT_ERR_SIG_NULLDUMMY); } - popstack(stack); + + // Clean up stack of arguments + for (int i = 0; i < idxDummy; i++) { + popstack(stack); + } stack.push_back(fSuccess ? vchTrue : vchFalse); if (opcode == OP_CHECKMULTISIGVERIFY) {