Skip to content

Commit 187d885

Browse files
authored
Merge pull request #1876 from Merkleize/ccv-fixes
443: Fix some mistakes, and add paragraph on fees
2 parents f9017e5 + e4e2b7c commit 187d885

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

bip-0443.mediawiki

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ exhaustive, as there are many more possible combinations.
100100
in the same transaction, or multiple times with the ''deduct'' logic. This prevents duplicate or inconsistent counting
101101
of the same amounts.
102102

103-
'''Remark:''' it is allowed to check for multiple inputs to check the same output with the ''default'' logic. This
103+
'''Remark:''' it is allowed for multiple inputs to check the same output with the ''default'' logic. This
104104
allows multiple inputs to aggregate (in full or in part) their amounts to the same output.
105105

106106
-----
@@ -129,6 +129,18 @@ Note that the ''deduct'' semantic does not allow to check the exact amount of it
129129
a scheme similar to figure 3 or 4 above, amounts should be constrained either with a signature, or with future
130130
introspection opcodes that allow fixing the amount. In lack of that, amounts would be malleable.
131131

132+
=== Paying fees ===
133+
134+
Since the amount-checking semantics of <code>OP_CHECKCONTRACTVERIFY</code> are designed to preserve the entire input
135+
amount across one or more outputs, transaction fees must be paid exogenously. This can be achieved by adding an extra
136+
input to the transaction, by using an anchor output, or with other future mechanisms.
137+
138+
The ''ignore'' amount mode is not a safe mechanism for paying endogenous fees. An output checked with this mode has no
139+
amount constraint, which would allow a miner to claim the entire value of that input. This mode is included for forward
140+
compatibility with potential future soft forks that may introduce other amount-related logic that is compatible with
141+
<code>OP_CHECKCONTRACTVERIFY</code>'s script checks.
142+
143+
132144
== Specification ==
133145

134146
The tapscript opcode <code>OP_SUCCESS187</code> (<code>0xbb</code>) is constrained with new rules to implement
@@ -176,7 +188,7 @@ would always be hard-coded via a push in the script, the risk of mistakes seems
176188

177189
The following values of the other parameters have special meanings:
178190
* If the <code><taptree></code> is -1, it is replaced with the Merkle root of the current input's tapscript tree. If the taptree is the empty buffer, then the taptweak is skipped.
179-
* If the <code><pk></code> is 0, it is replaced with the NUMS x-only pubkey <code>0x50929b74c1a04954b78b4b6035e97a5e078a5a0f28ec96d547bfee9ace803ac0</code> defined in [[bip-0340.mediawiki|BIP-340]]. If the <code><pk></code> is -1, it is replaced with the taproot internal key of the current input.
191+
* If the <code><pk></code> is 0, it is replaced with the NUMS x-only pubkey <code>0x50929b74c1a04954b78b4b6035e97a5e078a5a0f28ec96d547bfee9ace803ac0</code> defined in [[bip-0341.mediawiki|BIP-341]]. If the <code><pk></code> is -1, it is replaced with the taproot internal key of the current input.
180192
* If the <code><index></code> is -1, it is replaced with the index of the current input.
181193
* If the <code><data></code> is the empty buffer, then there is no data tweak for the input/output being checked.
182194
@@ -190,13 +202,17 @@ The specification is divided into three parts:
190202
* the input initialization;
191203
* the opcode evaluation.
192204
193-
The following helper function is a version of <code>taproot_tweak_pubkey</code>, except that a raw 32-byte data is used
194-
as the tweak.
205+
The following helper function is a variant of <code>taproot_tweak_pubkey</code> from [[bip-0341.mediawiki|BIP341]],
206+
except that a regular SHA256-hash is used instead of a tagged hash, and the pubkey is returned unchanged if the length
207+
of <code>data</code> is 0.
195208

196209
<source lang="python">
197210
def tweak_embed_data(pubkey, data):
198211
assert len(pubkey) == 32
199212

213+
if len(data) == 0:
214+
return None, pubkey
215+
200216
data_tweak = sha256(pubkey + data)
201217

202218
t = int_from_bytes(data_tweak)
@@ -209,7 +225,7 @@ def tweak_embed_data(pubkey, data):
209225
return 0 if has_even_y(Q) else 1, bytes_from_int(x(Q))
210226
</source>
211227

212-
The <code>taproot_tweak_pubkey</code> from [[bip-0341.mediawiki|BIP-341]] is also used as a helper function.
228+
The <code>taproot_tweak_pubkey</code> function is also used as a helper in the pseudocode below.
213229

214230
The following notations are used in the pseudocode below:
215231
* <code>n_inputs</code> and <code>n_outputs</code> are the number of inputs and outputs of the transaction, respectively;

0 commit comments

Comments
 (0)