1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Distributed under the MIT/X11 software license, see the accompanying
3 // file license.txt or http://www.opensource.org/licenses/mit-license.php.
9 bool CheckSig(vector<unsigned char> vchSig, vector<unsigned char> vchPubKey, CScript scriptCode, const CTransaction& txTo, unsigned int nIn, int nHashType);
13 typedef vector<unsigned char> valtype;
14 static const valtype vchFalse(0);
15 static const valtype vchZero(0);
16 static const valtype vchTrue(1, 1);
17 static const CBigNum bnZero(0);
18 static const CBigNum bnOne(1);
19 static const CBigNum bnFalse(0);
20 static const CBigNum bnTrue(1);
21 static const size_t nMaxNumSize = 4;
24 CBigNum CastToBigNum(const valtype& vch)
26 if (vch.size() > nMaxNumSize)
27 throw runtime_error("CastToBigNum() : overflow");
28 // Get rid of extra leading zeros
29 return CBigNum(CBigNum(vch).getvch());
32 bool CastToBool(const valtype& vch)
34 for (int i = 0; i < vch.size(); i++)
38 // Can be negative zero
39 if (i == vch.size()-1 && vch[i] == 0x80)
47 void MakeSameSize(valtype& vch1, valtype& vch2)
49 // Lengthen the shorter one
50 if (vch1.size() < vch2.size())
51 vch1.resize(vch2.size(), 0);
52 if (vch2.size() < vch1.size())
53 vch2.resize(vch1.size(), 0);
59 // Script is a stack machine (like Forth) that evaluates a predicate
60 // returning a bool indicating valid or not. There are no loops.
62 #define stacktop(i) (stack.at(stack.size()+(i)))
63 #define altstacktop(i) (altstack.at(altstack.size()+(i)))
64 static inline void popstack(vector<valtype>& stack)
67 throw runtime_error("popstack() : stack empty");
72 bool EvalScript(vector<vector<unsigned char> >& stack, const CScript& script, const CTransaction& txTo, unsigned int nIn, int nHashType)
75 CScript::const_iterator pc = script.begin();
76 CScript::const_iterator pend = script.end();
77 CScript::const_iterator pbegincodehash = script.begin();
81 vector<valtype> altstack;
82 if (script.size() > 10000)
91 bool fExec = !count(vfExec.begin(), vfExec.end(), false);
96 if (!script.GetOp(pc, opcode, vchPushValue))
98 if (vchPushValue.size() > 520)
100 if (opcode > OP_16 && ++nOpCount > 201)
103 if (opcode == OP_CAT ||
104 opcode == OP_SUBSTR ||
106 opcode == OP_RIGHT ||
107 opcode == OP_INVERT ||
116 opcode == OP_LSHIFT ||
120 if (fExec && 0 <= opcode && opcode <= OP_PUSHDATA4)
121 stack.push_back(vchPushValue);
122 else if (fExec || (OP_IF <= opcode && opcode <= OP_ENDIF))
147 CBigNum bn((int)opcode - (int)(OP_1 - 1));
148 stack.push_back(bn.getvch());
157 case OP_NOP1: case OP_NOP2: case OP_NOP3: case OP_NOP4: case OP_NOP5:
158 case OP_NOP6: case OP_NOP7: case OP_NOP8: case OP_NOP9: case OP_NOP10:
164 // <expression> if [statements] [else [statements]] endif
168 if (stack.size() < 1)
170 valtype& vch = stacktop(-1);
171 fValue = CastToBool(vch);
172 if (opcode == OP_NOTIF)
176 vfExec.push_back(fValue);
184 vfExec.back() = !vfExec.back();
199 // (false -- false) and return
200 if (stack.size() < 1)
202 bool fValue = CastToBool(stacktop(-1));
222 if (stack.size() < 1)
224 altstack.push_back(stacktop(-1));
229 case OP_FROMALTSTACK:
231 if (altstack.size() < 1)
233 stack.push_back(altstacktop(-1));
241 if (stack.size() < 2)
250 // (x1 x2 -- x1 x2 x1 x2)
251 if (stack.size() < 2)
253 valtype vch1 = stacktop(-2);
254 valtype vch2 = stacktop(-1);
255 stack.push_back(vch1);
256 stack.push_back(vch2);
262 // (x1 x2 x3 -- x1 x2 x3 x1 x2 x3)
263 if (stack.size() < 3)
265 valtype vch1 = stacktop(-3);
266 valtype vch2 = stacktop(-2);
267 valtype vch3 = stacktop(-1);
268 stack.push_back(vch1);
269 stack.push_back(vch2);
270 stack.push_back(vch3);
276 // (x1 x2 x3 x4 -- x1 x2 x3 x4 x1 x2)
277 if (stack.size() < 4)
279 valtype vch1 = stacktop(-4);
280 valtype vch2 = stacktop(-3);
281 stack.push_back(vch1);
282 stack.push_back(vch2);
288 // (x1 x2 x3 x4 x5 x6 -- x3 x4 x5 x6 x1 x2)
289 if (stack.size() < 6)
291 valtype vch1 = stacktop(-6);
292 valtype vch2 = stacktop(-5);
293 stack.erase(stack.end()-6, stack.end()-4);
294 stack.push_back(vch1);
295 stack.push_back(vch2);
301 // (x1 x2 x3 x4 -- x3 x4 x1 x2)
302 if (stack.size() < 4)
304 swap(stacktop(-4), stacktop(-2));
305 swap(stacktop(-3), stacktop(-1));
312 if (stack.size() < 1)
314 valtype vch = stacktop(-1);
316 stack.push_back(vch);
323 CBigNum bn(stack.size());
324 stack.push_back(bn.getvch());
331 if (stack.size() < 1)
340 if (stack.size() < 1)
342 valtype vch = stacktop(-1);
343 stack.push_back(vch);
350 if (stack.size() < 2)
352 stack.erase(stack.end() - 2);
358 // (x1 x2 -- x1 x2 x1)
359 if (stack.size() < 2)
361 valtype vch = stacktop(-2);
362 stack.push_back(vch);
369 // (xn ... x2 x1 x0 n - xn ... x2 x1 x0 xn)
370 // (xn ... x2 x1 x0 n - ... x2 x1 x0 xn)
371 if (stack.size() < 2)
373 int n = CastToBigNum(stacktop(-1)).getint();
375 if (n < 0 || n >= stack.size())
377 valtype vch = stacktop(-n-1);
378 if (opcode == OP_ROLL)
379 stack.erase(stack.end()-n-1);
380 stack.push_back(vch);
386 // (x1 x2 x3 -- x2 x3 x1)
387 // x2 x1 x3 after first swap
388 // x2 x3 x1 after second swap
389 if (stack.size() < 3)
391 swap(stacktop(-3), stacktop(-2));
392 swap(stacktop(-2), stacktop(-1));
399 if (stack.size() < 2)
401 swap(stacktop(-2), stacktop(-1));
407 // (x1 x2 -- x2 x1 x2)
408 if (stack.size() < 2)
410 valtype vch = stacktop(-1);
411 stack.insert(stack.end()-2, vch);
422 if (stack.size() < 2)
424 valtype& vch1 = stacktop(-2);
425 valtype& vch2 = stacktop(-1);
426 vch1.insert(vch1.end(), vch2.begin(), vch2.end());
428 if (stacktop(-1).size() > 520)
435 // (in begin size -- out)
436 if (stack.size() < 3)
438 valtype& vch = stacktop(-3);
439 int nBegin = CastToBigNum(stacktop(-2)).getint();
440 int nEnd = nBegin + CastToBigNum(stacktop(-1)).getint();
441 if (nBegin < 0 || nEnd < nBegin)
443 if (nBegin > vch.size())
445 if (nEnd > vch.size())
447 vch.erase(vch.begin() + nEnd, vch.end());
448 vch.erase(vch.begin(), vch.begin() + nBegin);
458 if (stack.size() < 2)
460 valtype& vch = stacktop(-2);
461 int nSize = CastToBigNum(stacktop(-1)).getint();
464 if (nSize > vch.size())
466 if (opcode == OP_LEFT)
467 vch.erase(vch.begin() + nSize, vch.end());
469 vch.erase(vch.begin(), vch.end() - nSize);
477 if (stack.size() < 1)
479 CBigNum bn(stacktop(-1).size());
480 stack.push_back(bn.getvch());
491 if (stack.size() < 1)
493 valtype& vch = stacktop(-1);
494 for (int i = 0; i < vch.size(); i++)
504 if (stack.size() < 2)
506 valtype& vch1 = stacktop(-2);
507 valtype& vch2 = stacktop(-1);
508 MakeSameSize(vch1, vch2);
509 if (opcode == OP_AND)
511 for (int i = 0; i < vch1.size(); i++)
514 else if (opcode == OP_OR)
516 for (int i = 0; i < vch1.size(); i++)
519 else if (opcode == OP_XOR)
521 for (int i = 0; i < vch1.size(); i++)
530 //case OP_NOTEQUAL: // use OP_NUMNOTEQUAL
533 if (stack.size() < 2)
535 valtype& vch1 = stacktop(-2);
536 valtype& vch2 = stacktop(-1);
537 bool fEqual = (vch1 == vch2);
538 // OP_NOTEQUAL is disabled because it would be too easy to say
539 // something like n != 1 and have some wiseguy pass in 1 with extra
540 // zero bytes after it (numerically, 0x01 == 0x0001 == 0x000001)
541 //if (opcode == OP_NOTEQUAL)
545 stack.push_back(fEqual ? vchTrue : vchFalse);
546 if (opcode == OP_EQUALVERIFY)
570 if (stack.size() < 1)
572 CBigNum bn = CastToBigNum(stacktop(-1));
575 case OP_1ADD: bn += bnOne; break;
576 case OP_1SUB: bn -= bnOne; break;
577 case OP_2MUL: bn <<= 1; break;
578 case OP_2DIV: bn >>= 1; break;
579 case OP_NEGATE: bn = -bn; break;
580 case OP_ABS: if (bn < bnZero) bn = -bn; break;
581 case OP_NOT: bn = (bn == bnZero); break;
582 case OP_0NOTEQUAL: bn = (bn != bnZero); break;
585 stack.push_back(bn.getvch());
599 case OP_NUMEQUALVERIFY:
603 case OP_LESSTHANOREQUAL:
604 case OP_GREATERTHANOREQUAL:
609 if (stack.size() < 2)
611 CBigNum bn1 = CastToBigNum(stacktop(-2));
612 CBigNum bn2 = CastToBigNum(stacktop(-1));
625 if (!BN_mul(&bn, &bn1, &bn2, pctx))
630 if (!BN_div(&bn, NULL, &bn1, &bn2, pctx))
635 if (!BN_mod(&bn, &bn1, &bn2, pctx))
640 if (bn2 < bnZero || bn2 > CBigNum(2048))
642 bn = bn1 << bn2.getulong();
646 if (bn2 < bnZero || bn2 > CBigNum(2048))
648 bn = bn1 >> bn2.getulong();
651 case OP_BOOLAND: bn = (bn1 != bnZero && bn2 != bnZero); break;
652 case OP_BOOLOR: bn = (bn1 != bnZero || bn2 != bnZero); break;
653 case OP_NUMEQUAL: bn = (bn1 == bn2); break;
654 case OP_NUMEQUALVERIFY: bn = (bn1 == bn2); break;
655 case OP_NUMNOTEQUAL: bn = (bn1 != bn2); break;
656 case OP_LESSTHAN: bn = (bn1 < bn2); break;
657 case OP_GREATERTHAN: bn = (bn1 > bn2); break;
658 case OP_LESSTHANOREQUAL: bn = (bn1 <= bn2); break;
659 case OP_GREATERTHANOREQUAL: bn = (bn1 >= bn2); break;
660 case OP_MIN: bn = (bn1 < bn2 ? bn1 : bn2); break;
661 case OP_MAX: bn = (bn1 > bn2 ? bn1 : bn2); break;
665 stack.push_back(bn.getvch());
667 if (opcode == OP_NUMEQUALVERIFY)
669 if (CastToBool(stacktop(-1)))
679 // (x min max -- out)
680 if (stack.size() < 3)
682 CBigNum bn1 = CastToBigNum(stacktop(-3));
683 CBigNum bn2 = CastToBigNum(stacktop(-2));
684 CBigNum bn3 = CastToBigNum(stacktop(-1));
685 bool fValue = (bn2 <= bn1 && bn1 < bn3);
689 stack.push_back(fValue ? vchTrue : vchFalse);
704 if (stack.size() < 1)
706 valtype& vch = stacktop(-1);
707 valtype vchHash((opcode == OP_RIPEMD160 || opcode == OP_SHA1 || opcode == OP_HASH160) ? 20 : 32);
708 if (opcode == OP_RIPEMD160)
709 RIPEMD160(&vch[0], vch.size(), &vchHash[0]);
710 else if (opcode == OP_SHA1)
711 SHA1(&vch[0], vch.size(), &vchHash[0]);
712 else if (opcode == OP_SHA256)
713 SHA256(&vch[0], vch.size(), &vchHash[0]);
714 else if (opcode == OP_HASH160)
716 uint160 hash160 = Hash160(vch);
717 memcpy(&vchHash[0], &hash160, sizeof(hash160));
719 else if (opcode == OP_HASH256)
721 uint256 hash = Hash(vch.begin(), vch.end());
722 memcpy(&vchHash[0], &hash, sizeof(hash));
725 stack.push_back(vchHash);
729 case OP_CODESEPARATOR:
731 // Hash starts after the code separator
737 case OP_CHECKSIGVERIFY:
739 // (sig pubkey -- bool)
740 if (stack.size() < 2)
743 valtype& vchSig = stacktop(-2);
744 valtype& vchPubKey = stacktop(-1);
747 //PrintHex(vchSig.begin(), vchSig.end(), "sig: %s\n");
748 //PrintHex(vchPubKey.begin(), vchPubKey.end(), "pubkey: %s\n");
750 // Subset of script starting at the most recent codeseparator
751 CScript scriptCode(pbegincodehash, pend);
753 // Drop the signature, since there's no way for a signature to sign itself
754 scriptCode.FindAndDelete(CScript(vchSig));
756 bool fSuccess = CheckSig(vchSig, vchPubKey, scriptCode, txTo, nIn, nHashType);
760 stack.push_back(fSuccess ? vchTrue : vchFalse);
761 if (opcode == OP_CHECKSIGVERIFY)
771 case OP_CHECKMULTISIG:
772 case OP_CHECKMULTISIGVERIFY:
774 // ([sig ...] num_of_signatures [pubkey ...] num_of_pubkeys -- bool)
777 if (stack.size() < i)
780 int nKeysCount = CastToBigNum(stacktop(-i)).getint();
781 if (nKeysCount < 0 || nKeysCount > 20)
783 nOpCount += nKeysCount;
788 if (stack.size() < i)
791 int nSigsCount = CastToBigNum(stacktop(-i)).getint();
792 if (nSigsCount < 0 || nSigsCount > nKeysCount)
796 if (stack.size() < i)
799 // Subset of script starting at the most recent codeseparator
800 CScript scriptCode(pbegincodehash, pend);
802 // Drop the signatures, since there's no way for a signature to sign itself
803 for (int k = 0; k < nSigsCount; k++)
805 valtype& vchSig = stacktop(-isig-k);
806 scriptCode.FindAndDelete(CScript(vchSig));
809 bool fSuccess = true;
810 while (fSuccess && nSigsCount > 0)
812 valtype& vchSig = stacktop(-isig);
813 valtype& vchPubKey = stacktop(-ikey);
816 if (CheckSig(vchSig, vchPubKey, scriptCode, txTo, nIn, nHashType))
824 // If there are more signatures left than keys left,
825 // then too many signatures have failed
826 if (nSigsCount > nKeysCount)
832 stack.push_back(fSuccess ? vchTrue : vchFalse);
834 if (opcode == OP_CHECKMULTISIGVERIFY)
849 if (stack.size() + altstack.size() > 1000)
873 uint256 SignatureHash(CScript scriptCode, const CTransaction& txTo, unsigned int nIn, int nHashType)
875 if (nIn >= txTo.vin.size())
877 printf("ERROR: SignatureHash() : nIn=%d out of range\n", nIn);
880 CTransaction txTmp(txTo);
882 // In case concatenating two scripts ends up with two codeseparators,
883 // or an extra one at the end, this prevents all those possible incompatibilities.
884 scriptCode.FindAndDelete(CScript(OP_CODESEPARATOR));
886 // Blank out other inputs' signatures
887 for (int i = 0; i < txTmp.vin.size(); i++)
888 txTmp.vin[i].scriptSig = CScript();
889 txTmp.vin[nIn].scriptSig = scriptCode;
891 // Blank out some of the outputs
892 if ((nHashType & 0x1f) == SIGHASH_NONE)
897 // Let the others update at will
898 for (int i = 0; i < txTmp.vin.size(); i++)
900 txTmp.vin[i].nSequence = 0;
902 else if ((nHashType & 0x1f) == SIGHASH_SINGLE)
904 // Only lockin the txout payee at same index as txin
905 unsigned int nOut = nIn;
906 if (nOut >= txTmp.vout.size())
908 printf("ERROR: SignatureHash() : nOut=%d out of range\n", nOut);
911 txTmp.vout.resize(nOut+1);
912 for (int i = 0; i < nOut; i++)
913 txTmp.vout[i].SetNull();
915 // Let the others update at will
916 for (int i = 0; i < txTmp.vin.size(); i++)
918 txTmp.vin[i].nSequence = 0;
921 // Blank out other inputs completely, not recommended for open transactions
922 if (nHashType & SIGHASH_ANYONECANPAY)
924 txTmp.vin[0] = txTmp.vin[nIn];
928 // Serialize and hash
929 CDataStream ss(SER_GETHASH);
931 ss << txTmp << nHashType;
932 return Hash(ss.begin(), ss.end());
936 bool CheckSig(vector<unsigned char> vchSig, vector<unsigned char> vchPubKey, CScript scriptCode,
937 const CTransaction& txTo, unsigned int nIn, int nHashType)
940 if (!key.SetPubKey(vchPubKey))
943 // Hash type is one byte tacked on to the end of the signature
947 nHashType = vchSig.back();
948 else if (nHashType != vchSig.back())
952 return key.Verify(SignatureHash(scriptCode, txTo, nIn, nHashType), vchSig);
964 bool Solver(const CScript& scriptPubKey, vector<pair<opcodetype, valtype> >& vSolutionRet)
967 static vector<CScript> vTemplates;
968 if (vTemplates.empty())
970 // Standard tx, sender provides pubkey, receiver adds signature
971 vTemplates.push_back(CScript() << OP_PUBKEY << OP_CHECKSIG);
973 // Bitcoin address tx, sender provides hash of pubkey, receiver provides signature and pubkey
974 vTemplates.push_back(CScript() << OP_DUP << OP_HASH160 << OP_PUBKEYHASH << OP_EQUALVERIFY << OP_CHECKSIG);
978 const CScript& script1 = scriptPubKey;
979 BOOST_FOREACH(const CScript& script2, vTemplates)
981 vSolutionRet.clear();
982 opcodetype opcode1, opcode2;
983 vector<unsigned char> vch1, vch2;
986 CScript::const_iterator pc1 = script1.begin();
987 CScript::const_iterator pc2 = script2.begin();
990 if (pc1 == script1.end() && pc2 == script2.end())
993 reverse(vSolutionRet.begin(), vSolutionRet.end());
996 if (!script1.GetOp(pc1, opcode1, vch1))
998 if (!script2.GetOp(pc2, opcode2, vch2))
1000 if (opcode2 == OP_PUBKEY)
1002 if (vch1.size() < 33 || vch1.size() > 120)
1004 vSolutionRet.push_back(make_pair(opcode2, vch1));
1006 else if (opcode2 == OP_PUBKEYHASH)
1008 if (vch1.size() != sizeof(uint160))
1010 vSolutionRet.push_back(make_pair(opcode2, vch1));
1012 else if (opcode1 != opcode2 || vch1 != vch2)
1019 vSolutionRet.clear();
1024 bool Solver(const CKeyStore& keystore, const CScript& scriptPubKey, uint256 hash, int nHashType, CScript& scriptSigRet)
1026 scriptSigRet.clear();
1028 vector<pair<opcodetype, valtype> > vSolution;
1029 if (!Solver(scriptPubKey, vSolution))
1033 CRITICAL_BLOCK(keystore.cs_KeyStore)
1035 BOOST_FOREACH(PAIRTYPE(opcodetype, valtype)& item, vSolution)
1037 if (item.first == OP_PUBKEY)
1040 const valtype& vchPubKey = item.second;
1042 if (!keystore.GetPrivKey(vchPubKey, key))
1046 vector<unsigned char> vchSig;
1047 if (!key.Sign(hash, vchSig))
1049 vchSig.push_back((unsigned char)nHashType);
1050 scriptSigRet << vchSig;
1053 else if (item.first == OP_PUBKEYHASH)
1055 // Sign and give pubkey
1056 map<uint160, valtype>::iterator mi = mapPubKeys.find(uint160(item.second));
1057 if (mi == mapPubKeys.end())
1059 const vector<unsigned char>& vchPubKey = (*mi).second;
1061 if (!keystore.GetPrivKey(vchPubKey, key))
1065 vector<unsigned char> vchSig;
1066 if (!key.Sign(hash, vchSig))
1068 vchSig.push_back((unsigned char)nHashType);
1069 scriptSigRet << vchSig << vchPubKey;
1083 bool IsStandard(const CScript& scriptPubKey)
1085 vector<pair<opcodetype, valtype> > vSolution;
1086 return Solver(scriptPubKey, vSolution);
1090 bool IsMine(const CKeyStore &keystore, const CScript& scriptPubKey)
1092 vector<pair<opcodetype, valtype> > vSolution;
1093 if (!Solver(scriptPubKey, vSolution))
1097 CRITICAL_BLOCK(keystore.cs_KeyStore)
1099 BOOST_FOREACH(PAIRTYPE(opcodetype, valtype)& item, vSolution)
1101 if (item.first == OP_PUBKEY)
1104 const valtype& vchPubKey = item.second;
1105 if (!keystore.HaveKey(vchPubKey))
1108 else if (item.first == OP_PUBKEYHASH)
1110 // Sign and give pubkey
1111 map<uint160, valtype>::iterator mi = mapPubKeys.find(uint160(item.second));
1112 if (mi == mapPubKeys.end())
1114 const vector<unsigned char>& vchPubKey = (*mi).second;
1115 if (!keystore.HaveKey(vchPubKey))
1129 bool ExtractPubKey(const CScript& scriptPubKey, const CKeyStore* keystore, vector<unsigned char>& vchPubKeyRet)
1131 vchPubKeyRet.clear();
1133 vector<pair<opcodetype, valtype> > vSolution;
1134 if (!Solver(scriptPubKey, vSolution))
1137 CRITICAL_BLOCK(cs_mapPubKeys)
1139 BOOST_FOREACH(PAIRTYPE(opcodetype, valtype)& item, vSolution)
1142 if (item.first == OP_PUBKEY)
1144 vchPubKey = item.second;
1146 else if (item.first == OP_PUBKEYHASH)
1148 map<uint160, valtype>::iterator mi = mapPubKeys.find(uint160(item.second));
1149 if (mi == mapPubKeys.end())
1151 vchPubKey = (*mi).second;
1153 if (keystore == NULL || keystore->HaveKey(vchPubKey))
1155 vchPubKeyRet = vchPubKey;
1164 bool ExtractHash160(const CScript& scriptPubKey, uint160& hash160Ret)
1168 vector<pair<opcodetype, valtype> > vSolution;
1169 if (!Solver(scriptPubKey, vSolution))
1172 BOOST_FOREACH(PAIRTYPE(opcodetype, valtype)& item, vSolution)
1174 if (item.first == OP_PUBKEYHASH)
1176 hash160Ret = uint160(item.second);
1184 bool VerifyScript(const CScript& scriptSig, const CScript& scriptPubKey, const CTransaction& txTo, unsigned int nIn, int nHashType)
1186 vector<vector<unsigned char> > stack;
1187 if (!EvalScript(stack, scriptSig, txTo, nIn, nHashType))
1189 if (!EvalScript(stack, scriptPubKey, txTo, nIn, nHashType))
1193 return CastToBool(stack.back());
1197 bool SignSignature(const CKeyStore &keystore, const CTransaction& txFrom, CTransaction& txTo, unsigned int nIn, int nHashType, CScript scriptPrereq)
1199 assert(nIn < txTo.vin.size());
1200 CTxIn& txin = txTo.vin[nIn];
1201 assert(txin.prevout.n < txFrom.vout.size());
1202 const CTxOut& txout = txFrom.vout[txin.prevout.n];
1204 // Leave out the signature from the hash, since a signature can't sign itself.
1205 // The checksig op will also drop the signatures from its hash.
1206 uint256 hash = SignatureHash(scriptPrereq + txout.scriptPubKey, txTo, nIn, nHashType);
1208 if (!Solver(keystore, txout.scriptPubKey, hash, nHashType, txin.scriptSig))
1211 txin.scriptSig = scriptPrereq + txin.scriptSig;
1214 if (scriptPrereq.empty())
1215 if (!VerifyScript(txin.scriptSig, txout.scriptPubKey, txTo, nIn, 0))
1222 bool VerifySignature(const CTransaction& txFrom, const CTransaction& txTo, unsigned int nIn, int nHashType)
1224 assert(nIn < txTo.vin.size());
1225 const CTxIn& txin = txTo.vin[nIn];
1226 if (txin.prevout.n >= txFrom.vout.size())
1228 const CTxOut& txout = txFrom.vout[txin.prevout.n];
1230 if (txin.prevout.hash != txFrom.GetHash())
1233 if (!VerifyScript(txin.scriptSig, txout.scriptPubKey, txTo, nIn, nHashType))