mirror of
https://github.com/dashpay/dash.git
synced 2024-12-27 04:52:59 +01:00
Don't pass nHashType to EvalScript nor CheckSig
This commit is contained in:
parent
2b23a87599
commit
6dcfda2dc4
@ -697,7 +697,7 @@ bool AreInputsStandard(const CTransaction& tx, const CCoinsViewCache& mapInputs)
|
|||||||
// IsStandard() will have already returned false
|
// IsStandard() will have already returned false
|
||||||
// and this method isn't called.
|
// and this method isn't called.
|
||||||
vector<vector<unsigned char> > stack;
|
vector<vector<unsigned char> > stack;
|
||||||
if (!EvalScript(stack, tx.vin[i].scriptSig, tx, i, false, 0))
|
if (!EvalScript(stack, tx.vin[i].scriptSig, tx, i, false))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (whichType == TX_SCRIPTHASH)
|
if (whichType == TX_SCRIPTHASH)
|
||||||
|
@ -132,7 +132,7 @@ bool IsCanonicalSignature(const valtype &vchSig, unsigned int flags) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool EvalScript(vector<vector<unsigned char> >& stack, const CScript& script, const CTransaction& txTo, unsigned int nIn, unsigned int flags, int nHashType)
|
bool EvalScript(vector<vector<unsigned char> >& stack, const CScript& script, const CTransaction& txTo, unsigned int nIn, unsigned int flags)
|
||||||
{
|
{
|
||||||
CScript::const_iterator pc = script.begin();
|
CScript::const_iterator pc = script.begin();
|
||||||
CScript::const_iterator pend = script.end();
|
CScript::const_iterator pend = script.end();
|
||||||
@ -675,7 +675,7 @@ bool EvalScript(vector<vector<unsigned char> >& stack, const CScript& script, co
|
|||||||
scriptCode.FindAndDelete(CScript(vchSig));
|
scriptCode.FindAndDelete(CScript(vchSig));
|
||||||
|
|
||||||
bool fSuccess = IsCanonicalSignature(vchSig, flags) && IsCanonicalPubKey(vchPubKey, flags) &&
|
bool fSuccess = IsCanonicalSignature(vchSig, flags) && IsCanonicalPubKey(vchPubKey, flags) &&
|
||||||
CheckSig(vchSig, vchPubKey, scriptCode, txTo, nIn, nHashType, flags);
|
CheckSig(vchSig, vchPubKey, scriptCode, txTo, nIn, flags);
|
||||||
|
|
||||||
popstack(stack);
|
popstack(stack);
|
||||||
popstack(stack);
|
popstack(stack);
|
||||||
@ -736,7 +736,7 @@ bool EvalScript(vector<vector<unsigned char> >& stack, const CScript& script, co
|
|||||||
|
|
||||||
// Check signature
|
// Check signature
|
||||||
bool fOk = IsCanonicalSignature(vchSig, flags) && IsCanonicalPubKey(vchPubKey, flags) &&
|
bool fOk = IsCanonicalSignature(vchSig, flags) && IsCanonicalPubKey(vchPubKey, flags) &&
|
||||||
CheckSig(vchSig, vchPubKey, scriptCode, txTo, nIn, nHashType, flags);
|
CheckSig(vchSig, vchPubKey, scriptCode, txTo, nIn, flags);
|
||||||
|
|
||||||
if (fOk) {
|
if (fOk) {
|
||||||
isig++;
|
isig++;
|
||||||
@ -975,7 +975,7 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
bool CheckSig(vector<unsigned char> vchSig, const vector<unsigned char> &vchPubKey, const CScript &scriptCode, const CTransaction& txTo, unsigned int nIn, int nHashType, int flags)
|
bool CheckSig(vector<unsigned char> vchSig, const vector<unsigned char>& vchPubKey, const CScript& scriptCode, const CTransaction& txTo, unsigned int nIn, int flags)
|
||||||
{
|
{
|
||||||
static CSignatureCache signatureCache;
|
static CSignatureCache signatureCache;
|
||||||
|
|
||||||
@ -986,10 +986,7 @@ bool CheckSig(vector<unsigned char> vchSig, const vector<unsigned char> &vchPubK
|
|||||||
// Hash type is one byte tacked on to the end of the signature
|
// Hash type is one byte tacked on to the end of the signature
|
||||||
if (vchSig.empty())
|
if (vchSig.empty())
|
||||||
return false;
|
return false;
|
||||||
if (nHashType == 0)
|
int nHashType = vchSig.back();
|
||||||
nHashType = vchSig.back();
|
|
||||||
else if (nHashType != vchSig.back())
|
|
||||||
return false;
|
|
||||||
vchSig.pop_back();
|
vchSig.pop_back();
|
||||||
|
|
||||||
uint256 sighash = SignatureHash(scriptCode, txTo, nIn, nHashType);
|
uint256 sighash = SignatureHash(scriptCode, txTo, nIn, nHashType);
|
||||||
@ -1009,11 +1006,11 @@ bool CheckSig(vector<unsigned char> vchSig, const vector<unsigned char> &vchPubK
|
|||||||
bool VerifyScript(const CScript& scriptSig, const CScript& scriptPubKey, const CTransaction& txTo, unsigned int nIn, unsigned int flags)
|
bool VerifyScript(const CScript& scriptSig, const CScript& scriptPubKey, const CTransaction& txTo, unsigned int nIn, unsigned int flags)
|
||||||
{
|
{
|
||||||
vector<vector<unsigned char> > stack, stackCopy;
|
vector<vector<unsigned char> > stack, stackCopy;
|
||||||
if (!EvalScript(stack, scriptSig, txTo, nIn, flags, 0))
|
if (!EvalScript(stack, scriptSig, txTo, nIn, flags))
|
||||||
return false;
|
return false;
|
||||||
if (flags & SCRIPT_VERIFY_P2SH)
|
if (flags & SCRIPT_VERIFY_P2SH)
|
||||||
stackCopy = stack;
|
stackCopy = stack;
|
||||||
if (!EvalScript(stack, scriptPubKey, txTo, nIn, flags, 0))
|
if (!EvalScript(stack, scriptPubKey, txTo, nIn, flags))
|
||||||
return false;
|
return false;
|
||||||
if (stack.empty())
|
if (stack.empty())
|
||||||
return false;
|
return false;
|
||||||
@ -1036,7 +1033,7 @@ bool VerifyScript(const CScript& scriptSig, const CScript& scriptPubKey, const C
|
|||||||
CScript pubKey2(pubKeySerialized.begin(), pubKeySerialized.end());
|
CScript pubKey2(pubKeySerialized.begin(), pubKeySerialized.end());
|
||||||
popstack(stackCopy);
|
popstack(stackCopy);
|
||||||
|
|
||||||
if (!EvalScript(stackCopy, pubKey2, txTo, nIn, flags, 0))
|
if (!EvalScript(stackCopy, pubKey2, txTo, nIn, flags))
|
||||||
return false;
|
return false;
|
||||||
if (stackCopy.empty())
|
if (stackCopy.empty())
|
||||||
return false;
|
return false;
|
||||||
|
@ -38,8 +38,8 @@ bool IsCanonicalPubKey(const std::vector<unsigned char> &vchPubKey, unsigned int
|
|||||||
bool IsCanonicalSignature(const std::vector<unsigned char> &vchSig, unsigned int flags);
|
bool IsCanonicalSignature(const std::vector<unsigned char> &vchSig, unsigned int flags);
|
||||||
|
|
||||||
uint256 SignatureHash(const CScript &scriptCode, const CTransaction& txTo, unsigned int nIn, int nHashType);
|
uint256 SignatureHash(const CScript &scriptCode, const CTransaction& txTo, unsigned int nIn, int nHashType);
|
||||||
bool CheckSig(std::vector<unsigned char> vchSig, const std::vector<unsigned char> &vchPubKey, const CScript &scriptCode, const CTransaction& txTo, unsigned int nIn, int nHashType, int flags);
|
bool CheckSig(std::vector<unsigned char> vchSig, const std::vector<unsigned char> &vchPubKey, const CScript &scriptCode, const CTransaction& txTo, unsigned int nIn, int flags);
|
||||||
bool EvalScript(std::vector<std::vector<unsigned char> >& stack, const CScript& script, const CTransaction& txTo, unsigned int nIn, unsigned int flags, int nHashType);
|
bool EvalScript(std::vector<std::vector<unsigned char> >& stack, const CScript& script, const CTransaction& txTo, unsigned int nIn, unsigned int flags);
|
||||||
bool VerifyScript(const CScript& scriptSig, const CScript& scriptPubKey, const CTransaction& txTo, unsigned int nIn, unsigned int flags);
|
bool VerifyScript(const CScript& scriptSig, const CScript& scriptPubKey, const CTransaction& txTo, unsigned int nIn, unsigned int flags);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -174,7 +174,7 @@ static CScript CombineMultisig(CScript scriptPubKey, const CMutableTransaction&
|
|||||||
if (sigs.count(pubkey))
|
if (sigs.count(pubkey))
|
||||||
continue; // Already got a sig for this pubkey
|
continue; // Already got a sig for this pubkey
|
||||||
|
|
||||||
if (CheckSig(sig, pubkey, scriptPubKey, txTo, nIn, 0, 0))
|
if (CheckSig(sig, pubkey, scriptPubKey, txTo, nIn, 0))
|
||||||
{
|
{
|
||||||
sigs[pubkey] = sig;
|
sigs[pubkey] = sig;
|
||||||
break;
|
break;
|
||||||
@ -252,9 +252,9 @@ CScript CombineSignatures(CScript scriptPubKey, const CTransaction& txTo, unsign
|
|||||||
Solver(scriptPubKey, txType, vSolutions);
|
Solver(scriptPubKey, txType, vSolutions);
|
||||||
|
|
||||||
vector<valtype> stack1;
|
vector<valtype> stack1;
|
||||||
EvalScript(stack1, scriptSig1, CTransaction(), 0, SCRIPT_VERIFY_STRICTENC, 0);
|
EvalScript(stack1, scriptSig1, CTransaction(), 0, SCRIPT_VERIFY_STRICTENC);
|
||||||
vector<valtype> stack2;
|
vector<valtype> stack2;
|
||||||
EvalScript(stack2, scriptSig2, CTransaction(), 0, SCRIPT_VERIFY_STRICTENC, 0);
|
EvalScript(stack2, scriptSig2, CTransaction(), 0, SCRIPT_VERIFY_STRICTENC);
|
||||||
|
|
||||||
return CombineSignatures(scriptPubKey, txTo, nIn, txType, vSolutions, stack1, stack2);
|
return CombineSignatures(scriptPubKey, txTo, nIn, txType, vSolutions, stack1, stack2);
|
||||||
}
|
}
|
||||||
|
@ -116,18 +116,18 @@ BOOST_AUTO_TEST_CASE(script_PushData)
|
|||||||
static const unsigned char pushdata4[] = { OP_PUSHDATA4, 1, 0, 0, 0, 0x5a };
|
static const unsigned char pushdata4[] = { OP_PUSHDATA4, 1, 0, 0, 0, 0x5a };
|
||||||
|
|
||||||
vector<vector<unsigned char> > directStack;
|
vector<vector<unsigned char> > directStack;
|
||||||
BOOST_CHECK(EvalScript(directStack, CScript(&direct[0], &direct[sizeof(direct)]), CTransaction(), 0, true, 0));
|
BOOST_CHECK(EvalScript(directStack, CScript(&direct[0], &direct[sizeof(direct)]), CTransaction(), 0, true));
|
||||||
|
|
||||||
vector<vector<unsigned char> > pushdata1Stack;
|
vector<vector<unsigned char> > pushdata1Stack;
|
||||||
BOOST_CHECK(EvalScript(pushdata1Stack, CScript(&pushdata1[0], &pushdata1[sizeof(pushdata1)]), CTransaction(), 0, true, 0));
|
BOOST_CHECK(EvalScript(pushdata1Stack, CScript(&pushdata1[0], &pushdata1[sizeof(pushdata1)]), CTransaction(), 0, true));
|
||||||
BOOST_CHECK(pushdata1Stack == directStack);
|
BOOST_CHECK(pushdata1Stack == directStack);
|
||||||
|
|
||||||
vector<vector<unsigned char> > pushdata2Stack;
|
vector<vector<unsigned char> > pushdata2Stack;
|
||||||
BOOST_CHECK(EvalScript(pushdata2Stack, CScript(&pushdata2[0], &pushdata2[sizeof(pushdata2)]), CTransaction(), 0, true, 0));
|
BOOST_CHECK(EvalScript(pushdata2Stack, CScript(&pushdata2[0], &pushdata2[sizeof(pushdata2)]), CTransaction(), 0, true));
|
||||||
BOOST_CHECK(pushdata2Stack == directStack);
|
BOOST_CHECK(pushdata2Stack == directStack);
|
||||||
|
|
||||||
vector<vector<unsigned char> > pushdata4Stack;
|
vector<vector<unsigned char> > pushdata4Stack;
|
||||||
BOOST_CHECK(EvalScript(pushdata4Stack, CScript(&pushdata4[0], &pushdata4[sizeof(pushdata4)]), CTransaction(), 0, true, 0));
|
BOOST_CHECK(EvalScript(pushdata4Stack, CScript(&pushdata4[0], &pushdata4[sizeof(pushdata4)]), CTransaction(), 0, true));
|
||||||
BOOST_CHECK(pushdata4Stack == directStack);
|
BOOST_CHECK(pushdata4Stack == directStack);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user