Skip to content

Commit 3bfecc3

Browse files
committed
Split up shares and proofs into global or per input fields
1 parent c9589c5 commit 3bfecc3

File tree

1 file changed

+88
-22
lines changed

1 file changed

+88
-22
lines changed

bip-PSBT-SP.mediawiki

Lines changed: 88 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
Created: 2024-05-14
1313
License: BSD-2-Clause
1414
Post-History: https://groups.google.com/g/bitcoindev/c/5G5wzqUXyk4
15-
Requires: 352, 370
15+
Requires: 352, 370, 374
1616
</pre>
1717

1818
==Introduction==
@@ -52,20 +52,54 @@ The new global types are defined as follows:
5252
|-
5353
| Silent Payment Global ECDH Share
5454
| <tt>PSBT_GLOBAL_SP_ECDH_SHARE = 0x07</tt>
55-
| <tt><33 byte scan key> <36 byte outpoint>*</tt>
56-
| The scan key and a list of outpoints corresponding to the prevouts of the inputs that this ECDH share is for. The outpoints are composed of a 32 byte txid followed by a 32-bit little endian uint.
55+
| <tt><33 byte scan key></tt>
56+
| The scan key that this ECDH share is for.
5757
| <tt><33 byte share></tt>
58-
| An ECDH share for a scan key, followed by a list of outpoints. The ECDH shared is computed with ''a * B_scan'', where ''a'' is the sum of all private keys of the inputs matching the list of outpoints, and ''B_scan'' is the scan key of a recipient.
58+
| An ECDH share for a scan key. The ECDH shared is computed with ''a * B_scan'', where ''a'' is the sum of all private keys of all eligible inputs, and ''B_scan'' is the scan key of a recipient.
5959
|
6060
| 0
6161
| 2
6262
|-
6363
| Silent Payment Global DLEQ Proof
6464
| <tt>PSBT_GLOBAL_SP_DLEQ = 0x08</tt>
65-
| <tt><33 byte scan key> <36 byte outpoint>*</tt>
66-
| The scan key and a list of outpoints corresponding to the prevouts of the inputs that this proof covers. The outpoints are composed of a 32 byte txid followed by a 32-bit little endian uint.
65+
| <tt><33 byte scan key></tt>
66+
| The scan key that this proof covers.
6767
| <tt><64-byte proof></tt>
68-
| A DLEQ proof computed for the matching ECDH share.
68+
| A BIP374 DLEQ proof computed for the matching ECDH share.
69+
|
70+
| 0
71+
| 2
72+
|}
73+
74+
The new per-input types are defined as follows:
75+
76+
{|
77+
! Name
78+
! <tt><keytype></tt>
79+
! <tt><keydata></tt>
80+
! <tt><keydata></tt> Description
81+
! <tt><valuedata></tt>
82+
! <tt><valuedata></tt> Description
83+
! Versions Requiring Inclusion
84+
! Versions Requiring Exclusion
85+
! Versions Allowing Inclusion
86+
|-
87+
| Silent Payment Input ECDH Share
88+
| <tt>PSBT_IN_SP_ECDH_SHARE = 0x1d</tt>
89+
| <tt><33 byte scan key></tt>
90+
| The scan key that this ECDH share is for.
91+
| <tt><33 byte share></tt>
92+
| An ECDH share for a scan key. The ECDH shared is computed with ''a * B_scan'', where ''a'' is the private key of the corresponding prevout public key, and ''B_scan'' is the scan key of a recipient.
93+
|
94+
| 0
95+
| 2
96+
|-
97+
| Silent Payment Input DLEQ Proof
98+
| <tt>PSBT_IN_SP_DLEQ = 0x1e</tt>
99+
| <tt><33 byte scan key></tt>
100+
| The scan key that this proof covers.
101+
| <tt><64-byte proof></tt>
102+
| A BIP374 DLEQ proof computed for the matching ECDH share.
69103
|
70104
| 0
71105
| 2
@@ -85,14 +119,24 @@ One new per-output type is defined as follows:
85119
! Versions Allowing Inclusion
86120
|-
87121
| Silent Payment Data
88-
| <tt>PSBT_OUT_SP_V0_INFO = 0x08</tt>
122+
| <tt>PSBT_OUT_SP_V0_INFO = 0x09</tt>
89123
| None
90124
| No key data
91125
| <tt><33 byte scan key> <33 byte spend key></tt>
92126
| The scan and spend public keys from the silent payments address.
93127
|
94128
| 0
95129
| 2
130+
|-
131+
| Silent Payment Label
132+
| <tt>PSBT_OUT_SP_V0_LABEL = 0x10</tt>
133+
| None
134+
| No key data
135+
| <tt><32-bit little endian uint label></tt>
136+
| The label to use to compute the spend key of the silent payments address to verify change.
137+
|
138+
| 0
139+
| 2
96140
|}
97141

98142
<tt>PSBT_OUT_SCRIPT</tt> is modified to be optional for outputs in silent payments capable PSBTs. If this field is not included in the output, then the field PSBT_OUT_SP_V0_INFO must be included.
@@ -122,22 +166,24 @@ Outputs with PSBT_OUT_SP_V0_INFO set may only be added if there are no inputs sp
122166

123167
===Updater===
124168

169+
The updater should add a PSBT_IN_BIP32_DERIVATION for any p2wpkh, p2sh-p2wpkh, or p2pkh input so the public key is available for creating the ecdh_shared_secret when the private key is not known. If the updater does not want to reveal the fingerprint or derivation path, it can set the value of the field to zero.
170+
125171
====Change Detection====
126172

127-
Updaters may add two PSBT_OUT_BIP32_DERIVATION key-value-pairs with the corresponding derivation path of both the scan and spend keys. The Signer can then use these fields to verify that the silent payment code is change.
173+
Updaters may add two PSBT_OUT_BIP32_DERIVATION key-value-pairs with the corresponding derivation path of both the scan and spend keys. A label can be specified in PSBT_OUT_SP_V0_LABEL. The Signer can then use these fields to verify that the silent payment code is change.
128174

129175
===Signer===
130176

131177
All rules must be followed from PSBTv2 for this role. If there are any outputs with PSBT_OUT_SP_V0_INFO set, then the following additional rules must also be adhered to:
132178

133179
If any input is spending an output with script using Segwit version > 1, the Signer must fail.
134180

135-
For all outputs with PSBT_OUT_SP_V0_INFO set, the Signer should:
136-
* Compute and set an ECDH share and DLEQ proof using all inputs it has the private key for.
137-
* Verify the DLEQ proofs for all inputs it does not have the private keys for.
138-
* If all eligible inputs have an ECDH share, compute and set the PSBT_OUT_SCRIPT.
181+
For each output with PSBT_OUT_SP_V0_INFO set, the Signer should:
182+
* Compute and set an ECDH share and DLEQ proof for each input it has the private key for, or set a global ECDH share and DLEQ proof if it has private keys for all eligible inputs.
183+
* Verify the DLEQ proofs for all inputs it does not have the private keys for, or the global DLEQ proof if it is set.
184+
* If all eligible inputs have an ECDH share or the global ECDH share is set, compute and set the PSBT_OUT_SCRIPT.
139185
140-
If the Signer sets any missing PSBT_OUT_SCRIPTs, it must set the Inputs Modifiable flag to False.
186+
If the Signer sets any missing PSBT_OUT_SCRIPTs, it must set the Inputs Modifiable and Outputs Modifiable flags to False.
141187

142188
If any output does not have PSBT_OUT_SCRIPT set, the Signer must not yet add a signature.
143189

@@ -146,32 +192,52 @@ The Signer should additionally compute the silent payment addresses, optionally
146192
If a sighash type is provided and there are silent payment outputs present, the signer must fail if the sighash type is not SIGHASH_ALL.
147193
If a sighash type is not provided and there are silent payment outputs present, the signer must sign using SIGHASH_ALL.<ref name="why_use_sighash_all"> ''' Why use only SIGHASH_ALL?''' BIP352 allows signing with SIGHASH_NONE and SIGHASH_SINGLE. However, silent payment capable PSBTs compute the output scripts deterministically based on the number and position of silent payment codes with the same scan key. SIGHASH_NONE and SIGHASH_SINGLE allow changing the amount or position of silent payment codes with the same scan and spend keys, which would invalidate computed output scripts.</ref>
148194

149-
====Computing the DLEQ Proof====
195+
====Computing the ECDH Shares and DLEQ Proofs====
150196

151197
For each output with PSBT_OUT_SP_V0_INFO set, the Signer may generate a proof for other entities to generate the output scripts and verify that the output scripts were generated correctly.
152198

153-
Generate a global ECDH share for each scan key ''B<sub>scan</sub>'' and all eligible inputs the Signer has private keys for as follows:
199+
If the Signer has the private keys for all eligible inputs, the Signer should generate a global ECDH share for each scan key ''B<sub>scan</sub>'' as follows:
154200

155201
Using the notation from [https://github.com/bitcoin/bips/blob/master/bip-0352.mediawiki#specification BIP352]
156202

157-
* Let ''A<sub>n</sub>'' be the sum of the public keys ''A'' of all eligible inputs
158203
* Let ''a<sub>n</sub>'' be the sum of the private keys ''a'' of all eligible inputs
159204
* Let ''C = a<sub>n</sub>·B<sub>scan</sub>''
160205
161-
Use a key ''B<sub>scan</sub>'' followed by a list of the outpoints of all eligible inputs.
206+
Set the key as ''B<sub>scan</sub>'' and the value as ''C'' for the PSBT_GLOBAL_SP_ECDH_SHARE field.
207+
208+
Compute the DLEQ proof for ''C'' using [https://github.com/bitcoin/bips/blob/master/bip-0374.mediawiki#user-content-DLEQ_Proof_Generation BIP374 GenerateProof] and passing ''a<sub>n</sub>'' as ''a'' and ''B<sub>scan</sub>'' as ''B''.
209+
Set the key as ''B<sub>scan</sub>'' and the value as the proof for the PSBT_GLOBAL_SP_DLEQ field.
162210

163-
Set the value for the key of PSBT_GLOBAL_SP_ECDH_SHARE to ''C''.
211+
If the Signer has the private keys for some eligible inputs or does not want to create a global ECDH share, the Signer should generate a per-input ECDH share for each scan key ''B<sub>scan</sub>'' as follows:
164212

165-
Compute the DLEQ proof for ''C'' using ''a<sub>n</sub>'' and ''B<sub>scan</sub>''.
166-
Set the value for the key of PSBT_GLOBAL_SP_DLEQ to the proof.
213+
Using the notation from [https://github.com/bitcoin/bips/blob/master/bip-0352.mediawiki#specification BIP352], for each eligible input:
214+
215+
* Let ''a'' be the private key of the input
216+
* Let ''C = a·B<sub>scan</sub>''
217+
218+
Set the key as ''B<sub>scan</sub>'' and the value as ''C'' for the PSBT_IN_SP_ECDH_SHARE field of the input.
219+
220+
Compute the DLEQ proof for ''C'' using [https://github.com/bitcoin/bips/blob/master/bip-0374.mediawiki#user-content-DLEQ_Proof_Generation BIP374 GenerateProof] and passing ''B<sub>scan</sub>'' as ''B''.
221+
Set the key as ''B<sub>scan</sub>'' and the value as the proof for the PSBT_IN_SP_DLEQ field of the input.
167222

168223
====Verifying the DLEQ Proof====
169224

170225
For each output with PSBT_OUT_SP_V0_INFO set, the Signer should verify the ECDH shares for all eligible inputs it does not have the private key for using the proofs provided by other Signers.
171226

227+
If PSBT_GLOBAL_SP_ECDH_SHARE and PSBT_GLOBAL_SP_DLEQ are set, verify as follows:
228+
229+
* Let ''A<sub>n</sub>'' be the sum of the public keys ''A'' of all eligible inputs
230+
231+
Using [https://github.com/bitcoin/bips/blob/master/bip-0374.mediawiki#dleq-proof-verification BIP374 VerifyProof] and passing ''A'' as ''A<sub>n</sub>'', ''B'' as ''B<sub>scan</sub>'', ''C'' as the value of PSBT_GLOBAL_SP_ECDH_SHARE, and ''proof'' as the value of PSBT_GLOBAL_SP_DLEQ.
232+
233+
If PSBT_IN_SP_ECDH_SHARE and PSBT_IN_SP_DLEQ are set for a particular input, verify as follows:
234+
235+
Using [https://github.com/bitcoin/bips/blob/master/bip-0374.mediawiki#dleq-proof-verification BIP374 VerifyProof] and passing ''A'' as the public key of the input, ''B'' as ''B<sub>scan</sub>'', ''C'' as the value of PSBT_IN_SP_ECDH_SHARE, and ''proof'' as the value of PSBT_IN_SP_DLEQ.
236+
237+
172238
====Computing the Output Scripts====
173239

174-
Compute the PSBT_OUT_SCRIPT using the procedure in [https://github.com/bitcoin/bips/blob/master/bip-0352.mediawiki#user-content-Creating_outputs BIP352] but substituting ''a·B<sub>scan</sub>'' with the sum of all PSBT_GLOBAL_SP_ECDH_SHAREs for that scan key.
240+
Compute the PSBT_OUT_SCRIPT using the procedure in [https://github.com/bitcoin/bips/blob/master/bip-0352.mediawiki#user-content-Creating_outputs BIP352] but substituting ''a·B<sub>scan</sub>'' with the PSBT_GLOBAL_SP_ECDH_SHARE for that scan key if available, or the sum of all PSBT_IN_SP_ECDH_SHAREs for that scan key.
175241
If there are multiple silent payment codes with the same scan key, sort the codes lexicographically in ascending order to determine the ordering of the ''k'' value.
176242
If there are multiple silent payment codes with both the same scan and spend keys, sort the subgroup by output index in ascending order.
177243

0 commit comments

Comments
 (0)