Bitcoin Forum
May 26, 2019, 12:39:09 AM *
News: Latest Bitcoin Core release: 0.18.0 [Torrent] (New!)
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Is the "data" after OP_RETURN strictly a script?  (Read 105 times)
Coding Enthusiast
Hero Member
*****
Offline Offline

Activity: 626
Merit: 856


Novice C♯ Coder


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
Donation link using BIP21
Bech32 Donation link!
BitcoinTransactionTool (0.9.2):  Ann - Source Code
Watch Only Bitcoin Wallet (supporting SegWit) (3.1.0):  Ann - Source Code
SharpPusher (broadcast transactions) (0.10.0): Ann - Source Code

1558831149
Hero Member
*
Offline Offline

Posts: 1558831149

View Profile Personal Message (Offline)

Ignore
1558831149
Reply with quote  #2

1558831149
Report to moderator
1558831149
Hero Member
*
Offline Offline

Posts: 1558831149

View Profile Personal Message (Offline)

Ignore
1558831149
Reply with quote  #2

1558831149
Report to moderator
PLAY OVER 3000 GAMES
LIGHTNING FAST WITHDRAWALS
PLAY NOW
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction. Advertise here.
1558831149
Hero Member
*
Offline Offline

Posts: 1558831149

View Profile Personal Message (Offline)

Ignore
1558831149
Reply with quote  #2

1558831149
Report to moderator
1558831149
Hero Member
*
Offline Offline

Posts: 1558831149

View Profile Personal Message (Offline)

Ignore
1558831149
Reply with quote  #2

1558831149
Report to moderator
darosior
Full Member
***
Offline Offline

Activity: 171
Merit: 177



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)

Github profile ~ Crypto Lyon (french community)  ~ GPG key fingerprint : E13F C145 CD3F 430 ~ LN public key : 03678b4f041fbfbeebcafc076469df75decf81da20a53bd490172e83ce532df1fa
Tutorials/posts : Address from private keyBitcoin smart contracts ~ Setup a Bitcoin node ~ Raw P2PKH transaction in Python ~ P2SH ~ 51% attack
Coding Enthusiast
Hero Member
*****
Offline Offline

Activity: 626
Merit: 856


Novice C♯ Coder


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
Donation link using BIP21
Bech32 Donation link!
BitcoinTransactionTool (0.9.2):  Ann - Source Code
Watch Only Bitcoin Wallet (supporting SegWit) (3.1.0):  Ann - Source Code
SharpPusher (broadcast transactions) (0.10.0): Ann - Source Code

achow101
Moderator
Legendary
*
expert
Offline Offline

Activity: 1778
Merit: 2401


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
Full Member
***
Offline Offline

Activity: 171
Merit: 177



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.

Github profile ~ Crypto Lyon (french community)  ~ GPG key fingerprint : E13F C145 CD3F 430 ~ LN public key : 03678b4f041fbfbeebcafc076469df75decf81da20a53bd490172e83ce532df1fa
Tutorials/posts : Address from private keyBitcoin smart contracts ~ Setup a Bitcoin node ~ Raw P2PKH transaction in Python ~ P2SH ~ 51% attack
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!