Repository navigation
Description
Summary
The built-in P2MR descriptor and signing path can create high-threshold, single-leaf mr(multi_a(...)) outputs whose normal annexless satisfaction is rejected with SCRIPT_ERR_P2MR_VALIDATION_WEIGHT.
The smallest affected case is a direct 5-of-5 leaf with default-sighash 3,680-byte signatures. The descriptor accepts the output, but the annexless witness has a validation budget of 18,641 and five successful PQC checks cost 18,650, leaving a deficit of 9.
This is a real wallet/descriptor safety problem, but it is narrower than permanent consensus-level fund loss. Extra committed script bytes, a deeper control path, or a consensus-valid annex increase the budget. Annexes are currently nonstandard and the built-in signing code only supports annexless signatures, so those alternatives do not make the default output safely spendable through the normal wallet and relay path.
Verified on
origin/1.0.0 at 988756471aeecdf4463c04be49da2b7b89a98c21.
Source trace
- Each non-empty P2MR signature operation costs 3,730 units:
src/script/script.h#L70-L77,src/script/interpreter.cpp#L403-L417. - The budget is the serialized size of the entire input witness plus 50:
src/script/interpreter.cpp#L2389-L2399. - PQC signatures are 3,680 bytes:
src/crypto/pqc.h#L20-L27. - The P2MR descriptor builds 34 bytes per key plus the threshold and
OP_NUMEQUAL, and does not reject unsafe threshold/key-count combinations:src/script/descriptor.cpp#L1729-L1804. - P2MR signing explicitly constructs annexless signature hashes:
src/script/sign.cpp#L108-L137. - P2MR annexes are consensus-valid and included in the original witness size used for the budget, but policy rejects them as nonstandard:
src/script/interpreter.cpp#L2345-L2399,src/policy/policy.cpp#L354-L383.
Exact 5-of-5 calculation
For a direct, depth-0 mr(multi_a(5,...)) using raw default-sighash signatures:
| Witness component | Serialized bytes |
|---|---|
| Witness item count | 1 |
Five signatures: 5 * (CompactSize(3680) + 3680) |
18,415 |
| 172-byte leaf script plus length prefix | 173 |
| One-byte control block plus length prefix | 2 |
| Validation offset | 50 |
| Initial budget | 18,641 |
| Five checks at 3,730 each | 18,650 |
| Margin | -9 |
Non-default-sighash signatures add one byte each but still leave the 5-of-5 case short by 4.
For default-sighash, direct single-leaf failures begin as follows:
| Descriptor | Margin |
|---|---|
| 5-of-5 | -9 |
| 6-of-6 | -22 |
| 7-of-7 | -35 |
| 8-of-8 | -46 |
| 8-of-9 | -11 |
| 9-of-9 | -59 |
By contrast, 2-of-3, 3-of-5, and 5-of-7 have positive margins.
Important scope correction
This is not true for every 5-of-5 P2MR script and is not an absolute consensus lock:
- A control path one level deeper adds 32 serialized bytes and makes the direct 5-of-5 budget positive.
- Additional committed, executable-safe script bytes also increase the budget.
- An 8-byte annex adds 9 serialized bytes and makes the depth-0 default-sighash 5-of-5 witness exactly meet the budget.
However, annex spending is nonstandard and unsupported by the normal signer, and these workarounds must have been anticipated when the output or signatures were constructed. The built-in direct descriptor remains unsafe by default.
Expected behavior
Every descriptor configuration accepted for funding should have a standard, wallet-constructible satisfaction that meets consensus validation-weight limits.
Fix options
Because mainnet has not launched, prefer aligning the consensus validation-weight accounting so standard descriptor satisfactions do not require padding. Options include:
- reduce
VALIDATION_WEIGHT_PER_SIGOP_PQCto match the actual marginal witness budget while preserving the intended block-wide verification bound; or - add deterministic per-signature headroom to the initial P2MR budget.
If consensus accounting is intentionally left unchanged, reject unsafe mr(multi_a) configurations during descriptor/address creation and PSBT construction, with a clear error explaining the threshold and budget. This avoids new unsafe outputs but does not provide a normal recovery path for outputs already created.
Regression coverage
- Add a table-driven test for direct
k-of-nP2MR descriptor satisfactions around every budget boundary. - Verify that every descriptor accepted for funding can be finalized and passes
VerifyScriptunder mandatory and standard flags. - Include raw/default and one-byte non-default sighash signatures.
- Include depth-0 and nonzero-depth control blocks so the test documents that control-path size affects the budget.
- If annex padding remains a recovery mechanism, test it separately as consensus-valid but nonstandard behavior.
Acceptance criteria
- The wallet/descriptor layer cannot silently create an output whose normal satisfaction is rejected for P2MR validation weight.
- The 5-of-5 boundary has explicit regression coverage.
- The chosen accounting preserves a documented upper bound on PQC verification work.
- Error messages identify unsupported threshold/key-count combinations if creation is blocked.
Activity