From BIP62 I would expect to use OP_PUSHDATA1
followed by uint8_t:
Pushing 76 to 255 bytes must use OP_PUSHDATA1.
But then from this answer, the link to variable-length integer makes it seem that a value of 253 (0xfd) should be encoded by 0xFD followed by the length as uint16_t.
EDIT-1: Here is a dummy transaction I am trying to get to parse.
Here I have a tx with 252-byte scriptSig (all 1
s). I have fc
to encode its length and it parses:
0200000001517adf7ba2ab9fd2c514687b0774c93d87d3e959d202b66fed76782d832a94f800000000fc111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111ffffffff0280d1f008000000001976a9143bc28d6d92d9073fb5e3adf481795eaf446bceed88ac80f0fa02000000001976a914cc1b07838e387deacd0e5232e1e8b49f4c29e48488ac00000000
Then I tried adding two bytes to the start of the scriptSig (2222
) to make it 254 bytes long, and replaced the length fc
with 4cfe
(OP_PUSHDATA1
fe
), but it's not parsing anymore:
0200000001517adf7ba2ab9fd2c514687b0774c93d87d3e959d202b66fed76782d832a94f8000000004cfe2222111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111ffffffff0280d1f008000000001976a9143bc28d6d92d9073fb5e3adf481795eaf446bceed88ac80f0fa02000000001976a914cc1b07838e387deacd0e5232e1e8b49f4c29e48488ac00000000
EDIT-2: The answer is that encoding the length of the scriptSig is a varint rather than a push OP_CODE. So the correct way to get this to parse was to set the sigScript length to 0xfd
0xfe
0x00
:
0200000001517adf7ba2ab9fd2c514687b0774c93d87d3e959d202b66fed76782d832a94f800000000fdfe002222111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111ffffffff0280d1f008000000001976a9143bc28d6d92d9073fb5e3adf481795eaf446bceed88ac80f0fa02000000001976a914cc1b07838e387deacd0e5232e1e8b49f4c29e48488ac00000000