Bitcoin Forum
August 11, 2020, 04:49:11 AM *
News: Latest Bitcoin Core release: 0.20.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Is the "data" after OP_RETURN strictly a script?  (Read 141 times)
Coding Enthusiast
Legendary
*
Offline Offline

Activity: 811
Merit: 1567


Bitcoin and C♯ Enthusiast


View Profile WWW
April 09, 2019, 10:16:16 AM
Merited by Welsh (5), d5000 (1), ETFbitcoin (1), HeRetiK (1)
 #1

(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?

Projects List+Suggestion box
Donate: 1Q9s or bc1q
|
|
|
FinderOuter(0.4.1)Ann-git
Denovo(0.0.0)Ann-git
Bitcoin.Net(0.4.2)Ann-git
|
|
|
BitcoinTransactionTool(0.11.0)Ann-git
WatchOnlyBitcoinWallet(3.2.1)Ann-git
SharpPusher(0.10.0)Ann-git
1597121351
Hero Member
*
Offline Offline

Posts: 1597121351

View Profile Personal Message (Offline)

Ignore
1597121351
Reply with quote  #2

1597121351
Report to moderator
100% First Deposit Bonus Instant Withdrawals Best Odds 10+ Sports Since 2014 No KYC Asked Play Now
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction. Advertise here.
1597121351
Hero Member
*
Offline Offline

Posts: 1597121351

View Profile Personal Message (Offline)

Ignore
1597121351
Reply with quote  #2

1597121351
Report to moderator
1597121351
Hero Member
*
Offline Offline

Posts: 1597121351

View Profile Personal Message (Offline)

Ignore
1597121351
Reply with quote  #2

1597121351
Report to moderator
darosior
Sr. Member
****
Offline Offline

Activity: 268
Merit: 413



View Profile WWW
April 09, 2019, 11:10:54 AM
Last edit: April 09, 2019, 11:23:13 AM by darosior
Merited by ETFbitcoin (1), Coding Enthusiast (1)
 #2

(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)

Coding Enthusiast
Legendary
*
Offline Offline

Activity: 811
Merit: 1567


Bitcoin and C♯ Enthusiast


View Profile WWW
April 09, 2019, 12:10:18 PM
 #3


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!

Projects List+Suggestion box
Donate: 1Q9s or bc1q
|
|
|
FinderOuter(0.4.1)Ann-git
Denovo(0.0.0)Ann-git
Bitcoin.Net(0.4.2)Ann-git
|
|
|
BitcoinTransactionTool(0.11.0)Ann-git
WatchOnlyBitcoinWallet(3.2.1)Ann-git
SharpPusher(0.10.0)Ann-git
achow101
Moderator
Legendary
*
expert
Offline Offline

Activity: 2212
Merit: 3413


bc1qshxkrpe4arppq89fpzm6c0tpdvx5cfkve2c8kl


View Profile WWW
April 09, 2019, 02:52:29 PM
Merited by Welsh (6), bones261 (2), Coding Enthusiast (2), darosior (2), ETFbitcoin (1)
 #4

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.

darosior
Sr. Member
****
Offline Offline

Activity: 268
Merit: 413



View Profile WWW
April 09, 2019, 04:02:40 PM
 #5


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.

Pages: [1]
  Print  
 
Jump to:  

Sponsored by , a Bitcoin-accepting VPN.
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!