Difference between revisions of "History of OP RETURN"

 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
The OP_RETURN opcode has seen historical changes to its functionality that have resulted in it being used as the primary mechanism to store arbitrary data on-chain.
+
The [[OP_RETURN]] opcode has seen historical changes to its functionality that have resulted in it being used as the primary mechanism to store arbitrary data on-chain.
  
 
Its original functionality was as a return operation that ends execution of the script prematurely, with the topmost stack item presented as the execution result.
 
Its original functionality was as a return operation that ends execution of the script prematurely, with the topmost stack item presented as the execution result.
Line 12: Line 12:
 
OP_TRUE OP_RETURN
 
OP_TRUE OP_RETURN
  
True would be returned from the script and the script would terminate, ignoring any opcodes that came afterwards; because of this, this example script could prepend any unlocking script, granting the ability for one to steal anyone's bitcoin.  
+
True would be returned from the script and the script would terminate, ignoring any opcodes that came afterwards; because of this, this example script could prepend any unlocking script, granting the ability for one to steal anyone's Bitcoin.  
  
 
The functionality of the opcode was changed to always return false instead of returning the value on top of the stack.
 
The functionality of the opcode was changed to always return false instead of returning the value on top of the stack.
  
=== Further Changes to OP_RETURN functionality ===
+
=== Further changes to OP_RETURN functionality ===
 
In Bitcoin Core's [https://bitcoin.org/en/release/v0.9.0#rebranding-to-bitcoin-core v0.9.0 update], the 'OP_RETURN output' script was made into a standard output type, allowing users to append data to unspendable transaction outputs. The amount of data usable in these scripts was first limited to 40 bytes, and then later increased to an 80 byte limit.
 
In Bitcoin Core's [https://bitcoin.org/en/release/v0.9.0#rebranding-to-bitcoin-core v0.9.0 update], the 'OP_RETURN output' script was made into a standard output type, allowing users to append data to unspendable transaction outputs. The amount of data usable in these scripts was first limited to 40 bytes, and then later increased to an 80 byte limit.
  
Line 28: Line 28:
  
 
=== OP_RETURN in BSV ===
 
=== OP_RETURN in BSV ===
When the network was transitioned to a majority of nodes running the BitcoinSV node client, the 220 byte limit was retained for a short period. Then, in January 2019, a [https://www.yours.org/content/the-unfuckening-of-op_return-b10d2c4b52da discovery] was made that because the OP_RETURN opcode terminated the script such that nodes did not validate anything after it occurred, this also meant that nodes did not check that the script did not exceed the max script size limit of 520 bytes. Communication of this went out to the miners on the network who then raised their maximum transaction size to 100KB. This enabled users to create novel implementations that put various data onto the ledger including in at least one example, an entire [https://whatsonchain.com/tx/21a5c896f23bea81ae5018dfeb8801ddc68691d0186a7e2d8c011e65e0a396d9 website].
+
For a short while after the network was transitioned to a majority of nodes running the BitcoinSV node client, the 220 byte limit was retained for a short period. Then, in January 2019, it was shown that since the OP_RETURN opcode terminated scripts in such a way that nodes did not validate any subsequent opcodes, that nodes also did not check that the script was within the max script size limit of 520 bytes. This was communicated to node operators on the network who were then able to raise the maximum transaction size to 100KB, giving users the freedom to create novel implementations that put larger and more complex data onto the ledger including in this early example, an entire [https://whatsonchain.com/tx/21a5c896f23bea81ae5018dfeb8801ddc68691d0186a7e2d8c011e65e0a396d9 website].
  
 
=== Return to original functionality ===
 
=== Return to original functionality ===

Latest revision as of 11:55, 7 February 2021

The OP_RETURN opcode has seen historical changes to its functionality that have resulted in it being used as the primary mechanism to store arbitrary data on-chain.

Its original functionality was as a return operation that ends execution of the script prematurely, with the topmost stack item presented as the execution result.

The original implementation of the opcode created an easily exploitable vulnerability which was quickly patched by Satoshi Nakamoto.

1 RETURN Exploit

OP_RETURN was originally intended to terminate the script, presenting the top value on the stack as the result of the execution.

Given the script:

OP_TRUE OP_RETURN

True would be returned from the script and the script would terminate, ignoring any opcodes that came afterwards; because of this, this example script could prepend any unlocking script, granting the ability for one to steal anyone's Bitcoin.

The functionality of the opcode was changed to always return false instead of returning the value on top of the stack.

Further changes to OP_RETURN functionality

In Bitcoin Core's v0.9.0 update, the 'OP_RETURN output' script was made into a standard output type, allowing users to append data to unspendable transaction outputs. The amount of data usable in these scripts was first limited to 40 bytes, and then later increased to an 80 byte limit.

Storing data on-chain

The modification to OP_RETURN to always return false had interesting implications. Any opcodes or data are not evaluated after the OP_RETURN so users of the network began using this opcode to store arbitrary data.

This opcode was used instead of the OP_PUSHDATA opcodes since the max script size was limited to 520 bytes. These two fundamental changes to Bitcoin resulted in the opcode being used in an unforeseen and interesting way, outside of its original intent.

OP_RETURN in BCH

During the period while Bitcoin was more widely known as Bitcoin Cash (BCH), the length of data able to be appended to OP_RETURN outputs was extended to 220 bytes, allowing for the creation of larger data items and promoting its use in novel ways such as the creation of social media posting services and more.

OP_RETURN in BSV

For a short while after the network was transitioned to a majority of nodes running the BitcoinSV node client, the 220 byte limit was retained for a short period. Then, in January 2019, it was shown that since the OP_RETURN opcode terminated scripts in such a way that nodes did not validate any subsequent opcodes, that nodes also did not check that the script was within the max script size limit of 520 bytes. This was communicated to node operators on the network who were then able to raise the maximum transaction size to 100KB, giving users the freedom to create novel implementations that put larger and more complex data onto the ledger including in this early example, an entire website.

Return to original functionality

The Genesis upgrade in February 2020 restored the original functionality of the opcode. This did not impact the ability to store arbitrary data on-chain, however the best practice was amended to advise the use of False Return scripts for applications that still seek to do so.