Error messages in clean stack is misleading as it lets the user believe that there are extra elements on the stack which is incorrect if the stack is empty.
Let me know if this requires additional test.
Error messages in clean stack is misleading as it lets the user believe that there are extra elements on the stack which is incorrect if the stack is empty.
Let me know if this requires additional test.
ACK c2f00b7e2f6c17083b7c72555f5a366c9ff8c673
Agree that this is misleading.
ACK https://github.com/bitcoin/bitcoin/pull/20006/commits/c2f00b7e2f6c17083b7c72555f5a366c9ff8c673
An empty stack is a SCRIPT_ERR_EVAL_FALSE, yes?
An empty stack is a
SCRIPT_ERR_EVAL_FALSE, yes?
No, it's SCRIPT_ERR_CLEANSTACK.
That's actually the point of this change :) Relevant line: https://github.com/bitcoin/bitcoin/blob/1b313cacc99a1b372238f9036abed5491f9d28f7/src/script/interpreter.cpp#L1519-L1522
@darosior
I meant to clarify that, if we want a clean stack (i.e. script flag SCRIPT_VERIFY_CLEANSTACK), we want to end up with 1 item exactly.
We never want 0 items, as that would be a SCRIPT_ERR_EVAL_FALSE.
I wouldn't ACK without thinking there's a point :)
75 | @@ -76,7 +76,7 @@ std::string ScriptErrorString(const ScriptError serror) 76 | case SCRIPT_ERR_PUBKEYTYPE: 77 | return "Public key is neither compressed or uncompressed"; 78 | case SCRIPT_ERR_CLEANSTACK: 79 | - return "Extra items left on stack after execution"; 80 | + return "Stack size must be one after execution";
since this is trivial change anyways, maybe "must be exactly one", somehow reads better to me
Agreed. This sounds better.
ACK https://github.com/bitcoin/bitcoin/commit/c2f00b7e2f6c17083b7c72555f5a366c9ff8c673
An empty stack is a
SCRIPT_ERR_EVAL_FALSE, yes?
That was also my initial thought. After digging deeper into the VerifyScript() function though I think this is only true for native txs (w/o SegWit). With SegWit involved, in the following part, in the function ExecuteWitnessScript() it could happen that after running the witness script the stack is empty, but still SCRIPT_ERR_CLEANSTACK is thrown:
Don't know though if that is intended or it was just forgotten to implicitely check for empty and return SCRIPT_ERR_EVAL_FALSE in this place. (For practical matters it shouldn't make a difference, in any case the script fails).
Error messages in cleanstack is misleading as
it lets the user believe that there are extra
elements on stack which is incorrect if the
stack is empty.
For context, I believe the current behavior is:
I'm ok with this PR as is, but perhaps it's more insightful to split up the two cases entirely, and give them separate error codes?
@sipa if we do that might as well do minimalif too and any others similar
@instagibbs I don't think there are any others like that currently. Splitting out the consensus-defined MINIMALIF behavior in #19953 into a separate error code does make sense.
filed an issue in case someone wants to do it later(or sanket now if he wants)
re-ACK af57766182013e17c23245671a33463f754ccd28
re ACK af57766182013e17c23245671a33463f754ccd28