Skip to main content

Counterparty Data Encoding Methods

There are four different methods for storing data on the Bitcoin blockchain: OP_RETURN, MULTISIG, P2TR, and P2SH (deprecated). For small data (≤64 bytes), OP_RETURN is most efficient, while for larger data sizes, P2TR offers superior efficiency thanks to the witness discount. MULTISIG is impractical for large data storage due to its linear scaling with data size.

TLDR;

  1. For data ≤80 bytes, we use OP_RETURN, for simplicity.
  2. For data >64 bytes, P2TR is the most cost-effective.
  3. P2TR is strictly superior to MULTISIG and P2SH at all transaction sizes.

Transaction Types and Data Storage Methods

  1. LEGACY, OP_RETURN

    • One legacy input
    • One OP_RETURN output (containing data up to 80 bytes)
    • One legacy change output
    • Data storage method: Direct insertion in OP_RETURN output
  2. LEGACY, MULTISIG

    • One legacy input
    • N multisig outputs (1-of-3, storing 64 bytes per output)
    • One legacy change output
    • Data storage method: Data embedded in multisig redeem scripts
  3. BECH32, P2SH (two transactions)

    • Transaction 1:
      • One bech32 input
      • One P2SH output
      • One bech32 change output
    • Transaction 2:
      • One P2SH input
      • One OP_RETURN output
    • Data storage method: Data embedded in P2SH scriptsig using OP_FALSE OP_IF <data> OP_ENDIF
  4. BECH32, P2TR (two transactions; deprecated)

    • Transaction 1:
      • One bech32 input
      • One P2TR output
      • One bech32 change output
    • Transaction 2:
      • One P2TR input
      • One OP_RETURN output
    • Data storage method: Ordinal-style inscription in witness data using OP_FALSE OP_IF <data> OP_ENDIF

Transaction Size Comparison

SizeOP_RETURNMULTISIGP2TRP2SH
Bytes vBytesBytes vBytesBytes vBytesBytes vBytes
10212 212303 303353 239295 241
16218 218303 303359 240301 247
32234 234303 303375 244317 263
64266 266303 303407 252349 295
80282 282415 415423 256365 311
128N/A N/A415 415471 268413 359
256N/A N/A639 639599 300541 487
1KBN/A N/A1983 19831367 4921309 1255
2KBN/A N/A3775 37752391 7482333 2279

Efficiency Ratio (vBytes per byte of data)

SizeOP_RETURNMULTISIGP2TRP2SH
1021.2030.3023.9024.10
1613.6318.9415.0015.44
327.319.477.638.22
644.164.733.944.61
803.525.193.203.89
128N/A3.242.092.80
256N/A2.501.171.90
1KBN/A1.940.481.23
2KBN/A1.840.371.11

Most Efficient Method by Data Size

SizeOptimal MethodEfficiency (vBytes/byte)
10OP_RETURN21.20
16OP_RETURN13.63
32OP_RETURN7.31
64P2TR3.94
80P2TR3.20
128P2TR2.09
256P2TR1.17
1KBP2TR0.48
2KBP2TR0.37