Repository navigation
Description
Summary
Production libbitcoinpqc builds correctly pin SHA-256 to the scalar backend, but that guarantee is conditional on SPX_PRODUCTION_BUILD=1. Setting SPX_ENABLE_TEST_BENCH_ENV_KNOBS=ON replaces the production define with runtime-selectable SHA backend controls, and the top-level qbit build does not reject that configuration for a release artifact.
No acceptance divergence has been demonstrated: the scalar, SHA-NI, ARM, and CommonCrypto backends are intended to implement the same SHA-2 function, and the repository has known-answer tests. This issue is release hardening so a packaging mistake cannot expand the consensus-critical runtime surface.
Verified on
origin/1.0.0 at 988756471aeecdf4463c04be49da2b7b89a98c21.
Source trace
SPX_ENABLE_TEST_BENCH_ENV_KNOBSis a cache option defaulting toOFF:src/libbitcoinpqc/CMakeLists.txt#L11-L16.- When enabled, the library receives
SPX_ENABLE_TEST_BENCH_ENV_KNOBS=1; otherwise it receivesSPX_PRODUCTION_BUILD=1:src/libbitcoinpqc/CMakeLists.txt#L159-L174. - Production mode unconditionally selects the scalar SHA backend. Test mode can select a backend from environment variables:
src/libbitcoinpqc/sphincsplus/ref/opt_flags.h#L98-L145. - The SHA-256 and SHA-512 dispatchers use that mode for both scalar and accelerated implementations:
src/libbitcoinpqc/sphincsplus/ref/sha2.c#L579-L630,src/libbitcoinpqc/sphincsplus/ref/sha2.c#L632-L683. - The top-level integration adds the subtree without an explicit release-mode check for this option:
cmake/libbitcoinpqc.cmake#L7-L44. - Known-answer tests exist for SHA-256 backends and bounded30 signatures, but they are test-time checks rather than a release startup self-test:
src/libbitcoinpqc/tests/sha2_backend_tests.rs,src/libbitcoinpqc/tests/golden_vector_tests.rs.
Scope correction: WOTS+C counter
The audit also noted that verification permits counters through 0xffff while signing uses BITCOINPQC_WOTSC_MAX_COUNTER. This is not an active verification mismatch:
- the configurable value is an operational signing cap used while signing statistics are active;
- verification intentionally accepts the full 16-bit protocol range; and
- compilation rejects a configured signer cap greater than
0xffff.
See src/libbitcoinpqc/sphincsplus/ref/wots.c#L104-L145 and src/libbitcoinpqc/sphincsplus/ref/sign_stats.h#L8-L26. A deliberately lower signer cap may prevent the local signer from producing some signatures, but it does not cause nodes to reject an otherwise valid protocol signature.
That behavior should be documented, but it does not need to be coupled to the release-backend guard.
Expected behavior
Official and package/release qbit builds should fail configuration if consensus-critical PQC test/benchmark runtime controls are enabled.
Recommended changes
- Add a top-level release/package guard that rejects
SPX_ENABLE_TEST_BENCH_ENV_KNOBS=ONunless an explicit developer-only build mode is selected. - Add CI checks for every release artifact that prove
SPX_PRODUCTION_BUILD=1and the runtime knob macro is absent. - Keep backend differential known-answer tests in CI on every supported architecture.
- Consider a small startup known-answer test for the exact verification entry point used by qbit. If adopted, fail closed before networking or chainstate activation and keep the vector stable and inexpensive.
- Document that
BITCOINPQC_WOTSC_MAX_COUNTERis a signer resource cap, not the verifier's protocol maximum.
Acceptance criteria
- A normal release/package configuration cannot enable PQC runtime backend environment knobs.
- CI verifies the effective compile definitions of shipped
libbitcoinpqcobjects rather than relying only on option defaults. - Scalar and every supported accelerated backend continue to pass the same known-answer suite.
- The distinct roles of the WOTS+C signer cap and 16-bit verification bound are documented.
Activity
kiwidream commentedon Jul 12, 2026
Scope clarification for #104 and PR #107
PR #107 completes the downstream qbit release-build guard: integrated builds reject
SPX_ENABLE_TEST_BENCH_ENV_KNOBS=ON, enforceSPX_PRODUCTION_BUILD=1on the effectivebitcoinpqctarget, cover direct option, stale-cache, and compiler-flag injection paths, pin the Guix configuration, and document the production policy and WOTS+C signing-cap distinction.The separate requirement to prove which accelerated SHA implementation actually executed is explicitly deferred to Qbit-Org/qbit-libbitcoinpqc#3. That upstream issue owns:
This deferral does not weaken qbit's production policy: official integrated builds remain pinned to the scalar production backend, while accelerator experiments and differential evidence stay in the standalone upstream library. With that scope split recorded here, merging PR #107 can close #104; the linked upstream issue remains the source of truth for the deferred accelerator-evidence work.