3

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: 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. Together these two mean 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?

1

2 Answers 2

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. 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).

6
  • 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). Commented Oct 4, 2023 at 18:08
  • 1
    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. Commented Oct 4, 2023 at 18:21
  • 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... Commented Oct 4, 2023 at 18:49
  • 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. Commented Oct 4, 2023 at 18:53
  • 1
    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. Commented Oct 4, 2023 at 19:15
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. 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.

2
  • 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). Commented Oct 4, 2023 at 18:06
  • 3
    @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
    Commented Oct 4, 2023 at 19:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.