When executing bitcoin validation scripts, does the final stack have to end with just true on the stack, or can there be some elements under the true? In other words, are both of these final stack configurations valid, or just the first?




0 {pub_key} true

1 Answer 1


Quoting Bitcoin wiki:

A transaction is valid if nothing in the combined script triggers failure and the top stack item is true (non-zero).

From the source code:

if (CastToBool(stack.back()) == false)
    return false;

(In case you don't know what vector.back() does, it returns the last item.)

  • 1
    They really coded up == false?
    – djechlin
    Oct 26, 2014 at 15:42
  • @djechlin CastToBool only returns true or false.
    – Nick ODell
    Oct 26, 2014 at 15:43
  • I think djechlin was surprised they didn't do if (!Cast... Or just return CastTo...
    – morsecoder
    Oct 26, 2014 at 17:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.