2

According to https://en.bitcoin.it/wiki/Script#Constants, for data between 1-75 bytes, the length byte is directly appended to the data, without any OP_PUSHDATA op-codes.

However, I noticed that in many coinbase transactions, there exists OP_PUSHDATA1 for data less than 76 bytes.

Are both ways of encoding data between 1~75 bytes correct, with and without OP_PUSHDATA1?

For example, in the last output of transaction 2c1f1797e05d0b16c0a0aa03985a47920275ffb080439614ef08b7ee019b9511, the 41 (0x29) bytes data 52534b424c4f434b3a4cf1e3f3539bb748501d706ad13227e5eb123b2f226f03d735001321004c43f7 was encoded as:

6a4c2952534b424c4f434b3a4cf1e3f3539bb748501d706ad13227e5eb123b2f226f03d735001321004c43f7

instead of

6a2952534b424c4f434b3a4cf1e3f3539bb748501d706ad13227e5eb123b2f226f03d735001321004c43f7

Below is the Bitcoin transaction in question:

{
  "txid": "2c1f1797e05d0b16c0a0aa03985a47920275ffb080439614ef08b7ee019b9511",
  "hash": "fe33cf3518e858f5301edb792e6d48e7176a35eebdb6c64aba3641dc291c5874",
  "version": 1,
  "size": 368,
  "vsize": 341,
  "weight": 1364,
  "locktime": 1060266043,
  "vin": [
    {
      "coinbase": "0382cd0b2cfabe6d6d559a043760d4418ea56a139ecc10c2f02618b68354d662d18e42972da7159a8210000000f09f909f092f4632506f6f6c2f660000000000000000000000000000000000000000000000000000000000000000000000050068000000",
      "txinwitness": [
        "0000000000000000000000000000000000000000000000000000000000000000"
      ],
      "sequence": 0
    }
  ],
  "vout": [
    {
      "value": 6.26354634,
      "n": 0,
      "scriptPubKey": {
        "asm": "OP_DUP OP_HASH160 c825a1ecf2a6830c4401620c3a16f1995057c2ab OP_EQUALVERIFY OP_CHECKSIG",
        "desc": "addr(1KFHE7w8BhaENAswwryaoccDb6qcT6DbYY)#flw9lhul",
        "hex": "76a914c825a1ecf2a6830c4401620c3a16f1995057c2ab88ac",
        "address": "1KFHE7w8BhaENAswwryaoccDb6qcT6DbYY",
        "type": "pubkeyhash"
      }
    },
    {
      "value": 0.00000000,
      "n": 1,
      "scriptPubKey": {
        "asm": "OP_RETURN aa21a9ed306308136280f52cb5206de82c5e143c4661a14833bfb4be86bb4f3bfb050e20",
        "desc": "raw(6a24aa21a9ed306308136280f52cb5206de82c5e143c4661a14833bfb4be86bb4f3bfb050e20)#zxjkvxlz",
        "hex": "6a24aa21a9ed306308136280f52cb5206de82c5e143c4661a14833bfb4be86bb4f3bfb050e20",
        "type": "nulldata"
      }
    },
    {
      "value": 0.00000000,
      "n": 2,
      "scriptPubKey": {
        "asm": "OP_RETURN 48617468c01245061cd08921f42aa661cd788e70ac71022b06ad6ea4a6017cd1a2a81f63",
        "desc": "raw(6a2448617468c01245061cd08921f42aa661cd788e70ac71022b06ad6ea4a6017cd1a2a81f63)#jndu367m",
        "hex": "6a2448617468c01245061cd08921f42aa661cd788e70ac71022b06ad6ea4a6017cd1a2a81f63",
        "type": "nulldata"
      }
    },
    {
      "value": 0.00000000,
      "n": 3,
      "scriptPubKey": {
        "asm": "OP_RETURN 52534b424c4f434b3a4cf1e3f3539bb748501d706ad13227e5eb123b2f226f03d735001321004c43f7",
        "desc": "raw(6a4c2952534b424c4f434b3a4cf1e3f3539bb748501d706ad13227e5eb123b2f226f03d735001321004c43f7)#akullk9c",
        "hex": "6a4c2952534b424c4f434b3a4cf1e3f3539bb748501d706ad13227e5eb123b2f226f03d735001321004c43f7",
        "type": "nulldata"
      }
    }
  ]
}

1 Answer 1

1

Yes, both encodings are valid. Of course, using just the length byte (sometimes called OP_PUSHBYTES_x) requires one fewer byte of space, so it's usually done that way.

1
  • 6
    It's also nonstandard to use the non-minimal one. However, standardness rules don't apply to coinbase transactions as those are created by miners (and obviously miners aren't subject to standardness). Jan 25 at 15:55

Your Answer

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

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