Skip to content

Commit c59e716

Browse files
committed
AreInputsStandard: Return specific reject reasons
1 parent 963da74 commit c59e716

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

src/policy/policy.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ bool IsStandardTx(const CTransaction& tx, std::string& reason, const bool witnes
160160
return true;
161161
}
162162

163-
bool AreInputsStandard(const CTransaction& tx, const CCoinsViewCache& mapInputs)
163+
bool AreInputsStandard(const CTransaction& tx, const CCoinsViewCache& mapInputs, const std::string& reason_prefix, std::string& out_reason)
164164
{
165165
if (tx.IsCoinBase())
166166
return true; // Coinbases don't use vin normally
@@ -173,19 +173,26 @@ bool AreInputsStandard(const CTransaction& tx, const CCoinsViewCache& mapInputs)
173173
txnouttype whichType;
174174
// get the scriptPubKey corresponding to this input:
175175
const CScript& prevScript = prev.scriptPubKey;
176-
if (!Solver(prevScript, whichType, vSolutions))
176+
if (!Solver(prevScript, whichType, vSolutions)) {
177+
out_reason = reason_prefix + "script-unknown";
177178
return false;
179+
}
178180

179181
if (whichType == TX_SCRIPTHASH)
180182
{
181183
std::vector<std::vector<unsigned char> > stack;
182184
// convert the scriptSig into a stack, so we can inspect the redeemScript
183-
if (!EvalScript(stack, tx.vin[i].scriptSig, SCRIPT_VERIFY_NONE, BaseSignatureChecker(), SIGVERSION_BASE))
185+
if (!EvalScript(stack, tx.vin[i].scriptSig, SCRIPT_VERIFY_NONE, BaseSignatureChecker(), SIGVERSION_BASE)) {
186+
out_reason = reason_prefix + "scriptsig-failure";
184187
return false;
185-
if (stack.empty())
188+
}
189+
if (stack.empty()) {
190+
out_reason = reason_prefix + "scriptcheck-missing";
186191
return false;
192+
}
187193
CScript subscript(stack.back().begin(), stack.back().end());
188194
if (subscript.GetSigOpCount(true) > MAX_P2SH_SIGOPS) {
195+
out_reason = reason_prefix + "scriptcheck-sigops";
189196
return false;
190197
}
191198
}

src/policy/policy.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,13 @@ bool IsStandardTx(const CTransaction& tx, std::string& reason, const bool witnes
8989
* @param[in] mapInputs Map of previous transactions that have outputs we're spending
9090
* @return True if all inputs (scriptSigs) use only standard transaction forms
9191
*/
92-
bool AreInputsStandard(const CTransaction& tx, const CCoinsViewCache& mapInputs);
92+
bool AreInputsStandard(const CTransaction& tx, const CCoinsViewCache& mapInputs, const std::string& reason_prefix, std::string& out_reason);
93+
94+
inline bool AreInputsStandard(const CTransaction& tx, const CCoinsViewCache& mapInputs) {
95+
std::string reason;
96+
return AreInputsStandard(tx, mapInputs, reason, reason);
97+
}
98+
9399
/**
94100
* Check if the transaction is over standard P2WSH resources limit:
95101
* 3600bytes witnessScript size, 80bytes per witness stack element, 100 witness stack elements

src/validation.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -572,8 +572,9 @@ static bool AcceptToMemoryPoolWorker(const CChainParams& chainparams, CTxMemPool
572572
}
573573

574574
// Check for non-standard pay-to-script-hash in inputs
575-
if (fRequireStandard && !AreInputsStandard(tx, view))
576-
return state.Invalid(false, REJECT_NONSTANDARD, "bad-txns-nonstandard-inputs");
575+
if (fRequireStandard && !AreInputsStandard(tx, view, "bad-txns-input-", reason)) {
576+
return state.Invalid(false, REJECT_NONSTANDARD, reason);
577+
}
577578

578579
// Check for non-standard witness in P2WSH
579580
if (tx.HasWitness() && fRequireStandard && !IsWitnessStandard(tx, view))

0 commit comments

Comments
 (0)