I think this is only true for the 0-16 numbers. The moment you want to push > 16 onto the stack, you have to add the full 8-byte representation to your script.
This leads me towards thinking we should keep variable length encoding the default, as we could move to the new format without incurring extra cost.
That being said, having worked with RISC-V emulation in Bitcoin Script lately (see Eltrace), I see a real need for the ability to get the 32/64 bit LE representation of a number during script execution. That we could easily add independently of the underlying number format (OP_SCRIPTNUM[TO/FROM]LE64
), and perhaps give us all what we need without introducing full arithmetic support for another format.
I think this is an important point. The reason we want 64-bit arithmetics in the first place is to enforce values on the next transaction, and the interesting values are indeed (AFAIK) encoded using fixed-length LE (notable exception is number of inputs/outputs).
How to handle this comes down to the introspection opcodes themselves, as they can be made to put ScriptNum
on the stack if that’s what we want.
Thanks for this writeup, Rusty! I agree moving to unsigned-only values could simplify a lot of things, especially if the format is backwards compatible with the existing ScriptNum
representation for positive numbers.
By bumping the leaf version you could also re-use all existing opcodes (no OP_ADDV
etc)?