Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
205 changes: 205 additions & 0 deletions bip-p2mr-pq-signatures.mediawiki
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
<pre>
BIP: ?
Layer: Consensus (soft fork)
Title: P2MR with Post-Quantum Signatures (BIP-360+)
Authors: Arshad <arshad@siliconfort.com>
Status: Draft
Type: Specification
Assigned: ?
License: BSD-3-Clause
Discussion: ?
Requires: 340, 341, 342, 360
</pre>

== Abstract ==

This document extends BIP 360 (Pay-to-Merkle-Root, P2MR) from protection against long-exposure quantum attacks only to protection against both long- and short-exposure attacks, in a single soft fork. It keeps the P2MR output format unchanged and adds a new tapscript leaf version that supports post-quantum (PQ) signatures through one algorithm-agile opcode. It also defines a safer rule for depth-zero script trees, resource limits suitable for large PQ signatures, and a recommended hybrid wallet template.

== Copyright ==

This BIP is licensed under the BSD-3-Clause license.

== Motivation ==

A cryptographically relevant quantum computer running Shor's algorithm could recover a secp256k1 private key from its public key. Hash functions lose only about half of their security bits to Grover's algorithm and remain secure at 256-bit output sizes.

{| class="wikitable"
! Attack !! Key exposure window !! Covered by BIP 360 !! Covered by this BIP
|-
| Long exposure || Months or years on-chain (P2PK, reused addresses, P2TR output keys) || Yes, for new P2MR outputs || Yes
|-
| Short exposure || Between broadcast and confirmation of any Schnorr or ECDSA spend || No || Yes, through PQ signatures
|-
| Break of a single PQ scheme || Whenever that scheme fails || n/a || Yes, through a hash-based backup leaf
|}

BIP 360 states that it protects only against long-exposure attacks and leaves PQ signatures to future work. Deploying the signature layer separately would require a second soft fork and a second wallet migration. Past upgrades such as SegWit and Taproot each took years to reach majority use, so combining both steps reduces total migration time.

== Summary of changes relative to BIP 360 ==

{| class="wikitable"
! # !! Area !! BIP 360 !! This BIP
|-
| 1 || PQ signatures || Not defined || Leaf version 0xC2 with OP_CHECKSIGPQ and OP_CHECKSIGPQVERIFY
|-
| 2 || Algorithm agility || n/a || One-byte algorithm identifier; unknown identifiers succeed, enabling future soft forks without new opcodes
|-
| 3 || Redundancy || Under consideration || Recommended hybrid template: Schnorr plus ML-DSA leaf, SLH-DSA backup leaf
|-
| 4 || Depth-zero trees || Spend succeeds without script execution || Treated as a single-leaf tree; the script is executed
|-
| 5 || Resource limits || 520-byte tapscript element limit prevents PQ signatures || Per-leaf element limit and per-algorithm validation costs
|-
| 6 || Legacy coins || Out of scope || Out of scope; left to a separate proposal
|}

== Specification ==

All rules in this section apply only to witness version 2 (P2MR) outputs. Values marked ''provisional'' are subject to benchmarking and review.

=== Output and address ===

Unchanged from BIP 360. The scriptPubKey is <code>OP_2 <32-byte Merkle root></code> (34 bytes). Addresses use Bech32m and begin with <code>bc1z</code> on mainnet. Leaves and branches are hashed with the BIP 341 <code>TapLeaf</code> and <code>TapBranch</code> tagged hashes, with no internal key and no tweak.

=== Depth-zero rule ===

A control block of exactly one byte (m = 0) denotes a tree containing a single leaf. The validator computes the leaf hash, requires it to equal the witness program, and then executes the leaf script according to its leaf version. A depth-zero spend never succeeds without executing its script.

=== Leaf version 0xC2: PQ tapscript ===

Scripts with leaf version 0xC2 follow all BIP 342 rules, with the additions below. Leaf version 0xC0 continues to denote plain tapscript, so existing Schnorr-only scripts can be used inside P2MR unchanged.

{| class="wikitable"
! Opcode !! Value (provisional) !! Stack input !! Result
|-
| OP_CHECKSIGPQ || 0xbb || <code><sig> <pk> <C></code> || Pushes 1 on success, 0 for an empty signature
|-
| OP_CHECKSIGPQVERIFY || 0xbc || <code><sig> <pk> <C></code> || Removes inputs on success, otherwise fails
|}

Scripts contain only a 32-byte commitment <code>C</code> to the PQ public key. The full public key is supplied in the witness at spend time:

<pre>
C = tagged_hash("BIP360PQ/Key", pk)
pk = alg_id || pk_bytes
</pre>

Execution proceeds as follows:

# Pop <code>C</code>, <code>pk</code> and <code>sig</code>. Fail if <code>C</code> is not 32 bytes or <code>pk</code> is empty.
# Fail if <code>tagged_hash("BIP360PQ/Key", pk)</code> does not equal <code>C</code>. The first byte of <code>pk</code> is <code>alg_id</code>.
# If <code>alg_id</code> is not listed in the registry below, push 1 (OP_CHECKSIGPQ) or continue (OP_CHECKSIGPQVERIFY). This reserves unknown identifiers for future soft forks, in the same way BIP 342 treats unknown public key types.
# If <code>sig</code> is empty, push 0 (OP_CHECKSIGPQ) or fail (OP_CHECKSIGPQVERIFY).
# If <code>sig</code> is exactly one byte longer than the algorithm's signature size, its final byte is the sighash type; otherwise SIGHASH_DEFAULT is used. Sighash types are interpreted as in BIP 341.
# Compute the BIP 342 signature message with <code>ext_flag = 1</code> and <code>key_version = 0x01</code>. The distinct key version prevents a PQ signature from being reinterpreted as a Schnorr signature or the reverse.
# Verify the signature using the algorithm's pure (non-pre-hash) signing mode with context string <code>"BIP360+"</code>. If verification fails for a non-empty signature, the script fails.
=== Algorithm registry ===

{| class="wikitable"
! alg_id !! Scheme !! Standard !! Public key (bytes) !! Signature (bytes) !! Validation cost (provisional)
|-
| 0x01 || ML-DSA-44 || FIPS 204 || 1,312 || 2,420 || 200
|-
| 0x02 || ML-DSA-65 || FIPS 204 || 1,952 || 3,309 || 300
|-
| 0x10 || SLH-DSA-SHA2-128s || FIPS 205 || 32 || 7,856 || 2,000
|-
| 0x20 || FN-DSA-512 || Reserved pending standardisation and review || 897 || about 666 || TBD
|}

Additional schemes may be added by a later soft fork that assigns an unused identifier. No new opcode or leaf version is required.

=== Resource limits ===

* In leaf version 0xC2, initial witness stack elements may be up to 8,192 bytes, instead of the 520-byte tapscript limit. Elements created during script execution remain limited to 520 bytes.
* Each PQ signature check subtracts the algorithm's validation cost from the BIP 342 validation budget (50 plus the witness size in bytes). Because PQ signatures are large, honest spends always carry sufficient budget.
* Transaction weight and fee calculation are unchanged from current Bitcoin Core rules: 1 weight unit per witness byte and 4 weight units per non-witness byte. PQ keys and signatures receive no additional discount.
== Recommended wallet template ==

Wallets should receive into a two-leaf P2MR output by default.

{| class="wikitable"
! Leaf !! Leaf version !! Script !! Purpose !! Approximate witness size
|-
| A (hybrid) || 0xC2 || <code><xonly_pk> OP_CHECKSIGVERIFY <C_mldsa> OP_CHECKSIGPQ</code> || Normal spending || 3,900 bytes (about 980 vB)
|-
| B (backup) || 0xC2 || <code><C_slhdsa> OP_CHECKSIGPQ</code> || Used if ML-DSA is broken or distrusted || 7,960 bytes (about 1,990 vB)
|}

Leaf A requires both a Schnorr and an ML-DSA signature, so it remains secure while either scheme is unbroken. Leaf B relies only on hash functions. Both keys are derived from the same seed using derivation paths to be specified in a companion wallet BIP.

For comparison, a P2TR key-path input is about 58 vB, so a leaf A spend uses roughly 17 times more block space.

== Migration ==

# The soft fork activates P2MR and leaf version 0xC2 together.
# Wallets switch new receive addresses to the recommended template.
# Users move funds from P2PK, P2PKH, P2WPKH and P2TR outputs into P2MR outputs. Exchanges and custodians, which hold the largest exposed balances, are expected to migrate first.
# Lightning and other second-layer protocols adopt P2MR-based scripts on their own schedules.
Treatment of coins that are never migrated (for example, rate-limiting their spends or freezing them with a seed-based recovery mechanism) is out of scope. Separating that policy question allows the protective upgrade to proceed independently.

== Deployment ==

P2MR and leaf version 0xC2 activate together through a single BIP 9 version-bits deployment, so the network never enforces P2MR without PQ signature support.

{| class="wikitable"
! Parameter !! Proposed value
|-
| Mechanism || BIP 9 version bits with a minimum activation height
|-
| Bit || TBD
|-
| Threshold || 90% of blocks in a 2,016-block retarget period
|-
| Signalling window || Approximately 12 months
|-
| Minimum activation height || Approximately 6 months after expected lock-in
|-
| Relay policy || Before activation, witness v2 outputs and leaf 0xC2 spends remain non-standard. After activation, they are standard when total transaction weight is at most 400,000 WU
|}

Deployment on signet, together with test vectors covering every rule in this specification, is a precondition for choosing mainnet parameters.

== Rationale ==

* '''Single soft fork.''' Each wallet migration takes years. Pairing the output type with the signatures that make it fully secure halves the number of migrations required.
* '''Key commitments.''' Placing a 32-byte commitment in the script instead of the full public key saves 1,312 to 1,952 bytes in every unused leaf and hides which PQ scheme was chosen until spend time.
* '''Hybrid signatures.''' ML-DSA is comparatively new and lattice cryptanalysis remains active. Requiring a Schnorr signature as well ensures that a classical break of ML-DSA alone, before quantum computers exist, does not put coins at risk.
* '''Hash-based backup.''' SLH-DSA depends only on hash functions. Its signatures are large, but the backup leaf is intended for rare use.
* '''No witness discount.''' A discount for PQ data would allow larger blocks and increase node resource requirements. That trade-off warrants separate discussion, so weight rules are left unchanged.
== Security Considerations ==

* Tagged hashes with 256-bit output retain at least 128-bit preimage security against Grover's algorithm.
* P2MR protects coins at rest only if users do not reveal the Schnorr public key elsewhere. In the recommended template, the Schnorr key is revealed only when leaf A is spent, at which point the ML-DSA signature also protects the transaction.
* Validation costs and the 8,192-byte element limit bound worst-case verification time per block. Final values must be derived from benchmarks on low-end node hardware.
* PQ signature verification code must be constant-time where secret data is involved in signing, and verification must match the NIST reference test vectors exactly.
== Backward Compatibility ==

Nodes that do not implement this BIP treat witness version 2 outputs as anyone-can-spend and do not relay or mine spends from them by default, so this is a soft fork. Wallets that implement BIP 350 can already send to <code>bc1z</code> addresses.

== Reference Implementation ==

A reference implementation for Bitcoin Core is planned and will cover:

* Consensus: witness version 2 programs, the depth-zero rule, leaf version 0xC2, OP_CHECKSIGPQ, element limits and validation costs (<code>src/script/interpreter.cpp</code>).
* Cryptography: ML-DSA and SLH-DSA verification pinned to NIST test vectors (<code>src/crypto/pq/</code>).
* Deployment parameters for regtest, signet and mainnet (<code>src/kernel/chainparams.cpp</code>).
* Standardness policy (<code>src/policy/policy.cpp</code>).
* Signing, descriptors and PSBT fields for PQ keys and signatures (<code>src/script/sign.cpp</code>, <code>src/wallet/</code>).
* Unit tests, test vectors and functional tests for every leaf type.
== Open Questions ==

* Final validation costs and element limit, based on benchmarks.
* Whether ML-DSA-44 or ML-DSA-65 should be the default in the hybrid leaf.
* Whether FN-DSA-512 should be defined in the initial deployment.
* Derivation paths and PSBT fields, to be specified in a companion BIP.
== Acknowledgements ==

This proposal builds directly on BIP 360 by Hunter Beast, Ethan Heilman and Isabel Foxen Duke.