Skip to content

Review finding: #259's invalid-signature cost is not mitigated, and #275 misdescribes #265 #332

Closed as duplicate

Description

@kiwidream

Summary

The issue's headline attack is not mitigated, and the follow-up issue misdescribes the fix.

Severity: low. Found in the 2026-11-04 review of the v1.0.1 change set (all 1.x.x merges since v1.0.0 plus the open PRs that target it), against 1.x.x 21fee6ee8e; area: #265, #259.

Observed

Confidence: confirmed.

Impact

Tracking accuracy for a DoS that is still open (~0.5 µs of cs_main time per witness byte, no peer penalty). Anyone reading #259/#275 could conclude the garbage-signature path is partly mitigated.

Suggested fix

Edit #275 to say "#265 caches verified successes only; it does not reduce the cost of invalid signatures", and link #259's headline scenario to #275 as the open item.
No other defects found. Checks that came back clean (attempted disproof):

  • Cache keys (script: cache successful P2MR PQC signature checks #162, script: cache verified P2MR data-signature checks (v1.0.1) #265). 'P' key = salted SHA256(sighash ‖ 32-byte pubkey ‖ 3,680-byte sig). CheckPQCSignature fixes both lengths before the seam (interpreter.cpp:2039-2057), so the concatenation is unambiguous. The P2MR sighash commits to hash type, annex, tapleaf hash (leaf version + script), key_version and codeseparator position (interpreter.cpp:1736-1827), and the SLH-DSA verdict depends only on (digest, pk, sig). Leaving script flags and leaf version out of the key is therefore sound, as for Core's ECDSA/Schnorr entries.
  • 'D' domain (script: cache verified P2MR data-signature checks (v1.0.1) #265). Separate salt; invalid key or wrong size bypasses the cache (sigcache.cpp:125-129). A 'P' entry cannot satisfy a 'D' lookup or the reverse.
  • Validation weight. The weight debit happens in EvalChecksigP2MR/EvalCheckDataSigPQC before any checker call (interpreter.cpp:416-427,447-457), so a hit never skips the weight charge or size, hash-type or missing-data checks.
  • Policy vs consensus. The cache stores primitive verdicts only, which are independent of flags. The script-execution cache key includes flags. GetBlockScriptFlags/GetNextBlockScriptFlags never add SCRIPT_VERIFY_P2MR_STACK_BYTES (validation.cpp:2385-2449). A policy-validated mempool entry therefore cannot make block validation skip a consensus check.
  • Concurrency. Get takes a shared lock (cuckoo erase flags are atomic), Set an exclusive one; unchanged from Core. With -par, two threads checking one signature can both miss and both verify; correct, just redundant. Assumevalid skips scripts entirely, and reindex consumes entries or misses, so results match a cacheless run.
  • Thread-safety of production hot paths. The test-only hooks cost one atomic load each (ScopedPQCVerificationCounter::g_counter in CPQCPubKey::Verify, the observer pointer).
  • Every BaseSignatureChecker subclass keeps its pre-script: cache verified P2MR data-signature checks (v1.0.1) #265 data-signature behavior (Deferring forwards; everything else runs the primitive).
  • policy: bound P2MR runtime stack bytes #263 distance to wallet spends.
    • Stack bytes are per input, so input count does not accumulate.
    • Single-sig P2MR input peak: 3,681 + 32 bytes = 3,713 B, 0.35% of the cap (about 282× headroom).
    • Largest consensus-possible multi-sig or data-sig leaf: at most 128 KiB of initial items + 32-byte pushes, about 131 KiB, about 12.5% of the cap (8× headroom).
    • Without copy opcodes no script can exceed 651,072 B (static_assert at script.h:57).
    • Miniscript/descriptor fragments copy only 1-byte selectors or 32-byte keys (miniscript.h:769,779,794), so no wallet-created, PSBT or OP_CHECKDATASIGPQC leaf comes near 1 MiB.
  • policy: bound P2MR runtime stack bytes #263 error contract. SCRIPT_ERR_P2MR_STACK_BYTES maps to TX_NOT_STANDARD with mempool-script-verify-flag-failed (Standard P2MR stack byte limit exceeded). qbit does not penalize peers for transaction failures (net_processing.cpp:3316-3326), so no peer penalty and no ban divergence. Inserting the enum value shifts later ScriptError integers, but none is serialized or exported (no kernel C API, RPC uses strings).
  • doc: fix pipe rendering and tighten P2MR v1 consensus profile #252. A word diff and a normative-token diff of the whole file show:
    • MUST/MUST NOT changes come only from line re-wraps; no value, error name or range changed.
    • The removed sentence "Commitment validation precedes known-leaf resource and script validation" is subsumed by the new "fails at the first failing stage, in this order" table. I checked that order against VerifyWitnessProgram (interpreter.cpp:2381-2440) and ExecuteWitnessScript (:2164-2208): witness presence → control shape → marker → commitment → initial resources → OP_SUCCESS pre-scan/script → cleanstack → truth. They match.
    • The §11 column split keeps every row's meaning, including the "unknown witness version" qualifier restored after Codex's comment.
  • doc: document bounded30 usage-dependent security margin and raw-key counter limits #264.
    • The §9 wording changes no MUST. RPC help texts match the code: FlatSigningProvider starts each key at counter 0 per call (rpc/rawtransaction_util.cpp:60,77; script/signingprovider.cpp:181-199).
    • The 118.2-bit figure re-derives as 128 − log2(Bell(7)=877).
    • The birthday figure re-derives as √(2 ln 2 · 2^30) ≈ 38,580.
    • Wallet thresholds match wallet/pqc_usage.h:23-24.
    • The "repeated digest reproduces the same signature" claim holds: signing randomness is derived from (sk, msg) in libbitcoinpqc/src/slh_dsa/sign.c:85-98.
  • Manifests and digests. sha256(src/test/data/p2mr_v1_manifest.json) = 00cd4e1c…7ab equals all 13 corpus_manifest_sha256 entries in doc/integration/p2mr-v1-support-matrix.json and the .md header. All four corpus files listed in the manifest match their recorded digests. ci/release/test_verify_p2mr_v1_conformance.py (31 tests) and contrib/devtools/test_p2mr_v1_generators.py (3 tests) pass.

Related: extends #275 and the #181 "Failed PQC signature checks are not cached" known limitation, both of which document the residual DoS correctly. New: the #259 closure and the #275 description are inaccurate.

Activity

  1. added
    documentation
    on Nov 4, 2026
  2. kiwidream commented on Nov 10, 2026

    @kiwidream
    MemberAuthor

    Consolidated into #275, which is now the single tracking issue for the validation cost of invalid PQC signatures. What this issue asked for is done:

    The checks this report found clean need no follow-up. Closing as a duplicate of #275.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentation

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions