Difference between revisions of "OP RETURN"

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 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]].
 
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.
 
 
=== Return to original functionality ===
 
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.
 
 
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.
 
 
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.
 
  
 
===OP_RETURN Functionality===
 
===OP_RETURN Functionality===

Revision as of 08:23, 22 January 2020

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 a controversial history in Bitcoin and as a result has been primarily used as a means of storing data on the blockchain.

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. OP_RETURN can be used in combination with flow control opcodes to implement branching, conditional logic in scripts.

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>