OP_RETURN

Revision as of 23:36, 9 January 2020 by Brendan (talk | contribs)

OP_RETURN is a script opcode used to end 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.

In 2010 an exploit was discovered in Bitcoin where users could steal anyone's funds leveraging the OP_RETURN opcode. Satoshi Nakamoto modified the opcode to always return false as an urgent fix.

Storing data on-chain

Due to the functionality of this opcode being modified to always return false instead of the top value on the stack, nodes do not validate any opcodes or data in the script after the OP_RETURN.

The max script size was limited to 520 bytes in the Bitcoin client early on (possibly as a justification to prevent DoS attacks), rendering the OP_PUSHDATA opcodes useless. Thus, users of the network leveraged this opcode to store arbitrary data in scripts.

Return of OP_RETURN

The 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 an 'OP_RETURN output' is no longer the only means of adding data into a transaction.