From 2245d254976a3ee761c52a829f246f37423916c1 Mon Sep 17 00:00:00 2001 From: UdjinM6 Date: Wed, 21 Sep 2016 18:03:04 +0400 Subject: [PATCH] fix: CDarksendPool::IsSignatureValid has misleading name and suboptimal params (#1035) --- src/darksend.cpp | 19 +++++++++++-------- src/darksend.h | 4 ++-- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/darksend.cpp b/src/darksend.cpp index 48b177aacc..f3c2b143e8 100644 --- a/src/darksend.cpp +++ b/src/darksend.cpp @@ -838,8 +838,8 @@ void CDarksendPool::CheckForCompleteQueue() } } -// check to see if the signature is valid -bool CDarksendPool::IsSignatureValid(const CScript& scriptSig, const CTxIn& txin) +// Check to make sure a given input matches an input in the pool and its scriptSig is valid +bool CDarksendPool::IsInputScriptSigValid(const CTxIn& txin) { CMutableTransaction txNew; txNew.vin.clear(); @@ -866,15 +866,18 @@ bool CDarksendPool::IsSignatureValid(const CScript& scriptSig, const CTxIn& txin } if(nTxInIndex >= 0) { //might have to do this one input at a time? - txNew.vin[nTxInIndex].scriptSig = scriptSig; - LogPrint("privatesend", "CDarksendPool::IsSignatureValid -- Sign with sig %s\n", ScriptToAsmStr(scriptSig).substr(0,24)); + txNew.vin[nTxInIndex].scriptSig = txin.scriptSig; + LogPrint("privatesend", "CDarksendPool::IsInputScriptSigValid -- verifying scriptSig %s\n", ScriptToAsmStr(txin.scriptSig).substr(0,24)); if(!VerifyScript(txNew.vin[nTxInIndex].scriptSig, sigPubKey, SCRIPT_VERIFY_P2SH | SCRIPT_VERIFY_STRICTENC, MutableTransactionSignatureChecker(&txNew, nTxInIndex))) { - LogPrint("privatesend", "CDarksendPool::IsSignatureValid -- Signing -- Error signing input %d\n", nTxInIndex); + LogPrint("privatesend", "CDarksendPool::IsInputScriptSigValid -- VerifyScript() failed on input %d\n", nTxInIndex); return false; } + } else { + LogPrint("privatesend", "CDarksendPool::IsInputScriptSigValid -- Failed to find matching input in pool, %s\n", txin.ToString()); + return false; } - LogPrint("privatesend", "CDarksendPool::IsSignatureValid -- Signing -- Successfully validated input\n"); + LogPrint("privatesend", "CDarksendPool::IsInputScriptSigValid -- Successfully validated input and scriptSig\n"); return true; } @@ -999,8 +1002,8 @@ bool CDarksendPool::AddScriptSig(const CTxIn& txinNew) } } - if(!IsSignatureValid(txinNew.scriptSig, txinNew)) { - LogPrint("privatesend", "CDarksendPool::AddScriptSig -- Invalid Sig\n"); + if(!IsInputScriptSigValid(txinNew)) { + LogPrint("privatesend", "CDarksendPool::AddScriptSig -- Invalid scriptSig\n"); return false; } diff --git a/src/darksend.h b/src/darksend.h index 89a28e4e9f..0e26740547 100644 --- a/src/darksend.h +++ b/src/darksend.h @@ -369,8 +369,8 @@ private: bool IsCollateralValid(const CTransaction& txCollateral); /// Check that all inputs are signed. (Are all inputs signed?) bool IsSignaturesComplete(); - /// Check to make sure a signature matches an input in the pool - bool IsSignatureValid(const CScript& scriptSig, const CTxIn& txin); + /// Check to make sure a given input matches an input in the pool and its scriptSig is valid + bool IsInputScriptSigValid(const CTxIn& txin); bool IsDenomSkipped(CAmount nDenomValue) { return std::find(vecDenominationsSkipped.begin(), vecDenominationsSkipped.end(), nDenomValue) != vecDenominationsSkipped.end();