5

Since January 2023 there have been many transactions that embed arbitrary data in the leaf script of a P2TR input using the opcodes OP_FALSE OP_IF (also called "inscription envelope"). This is usually cheaper than using OP_RETURN because the data benefits from the witness discount, but also comes with the overhead of having to first create the P2TR output and then spending it in a subsequent transaction. So, when is it cheaper to use OP_RETURN?

1 Answer 1

8

TL;DR: OP_RETURN is cheaper for data smaller than 143 bytes.

graph that compares OP_RETURN with inscriptions

The overhead of an OP_RETURN output is at least 11 bytes:

  • amount (8 bytes)
  • compact size of script (at least 1 byte)
  • script:
    • OP_RETURN opcode (1 byte)
    • push opcode (at least 1 byte)

The overhead of an inscription is at least 118.75 vB (84 base bytes and 139 witness bytes):

  • P2TR output (43 bytes)
  • P2TR input:
    • outpoint TXID (32 bytes)
    • outpoint index (4 bytes)
    • sequence (4 bytes)
    • compact size of input script (1 byte, script is empty)
    • witness data:
      • compact size of witness stack (1 WU)
      • compact size of signature (1 WU)
      • signature (64 WU)
      • compact size of script (at least 1 WU)
      • script:
        • public key push opcode (1 WU)
        • public key (32 WU)
        • OP_CHECKSIG opcode (1 WU)
        • OP_FALSE opcode (1 WU)
        • OP_IF opcode (1 WU)
        • push opcodes (at least 1 WU)
        • OP_ENDIF opcode (1 WU)
      • compact size of control block (1 WU)
      • control block (33 WU)

The witness discount cancels out the larger overhead at 143 bytes of data, which takes 155 vB using an OP_RETURN and 154.75 vB using an inscription. For anything smaller than that OP_RETURN is cheaper.

Notes:

  • The above assumes a best-case scenario in which the P2TR input is included in a transaction that serves some other purpose and would be made anyway. This often isn't the case, in which case the overhead is at least 129.25 vB and OP_RETURN is cheaper for up to at least 158 bytes of data.
  • It's necessary to split the data into chunks of 520 bytes in an inscription but not in an OP_RETURN output. This only affects data large enough that it doesn't change the answer.
  • We're ignoring the 80-byte standardness limit for OP_RETURN here.

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.