mirror of
https://github.com/bitcoin/bips.git
synced 2026-03-09 15:53:54 +00:00
bip347: Complete OP_CAT (#2090)
* OP_CAT to BIP 0003 format, add usecase * draft --> complete * Update bip-0347.mediawiki Co-authored-by: Mark "Murch" Erhardt <murch@murch.one> * BIP347: Update table entry to complete * Fix breaking test * Add test vectors --------- Co-authored-by: Mark "Murch" Erhardt <murch@murch.one>
This commit is contained in:
@@ -1198,13 +1198,13 @@ users (see also: [https://en.bitcoin.it/wiki/Economic_majority economic majority
|
||||
| Steven Roose, Brandon Black
|
||||
| Specification
|
||||
| Draft
|
||||
|-
|
||||
|- style="background-color: #ffffcf"
|
||||
| [[bip-0347.mediawiki|347]]
|
||||
| Consensus (soft fork)
|
||||
| OP_CAT in Tapscript
|
||||
| Ethan Heilman, Armin Sabouri
|
||||
| Specification
|
||||
| Draft
|
||||
| Complete
|
||||
|-
|
||||
| [[bip-0348.md|348]]
|
||||
| Consensus (soft fork)
|
||||
|
||||
@@ -4,11 +4,13 @@
|
||||
Title: OP_CAT in Tapscript
|
||||
Authors: Ethan Heilman <ethan.r.heilman@gmail.com>
|
||||
Armin Sabouri <arminsdev@gmail.com>
|
||||
Status: Draft
|
||||
Status: Complete
|
||||
Type: Specification
|
||||
Assigned: 2023-12-11
|
||||
License: BSD-3-Clause
|
||||
Discussion: 2023-10-21: https://lists.linuxfoundation.org/pipermail/bitcoin-dev/2023-October/022049.html [bitcoin-dev] Proposed BIP for OP_CAT
|
||||
Version: 1.0.0
|
||||
Requires: 340, 341, 342
|
||||
</pre>
|
||||
|
||||
==Abstract==
|
||||
@@ -42,6 +44,8 @@ OP_CAT aims to expand the toolbox of the tapscript developer with a simple, modu
|
||||
* Non-equivocation contracts <ref>T. Ruffing, A. Kate, D. Schröder, "Liar, Liar, Coins on Fire: Penalizing Equivocation by Loss of Bitcoins", 2015, https://web.archive.org/web/20221023121048/https://publications.cispa.saarland/565/1/penalizing.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.
|
||||
* Vaults <ref>M. Moser, I. Eyal, and E. G. Sirer, Bitcoin Covenants, https://web.archive.org/web/20220203124718/https://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.
|
||||
* Replicating CheckSigFromStack <ref>A. Poelstra, "CAT and Schnorr Tricks I", 2021, https://www.wpsoftware.net/andrew/blog/cat-and-schnorr-tricks-i.html</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>.
|
||||
* OP_CAT would allow tapscript to perform arbitrary computation on stack elements larger than 32-bits such as signatures and public keys. While Collider Script <ref>E. Heilman, V. I. Kolobov, A. M. Levy, A. Poelstra, "ColliderScript: Covenants in Bitcoin via 160-bit hash collisions", 2024, https://eprint.iacr.org/2024/1802</ref> showed that even without OP_CAT tapscript can perform arbitrary computation on stack elements larger than 32-bits, this approach is extremely computationally expensive. In practice, today's tapscript can only perform arbitrary computation on 32-bit stack elements. OP_CAT was not designed with this usecase in mind and OP_CAT an inefficient way to perform this task.
|
||||
* BitVM<ref>R. Linus, L. Aumayr, A. Zamyatin, A. Pelosi, Z. Avarikioti, M. Maffei "BitVM2: Bridging Bitcoin to Second Layers", 2025, https://bitvm.org/bitvm_bridge.pdf</ref> improvements. OP_CAT would enable BitVM2 to eliminating the trusted setup from its proof system allow BitVM2 to reduce the size of transactions it uses.
|
||||
|
||||
OP_CAT was available in early versions of Bitcoin.
|
||||
In 2010, a single commit disabled OP_CAT, along with another 15 opcodes.
|
||||
@@ -102,10 +106,75 @@ break;
|
||||
|
||||
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>.
|
||||
|
||||
|
||||
==Test Vectors==
|
||||
|
||||
The following test vectors use Bitcoin-core JSON script-test format.
|
||||
|
||||
<pre>
|
||||
[
|
||||
[
|
||||
"78a11a1260c1101260",
|
||||
"78a11a1260",
|
||||
"c1101260",
|
||||
"#SCRIPT# CAT EQUAL",
|
||||
"#CONTROLBLOCK#",
|
||||
0.00000001
|
||||
],
|
||||
"",
|
||||
"0x51 0x20 #TAPROOTOUTPUT#",
|
||||
"P2SH,WITNESS,TAPROOT,OP_CAT",
|
||||
"OK",
|
||||
"TAPSCRIPT CATs 78a11a1260 and c1101260 together and checks it is EQUAL to stack element 78a11a1260c1101260"
|
||||
],
|
||||
[
|
||||
[
|
||||
"51",
|
||||
"bbbb",
|
||||
"01",
|
||||
"#SCRIPT# IF CAT ELSE DROP ENDIF",
|
||||
"#CONTROLBLOCK#",
|
||||
0.00000001
|
||||
],
|
||||
"",
|
||||
"0x51 0x20 #TAPROOTOUTPUT#",
|
||||
"P2SH,WITNESS,TAPROOT,OP_CAT",
|
||||
"OK",
|
||||
"TAPSCRIPT Tests CAT inside of an IF ELSE conditional (true IF)"
|
||||
],
|
||||
[
|
||||
[
|
||||
"",
|
||||
"09ca7009ca7009ca7009ca7009ca70",
|
||||
"#SCRIPT# CAT",
|
||||
"#CONTROLBLOCK#",
|
||||
0.00000001
|
||||
],
|
||||
"",
|
||||
"0x51 0x20 #TAPROOTOUTPUT#",
|
||||
"P2SH,WITNESS,TAPROOT,OP_CAT",
|
||||
"OK",
|
||||
"TAPSCRIPT (['', 09ca7009ca7009ca7009ca7009ca70], CAT) Tests CAT succeeds when one of the two values to concatenate is of size zero"
|
||||
],
|
||||
</pre>
|
||||
|
||||
A full test suite with additional vectors can be found at the Bitcoin [https://github.com/bitcoin/bitcoin/pull/29247 OP_CAT PR].
|
||||
|
||||
==References==
|
||||
|
||||
<references/>
|
||||
|
||||
==Changelog==
|
||||
|
||||
* __1.0.0__ (2026-03-01) - Marked as complete.
|
||||
* __0.3.1__ (2026-01-23) - Made compliant with BIP 003, use cases added.
|
||||
* __0.3.0__ (2024-05-06) - Merged to BIP repo
|
||||
* __0.2.0__ (2024-04-24) - Assigned BIP number
|
||||
* __0.1.0__ (2023-12-11) - Initial draft posted
|
||||
|
||||
|
||||
May 6, 2024
|
||||
|
||||
==Acknowledgements==
|
||||
|
||||
We wish to acknowledge Dan Gould for encouraging and helping review this effort. We also want to thank Madars Virza, Jeremy Rubin, Andrew Poelstra, Bob Summerwill,
|
||||
|
||||
Reference in New Issue
Block a user