Skip to content

Commit afc605f

Browse files
committed
[BIP-119] Describe Synergies with future soft fork proposals
1 parent 27466fa commit afc605f

File tree

1 file changed

+59
-10
lines changed

1 file changed

+59
-10
lines changed

bip-0119.mediawiki

Lines changed: 59 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -397,9 +397,10 @@ a hash midstate in the script.
397397

398398
=====The Ordering of Fields=====
399399

400-
Strictly speaking, the ordering of fields is insignificant. However, with a carefully selected
401-
order, the efficiency of future scripts (e.g., those using a OP_CAT or OP_SHA256STREAM) may be
402-
improved.
400+
Strictly speaking, the ordering of fields is insignificant. However, with a
401+
carefully selected order, the efficiency of future scripts (e.g., those using a
402+
OP_CAT or OP_SHA256STREAM) may be improved (as described in the Future Upgrades
403+
section).
403404

404405
In particular, the order is selected in order of least likely to change to most.
405406

@@ -430,12 +431,6 @@ does not make sense for input index to be the last field. However, given the des
430431
able to express a "don't care" index easily (e.g., for decentralized kickstarter-type transactions),
431432
this value is placed last.
432433

433-
As an example, the following code checks an input index argument and concatenates it to the template and
434-
checks the template matches the transaction.
435-
436-
OP_SIZE 4 OP_EQUALVERIF
437-
<nVersion || nLockTime || input count || sequences hash || output count || outputs hash>
438-
OP_SWAP OP_CAT OP_SHA256 OP_CHECKTEMPLATEVERIFY
439434

440435
===Design Tradeoffs and Risks===
441436
Covenants have historically been controversial given their potential for fungibility risks -- coins
@@ -535,7 +530,7 @@ signature operations. This can be significant when constructing large payment
535530
trees or programmatic compilations. CHECKTEMPLATEVERIFY also has a feature-wise
536531
benefit in that it provides a robust pathway for future template upgrades.
537532

538-
CHECKSIGFROMSTACK along with OP_CAT may also be used to emulate
533+
OP_CHECKSIGFROMSTACKVERIFY along with OP_CAT may also be used to emulate
539534
CHECKTEMPLATEVERIFY. However such constructions are more complicated to use
540535
than CHECKTEMPLATEVERIFY, and encumbers additional verification overhead absent
541536
from CHECKTEMPLATEVERIFY. These types of covenants also bear similar potential
@@ -546,6 +541,60 @@ Given the simplicity of this approach to implement and analyze, and the benefits
546541
applications, CHECKTEMPLATEVERIFY's template based approach is proposed in lieu of more complete
547542
covenants system.
548543

544+
====Future Upgrades====
545+
546+
This section describes updates to OP_CHECKTEMPLATEVERIFY that are possible in
547+
the future as well as synergies with other possible upgrades.
548+
549+
=====CHECKTEMPLATEVERIFY Versions=====
550+
OP_CHECKTEMPLATEVERIFY currently only verifies properties of 32 byte arguments.
551+
In the future, meaning could be ascribed to other length arguments. For
552+
example, a 33-byte argument could just the last byte as a control program. In
553+
that case, DefaultCheckTemplateVerifyHash could be computed when the flag byte
554+
is set to CTVHASH_ALL. Other programs could be added similar to SIGHASH_TYPEs.
555+
For example, CTVHASH_GROUP could read data from the Taproot Annex for
556+
compatibility with SIGHASH_GROUP type proposals and allow dynamic malleability
557+
of which indexes get hashed for bundling.
558+
559+
=====Eltoo with OP_CHECKSIGFROMSTACKVERIFY=====
560+
561+
Were both OP_CHECKTEMPLATEVERIFY and OP_CHECKSIGFROMSTACKVERIFY to be added to
562+
Bitcoin, it would be possible to implement a variant of Eltoo's floating
563+
transactions using the following script:
564+
565+
witness(S+n): <sig> <H(tx with nLockTime S+n paying to program(S+n))>
566+
program(S): OP_CHECKTEMPLATEVERIFY <musig_key(pk_update_a, pk_update_b)> OP_CHECKSIGFROMSTACKVERIFY <S+1> OP_CHECKLOCKTIMEVERIFY
567+
568+
Compared to SIGHASH_ANYPREVOUTANYSCRIPT, because OP_CHECKTEMPLATEVERIFY does not
569+
allow something similar to SIGHASH_ANYONECANPAY or SIGHASH_SINGLE, protocol
570+
implementers might elect to sign multiple versions of transactions with CPFP
571+
Anchor Outputs or Inputs for paying fees or an alternative such as transaction
572+
sponsors might be considered.
573+
574+
=====OP_AMOUNTVERIFY=====
575+
576+
An opcode which verifies the exact amount that is being spent in the
577+
transaction, the amount paid as fees, or made available in a given output could
578+
be used to make safer OP_CHECKTEMPLATEVERIFY addressses. For instance, if the
579+
OP_CHECKTEMPLATEVERIFY program P expects exactly S satoshis, sending S-1
580+
satoshis would result in a frozen UTXO and sending S+n satoshis would result in
581+
n satoshis being paid to fee. A range check could restrict the program to only
582+
apply for expected values and default to a keypath otherwise, e.g.:
583+
584+
IF OP_AMOUNTVERIFY <N> OP_GREATER <PK> CHECKSIG ELSE <H> OP_CHECKTEMPLATEVERIFY
585+
586+
=====OP_CAT/OP_SHA256STREAM=====
587+
588+
OP_CHECKTEMPLATEVERIFY is (as described in the Ordering of Fields section)
589+
efficient for building covenants dynamically should Bitcoin get enhanced string
590+
manipulation opcodes.
591+
592+
As an example, the following code checks an input index argument and
593+
concatenates it to the template and checks the template matches the transaction.
594+
595+
OP_SIZE 4 OP_EQUALVERIF
596+
<nVersion || nLockTime || input count || sequences hash || output count || outputs hash>
597+
OP_SWAP OP_CAT OP_SHA256 OP_CHECKTEMPLATEVERIFY
549598
== Backwards Compatibility ==
550599

551600
OP_CHECKTEMPLATEVERIFY replaces a OP_NOP4 with stricter verification semantics. Therefore, scripts

0 commit comments

Comments
 (0)