@@ -57,7 +57,6 @@ for purposes of confirmation using CHECKTEMPLATEVERIFY. Then, some time later, t
57
57
be expanded out of that UTXO when the demand for blockspace is decreased. These payments can be
58
58
structured in a tree-like fashion to reduce individual costs of redemption.
59
59
60
-
61
60
The below chart showcases the structure of these transactions in comparison to
62
61
normal transactions and batched transactions.
63
62
@@ -71,6 +70,7 @@ is provided in this BIP's subdirectory.
71
70
<img src="bip-0119/fifty.png" align="middle"></img>
72
71
73
72
===Payment Channels ===
73
+
74
74
There are numerous payment channel related uses.
75
75
76
76
====Channel Factories ====
@@ -84,6 +84,7 @@ penultimate transaction node.
84
84
Thus, coins sent using a congestion controlled transaction can still enjoy instant liquidity.
85
85
86
86
====Non-Interactive Channels ====
87
+
87
88
When opening a traditional payment channel, both parties to the channel must participate. This is
88
89
because the channel uses pre-signed multi-sig transactions to ensure that a channel can always be
89
90
exited by either party, before entering.
@@ -94,6 +95,7 @@ for their private key to be online.
94
95
<img src="bip-0119/nic.svg" align="middle"></img>
95
96
96
97
====Increased Channel Routes ====
98
+
97
99
In the Lightning Network protocol, Hashed Time Locked Contracts (HTLCS) are used in the construction
98
100
of channels. A new HTLC is required per route that the channel is serving in.
99
101
In BOLT #2, this maximum number of HTLCs in a channel is hard limited to 483 as the maximum safe
@@ -107,7 +109,6 @@ HTLCS.
107
109
Because each HTLC can have its own relative time lock in the tree, this also improves the latency
108
110
sensitivity of the lightning protocol on contested channel close.
109
111
110
-
111
112
===Wallet Vaults ===
112
113
113
114
When greater security is required for cold storage solutions, there can be
@@ -133,6 +134,7 @@ before. Further Each participant doesn't need to know the totality of the outpu
133
134
that output, they only have to verify their own sub-tree will pay them.
134
135
135
136
==Detailed Specification ==
137
+
136
138
The below code is the main logic for verifying CHECKTEMPLATEVERIFY, and is the canonical
137
139
specification for the semantics of OP_CHECKTEMPLATEVERIFY.
138
140
@@ -203,7 +205,6 @@ The hash is computed as follows:
203
205
return h.GetSHA256();
204
206
}
205
207
206
-
207
208
A PayToBareDefaultCheckTemplateVerifyHash output matches the following template:
208
209
209
210
bool CScript::IsPayToBareDefaultCheckTemplateVerifyHash() const
@@ -223,7 +224,7 @@ NEVER_ACTIVE/NO_TIMEOUT, but this is subject to change while the BIP is a draft.
223
224
224
225
For the avoidance of unclarity, the parameters to be determined are:
225
226
226
- // Deployment of CTV (BIP 119)
227
+ // Deployment of CTV (BIP 119)
227
228
consensus.vDeployments[Consensus::DEPLOYMENT_CHECKTEMPLATEVERIFY].bit = 5;
228
229
consensus.vDeployments[Consensus::DEPLOYMENT_CHECKTEMPLATEVERIFY].nStartTime = Consensus::BIP9Deployment::NEVER_ACTIVE;
229
230
consensus.vDeployments[Consensus::DEPLOYMENT_CHECKTEMPLATEVERIFY].nTimeout = Consensus::BIP9Deployment::NO_TIMEOUT;
@@ -234,7 +235,6 @@ SCRIPT_VERIFY_DEFAULT_CHECK_TEMPLATE_VERIFY_HASH flag is set, the network should
234
235
execute a NOP4 as SCRIPT_ERR_DISCOURAGE_UPGRADABLE_NOPS for policy and a NOP for
235
236
consensus.
236
237
237
-
238
238
In order to facilitate using CHECKTEMPLATEVERIFY, the common case of a
239
239
PayToBareDefaultCheckTemplateVerifyHash
240
240
with no scriptSig data shall be made standard to permit relaying. Future template types may be
@@ -245,26 +245,20 @@ standardized later as policy changes.
245
245
A reference implementation and tests are available here:
246
246
https://github.com/JeremyRubin/bitcoin/tree/checktemplateverify.
247
247
248
-
249
248
==Rationale ==
250
249
251
250
The goal of CHECKTEMPLATEVERIFY is to be minimal impact on the existing codebase -- in the
252
251
future, as we become aware of more complex but shown to be safe use cases new template types can be added.
253
252
254
-
255
253
Below we'll discuss the rules one-by-one:
256
254
257
-
258
-
259
255
====The DefaultCheckTemplateVerifyHash of the transaction at the current input index matches the top of the stack ====
260
256
261
257
The set of data committed to is a superset of data which can impact the TXID of the transaction,
262
258
other than the inputs. This ensures that for a given known input, the TXIDs can also be known ahead
263
259
of time. Otherwise, CHECKTEMPLATEVERIFY would not be usable for Channel Factory type constructions
264
260
as the redemption TXID could be malleated and pre-signed transactions invalidated.
265
261
266
-
267
-
268
262
=====Committing to the version and locktime =====
269
263
270
264
Were these values not committed, it would be possible to delay the spending of
@@ -296,7 +290,6 @@ precomputed for each transaction to optimize SIGHASH_ALL signatures.
296
290
Committing to the hash additionally makes it simpler to construct DefaultCheckTemplateVerifyHash safely and unambiguously from
297
291
script.
298
292
299
-
300
293
=====Committing to the number of inputs =====
301
294
302
295
If we allow more than one input to be spent in the transaction then it would be
@@ -459,7 +452,6 @@ does not make sense for input index to be the last field. However, given the des
459
452
able to express a "don't care" index easily (e.g., for decentralized kickstarter-type transactions),
460
453
this value is placed last.
461
454
462
-
463
455
===Design Tradeoffs and Risks ===
464
456
Covenants have historically been controversial given their potential for fungibility risks -- coins
465
457
could be minted which have a permanent restriction on how they may or may not be spent or required
@@ -474,17 +466,18 @@ transactions which create all the inputs directly in this regard.
474
466
Furthermore, templates are restricted to be spendable as a known number of inputs only, preventing
475
467
unintentional introduction of the 'half spend' problem.
476
468
477
-
478
469
Templates, as restricted as they are, bear some risks.
479
470
480
471
====Permanently Unspendable Outputs ====
472
+
481
473
The preimage argument passed to CHECKTEMPLATEVERIFY may be unknown or otherwise unsatisfiable.
482
474
However, requiring knowledge that an address is spendable from is incompatible with sender's ability
483
475
to spend to any address (especially, OP_RETURN). If a sender needs to know the template can be spent
484
476
from before sending, they may request a signature of an provably non-transaction challenge string
485
477
from the leafs of the CHECKTEMPLATEVERIFY tree.
486
478
487
479
====Forwarding Addresses ====
480
+
488
481
Key-reuse with CHECKTEMPLATEVERIFY may be used as a form of "forwarding address contract".
489
482
A forwarding address is an address which can automatically execute in a predefined way.
490
483
For example, a exchange's hot wallet might use an address which can automatically be moved to a cold
@@ -510,7 +503,6 @@ reuse-unsafe.
510
503
Because CHECKTEMPLATEVERIFY commits to the input index currently being spent, reused-keys are
511
504
guaranteed to execute in separate transactions which reduces the risk of "half-spend" type issues.
512
505
513
-
514
506
====NOP-Default and Standardness Rules ====
515
507
516
508
If the argument length is not exactly 32, CHECKTEMPLATEVERIFY treats it as a NOP.
@@ -523,8 +515,8 @@ stricter standardness rules to be enforced during consensus. Should that develop
523
515
transaction directly to the network relying on standardness rejection, an standardness-invalid but
524
516
consensus-valid transaction may be caused, leading to a potential loss of funds.
525
517
526
-
527
518
====Feature Redundancy ====
519
+
528
520
CHECKTEMPLATEVERIFY templates are substantially less risky than other covenant systems. If
529
521
implemented, other covenant systems could make the CHECKTEMPLATEVERIFY's functionality redundant.
530
522
However, given CHECKTEMPLATEVERIFY's simple semantics and low on chain cost it's likely that it
@@ -538,7 +530,6 @@ unintended behavior.
538
530
Alternatively, SIGHASH_ANYPREVOUTANYSCRIPT based covenant designs can implement
539
531
something similar to templates, via a scriptPubKey like:
540
532
541
-
542
533
<sig of desired TX with PK and fixed nonce R || SIGHASH_ANYPREVOUTANYSCRIPT <PK with public SK> OP_CHECKSIG
543
534
544
535
SIGHASH_ANYPREVOUTANYSCRIPT bears additional technical and implementation risks
@@ -564,7 +555,6 @@ than CHECKTEMPLATEVERIFY, and encumbers additional verification overhead absent
564
555
from CHECKTEMPLATEVERIFY. These types of covenants also bear similar potential
565
556
recursion issues to OP_COV which make it unlikely for inclusion in Bitcoin.
566
557
567
-
568
558
Given the simplicity of this approach to implement and analyze, and the benefits realizable by user
569
559
applications, CHECKTEMPLATEVERIFY's template based approach is proposed in lieu of more complete
570
560
covenants system.
@@ -575,6 +565,7 @@ This section describes updates to OP_CHECKTEMPLATEVERIFY that are possible in
575
565
the future as well as synergies with other possible upgrades.
576
566
577
567
=====CHECKTEMPLATEVERIFY Versions =====
568
+
578
569
OP_CHECKTEMPLATEVERIFY currently only verifies properties of 32 byte arguments.
579
570
In the future, meaning could be ascribed to other length arguments. For
580
571
example, a 33-byte argument could just the last byte as a control program. In
@@ -623,6 +614,7 @@ concatenates it to the template and checks the template matches the transaction.
623
614
OP_SIZE 4 OP_EQUALVERIF
624
615
<nVersion || nLockTime || input count || sequences hash || output count || outputs hash>
625
616
OP_SWAP OP_CAT OP_SHA256 OP_CHECKTEMPLATEVERIFY
617
+
626
618
== Backwards Compatibility ==
627
619
628
620
OP_CHECKTEMPLATEVERIFY replaces a OP_NOP4 with stricter verification semantics. Therefore, scripts
@@ -638,13 +630,11 @@ Older wallet software will be able to accept spends from OP_CHECKTEMPLATEVERIFY
638
630
require an upgrade in order to treat PayToBareDefaultCheckTemplateVerifyHash chains with a confirmed ancestor as
639
631
being "trusted" (i.e., eligible for spending before the transaction is confirmed).
640
632
641
-
642
-
643
633
Backports of OP_CHECKTEMPLATEVERIFY can be trivially prepared (see the reference implementation)
644
634
for older node versions that can be patched but not upgraded to a newer major release.
645
635
646
-
647
636
== References ==
637
+
648
638
*[https://utxos.org utxos.org informational site ]
649
639
*[https://www.youtube.com/watch?v=YxsjdIl0034&t=2451 Scaling Bitcoin Presentation ]
650
640
*[https://bitcoinops.org/en/newsletters/2019/05/29/ Optech Newsletter Covering OP_CHECKOUTPUTSHASHVERIFY ]
@@ -656,6 +646,7 @@ for older node versions that can be patched but not upgraded to a newer major re
656
646
657
647
658
648
===Note on Similar Alternatives ===
649
+
659
650
An earlier version of CHECKTEMPLATEVERIFY, CHECKOUTPUTSHASHVERIFY, is withdrawn
660
651
in favor of CHECKTEMPLATEVERIFY. CHECKOUTPUTSHASHVERIFY did not commit to the
661
652
version or lock time and was thus insecure.
@@ -668,4 +659,5 @@ CHECKTEMPLATEVERIFY has also been previously referred to as OP_SECURETHEBAG, whi
668
659
to aid in searching and referencing discussion on this BIP.
669
660
670
661
==Copyright ==
662
+
671
663
This document is licensed under the 3-clause BSD license.
0 commit comments