1

On bitcoin wiki site I cant found this specification:

*The stacks hold byte vectors. When used as numbers, byte vectors are interpreted as little-endian variable-length integers with the most significant bit determining the sign of the integer. Thus 0x81 represents -1. 0x80 is another representation of zero (so called negative 0). Positive 0 is represented by a null-length vector. Byte vectors are interpreted as Booleans where False is represented by any representation of zero, and True is represented by any representation of non-zero. *

https://en.bitcoin.it/wiki/Script

But on bitcoins source code test scripts I have found this:

["0x02 0x417a", "'Az' EQUAL", "P2SH,STRICTENC"],

["0x4b 0x417a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a",
"'Azzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz' EQUAL", "P2SH,STRICTENC", "push 75 bytes"],

https://github.com/bitcoin/bitcoin/blob/master/src/test/data/script_valid.json#L26

So, as I understand this is test for script module of bitcoin core, and this few tests put numbers into stack, then put byte string into stack and process EQUAL opcode. But in case if numbers should stored in stack as little endian variable int with sign bit (bitcoin wiki) number 0x417a is stored as b'zA' and not as 'Az'.

Number 0x417a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a

will be

zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzA

What type of numbers representation in stack we have to use?

  • varint little endian with sign bit ? (bitcoin wiki)
  • big endian ?
  • 4 byte big endian ? (found on bitcoin source codes class CScriptNum github.com/bitcoin/bitcoin/blob/master/src/script/script.h#L187)

Where I can read exactly specification ?

Thank you

Nick ODell
  • 29,184
  • 11
  • 69
  • 129
bitaps.com
  • 649
  • 4
  • 14
  • 1
    It's not interpreted as a number in the example you give, because you're using OP_EQUAL, not OP_NUMEQUAL. The encoding for numbers doesn't enter into it at all. – Nick ODell Aug 02 '15 at 21:41
  • This is a really good example of how OP_EQUAL and OP_NUMEQUAL differ: https://github.com/bitcoin/bitcoin/blob/master/src/test/data/script_valid.json#L372 – Nick ODell Aug 02 '15 at 21:44
  • Thank you for quick reply, could you tell me what excatly format of integer numbers using in stack in case if using opcodes works with numbers? Is the correct specification on bitcoin wiki? – bitaps.com Aug 02 '15 at 21:49
  • https://github.com/richardkiss/pycoin/blob/master/pycoin/intbytes.py using BIG endian unsigned format ( I think its wrong) – bitaps.com Aug 02 '15 at 21:51
  • https://github.com/petertodd/python-bitcoinlib/blob/master/bitcoin/core/_bignum.py using little endian varing with sign bit like on bitwiki . Is this correct? – bitaps.com Aug 02 '15 at 21:52

0 Answers0