In some documentation about Script we sometimes have to use OP_PUSHBYTESx
or OP_PUSHDATAx
to indicate that some number of bytes will be an element to read.
They seem to do the same thing so is there a reason they have different names ?
In what documentation ? I believe you are talking about how rust-bitcoin
refers to the OPs > OP_FALSE
and < OP_PUSHDATA1
and will answer as such.
There are multiple OP codes pushing bytes to the stack, defined as integers.
Special case: pushing small integers
There are dedicating OP codes for pushing integers from -1
to 16
(named OP_1NEGATE
, OP_0
and OP_1
to OP_16
and valued 0x4f
, Ox00
and 0x51
to 0x60
).
They are used for instance for (small-ish) multisigs as it saves you 1 byte per number pushed compared to using a "real" push opcode.
"PUSHBYTES
": pushing small byte arrays
The (not named in the reference implementation) OP codes valued from 0x01
to 0x4b
allow to push from 1 (0x01
) to 75 (0x4b
) bytes to the stack.
They are commonly used to push pubkeys and signatures.
PUSHADATA
: pushing byte arrays
The PUSHDATA1
, PUSHDATA2
and PUSHDATA4
(0x4c
, 0x4d
and 0x4e
) operands are used to push a byte array to the stack which size is defined as a variable-length integer .
Further: too many encodings!
This flexibility of encoding introduced malleability in the scriptSig
, which was not protected by the signature (which it carries).
BIP62 proposed to restrict this encoding to avoid possible malleation.
rust-bitcoin
refers to the OPs> OP_FALSE
and< OP_PUSHDATA1
– darosior Jan 24 at 18:53