Skip to content

Reject non-P2MR raw funding outputs - #37

Merged
kiwidream merged 1 commit into
0.1.xfrom
fundrawtx-non-p2mr
Jun 30, 2026
Merged

kiwidream merged 1 commit into
0.1.xfrom
fundrawtx-non-p2mr

Conversation

@kiwidream

@kiwidream kiwidream commented Jun 28, 2026 •

Copy link
Copy Markdown
Member

Fixes #33

Summary

  • reject prebuilt raw fundrawtransaction outputs that are not allowed in restricted-output mode before wallet funding
  • preserve the reserved-witness wallet policy rejection while using restricted-output consensus rules for original raw recipient scripts
  • add P2MR wallet functional coverage for rejected legacy/P2SH/v0/v1 raw recipients and accepted P2MR/OP_RETURN/PayToAnchor raw outputs

Root Cause

On P2MR-only chains, fundrawtransaction converted decoded raw transaction outputs into CRecipients and cleared tx.vout without validating the original recipient scripts against restricted-output mode. Wallet funding then rebuilt those non-P2MR recipient scripts and only failed later at mempool validation.

Tests

  • python3 -m py_compile test/functional/wallet_p2mr.py
  • git diff --check
  • cmake --build build_issue33 --target qbitd qbit-cli -j 10
  • ulimit -n 256; build_issue33/test/functional/test_runner.py wallet_p2mr.py
  • DOCKER_BUILDKIT=1 docker run --rm -v "$(pwd)":/bitcoin -v /Users/miller/conductor/repos/qbit-v1/.git:/Users/miller/conductor/repos/qbit-v1/.git bitcoin-linter

View with Codesmith Autofix with Codesmith
Need help on this PR? Tag /codesmith with what you need. Autofix is disabled.


Note

Medium Risk
Changes wallet transaction-building policy on P2MR-only chains; scope is limited to fundrawtransaction’s new pre-funding check, not broader auth or consensus code.

Overview
fundrawtransaction on restricted-output chains now validates the decoded raw transaction’s vout scripts before wallet funding, instead of only failing later at mempool acceptance.

Wallet RPC funding adds RejectRestrictedOutputModeDisallowedOutput, which keeps the existing reserved-witness rejection and, when fRestrictedOutputMode is active, rejects outputs that fail Consensus::IsRestrictedOutputModeConsensusOutput at the next block height. The RPC FundTransaction helper takes an optional original_outputs pointer; fundrawtransaction snapshots tx.vout, clears it for the existing recipient path, and passes that snapshot so prebuilt recipient scripts are checked even though funding no longer reads tx.vout.

Functional coverage in wallet_p2mr.py asserts RPC errors for legacy, P2SH-SegWit, v0, and v1 raw recipients, and successful funding for P2MR, OP_RETURN, and PayToAnchor prebuilt outputs.

Reviewed by Cursor Bugbot for commit f394576. Bugbot is set up for automated code reviews on this repo. Configure here.

@kiwidream

Copy link
Copy Markdown
Member Author

PR Review

Findings

No blocking findings from this review pass.

Consensus Impact

Consensus-adjacent

This does not change consensus validation itself, but it moves restricted-output consensus allowlist checks into the wallet RPC funding path for fundrawtransaction. The relevant paths are src/wallet/rpc/spend.cpp:57, src/wallet/rpc/spend.cpp:789, and src/wallet/rpc/spend.cpp:927, using Consensus::IsRestrictedOutputModeConsensusOutput at the next block height.

Review Scope

Reviewed backing issue #33, the PR body, commit 4d280fb585, the full diff, and surrounding wallet/RPC and consensus helper code: fundrawtransaction, RPC recipient construction, wallet transaction creation, CNoDestination script preservation, PayToAnchor handling, restricted-output mempool/block validation, and policy reserved-witness handling. No PR comments, reviews, or unresolved review threads were present.

Deep Checks Performed

Traced the raw transaction path from DecodeHexTx through original_outputs, ExtractDestination, CreateRecipients, RPC FundTransaction, and wallet CreateTransaction. Checked that non-address scripts such as OP_RETURN round-trip through CNoDestination(script), PayToAnchor remains a destination script, reserved witness outputs still hit the existing wallet policy rejection, and the new height calculation matches the mempool next-block check.

Issue Fit

The PR matches issue #33’s requested behavior: prebuilt legacy, P2SH-SegWit, v0, and v1 raw recipient outputs are rejected before wallet funding; P2MR, OP_RETURN, and PayToAnchor raw outputs remain accepted; and the implementation reuses the restricted-output consensus helper rather than duplicating a wallet-only allowlist. I did not see scope drift outside fundrawtransaction and targeted P2MR wallet functional coverage.

qbit-Specific Checks

Focused on P2MR/restricted-output wallet safety and RPC behavior. AuxPoW, ASERT, PHOTON, release signing, and P2P surfaces are not touched. The change keeps consensus validation unchanged and aligns wallet preflight behavior with the existing restricted-output consensus checks.

Validation Reviewed

Author-reported validation includes py_compile, git diff --check, a qbitd/qbit-cli build, wallet_p2mr.py, and Docker lint. I also ran git diff --check origin/0.1.x...origin/pr/37 locally; it passed. GitHub Core Checks passed, including build smoke, functional smoke, focused unit suites, and the Core Checks Gate. Full Validation has multiple successful jobs including Docker lint, rpc-docs, Windows, ASan/UBSan, TSan, tidy, and CentOS depends/gui; the visible CentOS log tail shows the functional suite summary passed. At review time, MSan and the Required Merge Gate were still in progress.

Residual Risk

I did not locally rerun the full wallet_p2mr.py functional test. The accepted-output tests assert funding success but do not decode the funded transaction to assert final vout script equality; the reviewed code path does preserve P2MR, PayToAnchor, and CNoDestination(script) outputs.

@kiwidream
kiwidream merged commit d78b728 into 0.1.x Jun 30, 2026
38 of 39 checks passed
djh58 pushed a commit that referenced this pull request Jul 2, 2026
* Accept legacy AuxPoW RPC payloads (#23)

* Prevent AuxPoW signalling in permissionless GBT (#22)

* wallet: defer P2MR getnewaddress keypool refill (#13)

* wallet: defer P2MR getnewaddress keypool refill

* wallet: bound internal P2MR keypool refill

* wallet: align P2MR top-up lock ordering

* wallet: schedule raw change P2MR refills

* wallet: report paused P2MR refills as failed

* wallet: log inline P2MR refill failures

* ci: fix BuildKit helper lint

* Document AuxPoW commitment order fields (#35)

* Restrict explicit wallet output types on P2MR-only chains (#25)

* Restrict explicit wallet output types

* test: run BECH32 wallet suites on unrestricted regtest

* fuzz: run wallet transaction target on unrestricted regtest

* Fix BuildKit helper lint

* Report missing wallet output managers accurately

* Allow managerless wallets with default output options

* test: add independent P2MR and CTV script vectors (#29)

* Add independent P2MR PQC witness vector tests (#30)

* test: add independent P2MR PQC witness vector

* test: verify P2MR wrong-domain vector signature

* Fix AuxPoW legacy payload disambiguation

* wallet: avoid MarkUnused P2MR full top-up (#31)

* wallet: avoid MarkUnused P2MR full top-up

* wallet: avoid MarkUnused lock inversion

* wallet: preserve P2MR recovery lookahead

* Split P2MR wallet unit tests (#52)

* Remove unused P2MR wallet test import (#58)

* Shard P2MR wallet unit tests (#60)

* Add independent CHECKDATASIGPQC vector tests (#38)

* test: add P2MR data-hash proof fixtures (#43)

* test: add independent P2MR commitment vectors (#47)

* Reject invalid raw funding outputs (#37)

* Validate witness-pruned assumevalid before wipe (#59)

* Add independent CHECKDATASIGADDPQC vector tests (#42)

* qt: recommend wallet encryption by default (#62)

* Verify libbitcoinpqc tagged subtree imports (#41)

* ci: verify libbitcoinpqc tagged subtree imports

* ci: handle peeled libbitcoinpqc tag refs

* ci: peel libbitcoinpqc tag objects before compare

* ci: pass auth to libbitcoinpqc verifier

* ci: pin libbitcoinpqc verifier inputs

* ci: verify libbitcoinpqc import tree

* Add P2MR PQC annex sighash vectors (#54)

* Add P2MR PQC annex sighash vectors

* Guard annex mutation vector test

* Add P2MR data signature support to Qt Sign/Verify (#63)

* qt: add P2MR data signature dialog

* qt: support text data in P2MR signatures

* qt: align P2MR proof verification with RPC

* test: add P2MR CHECKSIGPQC sighash vectors (#55)

* Add rawmr future-leaf coverage (#64)

* test: cover P2MR SIGHASH_SINGLE missing outputs (#57)

* test: add P2MR PQC codeseparator vectors (#56)

* Fix PQC data-hash counter accounting (#46)

* Fix PQC data-hash counter accounting

* Fix PQC data-hash leaf error priority

* Report final PQC slot failures as exhausted

* doc: add v0.1.2-testnet4 release notes

* build: bump version to v0.1.2-testnet4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants