-
Notifications
You must be signed in to change notification settings - Fork 62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[feat] Implement OP_SUB opcode #26
Conversation
Thanks for looking into this! So the stack values for arithmetic operations are i32, but they will be represented as i64 to be safe in cases of overflow. You can see more info here from btcd : https://github.com/btcsuite/btcd/blob/b161cd6a199b4e35acec66afc5aad221f05fe1e3/txscript/scriptnum.go#L32 I can look more at this error it is giving you soon, but if you want to try and dig deeper, I think we might need to implement this function from btcd to handle cases of negative numbers : https://github.com/btcsuite/btcd/blob/b161cd6a199b4e35acec66afc5aad221f05fe1e3/txscript/scriptnum.go#L105 |
@b-j-roberts thanks, now I understand why we use i64 It seems indeed this function will be required |
Would you be interested in implementing that function and making any other required changes to get this working? If not, I'll try and get someone on it asap |
Yeah I can work on it |
@b-j-roberts just implemented the Needed changes in tests because the formatting of the stack is now different, doesnt appear with 8 elements all the time, just like the Go comment here:
|
Hi @b-j-roberts
I also added
OP_2
opcode for testing.I have 2 questions:
i32
noti64
, is it normal that we usei64
?https://en.bitcoin.it/wiki/Script
wiki says : "Note: Arithmetic inputs are limited to signed 32-bit integers, but may overflow their output."
this is why I tested the
OP_SUB
for1 - 1
2 - 1
1 - 2
in the last case, i guess an overflow is supposed to happen and return
-1
, currently represented as ai64
But as you can see in test, i get an unwrap error, related to the
assert_eq!
usage on the last line. is it an issue with the macro? but it should work and print the result right?when i print the ByteArray that will be added to the
ScriptStack
, i get this :