Repository navigation
Description
Existing Issue Search
- Searched open issues and PRs for
fundrawtransaction,tx-output-not-p2mr,restricted-output wallet raw, andprebuilt raw transaction P2MR. - Existing issue Wallet explicit output types can create non-P2MR outputs on restricted-output chains #19 and PR Restrict explicit wallet output types on P2MR-only chains #25 are adjacent, but they target explicit wallet output type selection (
address_type,change_type, receive/change guards). - This issue covers a different decoded raw transaction path: caller-supplied recipient outputs already present in the raw transaction passed to
fundrawtransaction. - PR Restrict explicit wallet output types on P2MR-only chains #25 head (
e9cf2acd8ded8a3e6ab508cd40d063fcaf94b785) does not modifysrc/wallet/rpc/spend.cpporsrc/wallet/spend.cpp, and its added test coverage checks explicitchange_type, not non-P2MR recipient outputs already embedded in a raw tx skeleton.
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:
Qbit-Org/qbitdefault branch ismain.public/mainat4b7e1043ced39218757f9c103460ef05ea4b86d7still has the raw recipient gap.- Adjacent PR Restrict explicit wallet output types on P2MR-only chains #25 head at
e9cf2acd8ded8a3e6ab508cd40d063fcaf94b785still has the same raw recipient gap.
Source trace on public/main:
src/wallet/rpc/spend.cpp:66-75:CreateRecipients()only callsRejectReservedWitnessOutput(GetScriptForDestination(destination)); it does not check restricted-output consensus allowability.src/wallet/rpc/spend.cpp:909-919:fundrawtransactiondecodes the caller-supplied raw tx, extracts destinations from each existingtx.vout, and feeds them intoCreateRecipients().src/wallet/rpc/spend.cpp:923-926: the originaltx.voutis cleared and the transaction is rebuilt through wallet funding from those recipients.src/wallet/spend.cpp:1251-1253: wallet transaction creation rematerializes each recipient withGetScriptForDestination(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 failHasOnlyRestrictedOutputModeOutputs()withtx-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
- Start a fresh regtest node with
-p2mronly=1. - Create/load a wallet and mine enough blocks for spendable funds.
- Construct a raw transaction with no inputs and one legacy P2PKH recipient output.
- Call
fundrawtransactionwith that raw transaction hex. - Decode the funded result.
- Observe that the wallet added P2MR change but preserved the legacy recipient output.
- Call
signrawtransactionwithwallet. - Call
testmempoolaccepton the signed transaction. - 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:
fundrawtransactionrejects a raw skeleton with a legacy P2PKH recipient.fundrawtransactionrejects raw skeletons with P2SH-SegWit, bech32 v0, and bech32m v1 spendable recipient outputs.fundrawtransactionstill accepts raw skeletons with P2MR recipients.fundrawtransactionstill accepts OP_RETURN and PayToAnchor exception outputs where consensus allows them.- The rejection happens before
signrawtransactionwithwalletand beforetestmempoolaccept.
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