@@ -2179,6 +2179,8 @@ bool CheckInputScripts(const CTransaction& tx, TxValidationState& state,
21792179 if (pvChecks) {
21802180 pvChecks->emplace_back (std::move (check));
21812181 } else if (!check ()) {
2182+ ScriptError error{check.GetScriptError ()};
2183+
21822184 if (flags & STANDARD_NOT_MANDATORY_VERIFY_FLAGS) {
21832185 // Check whether the failure was caused by a
21842186 // non-mandatory script verification check, such as
@@ -2192,6 +2194,14 @@ bool CheckInputScripts(const CTransaction& tx, TxValidationState& state,
21922194 flags & ~STANDARD_NOT_MANDATORY_VERIFY_FLAGS, cacheSigStore, &txdata);
21932195 if (check2 ())
21942196 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 ();
21952205 }
21962206 // MANDATORY flag failures correspond to
21972207 // TxValidationResult::TX_CONSENSUS. Because CONSENSUS
@@ -2202,7 +2212,7 @@ bool CheckInputScripts(const CTransaction& tx, TxValidationState& state,
22022212 // support, to avoid splitting the network (but this
22032213 // depends on the details of how net_processing handles
22042214 // 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 )));
22062216 }
22072217 }
22082218
0 commit comments