@@ -42,20 +42,17 @@ void MakeSameSize(valtype& vch1, valtype& vch2)
4242#define stacktop (i ) (stack.at(stack.size()+(i)))
4343#define altstacktop (i ) (altstack.at(altstack.size()+(i)))
4444
45- bool EvalScript (const CScript& script, const CTransaction& txTo, unsigned int nIn, int nHashType,
46- vector<vector<unsigned char > >* pvStackRet)
45+ bool EvalScript (vector<vector<unsigned char > >& stack, const CScript& script, const CTransaction& txTo, unsigned int nIn, int nHashType)
4746{
4847 CAutoBN_CTX pctx;
4948 CScript::const_iterator pc = script.begin ();
5049 CScript::const_iterator pend = script.end ();
5150 CScript::const_iterator pbegincodehash = script.begin ();
5251 vector<bool > vfExec;
53- vector<valtype> stack;
5452 vector<valtype> altstack;
55- if (pvStackRet)
56- pvStackRet->clear ();
57- if (script.size () > 20000 )
53+ if (script.size () > 10000 )
5854 return false ;
55+ int nOpCount = 0 ;
5956
6057
6158 try
@@ -73,6 +70,8 @@ bool EvalScript(const CScript& script, const CTransaction& txTo, unsigned int nI
7370 return false ;
7471 if (vchPushValue.size () > 5000 )
7572 return false ;
73+ if (opcode > OP_16 && nOpCount++ > 200 )
74+ return false ;
7675
7776 if (fExec && opcode <= OP_PUSHDATA4)
7877 stack.push_back (vchPushValue);
@@ -828,9 +827,7 @@ bool EvalScript(const CScript& script, const CTransaction& txTo, unsigned int nI
828827 if (!vfExec.empty ())
829828 return false ;
830829
831- if (pvStackRet)
832- *pvStackRet = stack;
833- return (stack.empty () ? false : CastToBool (stack.back ()));
830+ return true ;
834831}
835832
836833#undef top
@@ -1114,6 +1111,19 @@ bool ExtractHash160(const CScript& scriptPubKey, uint160& hash160Ret)
11141111}
11151112
11161113
1114+ bool VerifyScript (const CScript& scriptSig, const CScript& scriptPubKey, const CTransaction& txTo, unsigned int nIn, int nHashType)
1115+ {
1116+ vector<vector<unsigned char > > stack;
1117+ if (!EvalScript (stack, scriptSig, txTo, nIn, nHashType))
1118+ return false ;
1119+ if (!EvalScript (stack, scriptPubKey, txTo, nIn, nHashType))
1120+ return false ;
1121+ if (stack.empty ())
1122+ return false ;
1123+ return CastToBool (stack.back ());
1124+ }
1125+
1126+
11171127bool SignSignature (const CTransaction& txFrom, CTransaction& txTo, unsigned int nIn, int nHashType, CScript scriptPrereq)
11181128{
11191129 assert (nIn < txTo.vin .size ());
@@ -1132,7 +1142,7 @@ bool SignSignature(const CTransaction& txFrom, CTransaction& txTo, unsigned int
11321142
11331143 // Test solution
11341144 if (scriptPrereq.empty ())
1135- if (!EvalScript (txin.scriptSig + CScript (OP_CODESEPARATOR) + txout.scriptPubKey , txTo, nIn))
1145+ if (!VerifyScript (txin.scriptSig , txout.scriptPubKey , txTo, nIn, 0 ))
11361146 return false ;
11371147
11381148 return true ;
@@ -1150,7 +1160,7 @@ bool VerifySignature(const CTransaction& txFrom, const CTransaction& txTo, unsig
11501160 if (txin.prevout .hash != txFrom.GetHash ())
11511161 return false ;
11521162
1153- if (!EvalScript (txin.scriptSig + CScript (OP_CODESEPARATOR) + txout.scriptPubKey , txTo, nIn, nHashType))
1163+ if (!VerifyScript (txin.scriptSig , txout.scriptPubKey , txTo, nIn, nHashType))
11541164 return false ;
11551165
11561166 // Anytime a signature is successfully verified, it's proof the outpoint is spent,
0 commit comments