txscript: return ErrCleanStack for witness cleanstack failures
What changed, and why it matters
This is a tiny one-line change in btcd's transaction-script engine. It swaps the error code returned when a SegWit (witness) script leaves extra items on the stack after execution. Previously the code reported a generic 'evaluation returned false' error; now it reports the more specific 'clean stack' error expected by Bitcoin Core's reference test suite. The commit message frames this as test-compatibility, not a security fix, and the change does not alter whether a transaction is accepted or rejected—only which diagnostic error is produced.
No security action required. Treat as a normal test-compatibility / code-quality patch. If desired, verify that updated Bitcoin Core script tests now pass and that no other ErrEvalFalse vs ErrCleanStack mismatches remain.
Security signals we found
Error-code change only; no acceptance/rejection behavior change
Touched code path is SegWit witness script final-stack validation
Commit message describes test-suite alignment, not a vulnerability
Evidence from the diff
In txscript/engine.go, CheckErrorCondition changes the error returned when finalScript is true, a base SegWit witness version is active, and the data stack depth is not exactly 1. The error code moves from ErrEvalFalse to ErrCleanStack, while the message string remains the same. This aligns btcd with refreshed Bitcoin Core script reference tests that expect CLEANSTACK for witness clean-stack failures. No consensus logic, stack-depth check, or script execution behavior is changed.
Changed components
btcd/txscript/engine.goEngine.CheckErrorConditionSegWit witness script validationInspect captured patch +1 / −1
diff --git a/txscript/engine.go b/txscript/engine.go
index b443e40..96a5914 100644
--- a/txscript/engine.go
+++ b/txscript/engine.go
@@ -910,7 +910,7 @@ func (vm *Engine) CheckErrorCondition(finalScript bool) error {
// compatibility with BIP16.
if finalScript && vm.isWitnessVersionActive(BaseSegwitWitnessVersion) &&
vm.dstack.Depth() != 1 {
- return scriptError(ErrEvalFalse, "witness program must "+
+ return scriptError(ErrCleanStack, "witness program must "+
"have clean stack")
}
Why this scored 19/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.