(1) I can't figure out whether the data in OP_RETURN can be an arbitrary data with any format or or should it be formatted properly as a script. So when reading the transaction would it fail if it is not a proper script or ignored?
For example can the PubkeyScript be the following:
6a20
or should the "data" which is 0x20 here also be correctly formatted like this:
6a0120
The difference between the two is that the first one, if read as a script, tells you push 0x20 byte data but has no data afterwards. The second one, if read as a script, tells you to push 0x01 byte and is followed by a single byte (0x20).
(2) If it is being interpreted as a proper script, can it contain any script code or are there limitations? (I do realize the script won't run since it is OP_RETURN!).
Is this example valid? (contains OP_DUP and OP_SHA1 after the PUSHDATA):
6a012076a7
(3) Also is there anywhere I could see all the changes to OP_RETURN rules, any historical limits including but not limited to size?
Hi,
to answer the first question, correct answer is the second one.
Here is an OP_RETURN I made on the testnet, that "stores" a hash (32 bytes), you can see that the OP_RETURN opcode (6a) is followed by the OP_PUSHDATA32 (20, which is 32 in hex), and then the 32 bytes.
to answer the second question, yes. For instance there is a byte (the last one) which value is 0x65 in my example above. If it was interpreted (no OP_PUSHDATA before) the VM would do an OP_VERIF.
to answer the third one, here are some links :
https://bitcoin.stackexchange.com/questions/50414/what-was-the-very-initial-value-of-op-return/50416#50416 (funny answer from Nick O'Dell ^^)
https://bitcoinfoundation.org/core-development-update-5/ (OP_RETURN becames standard)
https://github.com/bitcoin/bitcoin/pull/3737 (80 to 40 bytes)