From: "'moonsettler' via Bitcoin Development Mailing List" <bitcoindev@googlegroups.com>
To: Bitcoin Development Mailing List <bitcoindev@googlegroups.com>
Subject: [bitcoindev] CTV++ OP_TEMPLATEHASH & OP_INPUTAMOUNTS
Date: Wed, 25 Dec 2024 20:57:21 +0000 [thread overview]
Message-ID: <rqgc7ysr5Px28EKRJu2nmE9cAsm47jPWKnEUAiY-9cw69B6bOUsPT1302MrX6r_6nlXZgayr1WKlBEe3x1UsgYnCX_1EJbAdiQDh95FVQBA=@protonmail.com> (raw)
Hi List,
There have been complaints voiced about being too paiful to work with CTV.
Especially when it comes to Vaults. OP_TX and OP_TXHASH/VERIFY are examples
how developers sought to overcome certain pain points. However they expand
the scope considerably and also rely on 64 bit integer arithmetic to handle
amounts. Here we aim to show and alternative approach that covers a lot of
useful ground in the in-between without state-carrying covenants or general
detailed introspection.
https://gist.github.com/moonsettler/d2369e043473c42ff7fa52878dd064a5
## CTV++
Two additional opcodes to consider as an addition to `OP_CHECKTEMPLATEVERIFY`:
* OP_TEMPLATEHASH
* OP_INPUTAMOUNTS
Together they relax the strict limitations that `OP_CHECKTEMPLATEVERIFY`
imposes, because it explicitly commits to the output amounts and therefore
implicitly commits to the spendable input amounts in a lot of cases.
### OP_TEMPLATEHASH
Builds the CTV template hash from the stack.
```
<inputIndex>
# FOR i = inputCount-1; i >= 0; i--; LOOP
<sequence[i]>
# END LOOP
<inputCount>
<nLockTime>
# FOR j = outputCount-1; j >= 0; j--; LOOP
<out[j].amount>
<out[j].script>
# END LOOP
<outputCount>
<nVersion>
OP_TEMPLATEHASH
OP_CHECKTEMPLATEVERIFY
```
### OP_INPUTAMOUNTS
Taproot only. Consumes a 32 bit signed integer `n` as parameter
* `n = 0` return the SUM of all input amounts with same script
* `n < 0` return the SUM of last abs(n) input amounts including current input
* `n > 0` return the SUM of first n input amounts of the transaction
fails if
* `n < 0` and `abs(n) > inputIndex + 1`
* `n > inputCount`
```
<n>
OP_INPUTAMOUNTS
```
#### Example use:
This contract below allows the comining of UTXOs locked by the same script for
something like a withdrawal from a Vault contract to a staging address where
the relative time lock can begin. It works with any amount UTXOs unlike basic
CTV Vaults. Also allows for paying fees endogenously and registering a change
address. The fee paying input would sign with SIGHASH_ALL.
```
### Witness stack BEGIN ###
<inputIndex>
# FOR i = inputCount-1; i >= 0; i--; LOOP
<sequence[i]>
# END LOOP
<inputCount>
<nLockTime>
<changeAmount> # out[1].amount
<changeScriptPub> # out[1].script
### Witness stack END ###
<0> # sum of all inputs with same script
OP_INPUTAMOUNTS # out[0].amount
<stagingScriptPub> # out[0].script 33 bytes for P2TR
<2> # outputCount
<2> # nVersion
OP_TEMPLATEHASH
OP_CHECKTEMPLATEVERIFY
```
### Credits:
* Jeremy Rubin who have already came up with everything many years ago
* James O'Beirne for his awesome work on OP_VAULT
* Salvatore Ingala for his work on CCV/MATT and to generalize state carrying
covenants
* Many others who have explored the covenant design space and CTV in particular
BR,
moonsettler
--
You received this message because you are subscribed to the Google Groups "Bitcoin Development Mailing List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bitcoindev+unsubscribe@googlegroups•com.
To view this discussion visit https://groups.google.com/d/msgid/bitcoindev/rqgc7ysr5Px28EKRJu2nmE9cAsm47jPWKnEUAiY-9cw69B6bOUsPT1302MrX6r_6nlXZgayr1WKlBEe3x1UsgYnCX_1EJbAdiQDh95FVQBA%3D%40protonmail.com.
reply other threads:[~2024-12-27 13:52 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='rqgc7ysr5Px28EKRJu2nmE9cAsm47jPWKnEUAiY-9cw69B6bOUsPT1302MrX6r_6nlXZgayr1WKlBEe3x1UsgYnCX_1EJbAdiQDh95FVQBA=@protonmail.com' \
--to=bitcoindev@googlegroups.com \
--cc=moonsettler@protonmail$(echo .)com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox