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