summaryrefslogtreecommitdiff
path: root/8f/e1107265b7a0a5d51ed67faf67322f05ccc3c3
blob: 36d903b82952c42963a39343a16fc57e1105f729 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
Delivery-date: Fri, 27 Dec 2024 05:52:17 -0800
Received: from mail-ot1-f61.google.com ([209.85.210.61])
	by mail.fairlystable.org with esmtps  (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
	(Exim 4.94.2)
	(envelope-from <bitcoindev+bncBAABBB7CXK5QMGQECIH5IZY@googlegroups.com>)
	id 1tRAlE-0003oj-Le
	for bitcoindev@gnusha.org; Fri, 27 Dec 2024 05:52:17 -0800
Received: by mail-ot1-f61.google.com with SMTP id 46e09a7af769-71e4219cf37sf2307569a34.1
        for <bitcoindev@gnusha.org>; Fri, 27 Dec 2024 05:52:16 -0800 (PST)
ARC-Seal: i=2; a=rsa-sha256; t=1735307530; cv=pass;
        d=google.com; s=arc-20240605;
        b=ecpI9DEp+zict3JsOWERIszxf/RnqaSV3K04/XLiz50Z6B2XMvI6SkDNSEk0yJcxeJ
         gyFrPPwL2aVVfFImMIUKjMC2M8sgYbD5Lz/2x9pF3qEW3edS9TpE8g1MDig+ccUXWqFE
         PlPW+w1wpFMDOpY1W1PycGcY4F/EJv3FohIGccBHVV2J+59RISKEcxBkzBUJKkScp5jK
         SgKx2BA/fwNA517qGMgpuFiW/rM6+L/7nDzfetSLkg8TNuZnx9cAtwwZbcOR3YCc/yRg
         LPwsc4lmL2eOQGSkNvBkUctqK1dTXl/27Ms4qvVOkc8YoT8IeiVZAboYQow3+9mEQvi+
         fuoA==
ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605;
        h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post
         :list-id:mailing-list:precedence:reply-to:mime-version:feedback-id
         :message-id:subject:from:to:date:dkim-signature;
        bh=DsTcEoAB45yxXmO6Lz/t4i3M8MP3IhHMGFtEnsSNFAs=;
        fh=Qc7V475NSoZlK5annaH9kNv2z4Nt+spqdNaUfyg9CvQ=;
        b=dVUp8YRTvB69Q6c+OZJNB2PwBRD6eroioKZJM0J9cGmBMwmZAl+Dw70WoHTccfhk9L
         3r6bhW5BZ6E6wXzf7Fxa1wMkJNsurm+wtQXLfanTjt4y9TT2wgHP5iIbPtNqSPqmwER+
         guosDngQaXF15irPkevMXporAGd+bIUiNjjSabGOJ0n9A4C5LhJcqXw0BESgrJtKunhK
         1niJfioOo3F5Cqr+u/Jd4qfUy8zXonasNvnqSdRnDH3SIDJqHL97xKrOauPGXkwwZMPr
         GG9RFwlIfyhOtpzhapN/nwA2LJnUTLGToWEgou7kBQ1ynoniu7ZmSnwp4kfTrkwaLG0B
         7Sug==;
        darn=gnusha.org
ARC-Authentication-Results: i=2; gmr-mx.google.com;
       dkim=pass header.i=@protonmail.com header.s=protonmail3 header.b=oUi0q5X2;
       spf=pass (google.com: domain of moonsettler@protonmail.com designates 79.135.106.103 as permitted sender) smtp.mailfrom=moonsettler@protonmail.com;
       dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=protonmail.com
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=googlegroups.com; s=20230601; t=1735307530; x=1735912330; darn=gnusha.org;
        h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post
         :list-id:mailing-list:precedence:reply-to
         :x-original-authentication-results:x-original-sender:mime-version
         :feedback-id:message-id:subject:from:to:date:from:to:cc:subject:date
         :message-id:reply-to;
        bh=DsTcEoAB45yxXmO6Lz/t4i3M8MP3IhHMGFtEnsSNFAs=;
        b=ddbNyYAaE1pkPlxPc3DSamwfkEY/yFue37iJkk809+ZLQ2YDa5cW3d27a1EkK7+vx5
         FR4n6L3clZmh97sIF35RqLlcSN5p/QE5h6jreXu81nz1fUGiWJk7d2iXmH05lh88xAgA
         bvvBgqLROklh3xe4CuB/GdYbLj1UJX/D479w7ZMZtnkJJyRRksvR03Pg9QKJXP9Pyto/
         A3eBW+xGNsPhkdo/Z/9EOKjHkhRWbHhraHnixK3obgGdzG7x5BkcIIL+KvrCM+tRujpY
         HDtbcb2XhHYqA6fDIlGR7eq+9U03dW2C2sgFxj+Yxn3kWipb+uFwz2rJhF/Lo4yUZqEb
         vBzw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20230601; t=1735307530; x=1735912330;
        h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post
         :list-id:mailing-list:precedence:reply-to
         :x-original-authentication-results:x-original-sender:mime-version
         :feedback-id:message-id:subject:from:to:date:x-beenthere
         :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to;
        bh=DsTcEoAB45yxXmO6Lz/t4i3M8MP3IhHMGFtEnsSNFAs=;
        b=lgKtlBYOcQh3YZdgOzM/1XhBmuc9fs+kjEE5cXBiYX3Ptv/XXXIFLWnQSkDK8Ds9tQ
         pohgE7HDsVJgVBBYgTSj1HKpo18Qipx8KedqULxvBE8kklz9AMnsD2UMjKJAVuNto1fw
         ZgeJRj/ycTBJtkVLn3iL1HokfYdGWhq1Gs4vtnBAHPboekVmkbzGyKnD8aCID1pSk4NV
         09Ur93L9XHMKgShrkTGMEj6psED04FVISXt2s87Q+bWCTWmxt9y5nWcdo/VOuWcv9C/I
         sREUwxb2o54aVLM7tYqcc0hhxJUuH8Hc976WMBZSUeotlLg7Uw7blxi2SS9IufqCc2Mv
         lTsQ==
X-Forwarded-Encrypted: i=2; AJvYcCWt6dIUpyOwvY0OFkKDzDbbFYupbDn0Tv7Qdno+yTvTN8F/usaXIwR2kPr+rj1Dx4503DQu7m+b7U44@gnusha.org
X-Gm-Message-State: AOJu0YxKkcI5PUtUG1MVqLd8IfXppONixyFxo4KsFIA27Nlyx5ImDEQh
	w0bUhoU1qXs+nb9AvoizTe8tvP6kFFuK/5FQdIPxgbq7BiXvw4KV
X-Google-Smtp-Source: AGHT+IHOA2UC11WMKMTPh8XMl0yOPGPnQroZLDLH+QEXesiWtmUOTsYqh3ZTBIcF56dw4wk7qq1iVg==
X-Received: by 2002:a05:6830:2b06:b0:71d:5336:df80 with SMTP id 46e09a7af769-720ff8b03e9mr17280447a34.20.1735307529898;
        Fri, 27 Dec 2024 05:52:09 -0800 (PST)
X-BeenThere: bitcoindev@googlegroups.com
Received: by 2002:a4a:de9a:0:b0:5f4:c50e:519a with SMTP id 006d021491bc7-5f4d81a0ae4ls1812634eaf.2.-pod-prod-06-us;
 Fri, 27 Dec 2024 05:52:07 -0800 (PST)
X-Received: by 2002:a05:6808:f16:b0:3eb:3d21:9d02 with SMTP id 5614622812f47-3ed890a9591mr13669548b6e.32.1735307527445;
        Fri, 27 Dec 2024 05:52:07 -0800 (PST)
Received: by 2002:a05:6808:46:b0:3ea:54d0:9259 with SMTP id 5614622812f47-3ecfde47b44msb6e;
        Wed, 25 Dec 2024 12:57:29 -0800 (PST)
X-Received: by 2002:a05:6a20:4308:b0:1e0:c8d9:3382 with SMTP id adf61e73a8af0-1e5e0847084mr34195196637.45.1735160248834;
        Wed, 25 Dec 2024 12:57:28 -0800 (PST)
ARC-Seal: i=1; a=rsa-sha256; t=1735160248; cv=none;
        d=google.com; s=arc-20240605;
        b=QTA3QORv2mek2eXxQ48IOaRsi+xidA/eogPeJG8wMwuhP4ziUpaQhZDPAKyOZEpCqH
         O5WGjBpGBTL60GInUmblbDRMzJJa+nC1I29ADhdFKkdGdNpoaSQGhNgjNo8d123q7sKf
         RKYUwmFgbvyIOV7UgVezOkl5gHcnJ88AUFbUMRczvct/9dp7lfWdt9vysm/HKnYdToZO
         kZHN4ufB7MyUheDyuuGm4kKJGaAr9+snlbIZE0BNNNCToTsW7D/WvzhrD5LTvJesKvBC
         DtRWb3knFsnyR5ygBxNO5PQWCwroFSKvGRVTELVRSVEpwAdUtk0yEjv98gvmny2n6kyB
         hwnA==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605;
        h=content-transfer-encoding:mime-version:feedback-id:message-id
         :subject:from:to:date:dkim-signature;
        bh=Txx4HT32K09BFyFYbQ7GT3dhgWrrjLiQyva6Nsdzynk=;
        fh=DMP0F9ULS1guKiqimntQRCN8ZraraesEgQuVcn7F0Z0=;
        b=AEiMXpEW967O7fXd2blFp7jPWyh2It6u2JbgrjJ+kbGJ02zcqB4XYwJB9zSr59vhVl
         q6jDomRTMXWsmr/upNbox5fXR848snvGHKvW7+4fbBMnq3Ok1FLMtRZ536SAIkG7b+wc
         NuNfdLSLhDPZQOOvIVu3FgPyI+f/tGl8m6QT3TCKTxTU5JU5u5De2Khg+QmxLuyWjH3I
         sDcHqGTaQoambB0M4eKZ+SHE+QtjFKeB8+yQ8zPauuq+p4B3RVNufdV/71U4szAYcYBW
         vtqPlBtsPnhgsWg3Fl8OgJExhXtusVpMF8YHBz0bD7CMSQQ3AYf6hPOpMtRf70zuygh8
         XYJw==;
        dara=google.com
ARC-Authentication-Results: i=1; gmr-mx.google.com;
       dkim=pass header.i=@protonmail.com header.s=protonmail3 header.b=oUi0q5X2;
       spf=pass (google.com: domain of moonsettler@protonmail.com designates 79.135.106.103 as permitted sender) smtp.mailfrom=moonsettler@protonmail.com;
       dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=protonmail.com
Received: from mail-106103.protonmail.ch (mail-106103.protonmail.ch. [79.135.106.103])
        by gmr-mx.google.com with ESMTPS id d2e1a72fcca58-72aad836c3bsi573685b3a.2.2024.12.25.12.57.28
        for <bitcoindev@googlegroups.com>
        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
        Wed, 25 Dec 2024 12:57:28 -0800 (PST)
Received-SPF: pass (google.com: domain of moonsettler@protonmail.com designates 79.135.106.103 as permitted sender) client-ip=79.135.106.103;
Date: Wed, 25 Dec 2024 20:57:21 +0000
To: Bitcoin Development Mailing List <bitcoindev@googlegroups.com>
From: "'moonsettler' via Bitcoin Development Mailing List" <bitcoindev@googlegroups.com>
Subject: [bitcoindev] CTV++ OP_TEMPLATEHASH & OP_INPUTAMOUNTS
Message-ID: <rqgc7ysr5Px28EKRJu2nmE9cAsm47jPWKnEUAiY-9cw69B6bOUsPT1302MrX6r_6nlXZgayr1WKlBEe3x1UsgYnCX_1EJbAdiQDh95FVQBA=@protonmail.com>
Feedback-ID: 38540639:user:proton
X-Pm-Message-ID: 3d85a6c0e4131bbabea10be71a9cf149424cb52e
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
X-Original-Sender: moonsettler@protonmail.com
X-Original-Authentication-Results: gmr-mx.google.com;       dkim=pass
 header.i=@protonmail.com header.s=protonmail3 header.b=oUi0q5X2;
       spf=pass (google.com: domain of moonsettler@protonmail.com designates
 79.135.106.103 as permitted sender) smtp.mailfrom=moonsettler@protonmail.com;
       dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=protonmail.com
X-Original-From: moonsettler <moonsettler@protonmail.com>
Reply-To: moonsettler <moonsettler@protonmail.com>
Precedence: list
Mailing-list: list bitcoindev@googlegroups.com; contact bitcoindev+owners@googlegroups.com
List-ID: <bitcoindev.googlegroups.com>
X-Google-Group-Id: 786775582512
List-Post: <https://groups.google.com/group/bitcoindev/post>, <mailto:bitcoindev@googlegroups.com>
List-Help: <https://groups.google.com/support/>, <mailto:bitcoindev+help@googlegroups.com>
List-Archive: <https://groups.google.com/group/bitcoindev
List-Subscribe: <https://groups.google.com/group/bitcoindev/subscribe>, <mailto:bitcoindev+subscribe@googlegroups.com>
List-Unsubscribe: <mailto:googlegroups-manage+786775582512+unsubscribe@googlegroups.com>,
 <https://groups.google.com/group/bitcoindev/subscribe>
X-Spam-Score: -1.0 (-)

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.