Author

Topic: Is the "data" after OP_RETURN strictly a script? (Read 182 times)

sr. member
Activity: 279
Merit: 435

Thanks but I was hoping for a bit more than just what you could find on Google. For example most validation stuff seems to be happening in validation.cpp but I can't find anything related to my question and I always have a hard time reading c++ code so I don't even know if I'm in the right place or not!
Links I gave you were not the top 3 links of a "OP_RETURN" google search, but what I thought was helpful to your question. You asked for
Also is there anywhere I could see all the changes to OP_RETURN rules, any historical limits including but not limited to size?
so I gave you two links about changes to OP_RETURN rules (standardization) and historical limits including but not limited to size (the PR that made the allowed size from 80 to 40 bytes). Moreover it was not the most important part of the answer.
staff
Activity: 3458
Merit: 6793
Just writing some code
OP_RETURN exits script execution early, so you can have any arbitrary data following it. In fact, you can have any arbitrary data in an output script since output scripts are not executed until they are spent.

However there are standardness rules that you need to follow if you want your transaction to be relayed. The standardness rules for OP_RETURN require that what follows an OP_RETURN is a script which only pushes data. It can be any number of OP_PUSHDATAs, it just has to be only OP_PUSHDATA opcodes.
legendary
Activity: 1042
Merit: 2805
Bitcoin and C♯ Enthusiast

Thanks but I was hoping for a bit more than just what you could find on Google. For example most validation stuff seems to be happening in validation.cpp but I can't find anything related to my question and I always have a hard time reading c++ code so I don't even know if I'm in the right place or not!
sr. member
Activity: 279
Merit: 435
(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:
Code:
6a20
or should the "data" which is 0x20 here also be correctly formatted like this:
Code:
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):
Code:
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)
legendary
Activity: 1042
Merit: 2805
Bitcoin and C♯ Enthusiast
(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:
Code:
6a20
or should the "data" which is 0x20 here also be correctly formatted like this:
Code:
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):
Code:
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?
Jump to: