{"type":"rich","version":"1.0","author_name":"npub1g5zswf6y48f7fy90jf3tlcuwdmjn8znhzaa4vkmtxaeskca8hpss23ms3l","author_url":"https://nostr.ae/npub1g5zswf6y48f7fy90jf3tlcuwdmjn8znhzaa4vkmtxaeskca8hpss23ms3l","provider_name":"njump","provider_url":"https://nostr.ae","html":"📅 Original date posted:2019-10-04\n📝 Original message:Good morning Jeremy,\n\n\u003e Awhile back, Ethan and I discussed having, rather than OP_CAT, an OP_SHA256STREAM that uses the streaming properties of a SHA256 hash function to allow concatenation of an unlimited amount of data, provided the only use is to hash it.\n\u003e\n\u003e You can then use it perhaps as follows:\n\u003e\n\u003e // start a new hash with item\n\u003e OP_SHA256STREAM  (-1) -\u003e [state]\n\u003e // Add item to the hash in state\n\u003e OP_SHA256STREAM n [item] [state] -\u003e [state]\n\u003e // Finalize\n\u003e OP_SHA256STREAM (-2) [state] -\u003e [Hash]\n\u003e\n\u003e \u003c-1\u003e OP_SHA256STREAM \u003ctag\u003e \u003csubnode 2\u003e \u003csubnode 3\u003e \u003c3\u003e OP_SHA256STREAM \u003c-2\u003e OP_SHA256STREAM\n\u003e\n\u003e Or it coul\n\u003e\n\nThis seems a good idea.\n\nThough it brings up the age-old tension between:\n\n* Generically-useable components, but due to generalization are less efficient.\n* Specific-use components, which are efficient, but which may end up not being useable in the future.\n\nIn particular, `OP_SHA256STREAM` would no longer be useable if SHA256 eventually is broken, while the `OP_CAT` will still be useable in the indefinite future.\nIn the future a new hash function can simply be defined and the same technique with `OP_CAT` would still be useable.\n\n\nRegards,\nZmnSCPxj\n\n\u003e --\n\u003e @JeremyRubin\n\u003e\n\u003e On Thu, Oct 3, 2019 at 8:04 PM Ethan Heilman \u003ceth3rs at gmail.com\u003e wrote:\n\u003e\n\u003e \u003e I hope you are having an great afternoon ZmnSCPxj,\n\u003e \u003e\n\u003e \u003e You make an excellent point!\n\u003e \u003e\n\u003e \u003e I had thought about doing the following to tag nodes\n\u003e \u003e\n\u003e \u003e || means OP_CAT\n\u003e \u003e\n\u003e \u003e `node = SHA256(type||SHA256(data))`\n\u003e \u003e so a subnode would be\n\u003e \u003e `subnode1 = SHA256(1||SHA256(subnode2||subnode3))`\n\u003e \u003e and a leaf node would be\n\u003e \u003e `leafnode = SHA256(0||SHA256(leafdata))`\n\u003e \u003e\n\u003e \u003e Yet, I like your idea better. Increasing the size of the two inputs to\n\u003e \u003e OP_CAT to be 260 Bytes each where 520 Bytes is the maximum allowable\n\u003e \u003e size of object on the stack seems sensible and also doesn't special\n\u003e \u003e case the logic of OP_CAT.\n\u003e \u003e\n\u003e \u003e It would also increase performance. SHA256(tag||subnode2||subnode3)\n\u003e \u003e requires 2 compression function calls whereas\n\u003e \u003e SHA256(1||SHA256(subnode2||subnode3)) requires 2+1=3 compression\n\u003e \u003e function calls (due to padding).\n\u003e \u003e\n\u003e \u003e \u003eOr we could implement tagged SHA256 as a new opcode...\n\u003e \u003e\n\u003e \u003e I agree that tagged SHA256 as an op code that would certainty be\n\u003e \u003e useful, but OP_CAT provides far more utility and is a simpler change.\n\u003e \u003e\n\u003e \u003e Thanks,\n\u003e \u003e Ethan\n\u003e \u003e\n\u003e \u003e On Thu, Oct 3, 2019 at 7:42 PM ZmnSCPxj \u003cZmnSCPxj at protonmail.com\u003e wrote:\n\u003e \u003e \u003e\n\u003e \u003e \u003e Good morning Ethan,\n\u003e \u003e \u003e\n\u003e \u003e \u003e\n\u003e \u003e \u003e \u003e To avoid derailing the NO_INPUT conversation, I have changed the\n\u003e \u003e \u003e \u003e subject to OP_CAT.\n\u003e \u003e \u003e \u003e\n\u003e \u003e \u003e \u003e Responding to:\n\u003e \u003e \u003e \u003e \"\"\"\n\u003e \u003e \u003e \u003e\n\u003e \u003e \u003e \u003e -   `SIGHASH` flags attached to signatures are a misdesign, sadly\n\u003e \u003e \u003e \u003e     retained from the original BitCoin 0.1.0 Alpha for Windows design, on\n\u003e \u003e \u003e \u003e     par with:\n\u003e \u003e \u003e \u003e     [..]\n\u003e \u003e \u003e \u003e\n\u003e \u003e \u003e \u003e -   `OP_CAT` and `OP_MULT` and `OP_ADD` and friends\n\u003e \u003e \u003e \u003e     [..]\n\u003e \u003e \u003e \u003e     \"\"\"\n\u003e \u003e \u003e \u003e\n\u003e \u003e \u003e \u003e     OP_CAT is an extremely valuable op code. I understand why it was\n\u003e \u003e \u003e \u003e     removed as the situation at the time with scripts was dire. However\n\u003e \u003e \u003e \u003e     most of the protocols I've wanted to build on Bitcoin run into the\n\u003e \u003e \u003e \u003e     limitation that stack values can not be concatenated. For instance\n\u003e \u003e \u003e \u003e     TumbleBit would have far smaller transaction sizes if OP_CAT was\n\u003e \u003e \u003e \u003e     supported in Bitcoin. If it happens to me as a researcher it is\n\u003e \u003e \u003e \u003e     probably holding other people back as well. If I could wave a magic\n\u003e \u003e \u003e \u003e     wand and turn on one of the disabled op codes it would be OP_CAT. Of\n\u003e \u003e \u003e \u003e     course with the change that size of each concatenated value must be 64\n\u003e \u003e \u003e \u003e     Bytes or less.\n\u003e \u003e \u003e\n\u003e \u003e \u003e Why 64 bytes in particular?\n\u003e \u003e \u003e\n\u003e \u003e \u003e It seems obvious to me that this 64 bytes is most suited for building Merkle trees, being the size of two SHA256 hashes.\n\u003e \u003e \u003e\n\u003e \u003e \u003e However we have had issues with the use of Merkle trees in Bitcoin blocks.\n\u003e \u003e \u003e Specifically, it is difficult to determine if a hash on a Merkle node is the hash of a Merkle subnode, or a leaf transaction.\n\u003e \u003e \u003e My understanding is that this is the reason for now requiring transactions to be at least 80 bytes.\n\u003e \u003e \u003e\n\u003e \u003e \u003e The obvious fix would be to prepend the type of the hashed object, i.e. add at least one byte to determine this type.\n\u003e \u003e \u003e Taproot for example uses tagged hash functions, with a different tag for leaves, and tagged hashes are just prepend-this-32-byte-constant-twice-before-you-SHA256.\n\u003e \u003e \u003e\n\u003e \u003e \u003e This seems to indicate that to check merkle tree proofs, an `OP_CAT` with only 64 bytes max output size would not be sufficient.\n\u003e \u003e \u003e\n\u003e \u003e \u003e Or we could implement tagged SHA256 as a new opcode...\n\u003e \u003e \u003e\n\u003e \u003e \u003e Regards,\n\u003e \u003e \u003e ZmnSCPxj\n\u003e \u003e \u003e\n\u003e \u003e \u003e\n\u003e \u003e \u003e \u003e\n\u003e \u003e \u003e \u003e     On Tue, Oct 1, 2019 at 10:04 PM ZmnSCPxj via bitcoin-dev\n\u003e \u003e \u003e \u003e     bitcoin-dev at lists.linuxfoundation.org wrote:\n\u003e \u003e \u003e \u003e\n\u003e \u003e \u003e \u003e\n\u003e \u003e \u003e \u003e \u003e Good morning lists,\n\u003e \u003e \u003e \u003e \u003e Let me propose the below radical idea:\n\u003e \u003e \u003e \u003e \u003e\n\u003e \u003e \u003e \u003e \u003e -   `SIGHASH` flags attached to signatures are a misdesign, sadly retained from the original BitCoin 0.1.0 Alpha for Windows design, on par with:\n\u003e \u003e \u003e \u003e \u003e     -   1 RETURN\n\u003e \u003e \u003e \u003e \u003e     -   higher-`nSequence` replacement\n\u003e \u003e \u003e \u003e \u003e     -   DER-encoded pubkeys\n\u003e \u003e \u003e \u003e \u003e     -   unrestricted `scriptPubKey`\n\u003e \u003e \u003e \u003e \u003e     -   Payee-security-paid-by-payer (i.e. lack of P2SH)\n\u003e \u003e \u003e \u003e \u003e     -   `OP_CAT` and `OP_MULT` and `OP_ADD` and friends\n\u003e \u003e \u003e \u003e \u003e     -   transaction malleability\n\u003e \u003e \u003e \u003e \u003e     -   probably many more\n\u003e \u003e \u003e \u003e \u003e\n\u003e \u003e \u003e \u003e \u003e So let me propose the more radical excision, starting with SegWit v1:\n\u003e \u003e \u003e \u003e \u003e\n\u003e \u003e \u003e \u003e \u003e -   Remove `SIGHASH` from signatures.\n\u003e \u003e \u003e \u003e \u003e -   Put `SIGHASH` on public keys.\n\u003e \u003e \u003e \u003e \u003e\n\u003e \u003e \u003e \u003e \u003e Public keys are now encoded as either 33-bytes (implicit `SIGHASH_ALL`) or 34-bytes (`SIGHASH` byte, followed by pubkey type, followed by pubkey coordinate).\n\u003e \u003e \u003e \u003e \u003e `OP_CHECKSIG` and friends then look at the public key to determine sighash algorithm rather than the signature.\n\u003e \u003e \u003e \u003e \u003e As we expect public keys to be indirectly committed to on every output `scriptPubKey`, this is automatically output tagging to allow particular `SIGHASH`.\n\u003e \u003e \u003e \u003e \u003e However, we can then utilize the many many ways to hide public keys away until they are needed, exemplified in MAST-inside-Taproot.\n\u003e \u003e \u003e \u003e \u003e I propose also the addition of the opcode:\n\u003e \u003e \u003e \u003e \u003e\n\u003e \u003e \u003e \u003e \u003e     \u003csighash\u003e \u003cpubkey\u003e OP_SETPUBKEYSIGHASH\n\u003e \u003e \u003e \u003e \u003e\n\u003e \u003e \u003e \u003e \u003e\n\u003e \u003e \u003e \u003e \u003e -   `sighash` must be one byte.\n\u003e \u003e \u003e \u003e \u003e -   `pubkey` may be the special byte `0x1`, meaning \"just use the Taproot internal pubkey\".\n\u003e \u003e \u003e \u003e \u003e -   `pubkey` may be 33-byte public key, in which case the `sighash` byte is just prepended to it.\n\u003e \u003e \u003e \u003e \u003e -   `pubkey` may be 34-byte public key with sighash, in which case the first byte is replaced with `sighash` byte.\n\u003e \u003e \u003e \u003e \u003e -   If `sighash` is `0x00` then the result is a 33-byte public key (the sighash byte is removed) i.e. `SIGHASH_ALL` implicit.\n\u003e \u003e \u003e \u003e \u003e\n\u003e \u003e \u003e \u003e \u003e This retains the old feature where the sighash is selected at time-of-spending rather than time-of-payment.\n\u003e \u003e \u003e \u003e \u003e This is done by using the script:\n\u003e \u003e \u003e \u003e \u003e\n\u003e \u003e \u003e \u003e \u003e     \u003cpubkey\u003e OP_SETPUBKEYSIGHASH OP_CHECKSIG\n\u003e \u003e \u003e \u003e \u003e\n\u003e \u003e \u003e \u003e \u003e\n\u003e \u003e \u003e \u003e \u003e Then the sighash can be put in the witness stack after the signature, letting the `SIGHASH` flag be selected at time-of-signing, but only if the SCRIPT specifically is formed to do so.\n\u003e \u003e \u003e \u003e \u003e This is malleability-safe as the signature still commits to the `SIGHASH` it was created for.\n\u003e \u003e \u003e \u003e \u003e However, by default, public keys will not have an attached `SIGHASH` byte, implying `SIGHASH_ALL` (and disallowing-by-default non-`SIGHASH_ALL`).\n\u003e \u003e \u003e \u003e \u003e This removes the problems with `SIGHASH_NONE` `SIGHASH_SINGLE`, as they are allowed only if the output specifically says they are allowed.\n\u003e \u003e \u003e \u003e \u003e Would this not be a superior solution?\n\u003e \u003e \u003e \u003e \u003e Regards,\n\u003e \u003e \u003e \u003e \u003e ZmnSCPxj\n\u003e \u003e \u003e \u003e \u003e\n\u003e \u003e \u003e \u003e \u003e bitcoin-dev mailing list\n\u003e \u003e \u003e \u003e \u003e bitcoin-dev at lists.linuxfoundation.org\n\u003e \u003e \u003e \u003e \u003e https://lists.linuxfoundation.org/mailman/listinfo/bitcoin-dev\n\u003e \u003e \u003e \u003e\n\u003e \u003e \u003e \u003e Lightning-dev mailing list\n\u003e \u003e \u003e \u003e Lightning-dev at lists.linuxfoundation.org\n\u003e \u003e \u003e \u003e https://lists.linuxfoundation.org/mailman/listinfo/lightning-dev\n\u003e \u003e \u003e\n\u003e \u003e \u003e\n\u003e \u003e _______________________________________________\n\u003e \u003e Lightning-dev mailing list\n\u003e \u003e Lightning-dev at lists.linuxfoundation.org\n\u003e \u003e https://lists.linuxfoundation.org/mailman/listinfo/lightning-dev"}
