Skip to content

Restricted-output fundrawtransaction accepts prebuilt non-P2MR recipient outputs #33

Closed

Description

@kiwidream

Existing Issue Search

Current Behaviour

On a restricted-output chain (-p2mronly=1), fundrawtransaction can successfully fund a caller-supplied raw transaction that already contains a spendable non-P2MR recipient output, such as legacy P2PKH.

The wallet adds P2MR change and returns success. signrawtransactionwithwallet can then sign the funded transaction. The same node later rejects the fully signed transaction through mempool validation with:

tx-output-not-p2mr

This means the wallet/RPC path reports success for a transaction shape that is already disallowed by qbit restricted-output consensus rules.

Verified against public repository state:

Source trace on public/main:

  • src/wallet/rpc/spend.cpp:66-75: CreateRecipients() only calls RejectReservedWitnessOutput(GetScriptForDestination(destination)); it does not check restricted-output consensus allowability.
  • src/wallet/rpc/spend.cpp:909-919: fundrawtransaction decodes the caller-supplied raw tx, extracts destinations from each existing tx.vout, and feeds them into CreateRecipients().
  • src/wallet/rpc/spend.cpp:923-926: the original tx.vout is cleared and the transaction is rebuilt through wallet funding from those recipients.
  • src/wallet/spend.cpp:1251-1253: wallet transaction creation rematerializes each recipient with GetScriptForDestination(recipient.dest).
  • src/consensus/restricted_outputs.h:28-45: restricted-output consensus permits P2MR, OP_RETURN, PayToAnchor, and active reserved witness outputs, but not legacy spendable outputs.
  • src/validation.cpp:823-827: mempool validation rejects transactions that fail HasOnlyRestrictedOutputModeOutputs() with tx-output-not-p2mr.

Expected Behaviour

On restricted-output chains, wallet funding APIs should fail before funding/signing when a decoded raw transaction contains spendable recipient outputs that are not allowed by restricted-output consensus.

Allowed exceptions should stay allowed:

  • P2MR outputs.
  • OP_RETURN outputs.
  • PayToAnchor outputs.
  • Reserved witness outputs only where the chain's restricted-output consensus rules allow them.

The RPC error should happen in the funding path, before coin selection and signing, rather than after producing a fully signed transaction that local consensus rejects.

Steps To Reproduce

  1. Start a fresh regtest node with -p2mronly=1.
  2. Create/load a wallet and mine enough blocks for spendable funds.
  3. Construct a raw transaction with no inputs and one legacy P2PKH recipient output.
  4. Call fundrawtransaction with that raw transaction hex.
  5. Decode the funded result.
  6. Observe that the wallet added P2MR change but preserved the legacy recipient output.
  7. Call signrawtransactionwithwallet.
  8. Call testmempoolaccept on the signed transaction.
  9. Observe rejection with tx-output-not-p2mr.

The R11 review repro produced:

fundrawtransaction: success, changepos = 0
decoderawtransaction: vout[0].scriptPubKey.type = "witness_v2_p2mr"
decoderawtransaction: vout[1].scriptPubKey.type = "pubkeyhash"
testmempoolaccept: allowed = false, reject-reason = "tx-output-not-p2mr"

Impact

This is a wallet/RPC correctness footgun, not a consensus split. Consensus and mempool validation reject the final transaction correctly.

The issue is that a restricted-output wallet can report success from a funding/signing workflow even though the transaction is already invalid for the active chain policy/consensus boundary. This is especially confusing for raw transaction tooling, automated payout builders, and integrations that expect fundrawtransaction plus wallet signing to fail early for obviously chain-disallowed outputs.

Proposed Fix

Add restricted-output recipient validation to the decoded raw transaction path used by fundrawtransaction.

Implementation direction:

  • Validate each existing decoded output script before converting it into a CRecipient.
  • Reuse the same consensus allowlist as restricted-output validation where possible, with the correct next-block height.
  • Keep OP_RETURN and PayToAnchor exceptions.
  • Preserve the existing reserved-witness output guard and make its policy/consensus relationship explicit.
  • Return a clear RPC error before coin selection, funding, or signing.

Suggested Tests

Add functional coverage under wallet_p2mr.py or wallet_fundrawtransaction.py for -p2mronly=1:

  • fundrawtransaction rejects a raw skeleton with a legacy P2PKH recipient.
  • fundrawtransaction rejects raw skeletons with P2SH-SegWit, bech32 v0, and bech32m v1 spendable recipient outputs.
  • fundrawtransaction still accepts raw skeletons with P2MR recipients.
  • fundrawtransaction still accepts OP_RETURN and PayToAnchor exception outputs where consensus allows them.
  • The rejection happens before signrawtransactionwithwallet and before testmempoolaccept.

Also consider a walletcreatefundedpsbt companion check if its raw-output construction path can preserve caller-supplied spendable non-P2MR outputs in the same way.

Verification Notes

This was prepared from source-level verification against Qbit-Org/qbit remotes, plus the R11 production-mirror regtest repro from internal review finding R11-RO-WALLET-RAWTX-01.

Activity

  1. added
    bug
    and removed
    bug
    on Jun 26, 2026
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