Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: Cryddit on April 01, 2014, 03:05:10 AM



Title: redundant opcodes in script?
Post by: Cryddit on April 01, 2014, 03:05:10 AM

Script has unnamed opcodes from 0x01 to 0x4b whose semantics are that the values are simply pushed onto the stack.

Then it has OP_1 (aka OP_TRUE) through OP_16 from 0x51 through Ox60 whose semantics are that the values from 1 to 16 (a subrange of the above) are pushed onto the stack. 

0x51 through 0x60 repeat exactly the semantics of 0x01 through 0x10.

What is the rationale for not having simply given the names OP_1 through OP_16 to the codes 0x01 through 0x10?  Would anything work differently if the 0x51 through 0x60 range were reserved and completely unused? 

Cryddit


Title: Re: redundant opcodes in script?
Post by: uminatsu on April 01, 2014, 03:26:57 AM
The semantics are different. 0x53 pushes numer "3" while 0x03 indicates that the 3 bytes following it are pushed as one entity.


Title: Re: redundant opcodes in script?
Post by: Cryddit on April 01, 2014, 03:45:34 AM
No...  I'm looking straight at the code now.

0x03 and 0x53 both push the value '3' onto the stack.  They are the same.

0x4d aka OP_PUSHDATA2 means 'the next 2 bytes contain a number of following bytes to be pushed onto the stack' and 0x04e aka OP_PUSHDATA4 is the same thing for 4 bytes. 

If you wanted to push a 3-byte number onto the stack as a unit, you'd write

OP_PUSHDATA1, 0x03, DATA1, DATA2, DATA3





Title: Re: redundant opcodes in script?
Post by: etotheipi on April 01, 2014, 04:04:50 AM
no, 0x03 says "the next three bytes will be pushed onto the stack as a single object", then it reads and pushes those three bytes... the 3 itself is not pushed.


Title: Re: redundant opcodes in script?
Post by: Cryddit on April 01, 2014, 04:45:44 AM
Hrm.

On closer inspection of what the code actually does, you are right and the comment I was looking at is wrong. 

Thank you. 




Title: Re: redundant opcodes in script?
Post by: instagibbs on April 01, 2014, 06:41:09 PM
Glad it got figured out. The opcodes section can be quite confusing. Hopefully the Dev Guide ends up being clearer.

The multisig scenario is where this shows itself: Before each key in the script you have to append 0x21(push the 40 byte pub key on the stack) and when choosing m-of-n you use 0x51~whatever.