Difference between revisions of "OP RETURN"
(9 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 | + | '''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. |
− | + | ===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 | + | === 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. | |
− | The | + | === 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. | ||
− | + | === 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=== | ===Example=== | ||
− | The below script is a | + | 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" | ||
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>> < | + | | 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> |