1

I'm looking for the clearest way to check whether the top element of the stack is numeric or not.

Thank you in advance

1

The best way that I know is quite involved because bitcoin-core standardness rules around Minimal representation of script ints. If you really need to do this, I can add detail in an updated answer.

Execution vs Satisfaction:

But in almost all cases, you should never really need to check such a thing. Recall that Bitcoin Script satisfaction requires Script executes successfully. At the end of the day, we are not interested in what is execution result, we are interested in whether the witness is valid or not. And the user redeeming the coins knows whether the pushed number is ScriptInt or not, they are let the interpreter know via additional boolean input.

Previous Code: where stack top is element `e`
OP_ISTOPNUMERIC # hypothetical that pushes 1 or 0 onto the stack top
OP_IF 
    <process_num>
OP_ELSE
    <something_else>
OP_ENDIF

can be read written equivalently with two user input elements [e, e_is_num] where e_is_num is at stack top denoting whether e is numeric or not.

New code: with stack as `[e, e_is_num]`
OP_IF 
    <process_num>
OP_ELSE
    <something_else>
OP_ENDIF

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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