Skip to content

Commit 61faee6

Browse files
committed
Correct inconsistencies in commitment and attestation structure. Switch from merkle tree commitment to sorted vector hash commitment.
1 parent 48eaf8f commit 61faee6

File tree

1 file changed

+91
-95
lines changed

1 file changed

+91
-95
lines changed

bip-0360.mediawiki

Lines changed: 91 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -287,23 +287,7 @@ The <code>scriptPubKey</code> for a P2QRH output is:
287287
Where:
288288

289289
* <code>OP_PUSHNUM_3</code> (<code>0x03</code>) indicates SegWit version 3.
290-
* <nowiki><hash></nowiki> is the 32-byte HASH256 of the merkle root of a tree of public key hashes, as defined in the Hash Computation section below.
291-
292-
=== Output Mechanics ===
293-
294-
To prevent storage of arbitrary data using P2QRH (QuBit) outputs,
295-
the witness stack for inputs spending SegWit v3 outputs is limited to the fixed-size signatures necessary for spending the
296-
output, and the output must be spendable to be considered valid within node consensus. A fixed signature size will also
297-
be helpful to disambiguate between signature types without an additional version byte. Consequently, the correct
298-
signature algorithm can be inferred through byte length. The public key and signature will be pushed separately to the
299-
attestation stack. Multiple signatures can be included in order to support multisig applications, and also for spending
300-
multiple inputs.
301-
302-
Since only valid signatures can be committed to in a SegWit v3 attestation, arbitrary data cannot be added by miners,
303-
as that would affect the consensus of their block. A CRQC operator is economically disincentivized from computing a
304-
spendable public key that matched arbitrary signature data due to the cost of that computation. That is because the
305-
cost of such a computation could prove quite substantial, rather than simply putting the arbitrary data within a
306-
Taproot witness.
290+
* <nowiki><hash></nowiki> is the 32-byte HASH256 of the commitment, as defined in the Hash Commitment section below.
307291
308292
==== Key Type Bitmask ====
309293

@@ -320,48 +304,53 @@ The key type bitmask is a 1-byte value that indicates the type of key used in th
320304
321305
Example key type bitmask using all supported key types:
322306

323-
0x01 | 0x02 | 0x04 | 0x08 = 0x0F
307+
0x01 | 0x02 | 0x04 | 0x08 = 0x0F
324308
325309
==== Hash Commitment ====
326310

327-
If there is only a single public key, the hash is computed as the HASH256 of the public key, as a commitment to the
328-
merkle root of a binary tree of public key hashes.
311+
If there is only a single public key, the hash is computed as the HASH256 of the public key.
329312

330313
In order to support multiple keys, as in the context of multisig or singlesig hybrid cryptography, the hash is
331-
computed as a sparse merkle tree of multiple public key hashes:
314+
computed as a commitment to a vector of public key hashes:
332315

333-
1. For each public key, compute its HASH256
334-
2. Pair the hashes and compute HASH256 of their concatenation
335-
3. Continue pairing and hashing until reaching a single root hash
336-
4. Compute the merkle root
337-
5. Prepend key type bitmask and threshold to the root hash
338-
6. Compute the HASH256 of the result
316+
1. Sort the public keys first by key type, then by public key value
317+
2. For each sorted public key, compute its HASH256
318+
3. Concatenate all the public key hashes in sorted order
319+
4. Prepend key type bitmask and threshold to the concatenated hashes
320+
5. Compute the HASH256 of the result
339321

340322
For example with 4 public keys:
341323

342-
h1 = HASH256(pubkey1)
343-
h2 = HASH256(pubkey2)
344-
h3 = HASH256(pubkey3)
345-
h4 = HASH256(pubkey4)
324+
// First sort the public keys
325+
sorted_pubkeys = sort_by_key_type_and_value([pubkey1, pubkey2, pubkey3, pubkey4])
346326
347-
h12 = HASH256(h1 <nowiki>||</nowiki> h2)
348-
h34 = HASH256(h3 <nowiki>||</nowiki> h4)
327+
// Then compute hashes of sorted keys
328+
h1 = HASH256(sorted_pubkeys[0])
329+
h2 = HASH256(sorted_pubkeys[1])
330+
h3 = HASH256(sorted_pubkeys[2])
331+
h4 = HASH256(sorted_pubkeys[3])
349332
350-
root = HASH256(h12 <nowiki>||</nowiki> h34)
333+
// Concatenate all hashes
334+
concatenated = h1 <nowiki>||</nowiki> h2 <nowiki>||</nowiki> h3 <nowiki>||</nowiki> h4
351335
352-
commitment = key_type_bitmask <nowiki>||</nowiki> threshold <nowiki>||</nowiki> root
336+
commitment = key_type_bitmask <nowiki>||</nowiki> threshold <nowiki>||</nowiki> concatenated
353337
354338
hash = HASH256(commitment)
355339
340+
With sort_by_key_type_and_value defined as:
341+
342+
def sort_by_key_type_and_value(pubkeys):
343+
return sorted(pubkeys, key=lambda x: (x.key_type, x.public_key))
344+
356345
When spending, if a public key hash is provided in the attestation with an empty signature, that hash will be used
357-
directly in the merkle tree computation rather than hashing the full public key. This allows unused public keys to be
346+
directly in the vector computation rather than hashing the full public key. This allows unused public keys to be
358347
excluded from the transaction while still proving they were part of the original commitment.
359348

360-
The merkle tree construction creates an efficient cryptographic commitment to multiple public keys while enabling
349+
The vector construction creates an efficient cryptographic commitment to multiple public keys while enabling
361350
selective disclosure.
362351

363352
A threshold is provided to indicate the number of signatures required to spend the output. This is used in the
364-
cryptographic commitment in the merkle tree hash computation and revealed in the attestation when spent.
353+
cryptographic commitment in the hash computation and revealed in the attestation when spent.
365354

366355
Only a single 32-byte X-only secp256k1 public key can be provided as key type 0. There are a few reasons for this:
367356

@@ -370,25 +359,23 @@ Only a single 32-byte X-only secp256k1 public key can be provided as key type 0.
370359
3. When a secp256k1 key is specified in the key type bitmask, how many keys it commits to is unambiguous.
371360
4. If multiple keys need to be committed to, they must be aggregated, which saves on transaction size.
372361

373-
This design maintains compatibility for [https://github.com/bitcoin/bips/blob/master/bip-0114.mediawiki BIP-114] Taproot
374-
Merkelized Alternative Script Tree (MAST) merkle root in the attestation, which makes P2QRH a quantum-resistant
375-
version of Taproot transactions.
362+
This design maintains compatibility for [https://github.com/bitcoin/bips/blob/master/bip-0114.mediawiki BIP-114]
363+
Taproot Merkelized Alternative Script Tree (MAST) merkle root in the commitment, which makes P2QRH a
364+
quantum-resistant version of Taproot transactions. The TapScript itself must however be provided in the witness,
365+
as no script execution is allowed in the attestation.
376366

377-
In a multisig context, aside from secp256k1 keys, the number of keys provided in the attestation is variable and must
378-
meet the threshold as committed to in the merkle tree hash computation and revealed in the attestation.
367+
In a multisig context, aside from secp256k1 keys, the number of keys provided in the attestation is variable and
368+
must meet the threshold as committed to in the hash computation and revealed in the attestation.
379369

380-
If an implementation for public key or signature aggregation for PQC algorithms is developed, key and signature
381-
aggregation must become the default behavior for P2QRH.
370+
When the address is generated, all public keys must be known in advance, and they must be sorted, first by key
371+
type, then by public key value, so as to be deterministic.
382372

383-
When the address is generated, all public keys must be known in advance, and they must be sorted, first by key type,
384-
then by public key value, so as to be deterministic.
373+
The key count does not need to be provided for PQC keys because the key type bitmask and threshold are sufficient
374+
to validate a multisig transaction.
385375

386-
The key count does not need to be provided for PQC keys because the key type bitmask and threshold are sufficient to
387-
validate a multisig transaction.
388-
389-
In a singlesig context, multiple PQC keys can be provided, but the key type bitmask and threshold must still also be
390-
provided to be consistent with the multisig semantics. The threshold will be set as 0x01, and the key type bitmask will
391-
indicate how many keys of each type are present.
376+
In a singlesig context, multiple PQC keys can be provided, but the key type bitmask and threshold must still also
377+
be provided to be consistent with the multisig semantics. The threshold will be set as 0x01, and the key type
378+
bitmask will indicate how many keys of each type are present.
392379

393380
=== Transaction Serialization ===
394381

@@ -412,11 +399,14 @@ attestation is present.
412399

413400
The attestation field consists of:
414401

415-
* <code>num_pubkeys</code>: The number of public keys ([https://learnmeabitcoin.com/technical/general/compact-size/ compact size]).
402+
* <code>key_type_bitmask</code>: A [https://learnmeabitcoin.com/technical/general/compact-size/ compact size] value indicating which key types are present.
403+
* <code>threshold</code>: A compact size value indicating the number of signatures required to spend the output.
404+
* <code>num_pubkeys</code>: The number of public keys (compact size).
416405
417406
For each public key:
418407

419-
* <code>pubkey_length</code>: compact size length of the public key.
408+
* <code>key_type</code>: The key type (compact size). Only one bit is used to indicate the key type.
409+
* <code>pubkey_length</code>: compact size length of the public key (compact size).
420410
* <code>pubkey</code>: The public key bytes.
421411
422412
Then:
@@ -434,10 +424,45 @@ quantum-resistant algorithms.
434424
For each input, a separate attestation field is used. To know how many attestation fields are present, implementations
435425
must count the number of inputs present in the transaction.
436426

427+
==== Attestation Parsing Example ====
428+
429+
Signing for a single input using both secp256k1 Schnorr and FALCON-512:
430+
431+
Number of public keys:
432+
433+
[key_type_bitmask]: 0x03
434+
[threshold]: 0x01
435+
[num_pubkeys]: 0x02
436+
437+
Pubkey 1:
438+
[key_type]: 0x01
439+
[pubkey_length]: 0x20 (32 bytes)
440+
[pubkey]: public_key_secp256k1
441+
442+
Pubkey 2:
443+
[key_type]: 0x02
444+
[pubkey_length]: 0x0701 (1793 bytes)
445+
[pubkey]: public_key_falcon_512
446+
447+
Number of signatures:
448+
449+
[num_signatures]: 0x02
450+
451+
Signature 1:
452+
[signature_length]: 0x40 (64 bytes)
453+
[signature]: signature_secp256k1
454+
455+
Signature 2:
456+
[signature_length]: 0x0500 (1280 bytes)
457+
[signature]: signature_falcon_512
458+
459+
Note: This contrasts with multisig inputs, where the attestation structure repeats for each public key and signature.
460+
437461
=== Signature Algorithms ===
438462

439-
The specific quantum-resistant signature algorithm used is inferred from the length of the public key.
440-
Implementations must recognize the supported algorithms and validate accordingly.
463+
The specific quantum-resistant signature algorithm used cannot be inferred from the length of the public key due to
464+
collisions in length between algorithms. Instead, when each key is revealed in the attestation, the key type bitmask
465+
indicates which algorithm was used.
441466

442467
Supported PQC algorithms and their NIST Level I parameters:
443468

@@ -470,14 +495,11 @@ Supported PQC algorithms and their NIST Level I parameters:
470495
** Cycles to sign: 4,682,570,992
471496
** Cycles to verify: 4,764,084
472497
473-
Implementations must reject public keys and signatures that do not match expected lengths for supported algorithms.
474-
475-
If a new algorithm is added, and one of the byte sizes overlaps, then an additional byte should be prepended to the
476-
new algorithm's public key length that indicates the specific algorithm used.
498+
Implementations must recognize the supported algorithms and validate accordingly.
477499

478-
A bitmask is used to indicate the algorithm used for each public key and signature pair. The bitmask is enumerates based on
479-
the key type as indicated above. This is used in the cryptographic commitment in the merkle tree hash computation and
480-
revealed in the attestation when spent.
500+
A bitmask is used to indicate the algorithm used for each public key and signature pair. The bitmask enumerates based on
501+
the key type as indicated above. This is used in the cryptographic commitment in the hash computation and
502+
revealed in the attestation for each public key when spent.
481503

482504
=== Script Validation ===
483505

@@ -494,9 +516,12 @@ the <code>scriptPubKey</code>.
494516

495517
* Valid signatures corresponding to the public key(s) and the transaction data.
496518
519+
* The key type bitmask and threshold must match the commitment in the <code>scriptPubKey</code>.
520+
497521
3. For multi-signature schemes, all required public keys and signatures must be provided for that input within the
498522
attestation. Public keys that are not needed or available can be selectively disclosed by including their hash in the
499-
attestation accompanied with an empty signature by providing a 0x00 signature length byte.
523+
attestation accompanied with an empty signature by providing a 0x00 signature length byte. This works so long as
524+
enough keys to meet the threshold are provided.
500525

501526
==== Sighash Calculation ====
502527

@@ -531,36 +556,6 @@ Signature verification is as follows:
531556
4. Ensure that the signature algorithm used matches the expected lengths for NIST Level I security, and is supported by
532557
the implementation.
533558

534-
==== Attestation Parsing Example ====
535-
536-
Signing for a single input using both secp256k1 Schnorr and FALCON-512:
537-
538-
Number of public keys:
539-
540-
[num_pubkeys]: 0x02
541-
542-
Pubkey 1:
543-
[pubkey_length]: 0x20 (32 bytes)
544-
[pubkey]: public_key_secp256k1
545-
546-
Pubkey 2:
547-
[pubkey_length]: 0x0701 (1793 bytes)
548-
[pubkey]: public_key_falcon_512
549-
550-
Number of signatures:
551-
552-
[num_signatures]: 0x02
553-
554-
Signature 1:
555-
[signature_length]: 0x40 (64 bytes)
556-
[signature]: signature_secp256k1
557-
558-
Signature 2:
559-
[signature_length]: 0x0500 (1280 bytes)
560-
[signature]: signature_falcon_512
561-
562-
Note: This contrasts with multisig inputs, where the attestation structure repeats for each public key and signature.
563-
564559
=== Compatibility with BIP-141 ===
565560

566561
By adhering to the SegWit transaction structure and versioning, P2QRH outputs are compatible with existing transaction
@@ -691,6 +686,7 @@ seeds to act as the authoritative secret when signing. These measures are deemed
691686

692687
To help implementors understand updates to this BIP, we keep a list of substantial changes.
693688

689+
* 2025-03-18 - Correct inconsistencies in commitment and attestation structure. Switch from merkle tree commitment to sorted vector hash commitment.
694690
* 2025-03-12 - Add verification times for each algorithm. 256 -> 128 (NIST V -> NIST I). Add key type bitmask. Clarify multisig semantics.
695691
* 2025-02-23 - More points of clarification from review. Update dead link.
696692
* 2025-01-20 - Remove SQIsign from consideration due to significant performance concerns. Refactor language from long-range attack to long-exposure so as to not be confused with the language around block re-org attacks.

0 commit comments

Comments
 (0)