Difference between revisions of "OP RETURN"

 
(10 intermediate revisions by 2 users not shown)
Line 1: Line 1:
'''OP_RETURN''' is a [[Opcodes_used_in_Bitcoin_Script|script]] opcode used to terminate the script and return the top value on the stack. This opcode is analogous to the return function in programming languages. The OP_RETURN opcode has a [[History_of_OP_RETURN|controversial history]] in Bitcoin and as a result has been primarily used as a means of storing data on the [[block_chain|blockchain]].
+
'''OP_RETURN''' is a [[Opcodes_used_in_Bitcoin_Script|script]] opcode used to terminate the script and return the top value on the stack. This opcode is analogous to the return function in programming languages. The OP_RETURN opcode has seen its functionality modified several times in its [[History_of_OP_RETURN|history]] in Bitcoin and as a result, has been primarily used as a means of storing data on the ledger.
  
In 2010 an exploit was discovered in Bitcoin where users could steal anyone's funds leveraging the OP_RETURN opcode. [[Satoshi_Nakamoto|Satoshi Nakamoto]] modified the opcode to always return false as an urgent fix.
+
===OP_RETURN Functionality===
 +
OP_RETURN terminates the script leaving the stack as-is and letting the result on top of the stack determine the success or failure of the script. Note that if the top stack is non-empty and non-zero (zero including a string of zeros, of zero bytes), then it is considered as successful. Otherwise, it is considered as fail.
  
=== Return to original functionality ===
+
=== False Return ===
The [[Genesis_upgrade|Genesis upgrade]] in February 2020 restores the original functionality of the opcode. This will not impact the ability to store arbitrary data on-chain, and it is advised to now use [[False Return]] scripts for applications that still seek to do so.  
+
One of the most common uses of OP_RETURN is to create [[False Return]] scripts that can be used to generate provably unspendable transaction outputs. The most common usage of these scripts is to hold arbitrary formatted data for use in [[Application Layer Protocols]]. False Return outputs can be used to hold data, information pertaining to ownership rights, software elements, art and more.
  
The Genesis upgrade essentially re-enables the original functionality of the push data opcodes via lifting the maximum transaction size such that using a so-called 'OP_RETURN output' is no longer the only means of adding large data items such as JSON formatted text or images into a transaction.  
+
=== Use in conditional logic ===
 +
OP_RETURN can be used in combination with [[Opcodes_used_in_Bitcoin_Script#Flow_control|flow control]] opcodes to implement branching and other conditional logic in scripts. The insertion of an OP_RETURN opcode in an IF loop, can allow a script to terminate without having to exit the IF loop, saving computation and reducing the cost of processing the transaction.
  
Reverting to the ability to return a value will enable more robust scripts to be created; for example scripts can now return different values based on conditional logic.
+
=== Commentary: Is storing data in the blockchain acceptable? ===
 
+
In a word, yes. The Bitcoin ledger and the [[blockchain]] that secures it, operate on the free market premise of user pays. If a user wishes to use the ledger to store data of any type, the only requirement upon them is they must pay for the space needed to store it.
===OP_RETURN Functionality===
+
This mechanism guards the ledger from abuse by allowing node operators to set a floor in the price of ledger space, while also allowing nodes to compete to provide users with lower cost services.
OP_RETURN terminates the script leaving the stack as-is and letting the result on top of the stack determine the success or failure of the script. OP_RETURN can be used in combination with [[Opcodes_used_in_Bitcoin_Script#Flow_control|flow control]] opcodes to implement branching, conditional logic in scripts.
+
It is node operators who decide which transactions they will accept into the blocks they append to the blockchain, and as such anyone seeking to use the ledger as a data storage medium, must meet the market in terms of the price they pay. Over time it is expected that the cost of ledger space will fall, not just in terms of the price in [[satoshis]], but in dollar terms as well. The ledger scales with technology and commensurate falls in price that comes with the unlocking of new and lower cost storage media, which will translate to larger swathes of ledger space becoming available for less fees.
  
 
===Example===  
 
===Example===  
The below script is a metanet node that attaches the Metanet data to a UTXO with funds. This can be used to ensure that metanet nodes are left in the UTXO set
+
The below script is a Metanet node that attaches the Metanet data to a UTXO with funds. This can be used to ensure that Metanet nodes are left in the UTXO set.
  
 
{| class="wikitable"  
 
{| class="wikitable"  
 
|-
 
|-
!  colspan="2" 𝑇𝑥𝐼𝐷<sub>𝑛𝑜𝑑𝑒</sub>
+
!  colspan="2"| 𝑇𝑥𝐼𝐷<sub>𝑛𝑜𝑑𝑒</sub>
 
|-
 
|-
 
| ''Inputs''
 
| ''Inputs''
Line 24: Line 26:
 
|-
 
|-
 
| <sig<sub>metaParent</sub>> <pubKey<sub>metaParent</sub>> <sig<sub>script</sub>> <pubKey<sub>script</sub>>  
 
| <sig<sub>metaParent</sub>> <pubKey<sub>metaParent</sub>> <sig<sub>script</sub>> <pubKey<sub>script</sub>>  
| DUP HASH160 <pkh<sub>script</sub>> EQUALVERIFY CHECKSIG RETURN <meta> <pk<sub>metaNode</sub>> <txid<sub>metaParent</sub>> <data>
+
| DUP HASH160 <pkh<sub>script</sub>> EQUALVERIFY CHECKSIG RETURN <meta> <pk<sub>metaNode</sub>> <txid<sub>metaParent</sub>> <metanetData>
 
|}
 
|}
  
 
{{DISPLAYTITLE:OP_RETURN}}
 
{{DISPLAYTITLE:OP_RETURN}}

Latest revision as of 01:52, 11 January 2022

OP_RETURN is a script opcode used to terminate the script and return the top value on the stack. This opcode is analogous to the return function in programming languages. The OP_RETURN opcode has seen its functionality modified several times in its history in Bitcoin and as a result, has been primarily used as a means of storing data on the ledger.

OP_RETURN Functionality

OP_RETURN terminates the script leaving the stack as-is and letting the result on top of the stack determine the success or failure of the script. Note that if the top stack is non-empty and non-zero (zero including a string of zeros, of zero bytes), then it is considered as successful. Otherwise, it is considered as fail.

False Return

One of the most common uses of OP_RETURN is to create False Return scripts that can be used to generate provably unspendable transaction outputs. The most common usage of these scripts is to hold arbitrary formatted data for use in Application Layer Protocols. False Return outputs can be used to hold data, information pertaining to ownership rights, software elements, art and more.

Use in conditional logic

OP_RETURN can be used in combination with flow control opcodes to implement branching and other conditional logic in scripts. The insertion of an OP_RETURN opcode in an IF loop, can allow a script to terminate without having to exit the IF loop, saving computation and reducing the cost of processing the transaction.

Commentary: Is storing data in the blockchain acceptable?

In a word, yes. The Bitcoin ledger and the blockchain that secures it, operate on the free market premise of user pays. If a user wishes to use the ledger to store data of any type, the only requirement upon them is they must pay for the space needed to store it. This mechanism guards the ledger from abuse by allowing node operators to set a floor in the price of ledger space, while also allowing nodes to compete to provide users with lower cost services. It is node operators who decide which transactions they will accept into the blocks they append to the blockchain, and as such anyone seeking to use the ledger as a data storage medium, must meet the market in terms of the price they pay. Over time it is expected that the cost of ledger space will fall, not just in terms of the price in satoshis, but in dollar terms as well. The ledger scales with technology and commensurate falls in price that comes with the unlocking of new and lower cost storage media, which will translate to larger swathes of ledger space becoming available for less fees.

Example

The below script is a Metanet node that attaches the Metanet data to a UTXO with funds. This can be used to ensure that Metanet nodes are left in the UTXO set.

𝑇𝑥𝐼𝐷𝑛𝑜𝑑𝑒
Inputs Outputs
<sigmetaParent> <pubKeymetaParent> <sigscript> <pubKeyscript> DUP HASH160 <pkhscript> EQUALVERIFY CHECKSIG RETURN <meta> <pkmetaNode> <txidmetaParent> <metanetData>