Skip to content

Add rawmr future-leaf P2MR funding guard or regression coverage #36

Closed

Description

@kiwidream

Summary

Public RPC and descriptor paths can create arbitrary-root P2MR outputs through rawmr(...) and generic witness-v2/32 address handling. That includes outputs whose root commits only to a future even P2MR leaf version.

Current consensus and policy then split intentionally but sharply:

  • mandatory P2MR rules verify the commitment and treat unknown even P2MR leaf versions as consensus-valid future upgrade stubs;
  • standard policy rejects the reveal spend with the upgradable Taproot/P2MR version discourage flag;
  • current wallet, PSBT, and data-signing paths only support P2MR v1 leaf version 0xc0.

This is a P3 review warning / hardening issue, not evidence that ordinary wallet P2MR receive/change flows are broken. mr(...) and wallet-native address generation remain pinned to P2MR v1 leaves. The concern is the explicit rawmr(...) / arbitrary-root creation boundary.

Current Status

Verified still present on 2026-06-26:

  • Default branch: main
  • main commit checked: 4b7e1043ced39218757f9c103460ef05ea4b86d7
  • R11 finding: R11-CARRYFORWARD-P2MR-01
  • Scope ID: r11-p2mr-future-leaf-footguns
  • Severity candidate: P3 WARN

This is not the older rawmr(...) solvability issue. main already reports RawMRDescriptor::IsSolvable() == false.

Issue searches for rawmr, future leaf P2MR, and reserved leaf P2MR found no existing public issue or PR for this narrower creation/policy/signing boundary.

Related but not duplicate:

  • #20 covers independent P2MR/PQC witness vector hardening.
  • #21 / #29 cover independent P2MR/CTV commitment vector hardening.

Those improve oracle quality but do not directly decide whether rawmr(...) should remain an accepted expert escape hatch, receive a warning, or gain tighter creation-time policy on restricted-output chains.

Impact

A user, tool, pool, bridge, or integration can derive and fund a normal-looking P2MR address from rawmr(<32-byte-root>), where the root commits to a future even leaf version.

The resulting output is easy to create and allowed as witness-v2/32 P2MR output, but current standard relay and signing behavior do not provide a normal spend path for the reveal:

  1. The output is created as a P2MR witness-v2/32 program.
  2. The reveal witness commits to a future even P2MR leaf version.
  3. Mandatory consensus verification succeeds after the root/leaf commitment checks.
  4. Standard policy rejects the spend under the upgradable-version discourage flag.
  5. Current wallet/PSBT signer paths skip or refuse non-0xc0 P2MR leaves.

If this is intentional, it should be documented and tested as an expert-only escape hatch. If not, restricted-output chains should avoid making these outputs look like ordinary safe P2MR receive targets.

Evidence

Code refs on main:

  • src/script/solver.cpp:144 classifies witness-v2/32 as TxoutType::WITNESS_V2_P2MR.
  • src/consensus/restricted_outputs.h:18 through :26 allow witness-v2/32 as the restricted-output-mode P2MR class.
  • src/policy/policy.cpp:156 through :159 reject reserved future outer witness outputs, but not witness-v2/32 P2MR outputs on the output side.
  • src/script/descriptor.cpp:1904 through :1920 keep rawmr(<root>) as a public descriptor that expands to a witness-v2/32 P2MR scriptPubKey while reporting unsolvable.
  • src/rpc/output_script.cpp:277 through :279 document rawmr(<merkle root>) for deriveaddresses.
  • src/script/interpreter.cpp:2389 through :2406 execute only leaf version 0xc0; future P2MR leaf versions succeed by consensus unless the discourage flag is present.
  • src/script/sign.cpp:503 through :506 keep transaction signing pinned to P2MR_LEAF_VERSION_V1.
  • src/wallet/scriptpubkeyman.cpp:2346 through :2349 keeps P2MR data signing pinned to P2MR_LEAF_VERSION_V1.

Existing tests that pin parts of the behavior:

  • script_p2mr_tests/p2mr_reserved_leaf_versions_policy_flag
  • script_p2mr_tests/p2mr_future_even_leaf_version_uses_masked_control_byte
  • descriptor_p2mr_tests/parse_rawmr_roundtrip
  • descriptor_p2mr_tests/rawmr_fixed_address_vector
  • psbt_p2mr_tests/psbt_p2mr_signing_refuses_reserved_leaf_versions
  • psbt_p2mr_tests/psbt_p2mr_finalization_refuses_reserved_leaf_versions
  • feature_p2mr.py::test_unknown_leaf_policy_rejection

Local verification after confirming the relevant source and tests are identical to main:

build/bin/test_qbit --run_test=script_p2mr_tests/p2mr_reserved_leaf_versions_policy_flag
build/bin/test_qbit --run_test=script_p2mr_tests/p2mr_future_even_leaf_version_uses_masked_control_byte
build/bin/test_qbit --run_test=descriptor_p2mr_tests/parse_rawmr_roundtrip
build/bin/test_qbit --run_test=descriptor_p2mr_tests/rawmr_fixed_address_vector
build/bin/test_qbit --run_test=psbt_p2mr_tests/psbt_p2mr_signing_refuses_reserved_leaf_versions
build/bin/test_qbit --run_test=psbt_p2mr_tests/psbt_p2mr_finalization_refuses_reserved_leaf_versions

All six targeted checks passed.

Reproduction Gap

The current suite pins the individual source-level pieces, but it does not appear to include one end-to-end functional repro that:

  1. derives a P2MR address from rawmr(<future-leaf-root>) via public RPC;
  2. funds that address;
  3. attempts a future-leaf reveal spend;
  4. proves standard mempool rejection;
  5. proves mandatory/block validation behavior for the same reveal; and
  6. proves wallet/PSBT signer refusal or inability for the same output.

Suggested Fix

Human triage should choose one of these outcomes:

  • Document rawmr(...) as an expert-only arbitrary-root escape hatch and add an end-to-end regression test for future-leaf funding, standard-policy rejection, and signer refusal.
  • Add RPC or descriptor warnings for rawmr(...) on restricted-output chains so users do not mistake arbitrary-root P2MR addresses for wallet-supported receive addresses.
  • Reject or require explicit opt-in for rawmr(...)-derived receive/funding surfaces on restricted-output chains.
  • Keep current behavior as accepted risk, but explicitly record why Taproot-style future-leaf behavior is intended for P2MR despite qbit's restricted-output default.

Reverify Requirement

Reverify by adding or checking an end-to-end functional test that funds a rawmr(...) future-leaf P2MR address and demonstrates the three-way behavior in one scenario: consensus-valid future-leaf reveal, standard mempool rejection, and current signer/PSBT refusal for non-0xc0 leaves.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions