I am currently developing a blockchain parser in Python, and it has been crashing in the file blk00006.dat for the coinbase transaction with the hash afbff1130b6fcbdceebbadfc48a842af1f03ee08a79e042b37fc467518b49a0f in the block 0000000000000a46714e1b03e5e0693e9ecaa3ec1853f1cdf34e9ca52e13f1ff. The reason it was crashing is because it has an OP_PUSHDATA2 in the script signature with a value of 28265. However, there are only 21 bytes left to read according to the size of the script.

I fixed my code to avoid crashing in this script, but I am still curious about how this script_signature got accepted by the network.


Scripts are not parsed. From the protocol perspective they are byte arrays, and their contents is irrelevant for transaction deserialization.

Scripts are executed however, at the time they participate in spending. For outputs, that is when they are (attempted to be) spent. For non-coinbase inputs, that is immediately. Coinbases never participate in spending, so for almost(*) all purposes, they are just byte arrays.

(*) There are two partial exceptions to this. BIP34 requires the coinbase to start with a push of the block height. The 80000 vsigops limit also counts CHECKSIG operations in coinbases (treating them as scripts, but it stops counting at the first invalid opcode).

  • Awesome1 Thanks for the great explanation. Apr 28 '20 at 18:51

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.