>> (p.1)
    Author Topic: Was scriptPubKey a mistake?  (Read 257 times)
    lushly (OP)
    Newbie
    *
    Offline Offline

    Activity: 4
    Merit: 10


    View Profile
    April 28, 2024, 08:04:47 AM
    Merited by ABCbits (3), odolvlobo (1), nc50lc (1), DdmrDdmr (1), NotATether (1), vjudeu (1)
     #1

    The original release of Bitcoin included the ability to use arbitrary lock scripts in scriptPubKey, but that ability was relatively quickly limited by introducing the standardness check. While arbitrary lock scripts are still valid from the consensus point of view, you would have to work with a miner to get them included into the blockchain, as only a few standard transaction types will be relayed by nodes in the default configuration.

    It is still possible to use custom scripts through P2SH/P2WSH/P2TR. They have significant advantages over placing the unlock conditions in scriptPubKey. So there's no practical issue with the standardness check.

    But it does mean that scriptPubKey has effectively become a weird binary format to define several standard transaction types in a very inefficient way. It requires each node to match the script against a few templates to determine what to do with the transaction. It is no longer generic, as some opcode combinations trigger special transaction processing, such as the extraction and additional evaluation of the redeemScript in P2SH.

    The same could be achieved by replacing scriptPubKey with an enum field for output type and a payload field for details. It would slightly decrease transaction size and computation requirements to verify it. It would also make building applications that interact with the blockchain easier, since developers would no longer have to implement nonstandard transaction handling. One could be certain that if a transaction doesn't have a destination address, it's P2PK, bare multisig or OP_RETURN. No other options would be possible.

    E. g. if output type is 1 (for P2PKH), the payload field contains a 20-byte key hash. Assuming that the output type field takes 1 byte, this saves 4 bytes per a P2PKH output. The opcodes OP_DUP OP_HASH160 OP_PUSHBYTES_20 OP_EQUALVERIFY OP_CHECKSIG are all replaced with output type.

    If output type is 2 (for P2SH), the payload is a 20-byte redeemScript hash. We save 2 bytes per P2SH output. And so on.

    I understand that such an upgrade would require a hard fork, and we don't do that in Bitcoin. However if that was somehow no longer a limitation, e. g. if Bitcoin was invented today, would removing scriptPubKey be the right thing to do? Are there any upsides to the current situation other than that it's what we have?

    (I'm sure this question has been asked many times before, but I couldn't find much info by searching.)
Page 1
Viewing Page: 1