Skip to content

Add independent P2MR PQC witness vector tests - #30

Merged
kiwidream merged 3 commits into
0.1.xfrom
investigate-issue-20
Jun 29, 2026
Merged

kiwidream merged 3 commits into
0.1.xfrom
investigate-issue-20

Conversation

@kiwidream

@kiwidream kiwidream commented Jun 26, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Add an independently generated P2MR/PQC witness vector fixture for a default-sighash single-key spend.
  • Register the fixture with the unit test data generator.
  • Add interpreter-level positive and near-miss tests for the vector, covering mutated signatures, wrong sighash domain, bad hashtype suffixes, and wrong script/pubkey commitments.

Closes #20.

Validation

  • cmake --build build --target test_bitcoin -j2
  • build/bin/test_qbit --run_test=script_p2mr_tests/p2mr_checksigpqc_accepts_independent_witness_vector --catch_system_error=no --log_level=message
  • build/bin/test_qbit --run_test=script_p2mr_tests/p2mr_checksigpqc_rejects_independent_witness_vector_near_misses --catch_system_error=no --log_level=message
  • build/bin/test_qbit --run_test=script_p2mr_tests --catch_system_error=no --log_level=message passed; the local environment printed repeated file-descriptor warnings, but Boost reported no test errors.
  • Docker lint targeted checks passed: commit_msg, tabs_whitespace, trailing_whitespace, trailing_newline.

Full Docker lint was also attempted. It failed on existing 0.1.x files outside this PR (.github/actions/configure-docker/buildkit-config.sh and ci/checks/test_configure_docker_buildkit_config.py) for shebang permission and shell-locale checks, so that failure is unrelated to this diff.


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


Note

Medium Risk
Touches script verification (P2MR/PQC) and AuxPoW decode used by submitauxblock; changes are mostly tests plus a narrow decode disambiguation rule.

Overview
Adds externally generated P2MR/PQC witness coverage so default-sighash single-key spends can be checked without qbit’s own wallet or sighash helpers.

A new JSON fixture (p2mr_pqc_witness_vectors.json) is wired into test_bitcoin. script_p2mr_tests loads it and adds a passing case that checks HASHER_P2MR_SIGHASH (not Taproot’s domain), PQC verify, and full VerifyScript, plus a near-miss suite that flips signatures, wrong-domain sigs, bad hashtype suffixes, leaf/control tweaks, and pubkey/script mismatches.

AuxPoW RPC decoding in DecodeHexAuxPow now tries canonical and legacy layouts together; when both parse, it picks legacy if only the legacy coinbase merkle branch matches the parent root. AuxPowCoinbaseBranchMatchesParent implements that check, with an auxpow_tests case for ambiguous hex.

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

@kiwidream

Copy link
Copy Markdown
Member Author

PR Review

Findings

  • [medium] src/test/script_p2mr_tests.cpp:1303 - Prove the wrong-domain signature is valid for the wrong-domain digest. The test checks that wrongDomainSighash is the TapSighash-tagged digest, then expects wrongDomainSignature to fail under P2MR. But this would also pass if wrongDomainSignature were just random valid-size bytes. Since Add independent P2MR PQC witness vectors for consensus verification tests #20 asks for a wrong sighash/domain companion vector, please add a direct assertion such as BOOST_CHECK(vector.pubkey.Verify(vector.wrong_domain_sighash, vector.wrong_domain_signature)); before using it as the near-miss witness.

Consensus Impact

Consensus-adjacent

The PR is test-only, but it hardens coverage for P2MR/PQC OP_CHECKSIGPQC, SignatureHashP2MR, witness layout, and script-error behavior. No production consensus code changes.

Review Scope

Reviewed issue #20, PR body, commit list, changed files, full diff, fixture registration, JSON vector contents, script_p2mr_tests.cpp loader/helpers/tests, PR comments/reviews, and visible CI. No PR comments, reviews, or unresolved threads were present.

Deep Checks Performed

Traced the fixture from JSON parsing through witness extraction, PrecomputedTransactionData, SignatureHashP2MR, and VerifyScript. Independently parsed the serialized spend transaction and recomputed the P2MR leaf roots, wrong-pubkey root, P2MRSighash, and TapSighash-domain digest from the fixture bytes. The attempted-disproof pass found the wrong-domain negative is not yet proven to be a valid wrong-domain signature.

Issue Fit

This mostly matches #20: it adds a fixed externally described P2MR/PQC witness vector, positive interpreter-level verification, and near-miss tests for mutated signature, wrong domain, bad hashtype suffixes, committed-leaf mismatch, and wrong pubkey. The finding above is the remaining issue-fit gap for the wrong-domain vector.

qbit-Specific Checks

Checked P2MR/PQC domain separation, single-leaf commitment construction, witness stack shape, default sighash handling, expected SCRIPT_ERR_P2MR_SIG, SCRIPT_ERR_P2MR_SIG_HASHTYPE, and witness-program mismatch paths. AuxPoW, wallet/RPC, PHOTON, and release surfaces are untouched.

Validation Reviewed

CI focused unit suites built test_qbit and ran both new tests: p2mr_checksigpqc_accepts_independent_witness_vector and p2mr_checksigpqc_rejects_independent_witness_vector_near_misses. Build smoke, functional smoke, release validator tests, Core Checks Gate, docs checks, and fuzz check were green at review time. I also checked git diff --check, JSON parsing, and independent fixture consistency locally. Windows native and Required Merge Gate were still pending at the last check.

Residual Risk

I did not regenerate the fixture from the stated libbitcoinpqc seed/Python generator, and I did not rerun the full unit suite locally. Pending CI still needs to finish.

@kiwidream
kiwidream force-pushed the investigate-issue-20 branch from 5287f54 to 955496a Compare June 28, 2026 15:26
@djh58
djh58 self-requested a review June 29, 2026 14:56
@kiwidream
kiwidream merged commit ab87bb9 into 0.1.x Jun 29, 2026
33 checks passed
kiwidream added a commit that referenced this pull request Jun 29, 2026
* test: add independent P2MR PQC witness vector

* test: verify P2MR wrong-domain vector signature

* Fix AuxPoW legacy payload disambiguation
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