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;
583 default: assert(!"invalid opcode"); break;
586 stack.push_back(bn.getvch());
600 case OP_NUMEQUALVERIFY:
604 case OP_LESSTHANOREQUAL:
605 case OP_GREATERTHANOREQUAL:
610 if (stack.size() < 2)
612 CBigNum bn1 = CastToBigNum(stacktop(-2));
613 CBigNum bn2 = CastToBigNum(stacktop(-1));
626 if (!BN_mul(&bn, &bn1, &bn2, pctx))
631 if (!BN_div(&bn, NULL, &bn1, &bn2, pctx))
636 if (!BN_mod(&bn, &bn1, &bn2, pctx))
641 if (bn2 < bnZero || bn2 > CBigNum(2048))
643 bn = bn1 << bn2.getulong();
647 if (bn2 < bnZero || bn2 > CBigNum(2048))
649 bn = bn1 >> bn2.getulong();
652 case OP_BOOLAND: bn = (bn1 != bnZero && bn2 != bnZero); break;
653 case OP_BOOLOR: bn = (bn1 != bnZero || bn2 != bnZero); break;
654 case OP_NUMEQUAL: bn = (bn1 == bn2); break;
655 case OP_NUMEQUALVERIFY: bn = (bn1 == bn2); break;
656 case OP_NUMNOTEQUAL: bn = (bn1 != bn2); break;
657 case OP_LESSTHAN: bn = (bn1 < bn2); break;
658 case OP_GREATERTHAN: bn = (bn1 > bn2); break;
659 case OP_LESSTHANOREQUAL: bn = (bn1 <= bn2); break;
660 case OP_GREATERTHANOREQUAL: bn = (bn1 >= bn2); break;
661 case OP_MIN: bn = (bn1 < bn2 ? bn1 : bn2); break;
662 case OP_MAX: bn = (bn1 > bn2 ? bn1 : bn2); break;
663 default: assert(!"invalid opcode"); break;
667 stack.push_back(bn.getvch());
669 if (opcode == OP_NUMEQUALVERIFY)
671 if (CastToBool(stacktop(-1)))
681 // (x min max -- out)
682 if (stack.size() < 3)
684 CBigNum bn1 = CastToBigNum(stacktop(-3));
685 CBigNum bn2 = CastToBigNum(stacktop(-2));
686 CBigNum bn3 = CastToBigNum(stacktop(-1));
687 bool fValue = (bn2 <= bn1 && bn1 < bn3);
691 stack.push_back(fValue ? vchTrue : vchFalse);
706 if (stack.size() < 1)
708 valtype& vch = stacktop(-1);
709 valtype vchHash((opcode == OP_RIPEMD160 || opcode == OP_SHA1 || opcode == OP_HASH160) ? 20 : 32);
710 if (opcode == OP_RIPEMD160)
711 RIPEMD160(&vch[0], vch.size(), &vchHash[0]);
712 else if (opcode == OP_SHA1)
713 SHA1(&vch[0], vch.size(), &vchHash[0]);
714 else if (opcode == OP_SHA256)
715 SHA256(&vch[0], vch.size(), &vchHash[0]);
716 else if (opcode == OP_HASH160)
718 uint160 hash160 = Hash160(vch);
719 memcpy(&vchHash[0], &hash160, sizeof(hash160));
721 else if (opcode == OP_HASH256)
723 uint256 hash = Hash(vch.begin(), vch.end());
724 memcpy(&vchHash[0], &hash, sizeof(hash));
727 stack.push_back(vchHash);
731 case OP_CODESEPARATOR:
733 // Hash starts after the code separator
739 case OP_CHECKSIGVERIFY:
741 // (sig pubkey -- bool)
742 if (stack.size() < 2)
745 valtype& vchSig = stacktop(-2);
746 valtype& vchPubKey = stacktop(-1);
749 //PrintHex(vchSig.begin(), vchSig.end(), "sig: %s\n");
750 //PrintHex(vchPubKey.begin(), vchPubKey.end(), "pubkey: %s\n");
752 // Subset of script starting at the most recent codeseparator
753 CScript scriptCode(pbegincodehash, pend);
755 // Drop the signature, since there's no way for a signature to sign itself
756 scriptCode.FindAndDelete(CScript(vchSig));
758 bool fSuccess = CheckSig(vchSig, vchPubKey, scriptCode, txTo, nIn, nHashType);
762 stack.push_back(fSuccess ? vchTrue : vchFalse);
763 if (opcode == OP_CHECKSIGVERIFY)
773 case OP_CHECKMULTISIG:
774 case OP_CHECKMULTISIGVERIFY:
776 // ([sig ...] num_of_signatures [pubkey ...] num_of_pubkeys -- bool)
779 if (stack.size() < i)
782 int nKeysCount = CastToBigNum(stacktop(-i)).getint();
783 if (nKeysCount < 0 || nKeysCount > 20)
785 nOpCount += nKeysCount;
790 if (stack.size() < i)
793 int nSigsCount = CastToBigNum(stacktop(-i)).getint();
794 if (nSigsCount < 0 || nSigsCount > nKeysCount)
798 if (stack.size() < i)
801 // Subset of script starting at the most recent codeseparator
802 CScript scriptCode(pbegincodehash, pend);
804 // Drop the signatures, since there's no way for a signature to sign itself
805 for (int k = 0; k < nSigsCount; k++)
807 valtype& vchSig = stacktop(-isig-k);
808 scriptCode.FindAndDelete(CScript(vchSig));
811 bool fSuccess = true;
812 while (fSuccess && nSigsCount > 0)
814 valtype& vchSig = stacktop(-isig);
815 valtype& vchPubKey = stacktop(-ikey);
818 if (CheckSig(vchSig, vchPubKey, scriptCode, txTo, nIn, nHashType))
826 // If there are more signatures left than keys left,
827 // then too many signatures have failed
828 if (nSigsCount > nKeysCount)
834 stack.push_back(fSuccess ? vchTrue : vchFalse);
836 if (opcode == OP_CHECKMULTISIGVERIFY)
851 if (stack.size() + altstack.size() > 1000)
875 uint256 SignatureHash(CScript scriptCode, const CTransaction& txTo, unsigned int nIn, int nHashType)
877 if (nIn >= txTo.vin.size())
879 printf("ERROR: SignatureHash() : nIn=%d out of range\n", nIn);
882 CTransaction txTmp(txTo);
884 // In case concatenating two scripts ends up with two codeseparators,
885 // or an extra one at the end, this prevents all those possible incompatibilities.
886 scriptCode.FindAndDelete(CScript(OP_CODESEPARATOR));
888 // Blank out other inputs' signatures
889 for (int i = 0; i < txTmp.vin.size(); i++)
890 txTmp.vin[i].scriptSig = CScript();
891 txTmp.vin[nIn].scriptSig = scriptCode;
893 // Blank out some of the outputs
894 if ((nHashType & 0x1f) == SIGHASH_NONE)
899 // Let the others update at will
900 for (int i = 0; i < txTmp.vin.size(); i++)
902 txTmp.vin[i].nSequence = 0;
904 else if ((nHashType & 0x1f) == SIGHASH_SINGLE)
906 // Only lockin the txout payee at same index as txin
907 unsigned int nOut = nIn;
908 if (nOut >= txTmp.vout.size())
910 printf("ERROR: SignatureHash() : nOut=%d out of range\n", nOut);
913 txTmp.vout.resize(nOut+1);
914 for (int i = 0; i < nOut; i++)
915 txTmp.vout[i].SetNull();
917 // Let the others update at will
918 for (int i = 0; i < txTmp.vin.size(); i++)
920 txTmp.vin[i].nSequence = 0;
923 // Blank out other inputs completely, not recommended for open transactions
924 if (nHashType & SIGHASH_ANYONECANPAY)
926 txTmp.vin[0] = txTmp.vin[nIn];
930 // Serialize and hash
931 CDataStream ss(SER_GETHASH);
933 ss << txTmp << nHashType;
934 return Hash(ss.begin(), ss.end());
938 bool CheckSig(vector<unsigned char> vchSig, vector<unsigned char> vchPubKey, CScript scriptCode,
939 const CTransaction& txTo, unsigned int nIn, int nHashType)
942 if (!key.SetPubKey(vchPubKey))
945 // Hash type is one byte tacked on to the end of the signature
949 nHashType = vchSig.back();
950 else if (nHashType != vchSig.back())
954 return key.Verify(SignatureHash(scriptCode, txTo, nIn, nHashType), vchSig);
966 bool Solver(const CScript& scriptPubKey, vector<pair<opcodetype, valtype> >& vSolutionRet)
969 static vector<CScript> vTemplates;
970 if (vTemplates.empty())
972 // Standard tx, sender provides pubkey, receiver adds signature
973 vTemplates.push_back(CScript() << OP_PUBKEY << OP_CHECKSIG);
975 // Bitcoin address tx, sender provides hash of pubkey, receiver provides signature and pubkey
976 vTemplates.push_back(CScript() << OP_DUP << OP_HASH160 << OP_PUBKEYHASH << OP_EQUALVERIFY << OP_CHECKSIG);
980 const CScript& script1 = scriptPubKey;
981 BOOST_FOREACH(const CScript& script2, vTemplates)
983 vSolutionRet.clear();
984 opcodetype opcode1, opcode2;
985 vector<unsigned char> vch1, vch2;
988 CScript::const_iterator pc1 = script1.begin();
989 CScript::const_iterator pc2 = script2.begin();
992 if (pc1 == script1.end() && pc2 == script2.end())
995 reverse(vSolutionRet.begin(), vSolutionRet.end());
998 if (!script1.GetOp(pc1, opcode1, vch1))
1000 if (!script2.GetOp(pc2, opcode2, vch2))
1002 if (opcode2 == OP_PUBKEY)
1004 if (vch1.size() < 33 || vch1.size() > 120)
1006 vSolutionRet.push_back(make_pair(opcode2, vch1));
1008 else if (opcode2 == OP_PUBKEYHASH)
1010 if (vch1.size() != sizeof(uint160))
1012 vSolutionRet.push_back(make_pair(opcode2, vch1));
1014 else if (opcode1 != opcode2 || vch1 != vch2)
1021 vSolutionRet.clear();
1026 bool Solver(const CKeyStore& keystore, const CScript& scriptPubKey, uint256 hash, int nHashType, CScript& scriptSigRet)
1028 scriptSigRet.clear();
1030 vector<pair<opcodetype, valtype> > vSolution;
1031 if (!Solver(scriptPubKey, vSolution))
1035 CRITICAL_BLOCK(keystore.cs_KeyStore)
1037 BOOST_FOREACH(PAIRTYPE(opcodetype, valtype)& item, vSolution)
1039 if (item.first == OP_PUBKEY)
1042 const valtype& vchPubKey = item.second;
1044 if (!keystore.GetKey(Hash160(vchPubKey), key))
1046 if (key.GetPubKey() != vchPubKey)
1050 vector<unsigned char> vchSig;
1051 if (!key.Sign(hash, vchSig))
1053 vchSig.push_back((unsigned char)nHashType);
1054 scriptSigRet << vchSig;
1057 else if (item.first == OP_PUBKEYHASH)
1059 // Sign and give pubkey
1061 if (!keystore.GetKey(uint160(item.second), key))
1065 vector<unsigned char> vchSig;
1066 if (!key.Sign(hash, vchSig))
1068 vchSig.push_back((unsigned char)nHashType);
1069 scriptSigRet << vchSig << key.GetPubKey();
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)
1103 const valtype& vchPubKey = item.second;
1104 vector<unsigned char> vchPubKeyFound;
1105 if (!keystore.GetPubKey(Hash160(vchPubKey), vchPubKeyFound))
1107 if (vchPubKeyFound != vchPubKey)
1110 else if (item.first == OP_PUBKEYHASH)
1112 if (!keystore.HaveKey(uint160(item.second)))
1126 bool ExtractAddress(const CScript& scriptPubKey, const CKeyStore* keystore, CBitcoinAddress& addressRet)
1128 vector<pair<opcodetype, valtype> > vSolution;
1129 if (!Solver(scriptPubKey, vSolution))
1132 CRITICAL_BLOCK(keystore->cs_KeyStore)
1134 BOOST_FOREACH(PAIRTYPE(opcodetype, valtype)& item, vSolution)
1137 if (item.first == OP_PUBKEY)
1138 addressRet.SetPubKey(item.second);
1139 else if (item.first == OP_PUBKEYHASH)
1140 addressRet.SetHash160((uint160)item.second);
1141 if (keystore == NULL || keystore->HaveKey(addressRet))
1149 bool VerifyScript(const CScript& scriptSig, const CScript& scriptPubKey, const CTransaction& txTo, unsigned int nIn, int nHashType)
1151 vector<vector<unsigned char> > stack;
1152 if (!EvalScript(stack, scriptSig, txTo, nIn, nHashType))
1154 if (!EvalScript(stack, scriptPubKey, txTo, nIn, nHashType))
1158 return CastToBool(stack.back());
1162 bool SignSignature(const CKeyStore &keystore, const CTransaction& txFrom, CTransaction& txTo, unsigned int nIn, int nHashType, CScript scriptPrereq)
1164 assert(nIn < txTo.vin.size());
1165 CTxIn& txin = txTo.vin[nIn];
1166 assert(txin.prevout.n < txFrom.vout.size());
1167 const CTxOut& txout = txFrom.vout[txin.prevout.n];
1169 // Leave out the signature from the hash, since a signature can't sign itself.
1170 // The checksig op will also drop the signatures from its hash.
1171 uint256 hash = SignatureHash(scriptPrereq + txout.scriptPubKey, txTo, nIn, nHashType);
1173 if (!Solver(keystore, txout.scriptPubKey, hash, nHashType, txin.scriptSig))
1176 txin.scriptSig = scriptPrereq + txin.scriptSig;
1179 if (scriptPrereq.empty())
1180 if (!VerifyScript(txin.scriptSig, txout.scriptPubKey, txTo, nIn, 0))
1187 bool VerifySignature(const CTransaction& txFrom, const CTransaction& txTo, unsigned int nIn, int nHashType)
1189 assert(nIn < txTo.vin.size());
1190 const CTxIn& txin = txTo.vin[nIn];
1191 if (txin.prevout.n >= txFrom.vout.size())
1193 const CTxOut& txout = txFrom.vout[txin.prevout.n];
1195 if (txin.prevout.hash != txFrom.GetHash())
1198 if (!VerifyScript(txin.scriptSig, txout.scriptPubKey, txTo, nIn, nHashType))