5

When using OP_PUSHDATAs in different Scripts, how are the next bytes denoting the amount of bytes to be pushed encoded? Are they to be treated as unsigned integer, or signed (like the data that is taken from the stack?)? Are they big endian, or little endian?

OP_PUSHDATA1    76  0x4c    (special)   data    The next byte contains the number of bytes to be pushed onto the stack.
OP_PUSHDATA2    77  0x4d    (special)   data    The next two bytes contain the number of bytes to be pushed onto the stack.
OP_PUSHDATA4    78  0x4e    (special)   data    The next four bytes contain the number of bytes to be pushed onto the stack.
7

Little endian.

See, for example, the script_PushData unit test in the source tree that pushes one 0x5a byte onto the stack 4 different ways:

// Check that PUSHDATA1, PUSHDATA2, and PUSHDATA4 create the same value on                                                                
// the stack as the 1-75 opcodes do.                                                                                                      
static const unsigned char direct[] = { 1, 0x5a };
static const unsigned char pushdata1[] = { OP_PUSHDATA1, 1, 0x5a };
static const unsigned char pushdata2[] = { OP_PUSHDATA2, 1, 0, 0x5a };
static const unsigned char pushdata4[] = { OP_PUSHDATA4, 1, 0, 0, 0, 0x5a };

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.