In data files, an input script of a transaction appears to be in this form:

[funky byte 1][signature][funky byte 2][public key]

Bitcoind displays an input script in this shape:

[signature][blank space][public key]

My questions are:

1. In general, how should I parse an input script?

2. What are the funky bytes?

3. How should I interpret/recognize the funky bytes during parsing?


The funky bytes, as you call them, are data-pushing op codes. The wiki has a complete list of op codes.

For example, the op code before a signature is probably OP_71 (0x47) which pushes 71 bytes to the stack as data. Without these data-pushing codes, there would be no way for Bitcoin to tell the difference between an arbitrary sequence of bytes (such as a signature) and op codes which need to be evaluated.

Parsing is simple:

  1. The first byte is an op code. Read it and do what it says. If it's a data-pushing op code, read that many more bytes and push them onto the stack as data.

  2. The next byte after that is an op code. Read it and do what it says. Repeat until all bytes have been processed.

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.