BIP 347: OP_CAT in Tapscript #1525

pull EthanHeilman wants to merge 58 commits into bitcoin:master from EthanHeilman:cat changing 2 files +120 −0
  1. EthanHeilman commented at 11:16 pm on December 11, 2023: contributor

    This BIP defines OP_CAT a new tapscript opcode which allows the concatenation of two values on the stack. This opcode would be activated via a soft fork by redefining the opcode OP_SUCCESS126.

    See our implementation PR in bitcoin-inquisition: https://github.com/bitcoin-inquisition/bitcoin/pull/39

  2. Create bip-???-cat.mediawiki 83ca57f222
  3. in bip-???-cat.mediawiki:42 in 83ca57f222 outdated
    37+The opcode OP_CAT was available in early versions of Bitcoin. However OP_CAT was removed because it enabled the construction of a script for which an evaluation could have memory usage exponential in the size of the script.
    38+For instance a script which pushed an 1 Byte value on the stack then repeated the opcodes OP_DUP, OP_CAT 40 times would result in a stack value whose size was greater than 1 Terabyte. This is no longer an issue because tapscript enforces a maximum stack element size of 520 Bytes.
    39+
    40+==Specification==
    41+
    42+OP_CAT pops two elements of the stack, concatenates them together in stack order and pushes the resultant element onto the stack. Given the stack [x1,x2], where x2 is at the top of the stack, OP_CAT will push x1||x2 onto the stack. By '||' we denote concatenation.
    


    kallewoof commented at 12:30 pm on December 12, 2023:
    0OP_CAT pops two elements off the stack, concatenates them together in stack order and pushes the resulting element onto the stack. Given the stack [x1,x2], where x2 is at the top of the stack, OP_CAT will push x1||x2 onto the stack. By '||' we denote concatenation.
    
  4. in bip-???-cat.mediawiki:49 in 83ca57f222 outdated
    44+Implementation
    45+<pre>
    46+case OP_CAT:
    47+{
    48+    if (stack.size() < 2)
    49+        return set_error(serror, SCRIPT_ERR_INVALID_STACK_OPERATION);
    


    kallewoof commented at 12:31 pm on December 12, 2023:
    0    if (stack.size() < 2) {
    1        return set_error(serror, SCRIPT_ERR_INVALID_STACK_OPERATION);
    2    }
    
  5. in bip-???-cat.mediawiki:53 in 83ca57f222 outdated
    48+    if (stack.size() < 2)
    49+        return set_error(serror, SCRIPT_ERR_INVALID_STACK_OPERATION);
    50+    valtype& vch1 = stacktop(-2);
    51+    valtype& vch2 = stacktop(-1);
    52+    if (vch1.size() + vch2.size() > MAX_SCRIPT_ELEMENT_SIZE)
    53+        return set_error(serror, SCRIPT_ERR_INVALID_STACK_OPERATION);
    


    kallewoof commented at 12:31 pm on December 12, 2023:
    0    if (vch1.size() + vch2.size() > MAX_SCRIPT_ELEMENT_SIZE) {
    1        return set_error(serror, SCRIPT_ERR_INVALID_STACK_OPERATION);
    2    }
    

    EthanHeilman commented at 1:27 pm on December 12, 2023:
    @kallewoof Thanks for the help!
  6. in bip-???-cat.mediawiki:59 in 83ca57f222 outdated
    54+    vch1.insert(vch1.end(), vch2.begin(), vch2.end());
    55+    stack.pop_back();
    56+}
    57+break;
    58+</pre>
    59+This implementation is inspired by the original implementation of OP_CAT as shown below. Alternative implementation of OP_CAT can be found in Elements <ref>Roose S., Elements Project, "Re-enable several disabled opcodes", 2019, https://github.com/ElementsProject/elements/commit/13e1103abe3e328c5a4e2039b51a546f8be6c60a#diff-a0337ffd7259e8c7c9a7786d6dbd420c80abfa1afdb34ebae3261109d9ae3c19R740-R759</ref>.
    


    kallewoof commented at 12:32 pm on December 12, 2023:
    0This implementation is inspired by the original implementation of OP_CAT as shown below. An alternative implementation of OP_CAT can be found in Elements <ref>Roose S., Elements Project, "Re-enable several disabled opcodes", 2019, https://github.com/ElementsProject/elements/commit/13e1103abe3e328c5a4e2039b51a546f8be6c60a#diff-a0337ffd7259e8c7c9a7786d6dbd420c80abfa1afdb34ebae3261109d9ae3c19R740-R759</ref>.
    
  7. kallewoof commented at 12:34 pm on December 12, 2023: member
    Some minor nits. Idea seems sensible. Mailing list post seems mostly positive sentiment as well. @luke-jr ?
  8. Fixes typo
    Co-authored-by: kallewoof <kalle.alm@gmail.com>
    f1169dd1fc
  9. Better fits bitcoin style guide
    "If an if only has a single-statement then-clause, it can appear on the same line as the if, without braces. In every other case, braces are required, and the then and else clauses must appear correctly indented on a new line."
    
    Co-authored-by: kallewoof <kalle.alm@gmail.com>
    26e8e5f7fc
  10. Grammar fix
    Co-authored-by: kallewoof <kalle.alm@gmail.com>
    0335c9d188
  11. Adds brackets
    Co-authored-by: kallewoof <kalle.alm@gmail.com>
    3d31e5c894
  12. Bloc6 commented at 11:21 pm on December 12, 2023: none
    Definitely looking forward to test drive this BIP.
  13. EthanHeilman commented at 6:55 pm on December 14, 2023: contributor
    Can we get a BIP number assigned? Any blockers to doing this?
  14. in bip-???-cat.mediawiki:16 in 3d31e5c894 outdated
    11+  License: BSD-3-Clause
    12+</pre>
    13+
    14+==Abstract==
    15+
    16+This BIP defines OP_CAT a new tapscript opcode which allows the concatenation of two values on the stack. This opcode would be activated via a soft fork by redefining the opcode OP_SUCCESS126.
    


    kallewoof commented at 2:46 am on December 15, 2023:
    0This BIP reintroduces OP_CAT in the form of a new tapscript opcode which allows the concatenation of two values on the stack. This opcode would be activated via a soft fork by redefining the opcode OP_SUCCESS126.
    
  15. in bip-???-cat.mediawiki:20 in 3d31e5c894 outdated
    15+
    16+This BIP defines OP_CAT a new tapscript opcode which allows the concatenation of two values on the stack. This opcode would be activated via a soft fork by redefining the opcode OP_SUCCESS126.
    17+
    18+When evaluated the OP_CAT instruction:
    19+# Pops the top two values off the stack,
    20+# concatenate the popped values together,
    


    kallewoof commented at 2:46 am on December 15, 2023:
    0# concatenates the popped values together,
    
  16. in bip-???-cat.mediawiki:23 in 3d31e5c894 outdated
    18+When evaluated the OP_CAT instruction:
    19+# Pops the top two values off the stack,
    20+# concatenate the popped values together,
    21+# and then pushes the concatenated value on the top of the stack.
    22+
    23+OP_CAT fails if there are less than two values on the stack or if a concatenated value would have a combined size of greater than the maximum script element size of 520 Bytes.
    


    kallewoof commented at 2:47 am on December 15, 2023:
    0OP_CAT fails if there are less than two values on the stack or if a concatenated value would have a combined size greater than the maximum script element size of 520 Bytes.
    
  17. in bip-???-cat.mediawiki:26 in 3d31e5c894 outdated
    21+# and then pushes the concatenated value on the top of the stack.
    22+
    23+OP_CAT fails if there are less than two values on the stack or if a concatenated value would have a combined size of greater than the maximum script element size of 520 Bytes.
    24+
    25+==Motivation==
    26+Bitcoin tapscript lacks a general purpose way of combining objects on the stack restricting the expressiveness and power of tapscript. For instance this prevents among many other things the ability to construct and evaluate merkle trees and other hashed data structures in tapscript. OP_CAT by adding a general purpose way to concatenate stack values would overcome this limitation and greatly increase the functionality of tapscript.
    


    kallewoof commented at 2:48 am on December 15, 2023:
    0Bitcoin tapscript lacks a general purpose way of combining objects on the stack restricting the expressiveness and power of tapscript. This prevents among many other things the ability to construct and evaluate merkle trees and other hashed data structures in tapscript. OP_CAT by adding a general purpose way to concatenate stack values would overcome this limitation and greatly increase the functionality of tapscript.
    

    (Alternatively, “For instance this prevents the ability to…”. Both “For instance” and “many other things” seem redundant.)

  18. in bip-???-cat.mediawiki:32 in 3d31e5c894 outdated
    27+
    28+OP_CAT aims to expands the toolbox of the tapscript developer with a simple, modular and useful opcode in the spirit of Unix <ref>R. Pike and B. Kernighan, "Program design in the UNIX environment", 1983, https://harmful.cat-v.org/cat-v/unix_prog_design.pdf</ref>. To demonstrate the usefulness of OP_CAT below we provide a non-exhaustive list of some usecases that OP_CAT would enable:
    29+
    30+* Bitstream, a protocol for the atomic swap (fair exchange) of bitcoins for decryption keys, that enables decentralized file hosting systems paid in Bitcoin. While such swaps are currently possible on Bitcoin without OP_CAT they require the use of complex and computationally expensive Verifiable Computation cryptographic techniques. OP_CAT would remove this requirement on Verifiable Computation, making such protocols far more practical to build in Bitcoin. <ref>R. Linus, "BitStream: Decentralized File Hosting Incentivised via Bitcoin Payments", 2023, https://robinlinus.com/bitstream.pdf</ref>
    31+* Tree Signatures provide a multisignature script whose size can be logarithmic in the number of public keys and can encode spend conditions beyond n-of-m. For instance a transaction less than 1KB in size could support tree signatures with a thousand public keys. This also enables generalized logical spend conditions. <ref> P. Wuille, "Multisig on steroids using tree signatures", 2015, https://blog.blockstream.com/en-treesignatures/</ref>
    32+* Post-Quantum Lamport Signatures in Bitcoin transactions. Lamport signatures merely requires the ability to hash and concatenate values on the stack. <ref>J. Rubin, "[bitcoin-dev] OP_CAT Makes Bitcoin Quantum Secure [was CheckSigFromStack for Arithmetic Values]", 2021, https://lists.linuxfoundation.org/pipermail/bitcoin-dev/2021-July/019233.html</ref>
    


    kallewoof commented at 2:49 am on December 15, 2023:
    0* Post-Quantum Lamport Signatures in Bitcoin transactions. Lamport signatures merely require the ability to hash and concatenate values on the stack. <ref>J. Rubin, "[bitcoin-dev] OP_CAT Makes Bitcoin Quantum Secure [was CheckSigFromStack for Arithmetic Values]", 2021, https://lists.linuxfoundation.org/pipermail/bitcoin-dev/2021-July/019233.html</ref>
    
  19. in bip-???-cat.mediawiki:34 in 3d31e5c894 outdated
    29+
    30+* Bitstream, a protocol for the atomic swap (fair exchange) of bitcoins for decryption keys, that enables decentralized file hosting systems paid in Bitcoin. While such swaps are currently possible on Bitcoin without OP_CAT they require the use of complex and computationally expensive Verifiable Computation cryptographic techniques. OP_CAT would remove this requirement on Verifiable Computation, making such protocols far more practical to build in Bitcoin. <ref>R. Linus, "BitStream: Decentralized File Hosting Incentivised via Bitcoin Payments", 2023, https://robinlinus.com/bitstream.pdf</ref>
    31+* Tree Signatures provide a multisignature script whose size can be logarithmic in the number of public keys and can encode spend conditions beyond n-of-m. For instance a transaction less than 1KB in size could support tree signatures with a thousand public keys. This also enables generalized logical spend conditions. <ref> P. Wuille, "Multisig on steroids using tree signatures", 2015, https://blog.blockstream.com/en-treesignatures/</ref>
    32+* Post-Quantum Lamport Signatures in Bitcoin transactions. Lamport signatures merely requires the ability to hash and concatenate values on the stack. <ref>J. Rubin, "[bitcoin-dev] OP_CAT Makes Bitcoin Quantum Secure [was CheckSigFromStack for Arithmetic Values]", 2021, https://lists.linuxfoundation.org/pipermail/bitcoin-dev/2021-July/019233.html</ref>
    33+* Non-equivocation contracts <ref>T. Ruffing, A. Kate, D. Schröder, "Liar, Liar, Coins on Fire: Penalizing Equivocation by Loss of Bitcoins", 2015, https://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.727.6262&rep=rep1&type=pdf</ref> in tapscript provide a mechanism to punish equivocation/double spending in Bitcoin payment channels. OP_CAT enables this by enforcing rules on the spending transaction's nonce. The capability is a useful building block for payment channels and other Bitcoin protocols.
    34+* Vaults <ref> M. Moser, I. Eyal, and E. G. Sirer, Bitcoin Covenants, http://fc16.ifca.ai/bitcoin/papers/MES16.pdf</ref> which are a specialized covenant that allows a user to block a malicious party who has compromised the user's secret key from stealing the funds in that output. As shown in <ref>A. Poelstra, "CAT and Schnorr Tricks II", 2021, https://www.wpsoftware.net/andrew/blog/cat-and-schnorr-tricks-ii.html</ref> OP_CAT is sufficent to build vaults in Bitcoin.
    


    kallewoof commented at 2:50 am on December 15, 2023:
    0* Vaults <ref>M. Moser, I. Eyal, and E. G. Sirer, Bitcoin Covenants, http://fc16.ifca.ai/bitcoin/papers/MES16.pdf</ref> which are a specialized covenant that allows a user to block a malicious party who has compromised the user's secret key from stealing the funds in that output. As shown in <ref>A. Poelstra, "CAT and Schnorr Tricks II", 2021, https://www.wpsoftware.net/andrew/blog/cat-and-schnorr-tricks-ii.html</ref> OP_CAT is sufficent to build vaults in Bitcoin.
    
  20. in bip-???-cat.mediawiki:35 in 3d31e5c894 outdated
    30+* Bitstream, a protocol for the atomic swap (fair exchange) of bitcoins for decryption keys, that enables decentralized file hosting systems paid in Bitcoin. While such swaps are currently possible on Bitcoin without OP_CAT they require the use of complex and computationally expensive Verifiable Computation cryptographic techniques. OP_CAT would remove this requirement on Verifiable Computation, making such protocols far more practical to build in Bitcoin. <ref>R. Linus, "BitStream: Decentralized File Hosting Incentivised via Bitcoin Payments", 2023, https://robinlinus.com/bitstream.pdf</ref>
    31+* Tree Signatures provide a multisignature script whose size can be logarithmic in the number of public keys and can encode spend conditions beyond n-of-m. For instance a transaction less than 1KB in size could support tree signatures with a thousand public keys. This also enables generalized logical spend conditions. <ref> P. Wuille, "Multisig on steroids using tree signatures", 2015, https://blog.blockstream.com/en-treesignatures/</ref>
    32+* Post-Quantum Lamport Signatures in Bitcoin transactions. Lamport signatures merely requires the ability to hash and concatenate values on the stack. <ref>J. Rubin, "[bitcoin-dev] OP_CAT Makes Bitcoin Quantum Secure [was CheckSigFromStack for Arithmetic Values]", 2021, https://lists.linuxfoundation.org/pipermail/bitcoin-dev/2021-July/019233.html</ref>
    33+* Non-equivocation contracts <ref>T. Ruffing, A. Kate, D. Schröder, "Liar, Liar, Coins on Fire: Penalizing Equivocation by Loss of Bitcoins", 2015, https://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.727.6262&rep=rep1&type=pdf</ref> in tapscript provide a mechanism to punish equivocation/double spending in Bitcoin payment channels. OP_CAT enables this by enforcing rules on the spending transaction's nonce. The capability is a useful building block for payment channels and other Bitcoin protocols.
    34+* Vaults <ref> M. Moser, I. Eyal, and E. G. Sirer, Bitcoin Covenants, http://fc16.ifca.ai/bitcoin/papers/MES16.pdf</ref> which are a specialized covenant that allows a user to block a malicious party who has compromised the user's secret key from stealing the funds in that output. As shown in <ref>A. Poelstra, "CAT and Schnorr Tricks II", 2021, https://www.wpsoftware.net/andrew/blog/cat-and-schnorr-tricks-ii.html</ref> OP_CAT is sufficent to build vaults in Bitcoin.
    35+* Replicating CheckSigFromStack <ref> A. Poelstra, "CAT and Schnorr Tricks I", 2021, https://medium.com/blockstream/cat-and-schnorr-tricks-i-faf1b59bd298 </ref> which would allow the creation of simple covenants and other advanced contracts without having to presign spending transactions, possibly reducing complexity and the amount of data that needs to be stored. Originally shown to work with Schnorr signatures, this result has been extended to ECDSA signatures <ref>R. Linus, "Covenants with CAT and ECDSA", 2023, https://gist.github.com/RobinLinus/9a69f5552be94d13170ec79bf34d5e85#file-covenants_cat_ecdsa-md</ref>.
    


    kallewoof commented at 2:51 am on December 15, 2023:
    0* Replicating CheckSigFromStack <ref>A. Poelstra, "CAT and Schnorr Tricks I", 2021, https://medium.com/blockstream/cat-and-schnorr-tricks-i-faf1b59bd298</ref> which would allow the creation of simple covenants and other advanced contracts without having to presign spending transactions, possibly reducing complexity and the amount of data that needs to be stored. Originally shown to work with Schnorr signatures, this result has been extended to ECDSA signatures <ref>R. Linus, "Covenants with CAT and ECDSA", 2023, https://gist.github.com/RobinLinus/9a69f5552be94d13170ec79bf34d5e85#file-covenants_cat_ecdsa-md</ref>.
    
  21. in bip-???-cat.mediawiki:38 in 3d31e5c894 outdated
    33+* Non-equivocation contracts <ref>T. Ruffing, A. Kate, D. Schröder, "Liar, Liar, Coins on Fire: Penalizing Equivocation by Loss of Bitcoins", 2015, https://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.727.6262&rep=rep1&type=pdf</ref> in tapscript provide a mechanism to punish equivocation/double spending in Bitcoin payment channels. OP_CAT enables this by enforcing rules on the spending transaction's nonce. The capability is a useful building block for payment channels and other Bitcoin protocols.
    34+* Vaults <ref> M. Moser, I. Eyal, and E. G. Sirer, Bitcoin Covenants, http://fc16.ifca.ai/bitcoin/papers/MES16.pdf</ref> which are a specialized covenant that allows a user to block a malicious party who has compromised the user's secret key from stealing the funds in that output. As shown in <ref>A. Poelstra, "CAT and Schnorr Tricks II", 2021, https://www.wpsoftware.net/andrew/blog/cat-and-schnorr-tricks-ii.html</ref> OP_CAT is sufficent to build vaults in Bitcoin.
    35+* Replicating CheckSigFromStack <ref> A. Poelstra, "CAT and Schnorr Tricks I", 2021, https://medium.com/blockstream/cat-and-schnorr-tricks-i-faf1b59bd298 </ref> which would allow the creation of simple covenants and other advanced contracts without having to presign spending transactions, possibly reducing complexity and the amount of data that needs to be stored. Originally shown to work with Schnorr signatures, this result has been extended to ECDSA signatures <ref>R. Linus, "Covenants with CAT and ECDSA", 2023, https://gist.github.com/RobinLinus/9a69f5552be94d13170ec79bf34d5e85#file-covenants_cat_ecdsa-md</ref>.
    36+
    37+The opcode OP_CAT was available in early versions of Bitcoin. However OP_CAT was removed because it enabled the construction of a script for which an evaluation could have memory usage exponential in the size of the script.
    38+For instance a script which pushed an 1 Byte value on the stack then repeated the opcodes OP_DUP, OP_CAT 40 times would result in a stack value whose size was greater than 1 Terabyte. This is no longer an issue because tapscript enforces a maximum stack element size of 520 Bytes.
    


    kallewoof commented at 2:52 am on December 15, 2023:
    0For instance a script which pushed a 1 Byte value on the stack and then repeated the opcodes OP_DUP, OP_CAT 40 times would result in a stack value whose size was greater than 1 Terabyte. This is no longer an issue because tapscript enforces a maximum stack element size of 520 Bytes.
    
  22. kallewoof approved
  23. kallewoof commented at 2:54 am on December 15, 2023: member
    Sorry, some more μ-nits. Fine with it as is though.
  24. Wording
    Co-authored-by: kallewoof <kalle.alm@gmail.com>
    bb725e6523
  25. Keeps past tense consistant
    Co-authored-by: kallewoof <kalle.alm@gmail.com>
    9779dc9920
  26. Better phrasing
    Co-authored-by: kallewoof <kalle.alm@gmail.com>
    c5d66d6706
  27. Phrasing
    Co-authored-by: kallewoof <kalle.alm@gmail.com>
    848352f408
  28. Typo
    Co-authored-by: kallewoof <kalle.alm@gmail.com>
    a2b0100671
  29. Removes space in ref
    Co-authored-by: kallewoof <kalle.alm@gmail.com>
    6a790ec526
  30. Removes space in ref
    Co-authored-by: kallewoof <kalle.alm@gmail.com>
    01db3acab0
  31. Typos
    TIL that it is "a one" rather than "an one"
    
    Co-authored-by: kallewoof <kalle.alm@gmail.com>
    945e2a3742
  32. in bip-???-cat.mediawiki:23 in 945e2a3742 outdated
    18+When evaluated the OP_CAT instruction:
    19+# Pops the top two values off the stack,
    20+# concatenates the popped values together,
    21+# and then pushes the concatenated value on the top of the stack.
    22+
    23+OP_CAT fails if there are less than two values on the stack or if a concatenated value would have a combined size greater than the maximum script element size of 520 Bytes.
    


    vostrnad commented at 5:30 am on December 15, 2023:
    0OP_CAT fails if there are less than two values on the stack or if a concatenated value would have a combined size greater than the maximum script element size of 520 bytes.
    

    kallewoof commented at 12:51 pm on December 15, 2023:
    Original fine. Tiny preference for the uncapitalized ‘bytes’ too, though.

    vostrnad commented at 1:21 pm on December 15, 2023:
    I’ve yet to find a source claiming the capitalized version is correct. And in particular, the BIP repository uses exclusively the lowercase version with two exceptions in BIP136.
  33. in bip-???-cat.mediawiki:26 in 945e2a3742 outdated
    21+# and then pushes the concatenated value on the top of the stack.
    22+
    23+OP_CAT fails if there are less than two values on the stack or if a concatenated value would have a combined size greater than the maximum script element size of 520 Bytes.
    24+
    25+==Motivation==
    26+Bitcoin tapscript lacks a general purpose way of combining objects on the stack restricting the expressiveness and power of tapscript. This prevents among many other things the ability to construct and evaluate merkle trees and other hashed data structures in tapscript. OP_CAT by adding a general purpose way to concatenate stack values would overcome this limitation and greatly increase the functionality of tapscript.
    


    vostrnad commented at 5:30 am on December 15, 2023:

    “Bitcoin Script” or just “tapscript” are perfectly normal terms, their combination somewhat less so:

    0Tapscript lacks a general purpose way of combining objects on the stack restricting the expressiveness and power of tapscript. This prevents among many other things the ability to construct and evaluate merkle trees and other hashed data structures in tapscript. OP_CAT by adding a general purpose way to concatenate stack values would overcome this limitation and greatly increase the functionality of tapscript.
    

    kallewoof commented at 12:50 pm on December 15, 2023:
    I think the original is fine.

    vostrnad commented at 3:15 am on December 16, 2023:
    Yes, I’ve checked and it seems “Bitcoin tapscript” isn’t actually all that uncommon. Disregard.
  34. in bip-???-cat.mediawiki:32 in 945e2a3742 outdated
    27+
    28+OP_CAT aims to expands the toolbox of the tapscript developer with a simple, modular and useful opcode in the spirit of Unix <ref>R. Pike and B. Kernighan, "Program design in the UNIX environment", 1983, https://harmful.cat-v.org/cat-v/unix_prog_design.pdf</ref>. To demonstrate the usefulness of OP_CAT below we provide a non-exhaustive list of some usecases that OP_CAT would enable:
    29+
    30+* Bitstream, a protocol for the atomic swap (fair exchange) of bitcoins for decryption keys, that enables decentralized file hosting systems paid in Bitcoin. While such swaps are currently possible on Bitcoin without OP_CAT they require the use of complex and computationally expensive Verifiable Computation cryptographic techniques. OP_CAT would remove this requirement on Verifiable Computation, making such protocols far more practical to build in Bitcoin. <ref>R. Linus, "BitStream: Decentralized File Hosting Incentivised via Bitcoin Payments", 2023, https://robinlinus.com/bitstream.pdf</ref>
    31+* Tree Signatures provide a multisignature script whose size can be logarithmic in the number of public keys and can encode spend conditions beyond n-of-m. For instance a transaction less than 1KB in size could support tree signatures with a thousand public keys. This also enables generalized logical spend conditions. <ref> P. Wuille, "Multisig on steroids using tree signatures", 2015, https://blog.blockstream.com/en-treesignatures/</ref>
    32+* Post-Quantum Lamport Signatures in Bitcoin transactions. Lamport signatures merely require the ability to hash and concatenate values on the stack. <ref>J. Rubin, "[bitcoin-dev] OP_CAT Makes Bitcoin Quantum Secure [was CheckSigFromStack for Arithmetic Values]", 2021, https://lists.linuxfoundation.org/pipermail/bitcoin-dev/2021-July/019233.html</ref>
    


    vostrnad commented at 5:30 am on December 15, 2023:
    Lamport signatures in tapscript aren’t actually quantum secure because the taptweak still relies on EC operations.

    EthanHeilman commented at 2:35 am on December 16, 2023:
    As far as I know it is an open question if the taptweak based commitment is quantum secure or not. This BIP could not take a position on this question. I will reword this to fix any confusion.

    vostrnad commented at 3:13 am on December 16, 2023:
    You’re right, I spoke too soon.

    EthanHeilman commented at 9:27 pm on December 16, 2023:
    I’m glad you brought this up. I wouldn’t want the BIP to be seen as making an authoritative statement on this question. Let me know if you think my change addresses the issue or not.
  35. in bip-???-cat.mediawiki:37 in 945e2a3742 outdated
    32+* Post-Quantum Lamport Signatures in Bitcoin transactions. Lamport signatures merely require the ability to hash and concatenate values on the stack. <ref>J. Rubin, "[bitcoin-dev] OP_CAT Makes Bitcoin Quantum Secure [was CheckSigFromStack for Arithmetic Values]", 2021, https://lists.linuxfoundation.org/pipermail/bitcoin-dev/2021-July/019233.html</ref>
    33+* Non-equivocation contracts <ref>T. Ruffing, A. Kate, D. Schröder, "Liar, Liar, Coins on Fire: Penalizing Equivocation by Loss of Bitcoins", 2015, https://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.727.6262&rep=rep1&type=pdf</ref> in tapscript provide a mechanism to punish equivocation/double spending in Bitcoin payment channels. OP_CAT enables this by enforcing rules on the spending transaction's nonce. The capability is a useful building block for payment channels and other Bitcoin protocols.
    34+* Vaults <ref>M. Moser, I. Eyal, and E. G. Sirer, Bitcoin Covenants, http://fc16.ifca.ai/bitcoin/papers/MES16.pdf</ref> which are a specialized covenant that allows a user to block a malicious party who has compromised the user's secret key from stealing the funds in that output. As shown in <ref>A. Poelstra, "CAT and Schnorr Tricks II", 2021, https://www.wpsoftware.net/andrew/blog/cat-and-schnorr-tricks-ii.html</ref> OP_CAT is sufficent to build vaults in Bitcoin.
    35+* Replicating CheckSigFromStack <ref>A. Poelstra, "CAT and Schnorr Tricks I", 2021, https://medium.com/blockstream/cat-and-schnorr-tricks-i-faf1b59bd298</ref> which would allow the creation of simple covenants and other advanced contracts without having to presign spending transactions, possibly reducing complexity and the amount of data that needs to be stored. Originally shown to work with Schnorr signatures, this result has been extended to ECDSA signatures <ref>R. Linus, "Covenants with CAT and ECDSA", 2023, https://gist.github.com/RobinLinus/9a69f5552be94d13170ec79bf34d5e85#file-covenants_cat_ecdsa-md</ref>.
    36+
    37+The opcode OP_CAT was available in early versions of Bitcoin. However OP_CAT was removed because it enabled the construction of a script for which an evaluation could have memory usage exponential in the size of the script.
    


    vostrnad commented at 5:30 am on December 15, 2023:
    0The opcode OP_CAT was available in early versions of Bitcoin. However OP_CAT was removed because it enabled the construction of a script whose evaluation could have memory usage exponential in the size of the script.
    

    kallewoof commented at 12:49 pm on December 15, 2023:
    Slightly like the change over original but both are fine IMO.
  36. in bip-???-cat.mediawiki:38 in 945e2a3742 outdated
    33+* Non-equivocation contracts <ref>T. Ruffing, A. Kate, D. Schröder, "Liar, Liar, Coins on Fire: Penalizing Equivocation by Loss of Bitcoins", 2015, https://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.727.6262&rep=rep1&type=pdf</ref> in tapscript provide a mechanism to punish equivocation/double spending in Bitcoin payment channels. OP_CAT enables this by enforcing rules on the spending transaction's nonce. The capability is a useful building block for payment channels and other Bitcoin protocols.
    34+* Vaults <ref>M. Moser, I. Eyal, and E. G. Sirer, Bitcoin Covenants, http://fc16.ifca.ai/bitcoin/papers/MES16.pdf</ref> which are a specialized covenant that allows a user to block a malicious party who has compromised the user's secret key from stealing the funds in that output. As shown in <ref>A. Poelstra, "CAT and Schnorr Tricks II", 2021, https://www.wpsoftware.net/andrew/blog/cat-and-schnorr-tricks-ii.html</ref> OP_CAT is sufficent to build vaults in Bitcoin.
    35+* Replicating CheckSigFromStack <ref>A. Poelstra, "CAT and Schnorr Tricks I", 2021, https://medium.com/blockstream/cat-and-schnorr-tricks-i-faf1b59bd298</ref> which would allow the creation of simple covenants and other advanced contracts without having to presign spending transactions, possibly reducing complexity and the amount of data that needs to be stored. Originally shown to work with Schnorr signatures, this result has been extended to ECDSA signatures <ref>R. Linus, "Covenants with CAT and ECDSA", 2023, https://gist.github.com/RobinLinus/9a69f5552be94d13170ec79bf34d5e85#file-covenants_cat_ecdsa-md</ref>.
    36+
    37+The opcode OP_CAT was available in early versions of Bitcoin. However OP_CAT was removed because it enabled the construction of a script for which an evaluation could have memory usage exponential in the size of the script.
    38+For instance a script which pushed a 1 Byte value on the stack and then repeated the opcodes OP_DUP, OP_CAT 40 times would result in a stack value whose size was greater than 1 Terabyte. This is no longer an issue because tapscript enforces a maximum stack element size of 520 Bytes.
    


    vostrnad commented at 5:30 am on December 15, 2023:
    0For example, a script that pushed a 1-byte value on the stack and then repeated the opcodes OP_DUP, OP_CAT 40 times would result in a stack value whose size was greater than 1 terabyte. This is no longer an issue because tapscript enforces a maximum stack element size of 520 bytes.
    

    kallewoof commented at 12:49 pm on December 15, 2023:
    For instance and for example mean the same thing. Original is fine, though I guess I agree ‘byte’ looks better uncapitalized.
  37. in bip-???-cat.mediawiki:42 in 945e2a3742 outdated
    37+The opcode OP_CAT was available in early versions of Bitcoin. However OP_CAT was removed because it enabled the construction of a script for which an evaluation could have memory usage exponential in the size of the script.
    38+For instance a script which pushed a 1 Byte value on the stack and then repeated the opcodes OP_DUP, OP_CAT 40 times would result in a stack value whose size was greater than 1 Terabyte. This is no longer an issue because tapscript enforces a maximum stack element size of 520 Bytes.
    39+
    40+==Specification==
    41+
    42+OP_CAT pops two elements off the stack, concatenates them together in stack order and pushes the resulting element onto the stack. Given the stack [x1,x2], where x2 is at the top of the stack, OP_CAT will push x1||x2 onto the stack. By '||' we denote concatenation.
    


    vostrnad commented at 5:31 am on December 15, 2023:
    0OP_CAT pops two elements off the stack, concatenates them together in stack order and pushes the resulting element onto the stack. Given the stack _[x1, x2]_, where _x2_ is at the top of the stack, OP_CAT will push _x1 || x2_ onto the stack. By _||_ we denote concatenation.
    

    kallewoof commented at 12:48 pm on December 15, 2023:
    Original is fine IMO.
  38. in bip-???-cat.mediawiki:44 in 945e2a3742 outdated
    39+
    40+==Specification==
    41+
    42+OP_CAT pops two elements off the stack, concatenates them together in stack order and pushes the resulting element onto the stack. Given the stack [x1,x2], where x2 is at the top of the stack, OP_CAT will push x1||x2 onto the stack. By '||' we denote concatenation.
    43+
    44+Implementation
    


    vostrnad commented at 5:31 am on December 15, 2023:
    0===Implementation===
    
  39. in bip-???-cat.mediawiki:63 in 945e2a3742 outdated
    58+}
    59+break;
    60+</pre>
    61+This implementation is inspired by the original implementation of OP_CAT as shown below. An alternative implementation of OP_CAT can be found in Elements <ref>Roose S., Elements Project, "Re-enable several disabled opcodes", 2019, https://github.com/ElementsProject/elements/commit/13e1103abe3e328c5a4e2039b51a546f8be6c60a#diff-a0337ffd7259e8c7c9a7786d6dbd420c80abfa1afdb34ebae3261109d9ae3c19R740-R759</ref>.
    62+
    63+The value of MAX_SCRIPT_ELEMENT_SIZE is 520 Bytes
    


    vostrnad commented at 5:31 am on December 15, 2023:
    0The value of <code>MAX_SCRIPT_ELEMENT_SIZE</code> is 520.
    

    kallewoof commented at 12:48 pm on December 15, 2023:
    This is not mediawiki formatting, it is markdown.

    vostrnad commented at 1:15 pm on December 15, 2023:
    My bad, corrected.
  40. in bip-???-cat.mediawiki:67 in 945e2a3742 outdated
    62+
    63+The value of MAX_SCRIPT_ELEMENT_SIZE is 520 Bytes
    64+
    65+==Notes==
    66+
    67+OP_CAT as it existed in the Bitcoin codebase prior to the commit "misc changes" 4bd188c<ref>S. Nakamoto, "misc changes", Aug 25 2010, https://github.com/bitcoin/bitcoin/commit/4bd188c4383d6e614e18f79dc337fbabe8464c82#diff-27496895958ca30c47bbb873299a2ad7a7ea1003a9faa96b317250e3b7aa1fefL381</ref> which disabled it.
    


    vostrnad commented at 5:31 am on December 15, 2023:
    0OP_CAT as it existed in the Bitcoin codebase prior to the commit "misc changes" 4bd188c<ref>S. Nakamoto, "misc changes", Aug 25 2010, https://github.com/bitcoin/bitcoin/commit/4bd188c4383d6e614e18f79dc337fbabe8464c82#diff-27496895958ca30c47bbb873299a2ad7a7ea1003a9faa96b317250e3b7aa1fefL381</ref> which disabled it:
    

    Also, perhaps have the link point to line 94 where the disabling happens, as opposed to the unreachable code?


    EthanHeilman commented at 8:51 pm on December 15, 2023:
    With regard to line 94, the intent here is to provide a citation to what OP_CAT looked like in the commit at which it was disabled not the mechanism which disabled it. Keeping the link to line 381 unless this is a blocker.

    vostrnad commented at 1:56 am on December 16, 2023:
    If that is the intent, I’d prefer linking to the last commit where it was still active (i.e. one commit before).
  41. in bip-???-cat.mediawiki:91 in 945e2a3742 outdated
    86+==Acknowledgements==
    87+
    88+We wish to acknowledge Dan Gould for encouraging and helping review this effort. 
    89+
    90+== Copyright ==
    91+This document is placed in the public domain.
    


    vostrnad commented at 5:31 am on December 15, 2023:
    The BIP header says BSD-3-Clause.
  42. Prefer bytes to Bytes
    Co-authored-by: Vojtěch Strnad <43024885+vostrnad@users.noreply.github.com>
    7180c1cf8c
  43. Increases conciseness and clarity
    Co-authored-by: Vojtěch Strnad <43024885+vostrnad@users.noreply.github.com>
    6f5a74d83e
  44. Lowercase bytes
    Co-authored-by: Vojtěch Strnad <43024885+vostrnad@users.noreply.github.com>
    d4f85b1146
  45. Adds subsection header
    Co-authored-by: Vojtěch Strnad <43024885+vostrnad@users.noreply.github.com>
    beb5802cc6
  46. Use BSD-3 license 0a143d3969
  47. Code formatting
    Co-authored-by: Vojtěch Strnad <43024885+vostrnad@users.noreply.github.com>
    82198302cd
  48. Code formatting
    Co-authored-by: Vojtěch Strnad <43024885+vostrnad@users.noreply.github.com>
    0b8a7e4b64
  49. Period to colon
    Co-authored-by: Vojtěch Strnad <43024885+vostrnad@users.noreply.github.com>
    77509f6c23
  50. in bip-???-cat.mediawiki:91 in d4f85b1146 outdated
    86+==Acknowledgements==
    87+
    88+We wish to acknowledge Dan Gould for encouraging and helping review this effort. 
    89+
    90+== Copyright ==
    91+This document is placed in the public domain.
    


    EthanHeilman commented at 8:43 pm on December 15, 2023:
    0This document is licensed under the 3-clause BSD license.
    
  51. Avoids designing or discussing how to add post-quantum commitments to Bitcoin 4f39e4b9d5
  52. in bip-???-cat.mediawiki:32 in 77509f6c23 outdated
    27+
    28+OP_CAT aims to expands the toolbox of the tapscript developer with a simple, modular and useful opcode in the spirit of Unix <ref>R. Pike and B. Kernighan, "Program design in the UNIX environment", 1983, https://harmful.cat-v.org/cat-v/unix_prog_design.pdf</ref>. To demonstrate the usefulness of OP_CAT below we provide a non-exhaustive list of some usecases that OP_CAT would enable:
    29+
    30+* Bitstream, a protocol for the atomic swap (fair exchange) of bitcoins for decryption keys, that enables decentralized file hosting systems paid in Bitcoin. While such swaps are currently possible on Bitcoin without OP_CAT they require the use of complex and computationally expensive Verifiable Computation cryptographic techniques. OP_CAT would remove this requirement on Verifiable Computation, making such protocols far more practical to build in Bitcoin. <ref>R. Linus, "BitStream: Decentralized File Hosting Incentivised via Bitcoin Payments", 2023, https://robinlinus.com/bitstream.pdf</ref>
    31+* Tree Signatures provide a multisignature script whose size can be logarithmic in the number of public keys and can encode spend conditions beyond n-of-m. For instance a transaction less than 1KB in size could support tree signatures with a thousand public keys. This also enables generalized logical spend conditions. <ref> P. Wuille, "Multisig on steroids using tree signatures", 2015, https://blog.blockstream.com/en-treesignatures/</ref>
    32+* Post-Quantum Lamport Signatures in Bitcoin transactions. Lamport signatures merely require the ability to hash and concatenate values on the stack. <ref>J. Rubin, "[bitcoin-dev] OP_CAT Makes Bitcoin Quantum Secure [was CheckSigFromStack for Arithmetic Values]", 2021, https://lists.linuxfoundation.org/pipermail/bitcoin-dev/2021-July/019233.html</ref>
    


    EthanHeilman commented at 9:21 pm on December 16, 2023:
    0* Post-Quantum Lamport Signatures in Bitcoin transactions. Lamport signatures merely require the ability to hash and concatenate values on the stack. <ref>J. Rubin, "[bitcoin-dev] OP_CAT Makes Bitcoin Quantum Secure [was CheckSigFromStack for Arithmetic Values]", 2021, https://lists.linuxfoundation.org/pipermail/bitcoin-dev/2021-July/019233.html</ref> It is an open question if the quantum resistance of Lamport Signatures can be preserved when used in a taproot output.
    
  53. in bip-???-cat.mediawiki:32 in 4f39e4b9d5 outdated
    27+
    28+OP_CAT aims to expands the toolbox of the tapscript developer with a simple, modular and useful opcode in the spirit of Unix <ref>R. Pike and B. Kernighan, "Program design in the UNIX environment", 1983, https://harmful.cat-v.org/cat-v/unix_prog_design.pdf</ref>. To demonstrate the usefulness of OP_CAT below we provide a non-exhaustive list of some usecases that OP_CAT would enable:
    29+
    30+* Bitstream, a protocol for the atomic swap (fair exchange) of bitcoins for decryption keys, that enables decentralized file hosting systems paid in Bitcoin. While such swaps are currently possible on Bitcoin without OP_CAT they require the use of complex and computationally expensive Verifiable Computation cryptographic techniques. OP_CAT would remove this requirement on Verifiable Computation, making such protocols far more practical to build in Bitcoin. <ref>R. Linus, "BitStream: Decentralized File Hosting Incentivised via Bitcoin Payments", 2023, https://robinlinus.com/bitstream.pdf</ref>
    31+* Tree Signatures provide a multisignature script whose size can be logarithmic in the number of public keys and can encode spend conditions beyond n-of-m. For instance a transaction less than 1KB in size could support tree signatures with a thousand public keys. This also enables generalized logical spend conditions. <ref> P. Wuille, "Multisig on steroids using tree signatures", 2015, https://blog.blockstream.com/en-treesignatures/</ref>
    32+* Post-Quantum Lamport Signatures in Bitcoin transactions. Lamport signatures merely require the ability to hash and concatenate values on the stack. <ref>J. Rubin, "[bitcoin-dev] OP_CAT Makes Bitcoin Quantum Secure [was CheckSigFromStack for Arithmetic Values]", 2021, https://lists.linuxfoundation.org/pipermail/bitcoin-dev/2021-July/019233.html</ref> It is an open question if the quantum resistance of Lamport Signatures can be preserved when used in a taproot output.
    


    vostrnad commented at 6:20 am on December 17, 2023:
    0* Post-Quantum Lamport Signatures in Bitcoin transactions. Lamport signatures merely require the ability to hash and concatenate values on the stack. <ref>J. Rubin, "[bitcoin-dev] OP_CAT Makes Bitcoin Quantum Secure [was CheckSigFromStack for Arithmetic Values]", 2021, https://lists.linuxfoundation.org/pipermail/bitcoin-dev/2021-July/019233.html</ref> It is an open question if the quantum resistance of Lamport signatures can be preserved when used in a taproot output.
    

    EthanHeilman commented at 5:46 pm on December 17, 2023:
    Looking at usage, you are correct, signature is lowercase. I’m rejecting this suggesting because I want to fix it in the first sentence as well.

    EthanHeilman commented at 5:49 pm on December 17, 2023:
    0* Tree signatures provide a multisignature script whose size can be logarithmic in the number of public keys and can encode spend conditions beyond n-of-m. For instance a transaction less than 1KB in size could support tree signatures with a thousand public keys. This also enables generalized logical spend conditions. <ref> P. Wuille, "Multisig on steroids using tree signatures", 2015, https://blog.blockstream.com/en-treesignatures/</ref>
    1* Post-Quantum Lamport signatures in Bitcoin transactions. Lamport signatures merely require the ability to hash and concatenate values on the stack. <ref>J. Rubin, "[bitcoin-dev] OP_CAT Makes Bitcoin Quantum Secure [was CheckSigFromStack for Arithmetic Values]", 2021, https://lists.linuxfoundation.org/pipermail/bitcoin-dev/2021-July/019233.html</ref> It is an open question if the quantum resistance of Lamport signatures can be preserved when used in a taproot output.
    
  54. in bip-???-cat.mediawiki:42 in 4f39e4b9d5 outdated
    37+The opcode OP_CAT was available in early versions of Bitcoin. However OP_CAT was removed because it enabled the construction of a script whose evaluation could have memory usage exponential in the size of the script.
    38+For example, a script that pushed a 1-byte value on the stack and then repeated the opcodes OP_DUP, OP_CAT 40 times would result in a stack value whose size was greater than 1 terabyte. This is no longer an issue because tapscript enforces a maximum stack element size of 520 bytes.
    39+
    40+==Specification==
    41+
    42+OP_CAT pops two elements off the stack, concatenates them together in stack order and pushes the resulting element onto the stack. Given the stack _[x1, x2]_, where _x2_ is at the top of the stack, OP_CAT will push _x1 || x2_ onto the stack. By _||_ we denote concatenation.
    


    vostrnad commented at 6:20 am on December 17, 2023:

    If you check the rendered version, the italics aren’t actually showing, it appears '' needs to be used. The brackets also mess with the result and need a nowiki tag. I’ve tested on my branch that this works:

    0OP_CAT pops two elements off the stack, concatenates them together in stack order and pushes the resulting element onto the stack. Given the stack ''<nowiki>[x1, x2]</nowiki>'', where ''x2'' is at the top of the stack, OP_CAT will push ''x1 || x2'' onto the stack. By ''||'' we denote concatenation.
    
  55. vostrnad approved
  56. Lowercase the signatures 97635f5c09
  57. Italicize variables
    Co-authored-by: Vojtěch Strnad <43024885+vostrnad@users.noreply.github.com>
    e3dc3ba361
  58. 0xBEEFCAF3 commented at 8:16 pm on December 18, 2023: contributor
    @kallewoof The BIP file is still name bip-???-cat.mediawiki. How do we go about numbering this BIP?
  59. in bip-???-cat.mediawiki:67 in e3dc3ba361 outdated
    62+
    63+The value of <code>MAX_SCRIPT_ELEMENT_SIZE</code> is 520.
    64+
    65+==Notes==
    66+
    67+OP_CAT as it existed in the Bitcoin codebase prior to the commit "misc changes" 4bd188c<ref>S. Nakamoto, "misc changes", Aug 25 2010, https://github.com/bitcoin/bitcoin/commit/4bd188c4383d6e614e18f79dc337fbabe8464c82#diff-27496895958ca30c47bbb873299a2ad7a7ea1003a9faa96b317250e3b7aa1fefL381</ref> which disabled it:
    


    EthanHeilman commented at 1:27 am on December 19, 2023:
    0[OP_CAT as it existed in the Bitcoin codebase](https://github.com/bitcoin/bitcoin/blob/01cd2fdaf3ac6071304ceb80fb7436ac02b1059e/script.cpp#L381-L393) prior to the commit "misc changes" 4bd188c<ref>S. Nakamoto, "misc changes", Aug 25 2010, https://github.com/bitcoin/bitcoin/commit/4bd188c4383d6e614e18f79dc337fbabe8464c82#diff-27496895958ca30c47bbb873299a2ad7a7ea1003a9faa96b317250e3b7aa1fefR94</ref> which disabled it:
    
  60. Better reference for OP_CAT removal e492a90fec
  61. kallewoof commented at 1:53 am on December 19, 2023: member

    @kallewoof The BIP file is still name bip-???-cat.mediawiki. How do we go about numbering this BIP?

    Once a BP number has been assigned, the authors are expected to fill that in in the right places.

  62. 0xBEEFCAF3 commented at 7:25 pm on December 19, 2023: contributor

    @kallewoof The BIP file is still name bip-???-cat.mediawiki. How do we go about numbering this BIP?

    Once a BP number has been assigned, the authors are expected to fill that in in the right places.

    Thanks for the reply. Of course, we’ll change and fill the bip number wherever it’s needed. Has this BIP already been assigned a number? I might have missed that comment

  63. luke-jr added the label New BIP on Dec 26, 2023
  64. luke-jr dismissed
  65. luke-jr commented at 7:28 pm on December 26, 2023: member
    Missing a section for backward compatibility
  66. Add backwards compatibility section 785b11e861
  67. Merge pull request #1 from 0xBEEFCAF3/patch-1
    Add backwards compatibility section
    e91621efce
  68. 0xBEEFCAF3 commented at 6:47 pm on December 29, 2023: contributor

    Missing a section for backward compatibility @luke-jr Added!

  69. specify the hex value of the opcode 82fe9fc3db
  70. in bip-???-cat.mediawiki:16 in e91621efce outdated
    11+  License: BSD-3-Clause
    12+</pre>
    13+
    14+==Abstract==
    15+
    16+This BIP reintroduces OP_CAT in the form of a new tapscript opcode which allows the concatenation of two values on the stack. This opcode would be activated via a soft fork by redefining the opcode OP_SUCCESS126.
    


    junderw commented at 10:58 pm on December 29, 2023:
    Adding a (0x7e) might help be a bit clearer. Libraries in various languages have small variations on OP code naming.

    EthanHeilman commented at 11:30 pm on December 29, 2023:
    Thanks, updated bip
  71. EthanHeilman requested review from luke-jr on Dec 30, 2023
  72. in bip-???-cat.mediawiki:15 in 82fe9fc3db outdated
    10+  Comments-URI: https://github.com/bitcoin/bips/wiki/Comments:BIP-op-cat
    11+  License: BSD-3-Clause
    12+</pre>
    13+
    14+==Abstract==
    15+
    


    halseth commented at 1:00 pm on January 4, 2024:
    Maybe add a note that this is the same opcode used for OP_CAT originally.

    0xBEEFCAF3 commented at 4:15 pm on January 4, 2024:
    Good point!

    EthanHeilman commented at 9:34 pm on January 7, 2024:
    Fixed
  73. illesdavid approved
  74. add clarifying note about the current opcode
    And some grammar + spelling cleanup
    ae68ef11cb
  75. Notes that the opcode used is the same as the original cat opcode f9e100e9de
  76. EthanHeilman requested review from halseth on Jan 7, 2024
  77. EthanHeilman requested review from 0xBEEFCAF3 on Jan 7, 2024
  78. Merge branch 'cat' into patch-1 799dc0c96d
  79. rm comment on disabled CAT opcode 2cec73a5b4
  80. revert changes to abstract 5dde7ea5cf
  81. Merge pull request #2 from 0xBEEFCAF3/patch-1
    add clarifying note about the current opcode
    2b5ab3b1fd
  82. EthanHeilman commented at 3:01 am on January 19, 2024: contributor
    @luke-jr We are requesting a BIP number for this PR
  83. halseth approved
  84. halseth commented at 9:12 pm on January 23, 2024: none
    ACK
  85. cf commented at 2:30 am on March 2, 2024: none
    Any updates on this, would love to see this BIP merged to make verification of FRI based zero knowledge proofs (pay to zkp) more efficient
  86. stevenroose commented at 5:37 pm on March 5, 2024: contributor

    I would like to propose to replace the per-item size limit with a total stack size limit that is equivalent and can be introduced as a softfork as well. Since we currently allow 1000 items of 520 bytes, I would propose a 520kB (520,000 bytes) size limit for the entire stack + altstack.

    This can be implemented as such:

     0diff --git a/src/script/interpreter.cpp b/src/script/interpreter.cpp
     1index 1583b5fadd3..cbe1695bab2 100644
     2--- a/src/script/interpreter.cpp
     3+++ b/src/script/interpreter.cpp
     4@@ -545,8 +545,6 @@ bool EvalScript(std::vector<std::vector<unsigned char> >& stack, const CScript&
     5                         return set_error(serror, SCRIPT_ERR_INVALID_STACK_OPERATION);
     6                     valtype& vch1 = stacktop(-2);
     7                     valtype& vch2 = stacktop(-1);
     8-                    if (vch1.size() + vch2.size() > MAX_SCRIPT_ELEMENT_SIZE)
     9-                        return set_error(serror, SCRIPT_ERR_INVALID_STACK_OPERATION);
    10                     vch1.insert(vch1.end(), vch2.begin(), vch2.end());
    11                     stack.pop_back();
    12                 }
    13@@ -1287,8 +1285,17 @@ bool EvalScript(std::vector<std::vector<unsigned char> >& stack, const CScript&
    14             }
    15
    16             // Size limits
    17+            // limit number of elements in stacks
    18             if (stack.size() + altstack.size() > MAX_STACK_SIZE)
    19                 return set_error(serror, SCRIPT_ERR_STACK_SIZE);
    20+            // limit total number of bytes in stacks
    21+            unsigned int total_bytes = 0;
    22+            for (size_t i = 0; i < stack.size() ; i++)
    23+                total_bytes += stack[i].size();
    24+            for (size_t i = 0; i < altstack.size() ; i++)
    25+                total_bytes += altstack[i].size();
    26+            if (total_bytes > MAX_STACK_BYTES)
    27+                return set_error(serror, SCRIPT_ERR_STACK_SIZE);
    28         }
    29     }
    30     catch (...)
    31diff --git a/src/script/script.h b/src/script/script.h
    32index 305919f5ba4..ef40c3672ee 100644
    33--- a/src/script/script.h
    34+++ b/src/script/script.h
    35@@ -38,6 +38,9 @@ static const int MAX_SCRIPT_SIZE = 10000;
    36 // Maximum number of values on script interpreter stack
    37 static const int MAX_STACK_SIZE = 1000;
    38
    39+// Maximum number of total bytes on script interpreter stack
    40+static const int MAX_STACK_BYTES = 520000; // 520 * 1000
    41+
    42 // Threshold for nLockTime: below this value it is interpreted as block number,
    43 // otherwise as UNIX timestamp.
    44 static const unsigned int LOCKTIME_THRESHOLD = 500000000; // Tue Nov  5 00:53:20 1985 UTC
    
  87. ChrisMartl commented at 3:51 pm on March 17, 2024: none

    NACK

    OP_CAT enables recursion which is computational equivalent to iteration; thus making Script Turing complete.

  88. EthanHeilman commented at 10:35 pm on March 17, 2024: contributor
    @ChrisMartl How does OP_CAT add recursion? What’s your source for this claim?
  89. apoelstra commented at 10:39 pm on March 17, 2024: contributor

    In case this claim originates with something I’ve said publicly: I am confident that CAT does not introduce recursion to Script and I have never (intentionally) said that it did.

    CAT does introduce a form of recursive covenants. But the form of “recursion” here is one that involves a fresh transaction for every iteration, and does not change the computational model at all.

  90. update OP_CAT implementation b3493746b1
  91. Merge pull request #3 from 0xBEEFCAF3/cat
    Update OP_CAT implementation code
    35641a87d7
  92. Fixes broken mediawiki link ac231a17c2
  93. Adds more acknowledgements c235aa4939
  94. weikengchen commented at 7:20 pm on April 3, 2024: none

    To stevenroose’s proposal. https://github.com/bitcoin/bips/pull/1525#issuecomment-1979297869

    I would like to propose to replace the per-item size limit with a total stack size limit that is equivalent and can be introduced as a softfork as well. Since we currently allow 1000 items of 520 bytes, I would propose a 520kB (520,000 bytes) size limit for the entire stack + altstack.

    This can be implemented as such:

     0diff --git a/src/script/interpreter.cpp b/src/script/interpreter.cpp
     1index 1583b5fadd3..cbe1695bab2 100644
     2--- a/src/script/interpreter.cpp
     3+++ b/src/script/interpreter.cpp
     4@@ -545,8 +545,6 @@ bool EvalScript(std::vector<std::vector<unsigned char> >& stack, const CScript&
     5                         return set_error(serror, SCRIPT_ERR_INVALID_STACK_OPERATION);
     6                     valtype& vch1 = stacktop(-2);
     7                     valtype& vch2 = stacktop(-1);
     8-                    if (vch1.size() + vch2.size() > MAX_SCRIPT_ELEMENT_SIZE)
     9-                        return set_error(serror, SCRIPT_ERR_INVALID_STACK_OPERATION);
    10                     vch1.insert(vch1.end(), vch2.begin(), vch2.end());
    11                     stack.pop_back();
    12                 }
    13@@ -1287,8 +1285,17 @@ bool EvalScript(std::vector<std::vector<unsigned char> >& stack, const CScript&
    14             }
    15
    16             // Size limits
    17+            // limit number of elements in stacks
    18             if (stack.size() + altstack.size() > MAX_STACK_SIZE)
    19                 return set_error(serror, SCRIPT_ERR_STACK_SIZE);
    20+            // limit total number of bytes in stacks
    21+            unsigned int total_bytes = 0;
    22+            for (size_t i = 0; i < stack.size() ; i++)
    23+                total_bytes += stack[i].size();
    24+            for (size_t i = 0; i < altstack.size() ; i++)
    25+                total_bytes += altstack[i].size();
    26+            if (total_bytes > MAX_STACK_BYTES)
    27+                return set_error(serror, SCRIPT_ERR_STACK_SIZE);
    28         }
    29     }
    30     catch (...)
    31diff --git a/src/script/script.h b/src/script/script.h
    32index 305919f5ba4..ef40c3672ee 100644
    33--- a/src/script/script.h
    34+++ b/src/script/script.h
    35@@ -38,6 +38,9 @@ static const int MAX_SCRIPT_SIZE = 10000;
    36 // Maximum number of values on script interpreter stack
    37 static const int MAX_STACK_SIZE = 1000;
    38
    39+// Maximum number of total bytes on script interpreter stack
    40+static const int MAX_STACK_BYTES = 520000; // 520 * 1000
    41+
    42 // Threshold for nLockTime: below this value it is interpreted as block number,
    43 // otherwise as UNIX timestamp.
    44 static const unsigned int LOCKTIME_THRESHOLD = 500000000; // Tue Nov  5 00:53:20 1985 UTC
    

    This seems to require checking the size limit after every opcode is computed, and it might not be scalable. I think this may need to be left to a different PR. Calculating the delta and only updating the delta is possible, but it would need to change the implementation a lot.

  95. ajtowns commented at 4:54 am on April 4, 2024: contributor

    I would like to propose to replace the per-item size limit with a total stack size limit that is equivalent and can be introduced as a softfork as well. Since we currently allow 1000 items of 520 bytes, I would propose a 520kB (520,000 bytes) size limit for the entire stack + altstack.

    Consider the following script:

    0"1234567" DUP CAT 8 CAT
    1DUP CAT DUP CAT DUP CAT DUP CAT DUP CAT DUP CAT DUP CAT
    2DUP CAT DUP CAT DUP CAT DUP CAT DUP CAT DUP CAT DUP CAT
    3
    41 SHA256 OVER CAT SHA256
    5[ OVER CAT SHA256 ] * 130000
    6CAT SHA256
    

    It constructs a ~246kB string on the stack consisting of lots of repeats of “123456712345678”, then repeatedly concatenates that string to a sha256 hash, using the hash of the result as the new sha256 hash. Doing this 130k times means you’re hashing about 32GB of data despite never having more than about 492kB on the stack in total, while still fitting in a standard tx with less than 400k weight units. For comparsion, constraining each stack element to being 520 bytes limits the total amount hashed to under 208MB for any standard transaction.

  96. Changes OP_CAT BIP based on feedback given by Bob Summerwill
    Bob Summerwill proposed a number of changes to the OP_CAT BIP to better follow BIP-2. This commit makes these changes:
    
    * Using the section order specified in BIP-2
    * Adding a Rationale section
    * Expand the specification section by moving details from the abstract into the specification
    
    Additionally this commit as rewords some confusing language.
    
    Thanks Bob
    f8ad6ede57
  97. in bip-???-cat.mediawiki:39 in f8ad6ede57 outdated
    34+
    35+OP_CAT aims to expand the toolbox of the tapscript developer with a simple, modular, and useful opcode in the spirit of Unix <ref>R. Pike and B. Kernighan, "Program design in the UNIX environment", 1983, https://harmful.cat-v.org/cat-v/unix_prog_design.pdf</ref>. To demonstrate the usefulness of OP_CAT below we provide a non-exhaustive list of some usecases that OP_CAT would enable:
    36+
    37+* Bitstream, a protocol for the atomic swap (fair exchange) of bitcoins for decryption keys, that enables decentralized file hosting systems paid in Bitcoin. While such swaps are currently possible on Bitcoin without OP_CAT they require the use of complex and computationally expensive Verifiable Computation cryptographic techniques. OP_CAT would remove this requirement on Verifiable Computation, making such protocols far more practical to build in Bitcoin. <ref>R. Linus, "BitStream: Decentralized File Hosting Incentivised via Bitcoin Payments", 2023, https://robinlinus.com/bitstream.pdf</ref>
    38+* Tree signatures provide a multisignature script whose size can be logarithmic in the number of public keys and can encode spend conditions beyond n-of-m. For instance a transaction less than 1KB in size could support tree signatures with a thousand public keys. This also enables generalized logical spend conditions. <ref> P. Wuille, "Multisig on steroids using tree signatures", 2015, https://blog.blockstream.com/en-treesignatures/</ref>
    39+* Post-Quantum Lamport signatures in Bitcoin transactions. Lamport signatures merely require the ability to hash and concatenate values on the stack. <ref>J. Rubin, "[bitcoin-dev] OP_CAT Makes Bitcoin Quantum Secure [was CheckSigFromStack for Arithmetic Values]", 2021, https://lists.linuxfoundation.org/pipermail/bitcoin-dev/2021-July/019233.html</ref> It is an open question if the quantum resistance of Lamport signatures can be preserved when used in a taproot output.
    


    real-or-random commented at 0:07 am on April 17, 2024:

    nit:

    0* Post-quantum Lamport signatures in Bitcoin transactions. Lamport signatures merely require the ability to hash and concatenate values on the stack. <ref>J. Rubin, "[bitcoin-dev] OP_CAT Makes Bitcoin Quantum Secure [was CheckSigFromStack for Arithmetic Values]", 2021, https://lists.linuxfoundation.org/pipermail/bitcoin-dev/2021-July/019233.html</ref> It is an open question if the quantum resistance of Lamport signatures can be preserved when used in a taproot output.
    

    It is an open question if the quantum resistance of Lamport signatures can be preserved when used in a taproot output.

    I’m not sure if this adds even more confusion. In the most direct sense, taproot outputs are clearly not post-quantum secure because the attacker can perform a key-path spend. Maybe something like: “Putting aside the ability to perform key-path spends, which clearly makes taproot insecure against a quantum attacker, it is an open question if the quantum resistance of Lamport signatures can be preserved when used in a script committed to in a taproot output.”



    EthanHeilman commented at 12:04 pm on April 17, 2024:

    @real-or-random Thanks for taking a look at this.

    There is some history behind the intentional ambiguity in our statement here. we’ve been doing research on the quantum security of tapscript. I agree the script spend commit is probably provably quantum resistant under some assumptions. I had hoped I could find a way to prevent key path spends by constructing the taproot output in such a way that it would break the key spend path, e.g. an output where the only key spend signatures result in an invalid curve point. I haven’t fully thrown in the towel on that attempt but it is looking highly unlikely at this point.

    Let me edit this


    EthanHeilman commented at 5:43 pm on April 25, 2024:
    @real-or-random Edited the quantum resistance section. Let me know what you think about it now

    real-or-random commented at 10:00 pm on May 2, 2024:

    Yep, great, I think it’s clearer now.

    Micro nit in the new paragraph: s/Lamport Signatures/Lamport signatures

  98. bitcoin deleted a comment on Apr 17, 2024
  99. Roasbeef commented at 5:54 pm on April 24, 2024: contributor
    Assigned BIP 347.
  100. delbonis commented at 6:27 pm on April 24, 2024: none
    Does this mean we can also formally propose OP_{LEFT,RIGHT,SUBSTR} now too? :heart_eyes:
  101. apoelstra commented at 6:32 pm on April 24, 2024: contributor

    @delbonis anybody can propose anything formally, by running through the process of creating a proposal, soliciting input on the mailing list, etc.

    But the three opcodes you mention can be fairly-cheaply emulated using CAT, and have fewer direct usecases, so it may not be a productive direction to pursue.

  102. JeremyRubin commented at 9:33 pm on April 24, 2024: contributor
    LEFT/RIGHT/SUBSTR/SPLIT etc are actually a bit nicer in some ways than CAT because they only create same size or smaller elements on the stack, forgoing the concerns of max element size / working seamlessly if the element size should ever be changed to allow larger.
  103. jonatack commented at 10:59 pm on April 24, 2024: contributor
    Please keep comments focused on technical review of the proposal – thanks.
  104. bitcoin deleted a comment on Apr 24, 2024
  105. bitcoin deleted a comment on Apr 24, 2024
  106. bitcoin deleted a comment on Apr 24, 2024
  107. weikengchen commented at 1:11 am on April 25, 2024: none

    @delbonis @JeremyRubin Re: OP_LEFT/RIGHT/SUBSTR

    There are still values in OP_LEFT/RIGHT/SUBSTR. To emulate them with OP_CAT, one needs to provide a hint, and this takes space in the witness stack / input stack. This is inconvenient because the witness stack can have at most 1000 elements.

    In our practice with Merkle trees for STARK proof verifier that uses OP_CAT, for each layer, we need to provide a sibling element. A standard transaction only prefers binary Merkle tree. And therefore, there are log_{2} n elements that we need to push in the witness stack. (nonstandard transaction is an easier situation, which allows log_{16} n) OP_LEFT/RIGHT/SUBSTR, if together with a nonstandard transaction, can allow one to pack elements compactly to save stack space.

    Here is the related codebase: https://github.com/Bitcoin-Wildlife-Sanctuary/bitcoin-circle-stark?tab=readme-ov-file#performance

    But I think people can agree that bringing back OP_SUBSTR is enough. This allows us to save other successful opcodes for other purposes.

    That said, this is not related to the OP_CAT BIP discussion, and may be better discussed in other venues.

  108. Renamed to use BIP-0347 6c729c4b41
  109. Fixes comment URI 0a3869d102
  110. Better quantum resistant section based Tim's comments
    Adds additional acks
    7ed8f6f38c
  111. Specifies exact tree signature limit (suggested by Ali Sherief) 852502b9cf
  112. OminousPeace commented at 12:55 pm on April 26, 2024: none
    Could you point me toward where i can learn more about the stack size limit referred? I’m not technically savvy enough to catch how the 520 bytes stack limit is imposed on OP_CAT operation when there are no mention of the rationale in the commit. Is it enforced by tapscript? @EthanHeilman thank you
  113. EthanHeilman commented at 2:43 pm on April 26, 2024: contributor

    Thanks for your question!

    Could you point me toward where i can learn more about the stack size limit referred? @OminousPeace

    In the OP_CAT reference implementation in BIP-347:

     0case OP_CAT:
     1{
     2 if (stack.size() < 2)
     3   return set_error(serror, SCRIPT_ERR_INVALID_STACK_OPERATION);
     4 valtype& vch1 = stacktop(-2);
     5 valtype& vch2 = stacktop(-1);
     6 if (vch1.size() + vch2.size() > MAX_SCRIPT_ELEMENT_SIZE)
     7   return set_error(serror, SCRIPT_ERR_PUSH_SIZE);
     8 vch1.insert(vch1.end(), vch2.begin(), vch2.end());
     9 stack.pop_back();
    10}
    11break;
    

    We check that their are sufficient elements on the stack:

    0  if (stack.size() < 2)
    1   return set_error(serror, SCRIPT_ERR_INVALID_STACK_OPERATION);
    

    Then we check that the CAT operation will not create a stack element larger than the max stack element:

    0  if (vch1.size() + vch2.size() > MAX_SCRIPT_ELEMENT_SIZE)
    1    return set_error(serror, SCRIPT_ERR_PUSH_SIZE);
    

    MAX_SCRIPT_ELEMENT_SIZE is defined as 520 (bytes) in bitcoin-core.

    0// Maximum number of bytes pushable to the stack
    1static const unsigned int MAX_SCRIPT_ELEMENT_SIZE = 520;
    

    OP_CAT is neutral with regard to the total size of stack because it joins two elements together which were already on the stack. That is, an OP_CAT operation should never increase or decrease the total size of stack in bytes.

    For running code see our implementation of OP_CAT in bitcoin-inquisition.

    Is it enforced by tapscript?

    Both script and tapscript enforce the element stack size limit and the total stack size limit when a OP_PUSH occurs. OP_CAT like any other opcode which pushes data on the stack, must also ensure that it does not violate this limit, which is why returns an error if it would push an element greater than the maximum stack element size (520).

    Rationale

    We do provide a rationale for why we don’t alter bitcoin consensus to increase the stack element size limit in the rationale section of the BIP.

    Did that answer your question?

  114. in bip-0347.mediawiki:11 in 852502b9cf outdated
     6+          Armin Sabouri <arminsdev@gmail.com>
     7+  Comments-URI: https://github.com/bitcoin/bips/wiki/Comments:BIP-0347
     8+  Status: Draft
     9+  Type: Standards Track
    10+  Created: 2023-10-21
    11+  License: BSD-3-Clause
    


    murchandamus commented at 3:09 pm on April 26, 2024:
    Could you please add the “Post-History” header to link to discussion on the mailing list about this proposal?

    EthanHeilman commented at 1:15 am on May 1, 2024:
    Added!
  115. in bip-0347.mediawiki:18 in 852502b9cf outdated
    13+
    14+==Abstract==
    15+
    16+This BIP introduces OP_CAT as a tapscript opcode which allows the concatenation of two values on the stack. OP_CAT would be activated via a soft fork by redefining the opcode OP_SUCCESS126 (126 in decimal and 0x7e in hexadecimal). This is the same opcode value used by the original OP_CAT.
    17+
    18+== Copyright ==
    


    murchandamus commented at 3:11 pm on April 26, 2024:

    Consistency-nit: Some of your Section Headings are followed by a blank line, while others are not. Please add blank lines under each Heading, or remove them all:

    0== Copyright ==
    
  116. in bip-0347.mediawiki:32 in 852502b9cf outdated
    27+
    28+Given the stack ''<nowiki>[x1, x2]</nowiki>'', where ''x2'' is at the top of the stack, OP_CAT will push ''x1 || x2'' onto the stack. By ''||'' we denote concatenation. OP_CAT fails if there are fewer than two values on the stack or if a concatenated value would have a combined size greater than the maximum script element size of 520 bytes.
    29+
    30+This opcode would be activated via a soft fork by redefining the tapscript opcode OP_SUCCESS126 (126 in decimal and 0x7e in hexadecimal) to OP_CAT.
    31+
    32+==Motivation==
    


    murchandamus commented at 3:15 pm on April 26, 2024:

    Nit: please use consistent formatting for Section Headings.

    0==Motivation==
    
  117. in bip-0347.mediawiki:23 in 852502b9cf outdated
    18+== Copyright ==
    19+This document is licensed under the 3-clause BSD license.
    20+
    21+==Specification==
    22+
    23+When evaluated the OP_CAT instruction:
    


    murchandamus commented at 3:17 pm on April 26, 2024:
    0When evaluated, the OP_CAT instruction:
    
  118. in bip-0347.mediawiki:39 in 852502b9cf outdated
    34+
    35+OP_CAT aims to expand the toolbox of the tapscript developer with a simple, modular, and useful opcode in the spirit of Unix <ref>R. Pike and B. Kernighan, "Program design in the UNIX environment", 1983, https://harmful.cat-v.org/cat-v/unix_prog_design.pdf</ref>. To demonstrate the usefulness of OP_CAT below we provide a non-exhaustive list of some usecases that OP_CAT would enable:
    36+
    37+* Bitstream, a protocol for the atomic swap (fair exchange) of bitcoins for decryption keys, that enables decentralized file hosting systems paid in Bitcoin. While such swaps are currently possible on Bitcoin without OP_CAT they require the use of complex and computationally expensive Verifiable Computation cryptographic techniques. OP_CAT would remove this requirement on Verifiable Computation, making such protocols far more practical to build in Bitcoin. <ref>R. Linus, "BitStream: Decentralized File Hosting Incentivised via Bitcoin Payments", 2023, https://robinlinus.com/bitstream.pdf</ref>
    38+* Tree signatures provide a multisignature script whose size can be logarithmic in the number of public keys and can encode spend conditions beyond n-of-m. For instance a transaction less than 1KB in size could support tree signatures with up to 4,294,967,296 public keys. This also enables generalized logical spend conditions. <ref> P. Wuille, "Multisig on steroids using tree signatures", 2015, https://blog.blockstream.com/en-treesignatures/</ref>
    39+* Post-Quantum Lamport signatures in Bitcoin transactions. Lamport signatures merely require the ability to hash and concatenate values on the stack. <ref>J. Rubin, "[bitcoin-dev] OP_CAT Makes Bitcoin Quantum Secure [was CheckSigFromStack for Arithmetic Values]", 2021, https://lists.linuxfoundation.org/pipermail/bitcoin-dev/2021-July/019233.html</ref> It is an open question if a tapscript commitment would preserve the quantum resistance of Lamport signatures. Beyond this question, the use of Lamport Signatures in taproot outputs is unlikely to be quantum resistant even if the script spend-path is made quantum resistant. This is because taproot outputs can also be spent with a key. An attacker with a sufficiently powerful quantum computer could bypass the taproot script spend-path by finding the discrete log of the taproot output and thus spending the output using the key spend-path. The use of "Nothing Up My Sleeve" (NUMS) points as described in [[bip-0341.mediawiki|BIP341]] to disable the key spend-path does not disable the key spend-path against a quantum attacker as NUMS relies on the hardness of finding discrete logs. We are not aware of any mechanism which could disable the key spend-path in a taproot output without a softfork change to taproot.
    


    murchandamus commented at 3:27 pm on April 26, 2024:
    I’m confused by the “Post-Quantum Lamport signature” example use-case. It seems to me that the description indicates that OP_CAT implemented in Tapscript would not enable quantum security.

    EthanHeilman commented at 5:59 pm on April 26, 2024:

    Thanks for this comment, I want to be very careful we are not over claiming the quantum security OP_CAT gets you.

    Assuming that the script-spend commitment is quantum resistant (there is no published security proof for this assumption), then OP_CAT in tapscript will not enable quantum security unless:

    1. Someone invents a way to construct a taproot output which can not be spent via the key spend path but can be spent via the script spend path. There is no known way to do this and it is probably impossible. However it has not been shown to be impossible.

    2. OR a mechanism is added to bitcoin to disable key-spend paths.

    It has been proposed that if ECDSA is broken or a powerful quantum computer was on the horizon, there might be an effort to protect ownership of bitcoins by allowing people to mark their taproot outputs as “script-spend only” and then move their coins into such outputs. Such a mechanism could be used in conjunction with OP_CAT to enable quantum security.

    This is a confusing topic to discuss without speculation on future unknowns and security countermeasures that go well beyond the scope of OP_CAT.

    What are your thoughts on increasing clarity of this paragraph while staying within the scope of the BIP? Should I just say less?


    murchandamus commented at 7:03 pm on April 26, 2024:

    I see thanks for the explanation. Perhaps another sentence to provide the context of the scenario you are alluding to would help to clarify:

    Perhaps:

    0* Post-Quantum Lamport signatures in Bitcoin transactions. Lamport signatures merely require the ability to hash and concatenate values on the stack. <ref>J. Rubin, "[bitcoin-dev] OP_CAT Makes Bitcoin Quantum Secure [was CheckSigFromStack for Arithmetic Values]", 2021, https://lists.linuxfoundation.org/pipermail/bitcoin-dev/2021-July/019233.html</ref> It has been proposed that if ECDSA is broken or a powerful computer was on the horizon, there might be an effort to protect ownership of bitcoins by allowing people to mark their taproot outputs as "script-path only" and then move their coins into such outputs with a leaf in the script tree requiring a Lamport signature. It is an open question if a tapscript commitment would preserve the quantum resistance of Lamport signatures. Beyond this question, the use of Lamport Signatures in taproot outputs is unlikely to be quantum resistant even if the script spend-path is made quantum resistant. This is because taproot outputs can also be spent with a key. An attacker with a sufficiently powerful quantum computer could bypass the taproot script spend-path by finding the discrete log of the taproot output and thus spending the output using the key spend-path. The use of "Nothing Up My Sleeve" (NUMS) points as described in [[bip-0341.mediawiki|BIP341]] to disable the key spend-path does not disable the key spend-path against a quantum attacker as NUMS relies on the hardness of finding discrete logs. We are not aware of any mechanism which could disable the key spend-path in a taproot output without a softfork change to taproot.
    

    murchandamus commented at 7:04 pm on April 26, 2024:
    Also, if your lines were shorter, it might be easier to see what I added. ;)
  119. in bip-0347.mediawiki:57 in 852502b9cf outdated
    52+
    53+While the OP_SUCCESSx opcode upgrade path could enable us to increase the stack element size while reenabling OP_CAT, we wanted to separate the decision to change the stack element size limit from the decision to reenable OP_CAT. This BIP takes no position in favor or against increasing the stack element size limit.
    54+
    55+==Backwards Compatibility==
    56+
    57+OP_CAT usage in an non-tapscript script will continue to trigger the SCRIPT_ERR_DISABLED_OPCODE. The only change would be to OP_CAT usage in tapscript. This change to tapscript would be activated a soft fork that redefines an OP_SUCCESSx opcode (OP_SUCCESS126) to OP_CAT.
    


    murchandamus commented at 3:31 pm on April 26, 2024:
    0OP_CAT usage in a non-tapscript script will continue to trigger the SCRIPT_ERR_DISABLED_OPCODE. The only change would be to OP_CAT usage in tapscript. This change to tapscript would be activated as a soft fork that redefines an OP_SUCCESSx opcode (OP_SUCCESS126) to OP_CAT.
    

    murchandamus commented at 3:47 pm on April 26, 2024:
    Perhaps some readers would find it useful, if you were to describe here how a transaction with OP_CAT would be interpreted by a node that has not upgraded to a version that enforces OP_CAT, and how it therefore is safe to be soft-forked in.
  120. in bip-0347.mediawiki:4 in 852502b9cf outdated
    0@@ -0,0 +1,106 @@
    1+<pre>
    2+  BIP: 347
    3+  Layer: Consensus (soft fork)
    4+  Title: OP_CAT
    


    murchandamus commented at 3:50 pm on April 26, 2024:

    Perhaps include in the title that the opcode is only added to Tapscript:

    0  Title: Reenable OP_CAT in Tapscript
    

    EthanHeilman commented at 5:41 pm on April 26, 2024:
    How about “Enable OP_CAT in Tapscript”? I’m concerned Renable may read as saying OP_CAT was enabled in the past in tapscript.

    murchandamus commented at 6:43 pm on April 26, 2024:
    Even better!

    murchandamus commented at 10:11 pm on April 29, 2024:
    You could also amend the title of the PR in the same manner

    EthanHeilman commented at 10:45 pm on April 29, 2024:
    Changed in title and PR title
  121. in bip-0347.mediawiki:33 in 852502b9cf outdated
    28+Given the stack ''<nowiki>[x1, x2]</nowiki>'', where ''x2'' is at the top of the stack, OP_CAT will push ''x1 || x2'' onto the stack. By ''||'' we denote concatenation. OP_CAT fails if there are fewer than two values on the stack or if a concatenated value would have a combined size greater than the maximum script element size of 520 bytes.
    29+
    30+This opcode would be activated via a soft fork by redefining the tapscript opcode OP_SUCCESS126 (126 in decimal and 0x7e in hexadecimal) to OP_CAT.
    31+
    32+==Motivation==
    33+Bitcoin tapscript lacks a general purpose way of combining objects on the stack restricting the expressiveness and power of tapscript. This prevents among many other things the ability to construct and evaluate merkle trees and other hashed data structures in tapscript. OP_CAT by adding a general purpose way to concatenate stack values would overcome this limitation and greatly increase the functionality of tapscript.
    


    murchandamus commented at 4:59 pm on April 26, 2024:

    “This prevents among many other things the ability to construct and evaluate merkle trees and other hashed data structures in tapscript.”

    This phrasing sounds a bit funny to me. Since there are other ways how such features could be implemented, the absence of OP_CAT does not prevent the implementation of said features. Rather, OP_CAT provides a means to achieve the features.


    EthanHeilman commented at 10:51 pm on April 29, 2024:

    This isn’t saying that the absence of OP_CAT specifically prevents this, but rather the absence of anyway to combine objects on the stack prevents this*. 256-bit add would let you do this, as would a hash op code that takes two stack elements. There are plenty of other ways to do this, OP_CAT is just a simple solution.

    *-Technically you can OP_ADD two 4 byte objects on the stack, but once you hash them, you can’t meaningfully combine that hash output with another hash output.


    murchandamus commented at 4:05 pm on May 1, 2024:

    Okay, I see that you distinguish the general situation from the specific tool and my feedback there is not convincing.

    Very nitty, but I would distinguish the Tapscript language (capitalized) from tapscripts (lowercased) appearing in script tree leafs, see e.g. https://bitcoin.stackexchange.com/a/122808/5406.

    I also think this sentence would be easier to read by adding a few more commas.

    0Bitcoin Tapscript lacks a general purpose way of combining objects on the stack, restricting the expressiveness and power of Tapscript. This prevents, among many other things, the ability to construct and evaluate merkle trees and other hashed data structures in Tapscript. OP_CAT, by adding a general purpose way to concatenate stack values, would overcome this limitation and greatly increase the functionality of Tapscript.
    
  122. murchandamus commented at 5:07 pm on April 26, 2024: contributor
    Looks mostly good to me. I have some suggestions for the Motivation section and the Backwards Compatibility section and I would suggest adding links to discussions about the proposal
  123. Adds comma
    Co-authored-by: Mark "Murch" Erhardt <murch@murch.one>
    c10870a390
  124. Consistent formatting for Section Headings
    Co-authored-by: Mark "Murch" Erhardt <murch@murch.one>
    5413e18fd9
  125. Consistent formatting for Section Headings
    Co-authored-by: Mark "Murch" Erhardt <murch@murch.one>
    dbc612edfa
  126. Changes title of BIP to "Enable OP_CAT in Tapscript" a05543cc58
  127. EthanHeilman renamed this:
    BIP for reenabling OP_CAT
    BIP for enabling OP_CAT in tapscript
    on Apr 29, 2024
  128. OP_CAT in Tapscript
    Co-authored-by: Vojtěch Strnad <43024885+vostrnad@users.noreply.github.com>
    1d5530443d
  129. Fixes typos
    Co-authored-by: Mark "Murch" Erhardt <murch@murch.one>
    3d78cc0886
  130. in bip-0347.mediawiki:4 in a05543cc58 outdated
    0@@ -0,0 +1,108 @@
    1+<pre>
    2+  BIP: 347
    3+  Layer: Consensus (soft fork)
    4+  Title: Enable OP_CAT in Tapscript
    


    vostrnad commented at 10:59 pm on April 29, 2024:

    BIP titles normally don’t start with a verb (unlike e.g. commit names):

    0  Title: OP_CAT in Tapscript
    
  131. murchandamus renamed this:
    BIP for enabling OP_CAT in tapscript
    BIP 347: OP_CAT in Tapscript
    on Apr 30, 2024
  132. murchandamus commented at 2:22 pm on April 30, 2024: contributor
    I put the BIP number in the title, I hope you don’t mind. It seems to me that there are still a couple open review comments, will swing by again later to check whether it’s ready for the next round of review.
  133. Adds post history, fixes created date 696cc1713b
  134. in bip-0347.mediawiki:40 in 696cc1713b outdated
    35+
    36+Bitcoin tapscript lacks a general purpose way of combining objects on the stack restricting the expressiveness and power of tapscript. This prevents among many other things the ability to construct and evaluate merkle trees and other hashed data structures in tapscript. OP_CAT by adding a general purpose way to concatenate stack values would overcome this limitation and greatly increase the functionality of tapscript.
    37+
    38+OP_CAT aims to expand the toolbox of the tapscript developer with a simple, modular, and useful opcode in the spirit of Unix <ref>R. Pike and B. Kernighan, "Program design in the UNIX environment", 1983, https://harmful.cat-v.org/cat-v/unix_prog_design.pdf</ref>. To demonstrate the usefulness of OP_CAT below we provide a non-exhaustive list of some usecases that OP_CAT would enable:
    39+
    40+* Bitstream, a protocol for the atomic swap (fair exchange) of bitcoins for decryption keys, that enables decentralized file hosting systems paid in Bitcoin. While such swaps are currently possible on Bitcoin without OP_CAT they require the use of complex and computationally expensive Verifiable Computation cryptographic techniques. OP_CAT would remove this requirement on Verifiable Computation, making such protocols far more practical to build in Bitcoin. <ref>R. Linus, "BitStream: Decentralized File Hosting Incentivised via Bitcoin Payments", 2023, https://robinlinus.com/bitstream.pdf</ref>
    


    murchandamus commented at 4:46 pm on May 1, 2024:
    0* Bitstream, a protocol for the atomic swap (fair exchange) of bitcoins for decryption keys, that enables decentralized file hosting systems paid in Bitcoin. While such swaps are currently possible on Bitcoin without OP_CAT, they require the use of complex and computationally expensive Verifiable Computation cryptographic techniques. OP_CAT would remove this requirement on Verifiable Computation, making such protocols far more practical to build in Bitcoin. <ref>R. Linus, "BitStream: Decentralized File Hosting Incentivised via Bitcoin Payments", 2023, https://robinlinus.com/bitstream.pdf</ref>
    
  135. murchandamus approved
  136. murchandamus commented at 5:10 pm on May 1, 2024: contributor

    I have left a couple more nits that you may address or ignore freely, I don’t consider any to be blocking.

    The BIP described in this PR fulfills the criteria set out in BIP2, it:

    • Is properly formatted
    • Has a complete preamble
    • Concisely specifies a new feature in sufficient detail for implementation
    • Covers Motivation, Rationale, Backwards Compatibility
    • Has an acceptable license

    and therefore appears to be ready to be merged.¹

    ACK 696cc1713b931589d01c544d3016f3cf57be0058

    ¹ This should be obvious, but to make it explicit: This is a clerical assessment of the completeness of this PR. I am neither endorsing this BIP nor expressing any opinion on whether OP_CAT should be activated.

  137. murchandamus commented at 5:13 pm on May 1, 2024: contributor

    @luke-jr had previously requested changes:

    Missing a section for backward compatibility

    which I consider to have been addressed. I will abstain from merging this PR for some time, to give other editors a chance to make their own assessment.

  138. Adds sentence suggested by murchandamus to quantum paragraph
    Co-authored-by: Mark "Murch" Erhardt <murch@murch.one>
    d670035b0c
  139. Increases commas and capital letters
    This improves readability, thanks!
    
    Co-authored-by: Mark "Murch" Erhardt <murch@murch.one>
    e9e7636f7e
  140. Adds commas
    Co-authored-by: Mark "Murch" Erhardt <murch@murch.one>
    6815c39f93
  141. in bip-0347.mediawiki:43 in 6815c39f93 outdated
    38+OP_CAT aims to expand the toolbox of the tapscript developer with a simple, modular, and useful opcode in the spirit of Unix <ref>R. Pike and B. Kernighan, "Program design in the UNIX environment", 1983, https://harmful.cat-v.org/cat-v/unix_prog_design.pdf</ref>. To demonstrate the usefulness of OP_CAT below we provide a non-exhaustive list of some usecases that OP_CAT would enable:
    39+
    40+* Bitstream, a protocol for the atomic swap (fair exchange) of bitcoins for decryption keys, that enables decentralized file hosting systems paid in Bitcoin. While such swaps are currently possible on Bitcoin without OP_CAT, they require the use of complex and computationally expensive Verifiable Computation cryptographic techniques. OP_CAT would remove this requirement on Verifiable Computation, making such protocols far more practical to build in Bitcoin. <ref>R. Linus, "BitStream: Decentralized File Hosting Incentivised via Bitcoin Payments", 2023, https://robinlinus.com/bitstream.pdf</ref>
    41+* Tree signatures provide a multisignature script whose size can be logarithmic in the number of public keys and can encode spend conditions beyond n-of-m. For instance a transaction less than 1KB in size could support tree signatures with up to 4,294,967,296 public keys. This also enables generalized logical spend conditions. <ref> P. Wuille, "Multisig on steroids using tree signatures", 2015, https://blog.blockstream.com/en-treesignatures/</ref>
    42+* Post-Quantum Lamport signatures in Bitcoin transactions. Lamport signatures merely require the ability to hash and concatenate values on the stack. <ref>J. Rubin, "[bitcoin-dev] OP_CAT Makes Bitcoin Quantum Secure [was CheckSigFromStack for Arithmetic Values]", 2021, https://lists.linuxfoundation.org/pipermail/bitcoin-dev/2021-July/019233.html</ref> It has been proposed that if ECDSA is broken or a powerful computer was on the horizon, there might be an effort to protect ownership of bitcoins by allowing people to mark their taproot outputs as "script-path only" and then move their coins into such outputs with a leaf in the script tree requiring a Lamport signature. It is an open question if a tapscript commitment would preserve the quantum resistance of Lamport signatures. Beyond this question, the use of Lamport Signatures in taproot outputs is unlikely to be quantum resistant even if the script spend-path is made quantum resistant. This is because taproot outputs can also be spent with a key. An attacker with a sufficiently powerful quantum computer could bypass the taproot script spend-path by finding the discrete log of the taproot output and thus spending the output using the key spend-path. The use of "Nothing Up My Sleeve" (NUMS) points as described in [[bip-0341.mediawiki|BIP341]] to disable the key spend-path does not disable the key spend-path against a quantum attacker as NUMS relies on the hardness of finding discrete logs. We are not aware of any mechanism which could disable the key spend-path in a taproot output without a softfork change to taproot.
    43+* Non-equivocation contracts <ref>T. Ruffing, A. Kate, D. Schröder, "Liar, Liar, Coins on Fire: Penalizing Equivocation by Loss of Bitcoins", 2015, https://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.727.6262&rep=rep1&type=pdf</ref> in tapscript provide a mechanism to punish equivocation/double spending in Bitcoin payment channels. OP_CAT enables this by enforcing rules on the spending transaction's nonce. The capability is a useful building block for payment channels and other Bitcoin protocols.
    


    jonatack commented at 10:11 pm on May 1, 2024:
    https://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.727.6262&rep=rep1&type=pdf doesn’t seem to be the correct link for me

    EthanHeilman commented at 1:22 am on May 2, 2024:
    I believe that link is dead now. Let me fix it, thanks for finding.

    EthanHeilman commented at 10:42 pm on May 2, 2024:
    Fixed!
  142. jonatack commented at 10:29 pm on May 1, 2024: contributor
    ACK, mod non-working url and squash commits
  143. weikengchen commented at 0:21 am on May 2, 2024: none

    It seems useful to use the ACM DOI URI for that paper mentioned above with the nonfunctional link: https://dl.acm.org/doi/10.1145/2810103.2813686

    It is very likely to still work for ten more years. Although it is paywalled, people can find free versions online.

  144. Fixes link to liar liar 6ea9fda9ac
  145. Add BIP-347 OP_CAT to table 31f51927f1
  146. Merge branch 'master' into cat f05e1627f9
  147. murchandamus commented at 2:02 am on May 3, 2024: contributor
    The build check was failing, because the BIP had not been added to the table in the README yet, so I added a commit to add it to the table.
  148. Improved accuracy of paragraph on OP_CAT's removal in 2010 cda34eef1c
  149. real-or-random commented at 10:44 am on May 6, 2024: contributor

    It seems useful to use the ACM DOI URI for that paper mentioned above with the nonfunctional link: dl.acm.org/doi/10.1145/2810103.2813686

    It is very likely to still work for ten more years. Although it is paywalled, people can find free versions online.

    Yep, sorry, we weren’t allowed to upload it to eprint.iacr.org or arXiv due to copyright reasons. (The ACM is evil…)

    But it’s lawfully available under https://publications.cispa.saarland/565/1/penalizing.pdf (Web Archive: https://web.archive.org/web/20221023121048/https://publications.cispa.saarland/565/1/penalizing.pdf), and I’ve also just made it available under https://raw.githubusercontent.com/real-or-random/accas/master/paper.pdf (Web Archive: https://web.archive.org/web/20240506104315/https://raw.githubusercontent.com/real-or-random/accas/master/paper.pdf).

  150. Adds stable URL for Liar, Liar, Coins on Fire! 7ad0f821dd
  151. in bip-0347.mediawiki:50 in cda34eef1c outdated
    43@@ -44,8 +44,12 @@ OP_CAT aims to expand the toolbox of the tapscript developer with a simple, modu
    44 * Vaults <ref>M. Moser, I. Eyal, and E. G. Sirer, Bitcoin Covenants, http://fc16.ifca.ai/bitcoin/papers/MES16.pdf</ref> which are a specialized covenant that allows a user to block a malicious party who has compromised the user's secret key from stealing the funds in that output. As shown in <ref>A. Poelstra, "CAT and Schnorr Tricks II", 2021, https://www.wpsoftware.net/andrew/blog/cat-and-schnorr-tricks-ii.html</ref> OP_CAT is sufficient to build vaults in Bitcoin.
    45 * Replicating CheckSigFromStack <ref>A. Poelstra, "CAT and Schnorr Tricks I", 2021, https://medium.com/blockstream/cat-and-schnorr-tricks-i-faf1b59bd298</ref> which would allow the creation of simple covenants and other advanced contracts without having to presign spending transactions, possibly reducing complexity and the amount of data that needs to be stored. Originally shown to work with Schnorr signatures, this result has been extended to ECDSA signatures <ref>R. Linus, "Covenants with CAT and ECDSA", 2023, https://gist.github.com/RobinLinus/9a69f5552be94d13170ec79bf34d5e85#file-covenants_cat_ecdsa-md</ref>.
    46 
    47-The opcode OP_CAT was available in early versions of Bitcoin. However, OP_CAT was removed because it enabled the construction of a script whose evaluation could have memory usage exponential in the size of the script.
    48-For example, a script that pushed a 1-byte value on the stack and then repeated the opcodes OP_DUP, OP_CAT 40 times would result in a stack value whose size was greater than 1 terabyte. This is no longer an issue because tapscript enforces a maximum stack element size of 520 bytes.
    49+OP_CAT was available in early versions of Bitcoin. 
    50+In 2010, a single commit disabled OP_CAT, along with another 15 opcodes.
    51+Folklore states that OP_CAT was removed in this commit because it enabled the construction of a script whose evaluation could have memory usage exponential in the size of the script.
    52+For example, a script that pushed a 1-byte value on the stack and then repeated the opcodes OP_DUP, OP_CAT 40 times would result in a stack element whose size was greater than 1 terabyte assuming no maximum stack element size. As Bitcoin at that time had a maximum stack element size of 5000 bytes, the effect of this expansion was limited to 5000 bytes.
    


    jonatack commented at 3:48 pm on May 6, 2024:

    In the new commit cda34eef1c2543ece1205240f27e8d1cfffb336d “As Bitcoin at that time had a maximum stack element size of 5000 bytes”

    I’m probably confused, but even in this commit git show 0a61b0df1224a5470bcddab302bc199ca5a9e356 from 2010 it looks like the maximum stack element size of 520 bytes was present, i.e. src/script.cpp#L343 - if (vchPushValue.size() > 520).


    EthanHeilman commented at 5:07 pm on May 6, 2024:

    @jonatack The same commit that removed the 15 opcodes also reduced the maximum stack element size from 5000 to 520.

    When OP_CAT was active in Bitcoin the maximum stack element size was 5000.

    The commit you reference 0a61b0df1224a5470bcddab302bc199ca5a9e356 is from Aug 29, 2010. OP_CAT and the maximum element size change was made in commit 4bd188c4383d6e614e18f79dc337fbabe8464c82 two weeks earlier on Aug 15 2010.


    jonatack commented at 5:32 pm on May 6, 2024:
    Thank you!
  152. EthanHeilman commented at 5:13 pm on May 6, 2024: contributor
    @real-or-random Just added a stable URL for Liar, Liar, Coins on Fire! citation.
  153. murchandamus approved
  154. murchandamus commented at 5:24 pm on May 6, 2024: contributor

    ACK 7ad0f821ddc60366e98344a1e3019114ae46c80f

    Seems to me that all open review comments have been addressed.

  155. jonatack approved
  156. jonatack commented at 5:33 pm on May 6, 2024: contributor
    ACK 7ad0f821ddc60366e98344a1e3019114ae46c80f
  157. murchandamus merged this on May 6, 2024
  158. murchandamus closed this on May 6, 2024


github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bips. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-11-21 12:10 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me