Skip to content

test: add P2MR PQC codeseparator vectors - #56

Merged
kiwidream merged 1 commit into
0.1.xfrom
p2mr-codesep-pqc-vectors
Jul 2, 2026
Merged

kiwidream merged 1 commit into
0.1.xfrom
p2mr-codesep-pqc-vectors

Conversation

@kiwidream

@kiwidream kiwidream commented Jun 29, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Add a Rust generator for independent P2MR OP_CHECKSIGPQC witness vectors.
  • Regenerate the fixture with default and non-default codeseparator positions, including same-leaf branch paths with different positions.
  • Update P2MR script tests to pin correct and wrong codeseparator sighashes and reject near-miss signatures/domains/scripts.

Root Cause

Issue #49 identified that the existing fixed vector only covered the default 0xffffffff codeseparator position, while the runtime already serializes m_codeseparator_pos. That left no independent fixture coverage for digest changes caused by OP_CODESEPARATOR.

Verification

  • Docker lint via ci/lint_imagefile
  • cmake --build build --target test_bitcoin -j 8
  • cargo fmt --manifest-path contrib/testgen/p2mr_checksigpqc_vectors/Cargo.toml -- --check
  • cargo check --manifest-path contrib/testgen/p2mr_checksigpqc_vectors/Cargo.toml
  • cargo run --manifest-path contrib/testgen/p2mr_checksigpqc_vectors/Cargo.toml -- src/test/data/p2mr_pqc_witness_vectors.json
  • ./build/bin/test_qbit --run_test=script_p2mr_tests --log_level=error

Fixes #49


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


Note

Low Risk
Test-only changes (generator, fixture JSON, and script unit tests); no consensus or production signing path is modified.

Overview
Adds independent P2MR OP_CHECKSIGPQC witness coverage for OP_CODESEPARATOR positions, which the prior fixture only exercised at the default 0xffffffff.

A new Rust tool under contrib/testgen/p2mr_checksigpqc_vectors builds P2MRSighash and spend data outside qbit’s wallet/sighash helpers, signs with libbitcoinpqc, and merges regenerated entries into p2mr_pqc_witness_vectors.json by vector name. Three new cases cover a leading codesep leaf, and IF/ELSE branch spends with different positions on the same leaf script.

script_p2mr_tests.cpp now loads codeSeparatorPosition and wrong-codesep fields, threads m_codeseparator_pos through BuildExecData, allows optional witness stack items between signature and leaf/control, and asserts sighash/signature behavior plus near-miss rejections (wrong codesep sig, cross-branch signatures).

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

@kiwidream
kiwidream force-pushed the p2mr-codesep-pqc-vectors branch from dcaa33d to 0a26ca4 Compare June 29, 2026 19:12
@kiwidream

Copy link
Copy Markdown
Member Author

PR Review

Findings

No blocking findings from this review pass.

Consensus Impact

Consensus-adjacent

This does not modify production consensus, script, wallet, or P2P behavior. It does change fixed P2MR OP_CHECKSIGPQC witness fixtures, adds an independent generator, and extends script_p2mr_tests around m_codeseparator_pos, which is a consensus-critical sighash transcript field.

Review Scope

Reviewed PR 56 (test: add P2MR PQC codeseparator vectors), commit 0a26ca412f11a18ac375f08f9a320387a75195ab, base 0.1.x, backing issue #49, changed files, full diff, fixture contents, generator logic, P2MR script test loader/assertions, PR comments/reviews, unresolved review threads, and CI status. There were no PR comments, reviews, or review threads at the time of review.

Deep Checks Performed

Traced the Rust generator’s manually serialized P2MR sighash message through prevouts, spent amounts/scripts, sequences, outputs, leaf hash, key version, and codeseparator position. Checked that the C++ tests hash pinned raw p2mrSigMsg bytes, compare SignatureHashP2MR() output against the pinned p2mrSighash, verify runtime witness spends, and reject wrong codeseparator/domain/script/signature near misses. Also checked the runtime uses opcode-index opcode_pos for OP_CODESEPARATOR, matching the branch vector positions 1 and 4.

Issue Fit

This matches issue #49. The fixture now has four entries: default, leading codeseparator position 0, and two branch-dependent spends of the same leaf with codeseparator positions 1 and 4. The tests load multiple vectors, require non-default/zero/same-leaf-different codeseparator coverage, pin raw sigmsg/sighash bytes, verify wrong-position signatures fail with SCRIPT_ERR_P2MR_SIG, and include cross-branch signature rejection.

qbit-Specific Checks

The reviewed surface is limited to P2MR/PQC test coverage and contrib generation tooling. The generator avoids qbit wallet/signing/sighash helpers for transcript construction and only uses libbitcoinpqc for key generation/sign/verify. No AuxPoW, ASERT, wallet persistence, RPC, GUI, PHOTON, release signing, or P2P behavior is touched.

Validation Reviewed

Locally ran:

  • cargo fmt --manifest-path contrib/testgen/p2mr_checksigpqc_vectors/Cargo.toml -- --check
  • cargo check --manifest-path contrib/testgen/p2mr_checksigpqc_vectors/Cargo.toml
  • cargo run --manifest-path contrib/testgen/p2mr_checksigpqc_vectors/Cargo.toml -- src/test/data/p2mr_pqc_witness_vectors.json plus a clean fixture diff check
  • git diff --check origin/0.1.x...origin/pr/56

CI reviewed: Core Checks passed, including build smoke, functional smoke, and focused unit suites. The focused unit log shows script_p2mr_tests entered and passed p2mr_checksigpqc_accepts_independent_witness_vectors and p2mr_checksigpqc_rejects_independent_witness_vector_near_misses. Windows native and Windows fuzz jobs passed. Full Validation still had pending matrix jobs, lint, tidy, sanitizer jobs, and Required Merge Gate at last check.

Residual Risk

I did not run the C++ unit binary locally because there was no ready build tree in the review worktree. This review also does not mark the PR fully validated until the pending Full Validation and Required Merge Gate jobs finish successfully.

djh58
djh58 previously approved these changes Jun 30, 2026
@kiwidream
kiwidream force-pushed the p2mr-codesep-pqc-vectors branch 2 times, most recently from b4d1863 to 40f4397 Compare July 2, 2026 13:51

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Want reviews to match your repository better? Bugbot Learning can learn team-specific rules from PR activity. A team admin can enable Learning in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 40f4397. Configure here.

@kiwidream
kiwidream force-pushed the p2mr-codesep-pqc-vectors branch from 9168195 to 3c98c5b Compare July 2, 2026 17:01
@kiwidream

Copy link
Copy Markdown
Member Author

Expediting merge for 0.1.2 release

@kiwidream
kiwidream merged commit 8965d60 into 0.1.x Jul 2, 2026
17 of 20 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