Hi everyone, a new update:
This version of 64bit arithmetic
- Removes 64bit specific opcodes in favor repurposing existing opcodes (
OP_ADD64→OP_ADD,OP_SUB64→OP_SUB,OP_MUL64→OP_MUL,OP_DIV64→OP_DIVetc). - Every opcode in
interpreter.cppthat use to accept aCScriptNuminput now accepts aint64_tstack parameter. For instance,OP_1ADDaccepts aint64_tstack top argument, and pushes aint64_tback onto the stack along with a bool indicating if theOP_1ADDexecution was successful. - Removes casting opcodes (
OP_SCRIPTNUMTOLE64,OP_LE64TOSCRIPTNUM,OP_LE32TOLE64)
I think this PR provides for a better developer experience as Script developers
- No longer have to think about which opcode to use (
OP_ADDorOP_ADD64,OP_LESSTHANorOP_LESSTHAN64, etc) - No longer have to worry about casting the stack top with previous casting op codes (
OP_SCRIPTNUMTOLE64,OP_LE64TOSCRIPTNUM,OP_LE32TOLE64)
This 64bit implementation would mean existing Scripts that typically use constant numeric arguments – such as OP_CHECKLOCKTIMEVERIFY/OP_CHECKSEQUENCEVERIFY would need to be rewritten to pass in 8 byte parameters rather than 5 byte parameters.
This PR heavily relies on pattern matching on SigVersion to determine what the implementation of the opcode should do.
For instance, here is the implementation of OP_DEPTH
In the future, if we want to redefine semantics of OP_DEPTH we can now pattern match on the SigVersion and substitute the new implementation.
I think this provides us a nice framework for upgrading the interpreter in the future. We will have the compiler give errors in places where we aren’t handling a new SigVersion introduced in the codebase (exhaustiveness checks), and force us to handle that case.