@@ -2179,6 +2179,8 @@ bool CheckInputScripts(const CTransaction& tx, TxValidationState& state,
2179
2179
if (pvChecks) {
2180
2180
pvChecks->emplace_back (std::move (check));
2181
2181
} else if (!check ()) {
2182
+ ScriptError error{check.GetScriptError ()};
2183
+
2182
2184
if (flags & STANDARD_NOT_MANDATORY_VERIFY_FLAGS) {
2183
2185
// Check whether the failure was caused by a
2184
2186
// non-mandatory script verification check, such as
@@ -2192,6 +2194,14 @@ bool CheckInputScripts(const CTransaction& tx, TxValidationState& state,
2192
2194
flags & ~STANDARD_NOT_MANDATORY_VERIFY_FLAGS, cacheSigStore, &txdata);
2193
2195
if (check2 ())
2194
2196
return state.Invalid (TxValidationResult::TX_NOT_STANDARD, strprintf (" non-mandatory-script-verify-flag (%s)" , ScriptErrorString (check.GetScriptError ())));
2197
+
2198
+ // If the second check failed, it failed due to a mandatory script verification
2199
+ // flag, but the first check might have failed on a non-mandatory script
2200
+ // verification flag.
2201
+ //
2202
+ // Avoid reporting a mandatory script check failure with a non-mandatory error
2203
+ // string by reporting the error from the second check.
2204
+ error = check2.GetScriptError ();
2195
2205
}
2196
2206
// MANDATORY flag failures correspond to
2197
2207
// TxValidationResult::TX_CONSENSUS. Because CONSENSUS
@@ -2202,7 +2212,7 @@ bool CheckInputScripts(const CTransaction& tx, TxValidationState& state,
2202
2212
// support, to avoid splitting the network (but this
2203
2213
// depends on the details of how net_processing handles
2204
2214
// such errors).
2205
- return state.Invalid (TxValidationResult::TX_CONSENSUS, strprintf (" mandatory-script-verify-flag-failed (%s)" , ScriptErrorString (check. GetScriptError () )));
2215
+ return state.Invalid (TxValidationResult::TX_CONSENSUS, strprintf (" mandatory-script-verify-flag-failed (%s)" , ScriptErrorString (error )));
2206
2216
}
2207
2217
}
2208
2218
0 commit comments