Skip to content

Add independent P2MR and CTV script vectors - #29

Merged
kiwidream merged 1 commit into
0.1.xfrom
issue-21-p2mr-ctv-vectors-0.1.x
Jun 29, 2026
Merged

kiwidream merged 1 commit into
0.1.xfrom
issue-21-p2mr-ctv-vectors-0.1.x

Conversation

@kiwidream

@kiwidream kiwidream commented Jun 26, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Add fixed byte-vector P2MR script-path tests for a single-leaf spend and a two-leaf branch spend.
  • Add a fixed byte-vector CTV spend test that avoids deriving the accepted spend from production commitment helpers.
  • Add negative companion checks for mutated script/control/program/branch data and CTV-covered transaction data.

Why

Issue #21 identified that several P2MR and CTV script tests built expected-good spends using the same helper paths that verification relies on. These fixtures harden the script tests by anchoring accepted spends to fixed serialized bytes.

Validation

  • cmake --build build --target test_qbit -j 8
  • build/bin/test_qbit --run_test=script_p2mr_tests
  • Docker changed-file checks: git diff --check HEAD~..HEAD && python3 test/lint/lint-includes.py

Note: full Docker lint was run and reaches unrelated pre-existing failures in .github/actions/configure-docker/buildkit-config.sh and ci/checks/test_configure_docker_buildkit_config.py on this base branch. This PR does not modify those files.


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


Note

Low Risk
Changes are limited to unit tests in script_p2mr_tests.cpp; no consensus or production script interpreter code is modified.

Overview
Hardens P2MR and CTV script-path coverage in script_p2mr_tests.cpp by anchoring good spends to fixed serialized hex instead of only deriving witnesses from the same merkle/CTV helpers used elsewhere in the suite.

Adds small hex helpers (ScriptFromHex, ParseHexBytes, Uint256FromHexBytes) and extends BuildP2MRSpend so tests can pass an explicit script_pubkey, not just a computed program root.

New cases: p2mr_fixed_single_leaf_vector and p2mr_fixed_two_leaf_branch_vector lock leaf hash, merkle root, and VerifyScript success, with negatives for wrong leaf, control byte, merkle path, and scriptPubKey. p2mr_ctv_fixed_spend_vector does the same for a CTV leaf (checks CTV hash, accepts spend, rejects wrong script/commitment and nLockTime mutation with SCRIPT_ERR_TEMPLATE_MISMATCH).

Reviewed by Cursor Bugbot for commit 1272af2. 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

The PR only changes src/test/script_p2mr_tests.cpp, but the covered behavior is P2MR/CTV script verification and commitment construction. It does not modify interpreter or consensus code; it strengthens tests around consensus-critical byte contracts.

Review Scope

Reviewed issue #21 as the contract, PR #29 body, the full one-file diff, surrounding P2MR/CTV test helpers, ComputeP2MRLeafHash, ComputeP2MRBranchHash, ComputeP2MRMerkleRoot, GetDefaultCheckTemplateVerifyHash, visible CI status, and review-thread state. There are no prior review comments or unresolved threads.

Deep Checks Performed

Traced the new fixed-vector path through explicit scriptPubKey, leaf script, control block, witness construction, VerifySpend, and CTV transaction-data refresh. I also checked that the negative CTV fixture uses a matching alternate P2MR root, so it reaches SCRIPT_ERR_TEMPLATE_MISMATCH instead of failing early at witness-program matching.

Issue Fit

The PR fits issue #21. It adds fixed-byte positive vectors for a single-leaf P2MR spend, a two-leaf P2MR branch spend, and a CTV spend, plus negative checks for mutated script bytes, leaf/control data, branch data, output program/root, CTV commitment bytes, and an nLockTime mutation covered by CTV. The accepted P2MR and CTV spends are anchored by hardcoded script and program bytes instead of deriving the final accepted output from the same helper path used by verification.

qbit-Specific Checks

For P2MR, I independently recomputed the P2MRLeaf and P2MRBranch tagged hashes for the new OP_TRUE, OP_FALSE, branch-root, CTV-leaf-root, and alternate CTV-leaf-root fixtures; the constants match. For CTV, I independently recomputed the default CTV hash for the helper-built one-input, one-output spend and it matches the hardcoded 659732...28ac value. AuxPoW, PHOTON, wallet, RPC, validation, and release surfaces are not touched.

Validation Reviewed

Visible CI shows build smoke, focused unit suites, functional smoke, Windows jobs, docs, Core Checks Gate, and Cursor Bugbot passing. The focused-unit job log shows script_p2mr_tests ran and includes the new p2mr_fixed_single_leaf_vector, p2mr_fixed_two_leaf_branch_vector, and p2mr_ctv_fixed_spend_vector cases. Local review checks: git diff --check passed, and I performed independent Node-based recomputation of the new P2MR and CTV constants. I did not run the full local unit suite because this workspace has no local build directory.

Residual Risk

Some broader full-validation jobs were still pending at review time, including sanitizer/platform/lint jobs and the required merge gate. The CTV vector is fixed by a hardcoded hash and independently checked here, but the test still constructs the surrounding transaction with local test helpers rather than embedding a fully serialized transaction fixture.

@kiwidream
kiwidream force-pushed the issue-21-p2mr-ctv-vectors-0.1.x branch from 914380a to 1272af2 Compare June 28, 2026 15:11
@djh58
djh58 self-requested a review June 29, 2026 14:56
@kiwidream
kiwidream merged commit cf88864 into 0.1.x Jun 29, 2026
33 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