diff options
author | Johnson Lau <jl2012@users.noreply.github.com> | 2016-09-22 15:06:54 +0800 |
---|---|---|
committer | Wladimir J. van der Laan <laanwj@gmail.com> | 2016-10-13 20:01:46 +0200 |
commit | 3e80ab7f2a338d1bb3d9321c13a18f1324130617 (patch) | |
tree | 25cb8185aae70ad6738aff11c573ab4353acea1f /src/script/interpreter.cpp | |
parent | 0027672c8075d063f376c8c84e1cce77d572d353 (diff) | |
download | bitcoin-3e80ab7f2a338d1bb3d9321c13a18f1324130617.tar.xz |
Add policy: null signature for failed CHECK(MULTI)SIG
Github-Pull: #8634
Rebased-From: e41bd449ab2b8d01260795383af2c40b659d8587
Diffstat (limited to 'src/script/interpreter.cpp')
-rw-r--r-- | src/script/interpreter.cpp | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/src/script/interpreter.cpp b/src/script/interpreter.cpp index fd356fed0a..41756ea711 100644 --- a/src/script/interpreter.cpp +++ b/src/script/interpreter.cpp @@ -885,6 +885,9 @@ bool EvalScript(vector<vector<unsigned char> >& stack, const CScript& script, un } bool fSuccess = checker.CheckSig(vchSig, vchPubKey, scriptCode, sigversion); + if (!fSuccess && (flags & SCRIPT_VERIFY_NULLFAIL) && vchSig.size()) + return set_error(serror, SCRIPT_ERR_SIG_NULLFAIL); + popstack(stack); popstack(stack); stack.push_back(fSuccess ? vchTrue : vchFalse); @@ -914,6 +917,9 @@ bool EvalScript(vector<vector<unsigned char> >& stack, const CScript& script, un if (nOpCount > MAX_OPS_PER_SCRIPT) return set_error(serror, SCRIPT_ERR_OP_COUNT); int ikey = ++i; + // ikey2 is the position of last non-signature item in the stack. Top stack item = 1. + // With SCRIPT_VERIFY_NULLFAIL, this is used for cleanup if operation fails. + int ikey2 = nKeysCount + 2; i += nKeysCount; if ((int)stack.size() < i) return set_error(serror, SCRIPT_ERR_INVALID_STACK_OPERATION); @@ -970,8 +976,14 @@ bool EvalScript(vector<vector<unsigned char> >& stack, const CScript& script, un } // Clean up stack of actual arguments - while (i-- > 1) + 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--; popstack(stack); + } // A bug causes CHECKMULTISIG to consume one extra argument // whose contents were not checked in any way. |