Friday, November 22, 2024

op return – When is OP_RETURN cheaper than OP_FALSE OP_IF?

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

graph that compares OP_RETURN with inscriptions

The overhead of an OP_RETURN output is not less than 11 bytes:

  • quantity (8 bytes)
  • compact measurement of script (not less than 1 byte)
  • script:
    • OP_RETURN opcode (1 byte)
    • push opcode (not less than 1 byte)

The overhead of an inscription is not less than 118.75 vB (84 base bytes and 139 witness bytes):

  • P2TR output (43 bytes)
  • P2TR enter:
    • outpoint TXID (32 bytes)
    • outpoint index (4 bytes)
    • sequence (4 bytes)
    • compact measurement of enter script (1 byte, script is empty)
    • witness knowledge:
      • compact measurement of witness stack (1 WU)
      • compact measurement of signature (1 WU)
      • signature (64 WU)
      • compact measurement of script (not less than 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 (not less than 1 WU)
        • OP_ENDIF opcode (1 WU)
      • compact measurement of management block (1 WU)
      • management block (33 WU)

The witness low cost cancels out the bigger overhead at 143 bytes of knowledge, which takes 155 vB utilizing an OP_RETURN and 154.75 vB utilizing an inscription. For something smaller than that OP_RETURN is cheaper.

Notes:

  • The above assumes a best-case situation by which the P2TR enter is included in a transaction that serves another function and can be made anyway. This usually is not the case, by which case the overhead is not less than 129.25 vB and OP_RETURN is cheaper for as much as not less than 158 bytes of knowledge.
  • It is necessary to separate the info into chunks of 520 bytes in an inscription however not in an OP_RETURN output. This solely impacts knowledge massive sufficient that it does not change the reply.
  • We’re ignoring the 80-byte standardness restrict for OP_RETURN right here.

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles