Skip to content

Commit c768b96

Browse files
authored
Merge pull request bitcoin#903 from kallewoof/2003-bip322-simplified
bip-322: simplify proposal to single proof case
2 parents eb34cf4 + f9e9584 commit c768b96

File tree

1 file changed

+14
-55
lines changed

1 file changed

+14
-55
lines changed

bip-0322.mediawiki

Lines changed: 14 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -34,24 +34,8 @@ The current message signing standard only works for P2PKH (1...) addresses. By e
3434

3535
A new structure <code>SignatureProof</code> is added, which is a simple serializable scriptSig & witness container.
3636

37-
Two actions "Sign" and "Verify" are defined along with one ''purpose'', "SignMessage", with the ability to expand in the future to add a potential "ProveFunds" purpose.
38-
3937
=== SignatureProof container ===
4038

41-
{|class="wikitable" style="text-align: center;"
42-
|-
43-
!Type
44-
!Length
45-
!Name
46-
!Comment
47-
|-
48-
|Uint32||4||version||BIP322 version format; must be equal to 1; if > 1, verifier must abort the verification process
49-
|-
50-
|Uint8||1||entries||number of proof entries<ref><strong>Why support multiple proofs?</strong> It is non-trivial to check a large number of individual proofs for duplicates. Software could be written to do so, but it seems more efficient to build this check into the specification itself.</ref>
51-
|}
52-
53-
The above is followed by [entries] number of signature entries:
54-
5539
{|class="wikitable" style="text-align: center;"
5640
|-
5741
!Type
@@ -79,74 +63,51 @@ A verification call will return a result code according to the table below.
7963
!Code
8064
!Description
8165
|-
82-
|INCOMPLETE||One or several of the given challenges had an empty proof. The prover may need some other entity to complete the proof.
66+
|INCOMPLETE||Empty proof.
8367
|-
84-
|INCONCLUSIVE||One or several of the given proofs was consensus-valid but policy-invalid.
68+
|INCONCLUSIVE||The given proof was consensus-valid but policy-invalid.
8569
|-
86-
|VALID||All proofs were deemed valid.
70+
|VALID||The proof was valid.
8771
|-
88-
|INVALID||One or more of the given proofs were invalid
72+
|INVALID||The proof was invalid
8973
|-
9074
|ERROR||An error was encountered
9175
|}
9276

9377
== Signing and Verifying ==
9478

95-
If the challenge consists of a single address and the address is in the P2PKH (legacy) format, sign using the legacy format (further information below). Otherwise continue as stated below.
79+
If the challenge consists of an address is in the P2PKH (legacy) format, sign using the legacy format (further information below). Otherwise continue as stated below.
9680

97-
Let there be an empty set <code>inputs</code> which is populated and tested at each call to one of the actions below.
81+
For both cases, generate a sighash based on the given scriptPubKey and message as follows:
9882

99-
=== Purpose: SignMessage ===
100-
101-
The "SignMessage" purpose generates a sighash based on a scriptPubKey and a message. It emits a VALID verification result code unless otherwise stated.
102-
103-
# Return INVALID if scriptPubKey already exists in <code>inputs</code> set, otherwise insert it<ref><strong>Why track duplicates?</strong> Because a 3-entry proof is not proving 3 entries unless they are all distinct</ref>
10483
# Define the message pre-image as the sequence "Bitcoin Signed Message:\n" concatenated with the message, encoded in UTF-8 using Normalization Form Compatibility Decomposition (NFKD)
10584
# Let sighash = sha256(sha256(scriptPubKey || pre-image))
10685
10786
A private key may be used directly to sign a message. In this case, its P2WPKH bech32 address shall be derived, and used as the input.
10887

109-
=== Action: Sign ===
88+
=== Signing ===
11089

111-
The "Sign" action takes as input a purpose. It returns a signature or fails.
90+
The signature is generated as follows:
11291

113-
# Obtain the sighash and scriptPubKey from the purpose; FAIL if not VALID
11492
# Derive the private key privkey for the scriptPubKey; FAIL if not VALID
11593
# Generate and return a signature sig with privkey=privkey, sighash=sighash
11694
117-
The resulting signature proof should be encoded using base64 encoding.
118-
119-
=== Action: Verify ===
95+
=== Verifying ===
12096

121-
The "Verify" action takes as input a standard flags value, a script sig, an optional witness, and a purpose.
122-
It emits one of INCONCLUSIVE, VALID, INVALID, or ERROR.
97+
Verify a proof, given a standard flags value, a script sig, an optional witness, and a derived sighash as described above.
12398

12499
While omitted below, ERROR is returned if an unforeseen error occurs at any point in the process. A concrete example of this is if a legacy proof is given as input to a non-legacy address; the deserialization of the proof will fail in this case, and this should result in an ERROR result.
125100

126-
# Obtain the sighash and scriptPubKey from the purpose; pass on result code if not VALID
127101
# Verify Script with flags=consensus flags (currently P2SH, DERSIG, NULLDUMMY, CLTV, CSV, WITNESS), scriptSig=script sig, scriptPubKey=scriptPubKey, witness=witness, and sighash=sighash
128102
# Return INVALID if verification fails
129103
# Verify Script with flags=standard flags (above plus STRICTENC, MINIMALDATA, etc.), scriptSig=script sig, scriptPubKey=scriptPubKey, witness=witness, and sighash=sighash
130104
# Return VALID if verification succeeds, otherwise return INCONCLUSIVE
131105
132-
=== Multiple Proofs ===
133-
134-
When more than one proof is created or verified, repeat the operation for each proof, retaining the inputs set. As noted, if the same input appears more than once, the operation must fail accordingly.
135-
136-
Note that the order of the entries in the proof must match the order of the entries given by the verifier.
137-
138-
* If any of the proofs are empty during a verification process, skip the verification and set the INCOMPLETE flag
139-
* If a verification call returns ERROR or INVALID, return ERROR or INVALID immediately, ignoring as yet unverified entries
140-
* After all verifications complete,
141-
** return INCONCLUSIVE if any verification call returned INCONCLUSIVE
142-
** return INCOMPLETE if the INCOMPLETE flag is set
143-
** return VALID
144-
145106
== Legacy format ==
146107

147-
The legacy format is restricted to the legacy P2PKH address format, and restricted to one single challenge (address).
108+
The legacy format is restricted to the legacy P2PKH address format.
148109

149-
Any other input (e.g. multiple addresses, or non-P2PKH address format(s)) must be signed using the new format described above.
110+
Any other input (i.e. non-P2PKH address format) must be signed using the new format described above.
150111

151112
=== Signing ===
152113

@@ -174,10 +135,6 @@ Given the P2PKH address <code>a</code>, the message <code>m</code>, the compact
174135

175136
This specification is backwards compatible with the legacy signmessage/verifymessage specification through the special case as described above.
176137

177-
== Rationale ==
178-
179-
<references/>
180-
181138
== Reference implementation ==
182139

183140
# Pull request to Bitcoin Core: https://github.com/bitcoin/bitcoin/pull/16440
@@ -228,6 +185,8 @@ All of the above, plus (subject to change):
228185
229186
== Test vectors ==
230187

188+
(TODO: update test vectors, which are based on previous iteration where signature proofs contained additional data)
189+
231190
== Native segwit test vector ==
232191

233192
<pre>

0 commit comments

Comments
 (0)