Skip to content

Commit 116419e

Browse files
committed
Don't overwrite validation state with corruption check
AcceptToMemoryPool has several classes of return false statements. - return state.Invalid or state.DoS directly itself - return false and set fMissingInputs (state is valid) - return false and state is set by failed CheckTransaction - return false and state is set by failed CheckInputs. This commit patches the last case where the state variable was reused for additional calls to CheckInputs to identify witness stripping as cause of validation failure. After this commit, it should be the case that if !fMissingInputs, state is always Invalid if AcceptToMemoryPool returns false.
1 parent 5754e03 commit 116419e

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/validation.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -919,12 +919,13 @@ bool AcceptToMemoryPoolWorker(CTxMemPool& pool, CValidationState& state, const C
919919
// SCRIPT_VERIFY_CLEANSTACK requires SCRIPT_VERIFY_WITNESS, so we
920920
// need to turn both off, and compare against just turning off CLEANSTACK
921921
// to see if the failure is specifically due to witness validation.
922-
if (!tx.HasWitness() && CheckInputs(tx, state, view, true, scriptVerifyFlags & ~(SCRIPT_VERIFY_WITNESS | SCRIPT_VERIFY_CLEANSTACK), true, txdata) &&
923-
!CheckInputs(tx, state, view, true, scriptVerifyFlags & ~SCRIPT_VERIFY_CLEANSTACK, true, txdata)) {
922+
CValidationState stateDummy; // Want reported failures to be from first CheckInputs
923+
if (!tx.HasWitness() && CheckInputs(tx, stateDummy, view, true, scriptVerifyFlags & ~(SCRIPT_VERIFY_WITNESS | SCRIPT_VERIFY_CLEANSTACK), true, txdata) &&
924+
!CheckInputs(tx, stateDummy, view, true, scriptVerifyFlags & ~SCRIPT_VERIFY_CLEANSTACK, true, txdata)) {
924925
// Only the witness is missing, so the transaction itself may be fine.
925926
state.SetCorruptionPossible();
926927
}
927-
return false;
928+
return false; // state filled in by CheckInputs
928929
}
929930

930931
// Check again against just the consensus-critical mandatory script

0 commit comments

Comments
 (0)