jb55 / btcs

bitcoin script parser/evaluator/compiler/decoder
BSD 2-Clause "Simplified" License
14 stars 7 forks source link

stack_hex not displaying correctly when stack contains the number 0 #41

Open ghost opened 4 years ago

ghost commented 4 years ago

examples:

script      0 OP_NOT
script_hex  0091
stack       1
stack_hex   01
results     success

script      1 OP_NOT
script_hex  5191
stack       0
stack_hex                                {missing 00}
results     success

script      0 0 OP_SUB
script_hex  000094
stack       0
stack_hex                                {missing 00}
results     success

script      1 0 OP_SUB
script_hex  510094
stack       1
stack_hex   01
results     success

script      127 0 127 1
script_hex  017f00017f51
stack       0x7f 0x 0x7f 1                {0x?}
stack_hex   7f7f01                        {missing 00}
results     success
jb55 commented 4 years ago

Thanks! I probably don't have time to look into this anytime soon. Let me know if you figure it out :)

ghost commented 4 years ago

Seems to be two issues:

  1. sn_serialize does not serialize the number zero. Easy fix.
  2. OP_0 is represented on the stack as an empty item, (not the number 0). According to the documentation that is OK. Empty stack items are shown as 0x in stack output which seems like an accident; not shown in stack_hex at all. Perhaps an empty array could be displayed as [] in both cases?

Documentation: https://en.bitcoin.it/wiki/Script OP_0, OP_FALSE An empty array of bytes is pushed onto the stack. (This is not a no-op: an item is added to the stack.)

jb55 commented 4 years ago

Perhaps an empty array could be displayed as [] in both cases?

sounds good to me!