OP_RETURN

Revision as of 02:06, 1 December 2020 by Brendan (talk | contribs)
(diff) โ† Older revision | Latest revision (diff) | Newer revision โ†’ (diff)

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 block chain 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 block chain, 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>