<p>Bitcoin Core doesn't explicitly define the unused opcodes. The fact that they cause the script to fail when executed is a result of the default branch of the large <code>switch</code> statement in <a href="https://github.com/bitcoin/bitcoin/blob/v25.0/src/script/interpreter.cpp#L1217" rel="nofollow noreferrer">interpreter.cpp</a>. The branch, which causes a script error, is only executed when none of the defined opcodes have matched the currently inspected opcode. The constant <code>MAX_OPCODE</code> you mention doesn't seem to be used by consensus-critical code.</p>
<p>Because they aren't the same opcode as OP_RETURN (<code>0x6a</code>), using them in a OP_RETURN-style output script will make the transaction non-standard (but not invalid).</p>

CC BY-SA 4.0
2023-10-04T18:08:07.483Z
This answer and the one above seem to slightly disagree...
>(1) If such opcodes were found in the script, they would make the it invalid.
>(2) using them in a OP_RETURN-style output script will make the transaction non-standard (but not invalid).
thunderbiscuit
CC BY-SA 4.0
2023-10-04T18:21:01.270Z
An OP_RETURN output doesn't make a transaction invalid, because the output script is not executed until it is spent. It does make the output provably unspendable, which is good because it can be excluded from the UTXO set.
Vojtěch Strnad
CC BY-SA 4.0
2023-10-04T18:49:05.190Z
That does make sense to me. But I assume the argument from @Filip above would be that these are not actually op_returns, and if found would make the script invalid? This is certainly not what the rust-bitcoin enum implies and so I'm tempted to believe your answer more, but I'm attempting to write documentation on opcodes and I'm looking to really make sure I understand these little weirdo opcodes...
thunderbiscuit
CC BY-SA 4.0
2023-10-04T18:53:34.977Z
I try not to trust ChatGPT too much, but here's the answer it gives me when I ask: _What would happen if I used the 0xfa opcode in a bitcoin script?_:
Opcode 0xfa in Bitcoin Script is currently undefined.

When the Bitcoin network encounters an undefined opcode, the script is considered invalid, and the transaction that includes such a script will be rejected by the network.

If you were to create a Bitcoin transaction that includes a script with the opcode 0xfa, that transaction would be considered invalid by Bitcoin nodes, and it would not be relayed or included in a block.
thunderbiscuit
CC BY-SA 4.0
2023-10-04T19:15:05.567Z
As I said, the output script is not executed until the output is spent, which means the script doesn't have to be satisfiable–it actually doesn't even need to be a valid script.
Vojtěch Strnad
CC BY-SA 4.0
2023-10-04T19:32:15.263Z
Ah yes I see. Thanks a bunch!
thunderbiscuit
CC BY-SA 4.0
2023-10-02T19:07:03.297Z
2023-10-02T22:53:40.707Z
2023-10-02T22:53:40.707Z
Vojtěch Strnad
<p>When determining consensus rules, and the opcode set certainly is, the most relevant implementation and the only one to look at is the <a href="https://github.com/bitcoin/bitcoin" rel="noreferrer">Bitcoin Core</a>. There are no OP_RETURN_187, OP_RETURN_188, ..., OP_RETURN_256 synonyms for OP_RETURN in the Bitcoin Core implementation. If such opcodes were found in the script, they would make the it invalid.</p>
<p>An OP_RETURN in an IF branch that is not executed during script execution will not invalidate the script.</p>

CC BY-SA 4.0
2023-10-04T18:06:09.997Z
This answer and the one below seem to slightly disagree...
>(1) If such opcodes were found in the script, they would make the it invalid.
>(2) using them in a OP_RETURN-style output script will make the transaction non-standard (but not invalid).
thunderbiscuit
CC BY-SA 4.0
2023-10-04T19:31:26.907Z
@thunderbiscuit The content of the output script is not checked when validating the transaction. Therefore, you can put whatever you want in the output script. If you want, you can write `thunderbiscuit`. This is not a standard output script, but it is valid. The validation of the output script is checked only when some input tries to consume that output. At that point, the output script `thunderbiscuit` will be invalid, and thus the entire transaction that tries to consume that output. Therefore, OP_RETURN_188 is an invalid opcode, but it can be in the output since its content is not checked.
dassd
CC BY-SA 4.0
2023-10-02T19:03:43.373Z
2023-10-02T19:28:52.570Z
2023-10-02T19:28:52.570Z
dassd
<p>In rust-bitcoin, opcodes past the <code>0xba</code> opcode are named as such: <code>OP_RETURN_187</code>, <code>OP_RETURN_188</code>, ..., <code>OP_RETURN_254</code>. <a href="https://docs.rs/bitcoin/latest/src/bitcoin/blockdata/opcodes.rs.html" rel="nofollow noreferrer">Their description is all the same</a>: <em>Synonym for OP_RETURN</em>. The definition for OP_RETURN is <em>Fail the script immediately. (Must be executed.).</em>, which implies (if I understand correctly) that a script that contains an OP_RETURN in an unexecuted branch of an OP_IF statement is not made invalid by the sole presence of the opcode.</p>
<p>Yet in the Bitcoin Core codebase, those opcodes are not even defined in the opcode enum, and a <a href="https://github.com/bitcoin/bitcoin/blob/dd314fe0c2f64818d2789955a8ceef50d3d6597d/src/script/script.h#L211C1-L212C49" rel="nofollow noreferrer">line defines the maximum value that an opcode can be to be <code>0xb9</code></a>. Together these two mean that I'm not quite sure what to make of these opcodes... are they valid? Not valid? Can they be used as rust-bitcoin implies, or not used as Bitcoin Core implies? I assume there is more to this story, but just looking at the codebases as is I wasn't able to get a feel for how to describe these opcodes.</p>
<p>Also implied in this question is: if they are indeed synonyms to OP_RETURN as rust-bitcoin indicates, can they be used interchangeably and in place of OP_RETURN the way it is used for storing data?</p>

CC BY-SA 4.0
2023-10-02T19:05:53.507Z
Related: [What is OP_RETURN_252?](https://bitcoin.stackexchange.com/q/116099/13866)
RedGrittyBrick
<script><bitcoin-core-development><consensus><opcodes><rust-bitcoin>
Undefined opcodes in Bitcoin Core defined as "Synonyms for OP_RETURN" in rust-bitcoin
thunderbiscuit
# Undefined opcodes in Bitcoin Core defined as "Synonyms for OP_RETURN" in rust-bitcoin

(Asked by: username_0 on 2023-10-02)

In rust-bitcoin, opcodes past the `0xba` opcode are named as such: `OP_RETURN_187`, `OP_RETURN_188`, ..., `OP_RETURN_254`. [Their description is all the same](https://docs.rs/bitcoin/latest/src/bitcoin/blockdata/opcodes.rs.html): *Synonym for OP\_RETURN*. The definition for OP\_RETURN is *Fail the script immediately. (Must be executed.).*, which implies (if I understand correctly) that a script that contains an OP\_RETURN in an unexecuted branch of an OP\_IF statement is not made invalid by the sole presence of the opcode.

Yet in the Bitcoin Core codebase, those opcodes are not even defined in the opcode enum, and a [line defines the maximum value that an opcode can be to be `0xb9`](https://github.com/bitcoin/bitcoin/blob/dd314fe0c2f64818d2789955a8ceef50d3d6597d/src/script/script.h#L211C1-L212C49). Together these two mean that I'm not quite sure what to make of these opcodes... are they valid? Not valid? Can they be used as rust-bitcoin implies, or not used as Bitcoin Core implies? I assume there is more to this story, but just looking at the codebases as is I wasn't able to get a feel for how to describe these opcodes.

Also implied in this question is: if they are indeed synonyms to OP\_RETURN as rust-bitcoin indicates, can they be used interchangeably and in place of OP\_RETURN the way it is used for storing data?

**Tags:** script, bitcoin-core-development, consensus, opcodes, rust-bitcoin

> **Comments:**
> **username_1**: Related: [What is OP_RETURN_252?](https://bitcoin.stackexchange.com/q/116099/13866)  

---

## 2 answers

### Answer by username_2 on 2023-10-02. Score: 5

Bitcoin Core doesn't explicitly define the unused opcodes. The fact that they cause the script to fail when executed is a result of the default branch of the large `switch` statement in [interpreter.cpp](https://github.com/bitcoin/bitcoin/blob/v25.0/src/script/interpreter.cpp#L1217). The branch, which causes a script error, is only executed when none of the defined opcodes have matched the currently inspected opcode. The constant `MAX_OPCODE` you mention doesn't seem to be used by consensus-critical code.

Because they aren't the same opcode as OP\_RETURN (`0x6a`), using them in a OP\_RETURN-style output script will make the transaction non-standard (but not invalid).

> **Comments:**
> **username_0**: This answer and the one above seem to slightly disagree... >(1) If such opcodes were found in the script, they would make the it invalid. >(2) using them in a OP_RETURN-style output script will make the transaction non-standard (but not invalid).  
> **username_2**: An OP_RETURN output doesn't make a transaction invalid, because the output script is not executed until it is spent. It does make the output provably unspendable, which is good because it can be excluded from the UTXO set.  
> **username_0**: That does make sense to me. But I assume the argument from @Filip above would be that these are not actually op_returns, and if found would make the script invalid? This is certainly not what the rust-bitcoin enum implies and so I'm tempted to believe your answer more, but I'm attempting to write documentation on opcodes and I'm looking to really make sure I understand these little weirdo opcodes...  
> **username_0**: I try not to trust ChatGPT too much, but here's the answer it gives me when I ask: _What would happen if I used the 0xfa opcode in a bitcoin script?_: Opcode 0xfa in Bitcoin Script is currently undefined.  When the Bitcoin network encounters an undefined opcode, the script is considered invalid, and the transaction that includes such a script will be rejected by the network.  If you were to create a Bitcoin transaction that includes a script with the opcode 0xfa, that transaction would be considered invalid by Bitcoin nodes, and it would not be relayed or included in a block.  
> **username_2**: As I said, the output script is not executed until the output is spent, which means the script doesn't have to be satisfiable–it actually doesn't even need to be a valid script.  
> **username_0**: Ah yes I see. Thanks a bunch!  

---

### Answer by username_3 on 2023-10-02. Score: 3

When determining consensus rules, and the opcode set certainly is, the most relevant implementation and the only one to look at is the [Bitcoin Core](https://github.com/bitcoin/bitcoin). There are no OP\_RETURN\_187, OP\_RETURN\_188, ..., OP\_RETURN\_256 synonyms for OP\_RETURN in the Bitcoin Core implementation. If such opcodes were found in the script, they would make the it invalid.

An OP\_RETURN in an IF branch that is not executed during script execution will not invalidate the script.

> **Comments:**
> **username_0**: This answer and the one below seem to slightly disagree... >(1) If such opcodes were found in the script, they would make the it invalid. >(2) using them in a OP_RETURN-style output script will make the transaction non-standard (but not invalid).  
> **username_3**: @username_0 The content of the output script is not checked when validating the transaction. Therefore, you can put whatever you want in the output script. If you want, you can write `username_0`. This is not a standard output script, but it is valid. The validation of the output script is checked only when some input tries to consume that output. At that point, the output script `username_0` will be invalid, and thus the entire transaction that tries to consume that output. Therefore, OP_RETURN_188 is an invalid opcode, but it can be in the output since its content is not checked.  

---

