Skip to content

Commit 48eaf8f

Browse files
authored
Updates - 2025/03/12 (#19)
- [x] Add verification times - [x] 256 -> 128 (NIST V -> NIST I) - [x] Multisig threshold and bitmask bytes - [x] Bitmask for all four signature types - [x] Taproot compatibility
1 parent 6f3748e commit 48eaf8f

File tree

1 file changed

+127
-50
lines changed

1 file changed

+127
-50
lines changed

bip-0360.mediawiki

Lines changed: 127 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ to gain a quadratic speedup on brute-force attacks on the hash functions used in
165165
CRQC is needed for these attacks to meaningfully impact Bitcoin. For instance, a preimage attack on
166166
HASH160 <ref name="hash160">Used by P2PKH, P2SH, and P2WPKH addresses, though not P2WSH because it uses 256-bit hashes.</ref>
167167
using Grover's algorithm would require at least 10^24 quantum operations. As for Grover's application to mining, see
168-
[https://quantumcomputing.stackexchange.com/a/12847 Sam Jaques post on this].
168+
[https://quantumcomputing.stackexchange.com/a/12847 Sam Jaques' post on this].
169169

170170
=== Rationale ===
171171

@@ -192,9 +192,10 @@ commitment to a public key in the style of a
192192
[https://github.com/bitcoin/bips/blob/master/bip-0141.mediawiki#user-content-Witness_program BIP-141 witness program].
193193
Because it goes into the scriptPubKey, it does not receive a witness or attestation discount.
194194

195-
Post-quantum public keys are generally larger than those used by ECC, depending on the security level. To promote user
196-
adoption and general user-friendliness, the most secure variant (NIST Level V, 256-bit security) is proposed, despite
197-
the increase in key length and verification time.
195+
Post-quantum public keys are generally larger than those used by ECC, depending on the security level.
196+
Originally BIP-360 proposed NIST Level V, 256-bit security, but this was changed to NIST Level I, 128-bit security
197+
due to concerns over the size of the public keys, the time it would take to verify signatures, and being generally
198+
deemed "overkill".
198199

199200
Support for FALCON signatures will be introduced first, with the intention of adding other post-quantum
200201
algorithms as they are approved. By way of comparison, FALCON signatures are roughly 20x larger than Schnorr signatures.
@@ -226,9 +227,9 @@ Bitcoin, but their signatures are smaller and might be considered by some to be
226227
signatures.
227228

228229
The reason multiple cryptosystems are included is in the interest of supporting hybrid cryptography, especially for
229-
high value outputs, such as cold wallets used by exchanges. To improve the viability of the activation client, and
230-
adoption by wallets and libraries, a library akin to libsecp256k1 will be developed to support the new PQC
231-
cryptosystems, called libbitcoinpqc.
230+
high value outputs, such as cold wallets used by exchanges. To improve the viability of the activation client and
231+
adoption by wallets and libraries, a library akin to libsecp256k1 will be developed. This library, libbitcoinpqc,
232+
will support the new PQC cryptosystems and can be used as a reference for other language-native implementations.
232233

233234
In the distant future, following the implementation of the P2QRH output type in a QuBit soft fork, there will likely
234235
be a need for Pay to Quantum Secure (P2QS) addresses. A distinction is made between cryptography that's merely resistant
@@ -304,18 +305,37 @@ spendable public key that matched arbitrary signature data due to the cost of th
304305
cost of such a computation could prove quite substantial, rather than simply putting the arbitrary data within a
305306
Taproot witness.
306307

307-
==== Hash Computation ====
308+
==== Key Type Bitmask ====
308309

309-
If there is only a single public key, the hash is computed as the HASH256 of the public key, as if it were a
310-
merkle root.
310+
The key type bitmask is a 1-byte value that indicates the type of key used in the commitment. It is encoded as follows:
311+
312+
* 0x01 - Key type 0 - secp256k1
313+
* 0x02 - Key type 1 - FALCON-512
314+
* 0x04 - Key type 2 - CRYSTALS-Dilithium Level I
315+
* 0x08 - Key type 3 - SPHINCS+-128s
316+
* 0x10 - Unused
317+
* 0x20 - Unused
318+
* 0x40 - Unused
319+
* 0x80 - Reserved for if additional key types are added in the future
320+
321+
Example key type bitmask using all supported key types:
322+
323+
0x01 | 0x02 | 0x04 | 0x08 = 0x0F
324+
325+
==== Hash Commitment ====
326+
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.
311329

312330
In order to support multiple keys, as in the context of multisig or singlesig hybrid cryptography, the hash is
313-
computed as a merkle tree of multiple public key hashes:
331+
computed as a sparse merkle tree of multiple public key hashes:
314332

315333
1. For each public key, compute its HASH256
316334
2. Pair the hashes and compute HASH256 of their concatenation
317335
3. Continue pairing and hashing until reaching a single root hash
318-
4. The final hash is the merkle root
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
319339

320340
For example with 4 public keys:
321341

@@ -329,33 +349,60 @@ For example with 4 public keys:
329349
330350
root = HASH256(h12 <nowiki>||</nowiki> h34)
331351
352+
commitment = key_type_bitmask <nowiki>||</nowiki> threshold <nowiki>||</nowiki> root
353+
354+
hash = HASH256(commitment)
355+
332356
When spending, if a public key hash is provided in the attestation with an empty signature, that hash will be used
333-
directly in the merkle tree computation rather than hashing the full public key. This allows excluding unused public
334-
keys from the transaction while still proving they were part of the original commitment.
357+
directly in the merkle tree computation rather than hashing the full public key. This allows unused public keys to be
358+
excluded from the transaction while still proving they were part of the original commitment.
335359

336-
This merkle tree construction creates an efficient cryptographic commitment to multiple public keys while enabling
360+
The merkle tree construction creates an efficient cryptographic commitment to multiple public keys while enabling
337361
selective disclosure.
338362

339-
This allows for inclusion of a [https://github.com/bitcoin/bips/blob/master/bip-0114.mediawiki BIP-114] Taproot
363+
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.
365+
366+
Only a single 32-byte X-only secp256k1 public key can be provided as key type 0. There are a few reasons for this:
367+
368+
1. It maintains Taproot compatibility by removing ambiguity which key is representative of the Taptree.
369+
2. It prevents abuse of public keys to store arbitrary data once quantum computing is ubiquitous.
370+
3. When a secp256k1 key is specified in the key type bitmask, how many keys it commits to is unambiguous.
371+
4. If multiple keys need to be committed to, they must be aggregated, which saves on transaction size.
372+
373+
This design maintains compatibility for [https://github.com/bitcoin/bips/blob/master/bip-0114.mediawiki BIP-114] Taproot
340374
Merkelized Alternative Script Tree (MAST) merkle root in the attestation, which makes P2QRH a quantum-resistant
341375
version of Taproot transactions.
342376

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.
379+
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.
382+
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.
385+
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.
392+
343393
=== Transaction Serialization ===
344394

345395
Following BIP-141, a new transaction serialization format is introduced to include an attestation field after the witness field:
346396

347397
[nVersion][marker][flag][txins][txouts][witness][attestation][nLockTime]
348398
349399
* <code>marker</code>: <code>0x00</code> (same as SegWit)
350-
351400
* <code>flag</code>:
352-
353401
** <code>0x02</code> (indicates the presence of attestation data only)
354402
** <code>0x03</code> (indicates the presence of both witness and attestation data)
355-
356403
* <code>attestation</code>: Contains the quantum-resistant public keys and signatures.
357404
358-
=== Transaction ID ===
405+
=== Quantum Transaction ID (qtxid) ===
359406

360407
The transaction ID is computed as the HASH256 of the serialized transaction, including the attestation and witness
361408
(if a witness is present). When decoded, this is called the qtxid, which will differ from the txid and wtxid if an
@@ -392,23 +439,46 @@ must count the number of inputs present in the transaction.
392439
The specific quantum-resistant signature algorithm used is inferred from the length of the public key.
393440
Implementations must recognize the supported algorithms and validate accordingly.
394441

395-
Supported PQC algorithms and their NIST Level V parameters:
396-
397-
* '''SPHINCS+-256f:'''
398-
* Public Key Length: 64 bytes
399-
* Signature Length: 49,856 bytes
400-
* '''CRYSTALS-Dilithium Level 5:'''
401-
* Public Key Length: 2,592 bytes
402-
* Signature Length: 4,595 bytes
403-
* '''FALCON-1024:'''
404-
* Public Key Length: 1,793 bytes
405-
* Signature Length: 1,280 bytes
442+
Supported PQC algorithms and their NIST Level I parameters:
443+
444+
* '''secp256k1 - BIP-340 - Schnorr + X-Only'''
445+
** Key Type 0
446+
** Public Key Length: 32 bytes
447+
** Signature Length: 64 bytes
448+
** Total Size: 96 bytes
449+
** Cycles to sign: 42,000 (EdDSA)
450+
** Cycles to verify: 130,000 (EdDSA)
451+
* '''FN-DSA-512 - FIPS 206 - FALCON-512:'''
452+
** Key Type 1
453+
** Public Key Length: 897 bytes
454+
** Signature Length: 667 bytes
455+
** Total Size: 1,564 bytes
456+
** Cycles to sign: 1,009,764
457+
** Cycles to verify: 81,036
458+
* '''ML-DSA-44 - FIPS 204 - CRYSTALS-Dilithium Level I:'''
459+
** Key Type 2
460+
** Public Key Length: 1,312 bytes
461+
** Signature Length: 2,420 bytes
462+
** Total Size: 3,732 bytes
463+
** Cycles to sign: 333,013
464+
** Cycles to verify: 118,412
465+
* '''SLH-DSA-SHAKE-128s - FIPS 205 - SPHINCS+-128s:'''
466+
** Key Type 3
467+
** Public Key Length: 32 bytes
468+
** Signature Length: 7,856 bytes
469+
** Total Size: 7,888 bytes
470+
** Cycles to sign: 4,682,570,992
471+
** Cycles to verify: 4,764,084
406472
407473
Implementations must reject public keys and signatures that do not match expected lengths for supported algorithms.
408474

409475
If a new algorithm is added, and one of the byte sizes overlaps, then an additional byte should be prepended to the
410476
new algorithm's public key length that indicates the specific algorithm used.
411477

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.
481+
412482
=== Script Validation ===
413483

414484
To spend a P2QRH output, the following conditions must be met:
@@ -425,18 +495,24 @@ the <code>scriptPubKey</code>.
425495
* Valid signatures corresponding to the public key(s) and the transaction data.
426496
427497
3. For multi-signature schemes, all required public keys and signatures must be provided for that input within the
428-
attestation. Public keys that are not needed can be excluded by including their hash in the attestation accompanied
429-
with an empty signature. This includes classical Schnorr signatures.
498+
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.
430500

431501
==== Sighash Calculation ====
432502

433-
The sighash for P2QRH outputs follows the same procedure as defined in BIP-0143 for SegWit transactions:
503+
The sighash for P2QRH outputs follows the same procedure as defined in [https://github.com/bitcoin/bips/blob/master/bip-0341.mediawiki BIP-341] for Taproot transactions:
504+
505+
* '''Signature Message:''' A single-SHA256 of a tagged hash with the tag "TapSighash", containing transaction data.
506+
* '''Tagged Hash:''' Computed as H(tag || tag || data) where H is SHA256 and tag is the SHA256 of the tag name.
507+
* '''Key Data:''' In addition to transaction data, the sighash includes the spent output's scriptPubKey.
508+
* '''Extension Fields:''' Specific data is included or excluded from the sighash based on the sighash flag.
434509
435-
* '''Hash Prevouts:''' Computed over the previous outputs being spent.
436-
* '''Hash Sequence:''' Computed over the sequence fields.
437-
* '''Hash Outputs:''' Computed over the outputs of the transaction.
510+
This signature hash construction ensures transaction malleability is prevented while providing flexibility through
511+
different sighash types (DEFAULT, ALL, NONE, SINGLE, and ANYONECANPAY variants). The exact computation follows the
512+
procedure specified in BIP-341 to maintain compatibility with Taproot signatures.
438513

439-
The message to be signed includes these hashes, ensuring transaction malleability is prevented.
514+
If a sighash flag other than DEFAULT is needed, it can be placed in the transaction witness. In this case, it will be
515+
the only field in the witness.
440516

441517
==== Signature Verification ====
442518

@@ -452,44 +528,44 @@ Signature verification is as follows:
452528
453529
3. Verify each signature against the corresponding public key and the sighash.
454530

455-
4. Ensure that the signature algorithm used matches the expected lengths for NIST Level V security, and is supported by
531+
4. Ensure that the signature algorithm used matches the expected lengths for NIST Level I security, and is supported by
456532
the implementation.
457533

458534
==== Attestation Parsing Example ====
459535

460-
Signing for a single input using both FALCON-1024 and secp256k1 Schnorr:
536+
Signing for a single input using both secp256k1 Schnorr and FALCON-512:
461537

462538
Number of public keys:
463539

464540
[num_pubkeys]: 0x02
465541
466542
Pubkey 1:
467-
[pubkey_length]: 0x0701 (1793 bytes)
468-
[pubkey]: public_key_falcon_1024
469-
470-
Pubkey 2:
471543
[pubkey_length]: 0x20 (32 bytes)
472544
[pubkey]: public_key_secp256k1
473545

546+
Pubkey 2:
547+
[pubkey_length]: 0x0701 (1793 bytes)
548+
[pubkey]: public_key_falcon_512
549+
474550
Number of signatures:
475551

476552
[num_signatures]: 0x02
477553
478554
Signature 1:
479-
[signature_length]: 0x0500 (1280 bytes)
480-
[signature]: signature_falcon_1024
481-
482-
Signature 2:
483555
[signature_length]: 0x40 (64 bytes)
484556
[signature]: signature_secp256k1
485557

558+
Signature 2:
559+
[signature_length]: 0x0500 (1280 bytes)
560+
[signature]: signature_falcon_512
561+
486562
Note: This contrasts with multisig inputs, where the attestation structure repeats for each public key and signature.
487563

488564
=== Compatibility with BIP-141 ===
489565

490566
By adhering to the SegWit transaction structure and versioning, P2QRH outputs are compatible with existing transaction
491567
processing rules. Nodes that do not recognize SegWit version 3 will treat these outputs as anyone-can-spend but, per
492-
BIP-141, will not relay or mine such transactions.
568+
[https://github.com/bitcoin/bips/blob/master/bip-0141.mediawiki BIP-141], will not relay or mine such transactions.
493569

494570
=== Usage Considerations ===
495571

@@ -498,7 +574,7 @@ BIP-141, will not relay or mine such transactions.
498574
Quantum-resistant signatures are significantly larger than traditional signatures, increasing transaction size and the
499575
fees required. Users and wallet developers should be aware of this and plan accordingly.
500576

501-
For example, for CRYSTALS-Dilithium Level V, a single signature is 4,595 bytes, a substantial increase over current
577+
For example, for CRYSTALS-Dilithium Level I, a single public key is 1,312 bytes, and a signature is 2,420 bytes, resulting in a substantial increase over current
502578
ECDSA or Schnorr signatures.
503579

504580
==== Performance Impact ====
@@ -615,6 +691,7 @@ seeds to act as the authoritative secret when signing. These measures are deemed
615691

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

694+
* 2025-03-12 - Add verification times for each algorithm. 256 -> 128 (NIST V -> NIST I). Add key type bitmask. Clarify multisig semantics.
618695
* 2025-02-23 - More points of clarification from review. Update dead link.
619696
* 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.
620697
* 2024-12-18 - Assigned BIP number.

0 commit comments

Comments
 (0)