{"id":2904,"date":"2019-07-27T15:00:22","date_gmt":"2019-07-27T15:00:22","guid":{"rendered":"https:\/\/bitcoinsv.io\/?p=2904"},"modified":"2020-09-28T06:18:34","modified_gmt":"2020-09-28T06:18:34","slug":"the-return-of-op_return-roadmap-to-genesis-part-4","status":"publish","type":"post","link":"https:\/\/bitcoinsv.io\/2019\/07\/27\/the-return-of-op_return-roadmap-to-genesis-part-4\/","title":{"rendered":"The return of OP_RETURN \u2013 roadmap to Genesis part 4"},"content":{"rendered":"\n

OP_RETURN is well known as the simplest mechanism for creating an unspendable output and carrying data within a bitcoin transaction.  It\u2019s had a checkered history with being the root cause of one of the worst bugs in Bitcoin\u2019s history and arguably also being a political football that led to the beginning of the great altcoin diaspora.  It is a far more important piece of the Bitcoin puzzle than is commonly understood though.  It\u2019s current usage is a subset of it\u2019s potential and it\u2019s also kind of wrong.  Lets take a look at the history.<\/p>\n\n\n\n

The original OP_RETURN<\/h2>\n\n\n\n

In the beginning the execution of scripts worked slightly differently than it does now.  In some respects more primitive. In others more in line with the original intent.  There are actually two scripts involved in the authorization of spending a UTXO.  The locking script (also known as scriptPubkey) which is designated at the time a new bitcoin output is created.  And the unlocking script (also known as scriptSig) which is provided at the time of spending the output (to create yet another new output).  First the unlocking script is executed, then the stack(s) that are a result of that are fed as input to the locking script. Think of the locking script as a puzzle and the unlocking script as the solution to the puzzle. If you can solve the puzzle you are authorized to spend the Bitcoin.<\/p>\n\n\n\n

In the original BitCoin this was achieved with the help of another op code OP_CODESEPERATOR.  This op code limits the scope of what subsequent OP_CHECKSIG operation will cover during a signature check  i.e. which parts of the transaction the signature signs.  This is necessary because usually there is a signature in the unlocking script and an OP_CHECKSIG in the locking script.  And the signature can\u2019t sign itself without creating a paradox and probably ending the universe as we know it.  What would happen is the two scripts were taken and turned into a single script a bit like this:<\/p>\n\n\n\n

Concatenate( unlockingScript | OP_CODESEPERATOR | lockingScript )<\/pre>\n\n\n\n

The single script was then executed.<\/p>\n\n\n\n

I can haz all your Bitcoinz<\/h2>\n\n\n\n

There was a glaring bug in this arrangement. What determines if the \u2018puzzle\u2019 has been successfully solved is that if at the end of script execution 1) it hasn\u2019t failed with an error and 2) that the top item remaining on the stack can be interpreted as a valid Boolean \u2018true\u2019.  OP_RETURN didn\u2019t change this.  It simply exited the script early and the above check was done to determine if the script was spendable. But it neglected to distinguish between the locking script which is set in stone once in the UTXO at the (earlier) time when the output is created, and the unlocking script which anyone can create in an attempt to spend the coin.  Consider the following locking script:<\/p>\n\n\n\n

<public_key> OP_CHECKSIG<\/pre>\n\n\n\n

This is the original pay-to-public-key script template.  It *should*<\/strong> only be able to be unlocked by providing a valid signature, which you should only be able to provide if you have the private key that corresponds to the public key.  In the original version of Bitcoin what\u2019s executed looks like this:<\/p>\n\n\n\n

Concatenate( <signature> | OP_CODESEPERATOR | <public_key> OP_CHECKSIG )<\/pre>\n\n\n\n

This would work fine as long as the signature is valid but you could also do this:<\/p>\n\n\n\n

Concatenate( OP_TRUE OP_RETURN | OP_CODESEPERATOR | <public_key> OP_CHECKSIG )<\/pre>\n\n\n\n

This pushes true onto the stack then exits the script.  The signature check is never performed and the script is considered valid because the top stack item is a Boolean \u2018true\u2019.  In fact it doesn\u2019t matter what the locking script is.  This behavior could be exploited to spend any bitcoin at all.<\/p>\n\n\n\n

Satoshi noticed this and fixed it. But he did it in a rush. The fix was to make OP_RETURN always exit and FAIL the script.  The reason for this is likely in way the code was structured at the time.  A better fix would have been to disallow OP_RETURN in the unlocking script.  Or ensure it always exits and fails if found in the unlocking script but behaves normally if found in the locking script.  The problem is that by concatenating the scripts there was no simple way for the script interpreter to know which part it was in.  OP_CODESEPERATOR is a valid op code that can be used anywhere in locking or unlocking scripts.  It can be used multiple times even.  So encountering that op code isn\u2019t a definite marker of the transition from unlocking to locking script.  There are other ways it could have been done but they introduce complexity and I suspect Satoshi was in a bit of a hurry to roll out a fix before this vulnerability got exploited.<\/p>\n\n\n\n

The data carrier<\/h2>\n\n\n\n

Roll forward in time and the way the script interpreter was called changed a bit.  First lets point out there is not just one stack in script, there are three.  The main stack, the alt stack and the \u201cif\u201d stack which is used to determine whether conditional branches in code are executed or not.  In the original implementation, because it was a single execution of the engine, all three of the resultant stacks from unlocking script were passed onto the locking script.  These days both scripts are executed separately with just the main stack contents from unlocking script being passed onto the locking script.  The function of OP_CODESEPERATOR is now subsumed by the semantics of the script execution engine so it has fallen into disuse although that is not to say it isn\u2019t useful in other ways, but that\u2019s a whole other story.  This is a significant change in semantics.<\/p>\n\n\n\n

The now nerfed OP_RETURN was noted for one of its potential use cases which is to make an output provably unspendable.  It\u2019s behaviour is now hard coded, if it is found and executed the script fails no matter what.  This was considered a useful property since miners will never need it for validating a future transaction they can optionally prune it.  So it was a useful way of embedding data in the blockchain in way that proved its existence at a point in time but without imposing a long term storage burden on miners. We still use it that way today.  It is not the only means of storing data in the blockchain and arguably not even the best.  But it is now a common use case on Bitcoin SV.<\/p>\n\n\n\n

To fix it we have to break it<\/h2>\n\n\n\n

That\u2019s right.  The way we are all using OP_RETURN right now is going to get broken if we fix OP_RETURN.  But don\u2019t worry too much, it\u2019s an easy fix and we can start right now. Almost all usages of OP_RETURN look a bit like this:<\/p>\n\n\n\n

OP_RETURN <data><\/pre>\n\n\n\n

And most have a value of zero so nothing is at risk.  But this form of OP_RETURN script will become spendable (by anyone) when the original functionality is restored.  Not for existing OP_RETURN outputs (please see part 3 of this series<\/a> for an explanation of UTXO height based activation).  But for new ones.  Consider the above script with an unlocking script that ends with OP_TRUE:<\/p>\n\n\n\n

OP_TRUE | OP_RETURN <data><\/pre>\n\n\n\n

As you can see anyone could spend this.  Whether that matters or not a point for others to debate but it is not the behavior we currently assume and expect.<\/p>\n\n\n\n

The call to action<\/h2>\n\n\n\n

If you\u2019re an app developer making use of OP_RETURN there is something very simple you can do right now that will ensure your app will maintain consistent behavior both now and after the Genesis upgrade.  Instead of starting your script with OP_RETURN, start it with OP_FALSE OP_RETURN.  A locking script that contains this will always fail when it hits this sequence of op codes both now and after the Genesis upgrade.  Here\u2019s an example of the how the same technique we showed above would look with this op code pattern:<\/p>\n\n\n\n

OP_TRUE | OP_FALSE OP_RETURN<\/pre>\n\n\n\n

As we can see the top stack item is OP_FALSE so when we encounter OP_RETURN and exit the script we will look at the top stack item, see that it is not a Boolean \u2018true\u2019 and the script will be deemed to have failed just like an old school OP_RETURN transaction.<\/p>\n\n\n\n

Bitcoin SV v0.2.1 released on 12th<\/sup> July 2019 contains a change to recognize this op code pattern as a standard transaction.  So once the majority of nodes are upgraded to this version there should be no functional difference to your app.  Additionally this version also sets the data carrier size default to 100kb so transmission of data carrier transactions will become a lot easier and more reliable.<\/p>\n\n\n\n

But what about my old OP_RETURN outputs?<\/h2>\n\n\n\n

I mentioned earlier that this won\u2019t be a problem for existing outputs.  I have written a separate article<\/a> to explain UTXO height based activation as it is a mechanism we will be using for several changes required in the Genesis upgrade.  You can read it HERE<\/a> but the TLDR is that no your old OP_RETURN transactions will behave the same way they always did.<\/p>\n\n\n\n

Get on it<\/h2>\n\n\n\n

The above section was titled \u2018call to action\u2019 and that\u2019s exactly what this article is.  You can change your code right now because OP_FALSE OP_RETURN behaves functionally identical to a simple OP_RETURN on its own right now.  The sooner your app supports this the sooner you can forget about it.  The behavior of this script type won\u2019t change after the upgrade.  So please update your software ASAP.  We are now 7 month out from the return to Genesis.  There is a lot of work to do both in the Bitcoin SV as well as in the wallet and app ecosystem.  We can knock this one off now so we can focus on the other stuff later.<\/p>\n\n\n\n

Steve Shadders<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"

OP_RETURN is well known as the simplest mechanism for creating an unspendable output and carrying data within a bitcoin transaction.  It\u2019s had a checkered history with being the root cause of one of the worst bugs in Bitcoin\u2019s history and arguably also being a political football that led to the beginning of the great altcoin […]<\/p>\n","protected":false},"author":4,"featured_media":4275,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[73],"tags":[],"lang":"en","translations":{"en":2904},"yoast_head":"\nThe return of OP_RETURN \u2013 roadmap to Genesis part 4 - Bitcoin SV<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/stag.bitcoinsv.io\/2019\/07\/27\/the-return-of-op_return-roadmap-to-genesis-part-4\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"The return of OP_RETURN \u2013 roadmap to Genesis part 4 - Bitcoin SV\" \/>\n<meta property=\"og:description\" content=\"OP_RETURN is well known as the simplest mechanism for creating an unspendable output and carrying data within a bitcoin transaction.  It\u2019s had a checkered history with being the root cause of one of the worst bugs in Bitcoin\u2019s history and arguably also being a political football that led to the beginning of the great altcoin […]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/stag.bitcoinsv.io\/2019\/07\/27\/the-return-of-op_return-roadmap-to-genesis-part-4\/\" \/>\n<meta property=\"og:site_name\" content=\"Bitcoin SV\" \/>\n<meta property=\"article:published_time\" content=\"2019-07-27T15:00:22+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-09-28T06:18:34+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/bitcoinsv.io\/wp-content\/uploads\/2020\/09\/roadmap-op_false-op_return.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1280\" \/>\n\t<meta property=\"og:image:height\" content=\"840\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@BitcoinSVNode\" \/>\n<meta name=\"twitter:site\" content=\"@BitcoinSVNode\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Organization\",\"@id\":\"https:\/\/bitcoinsv.io\/#organization\",\"name\":\"Bitcoin SV\",\"url\":\"https:\/\/bitcoinsv.io\/\",\"sameAs\":[\"https:\/\/twitter.com\/BitcoinSVNode\"],\"logo\":{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/bitcoinsv.io\/#logo\",\"inLanguage\":\"en-US\",\"url\":\"https:\/\/bitcoinsv.io\/wp-content\/uploads\/2020\/10\/bsv-logo-wh-medium.png\",\"width\":800,\"height\":144,\"caption\":\"Bitcoin SV\"},\"image\":{\"@id\":\"https:\/\/bitcoinsv.io\/#logo\"}},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/bitcoinsv.io\/#website\",\"url\":\"https:\/\/bitcoinsv.io\/\",\"name\":\"Bitcoin SV\",\"description\":\"Just another WordPress site\",\"publisher\":{\"@id\":\"https:\/\/bitcoinsv.io\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":\"https:\/\/bitcoinsv.io\/?s={search_term_string}\",\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/stag.bitcoinsv.io\/2019\/07\/27\/the-return-of-op_return-roadmap-to-genesis-part-4\/#primaryimage\",\"inLanguage\":\"en-US\",\"url\":\"https:\/\/bitcoinsv.io\/wp-content\/uploads\/2020\/09\/roadmap-op_false-op_return.jpg\",\"width\":1280,\"height\":840},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/stag.bitcoinsv.io\/2019\/07\/27\/the-return-of-op_return-roadmap-to-genesis-part-4\/#webpage\",\"url\":\"https:\/\/stag.bitcoinsv.io\/2019\/07\/27\/the-return-of-op_return-roadmap-to-genesis-part-4\/\",\"name\":\"The return of OP_RETURN \\u2013 roadmap to Genesis part 4 - Bitcoin SV\",\"isPartOf\":{\"@id\":\"https:\/\/bitcoinsv.io\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/stag.bitcoinsv.io\/2019\/07\/27\/the-return-of-op_return-roadmap-to-genesis-part-4\/#primaryimage\"},\"datePublished\":\"2019-07-27T15:00:22+00:00\",\"dateModified\":\"2020-09-28T06:18:34+00:00\",\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/stag.bitcoinsv.io\/2019\/07\/27\/the-return-of-op_return-roadmap-to-genesis-part-4\/\"]}]},{\"@type\":\"Article\",\"@id\":\"https:\/\/stag.bitcoinsv.io\/2019\/07\/27\/the-return-of-op_return-roadmap-to-genesis-part-4\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/stag.bitcoinsv.io\/2019\/07\/27\/the-return-of-op_return-roadmap-to-genesis-part-4\/#webpage\"},\"author\":{\"@id\":\"https:\/\/bitcoinsv.io\/#\/schema\/person\/d1b90c2f0b7b27b52e59ef856a57ab4e\"},\"headline\":\"The return of OP_RETURN \\u2013 roadmap to Genesis part 4\",\"datePublished\":\"2019-07-27T15:00:22+00:00\",\"dateModified\":\"2020-09-28T06:18:34+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/stag.bitcoinsv.io\/2019\/07\/27\/the-return-of-op_return-roadmap-to-genesis-part-4\/#webpage\"},\"publisher\":{\"@id\":\"https:\/\/bitcoinsv.io\/#organization\"},\"image\":{\"@id\":\"https:\/\/stag.bitcoinsv.io\/2019\/07\/27\/the-return-of-op_return-roadmap-to-genesis-part-4\/#primaryimage\"},\"articleSection\":\"Articles\",\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/bitcoinsv.io\/#\/schema\/person\/d1b90c2f0b7b27b52e59ef856a57ab4e\",\"name\":\"Steve Shadders\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/bitcoinsv.io\/#personlogo\",\"inLanguage\":\"en-US\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/d08dfcc7367f9cdd71cedbd77082b84f?s=96&d=mm&r=g\",\"caption\":\"Steve Shadders\"},\"description\":\"Steve has been involved in Bitcoin infrastructure since early 2011. In his role, he contributes his ecosystem-wide perspective, to support building the mining and UX infrastructure, needed to enable Satoshi\\u2019s Vision.\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","pll_sync_post":[],"_links":{"self":[{"href":"https:\/\/bitcoinsv.io\/wp-json\/wp\/v2\/posts\/2904"}],"collection":[{"href":"https:\/\/bitcoinsv.io\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bitcoinsv.io\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bitcoinsv.io\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/bitcoinsv.io\/wp-json\/wp\/v2\/comments?post=2904"}],"version-history":[{"count":2,"href":"https:\/\/bitcoinsv.io\/wp-json\/wp\/v2\/posts\/2904\/revisions"}],"predecessor-version":[{"id":4279,"href":"https:\/\/bitcoinsv.io\/wp-json\/wp\/v2\/posts\/2904\/revisions\/4279"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/bitcoinsv.io\/wp-json\/wp\/v2\/media\/4275"}],"wp:attachment":[{"href":"https:\/\/bitcoinsv.io\/wp-json\/wp\/v2\/media?parent=2904"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bitcoinsv.io\/wp-json\/wp\/v2\/categories?post=2904"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bitcoinsv.io\/wp-json\/wp\/v2\/tags?post=2904"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}