What is the functional purpose special case in ASM? #13085

issue tiger5226 opened this issue on April 26, 2018
  1. tiger5226 commented at 12:27 AM on April 26, 2018: none

    https://github.com/bitcoin/bitcoin/blob/master/src/core_write.cpp#L95

    Looking here the ASM will convert byte arrays of 4 or less to an integer. Specifically a 4 byte array is converted to little endian instead of hexstr for example. So if the 4 bytes is "cats" the ASM will output 1937006947.

    So I am more interested in why this is in bitcoin and what functional purpose this serves?

  2. achow101 commented at 1:45 AM on April 26, 2018: member

    Looking here the ASM will convert byte arrays of 4 or less to an integer

    That is not at all what this does. This is not a special case at all, nor is it specific to the ASM conversion, it is how scripts work.

    Firstly, OP_PUSHDATA4 does not mean that a 4 byte array is to pushed to the stack. OP_PUSHDATA4 means that the next 4 bytes should be interpreted as an integer which indicates the size of the next piece of data that will be pushed to the stack. ALL opcodes less than OP_PUSHDATA4 indicate the size of the next piece of data to be pushed to the stack. For all opcodes less than OP_PUSHDATA1, the single byte is the length of the data itself. For OP_PUSHDATA1, the next 1 byte indicates the size. Same for OP_PUSHDATA2 and OP_PUSHDATA4.

    If you wanted to have a 4 byte array with the string "cats", you would actually have 5 bytes, the first being 04 which indicates the length of the data and then the 4 bytes of data itself. You never just have data in a script without a length prefix.

    This is not an issue with Bitcoin Core and such questions should be asked elsewhere such as on bitcoin.stackexchange.com.

  3. kaykurokawa commented at 2:05 AM on April 26, 2018: none

    I think what he is asking is why does the size of vch determine whether vch is rendered as an integer as opposed to a hex string by https://github.com/bitcoin/bitcoin/blob/master/src/core_write.cpp#L95

    If I'm understanding the code correctly vch are the exact bytes being pushed onto the stack, not the number of bytes that are being pushed on to the stack.

  4. sipa commented at 2:11 AM on April 26, 2018: member

    Short pushes are usually small numbers, for use as counts in multisig or as timestamps for locktime checks. As humans prefer decimals for integers, and the asm format is for human consumption, it gets printed that way.

  5. sipa closed this on Apr 26, 2018

  6. sipa commented at 2:12 AM on April 26, 2018: member

    Please post future questions like this on bitcoin.stackexchange.com. This is not a support site.

  7. MarcoFalke locked this on Sep 8, 2021

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-13 21:15 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me