Skip to content

Review finding: docs understate the stack each qbit PQC secret-key call needs #333

Closed

Description

@kiwidream

Summary

The documented stack requirement (about 17 KiB) understates what each qbit secret-key call needs (32 KiB or more).

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: #270, #268.

Observed

Confidence: confirmed (from code).

  • Location: doc/subtrees/libbitcoinpqc.md:49 and doc/release-notes-268.md:19 at 21fee6ee8e; doc/release-notes-1.0.1.md:340-341 at 261d1b71eb. The behavior is in src/crypto/pqc.h:37 (PQC_STACK_BURN_BYTES = 32 * 1024) and src/crypto/pqc.cpp:66 (BurnReleasedStack).
  • Scenario: someone embedding qbit, or packaging it with small thread stacks (musl or Alpine at 128 KiB, custom QThread::setStackSize, or a future -par-style worker pool that signs), budgets 17 KiB per call. After crypto: clear stack released by PQC secret-key operations #270, every CPQCKey::MakeNewKey, Set, Sign and DerivePQCKey writes PQC_STACK_BURN_BYTES (32 KiB) plus the frames of BurnReleasedStack, memory_cleanse and memset below the caller. That is about 2× the documented figure. The burns run one after another, not nested, so the peak is about max(17 KiB, 32 KiB + ~0.2 KiB). crypto: clear stack released by PQC secret-key operations #270's own description gives a total of about 74 KiB for the deepest RPC-thread path.
  • Evidence: code (pqc.cpp:66-70, and the call sites at pqc.cpp:182, :224, :252, :289). The disassembly shows BurnReleasedStack reserving a page-probed 32 KiB frame and every call site present. crypto: clear stack released by PQC secret-key operations #270's test CheckBurnCoversReleasedStack requires burn_begin >= PQC_STACK_BURN_BYTES. test_qbit --run_test=pqc_tests,pqc_sigcache_tests passes (50 cases, 2,425 assertions), including pqc_secret_key_operations_fit_small_thread_stack.

Impact

Operator and integrator guidance does not match the implemented behavior Default thread stacks on the release platforms (512 KiB on macOS, 1–2 MiB on Windows, 8 MiB with glibc) are ample, so this is not a crash risk for v1.0.1 release binaries.

Suggested fix

Change the three texts to "each CPQCKey/DerivePQCKey call needs about 33 KiB of free stack (qbit's 32 KiB burn, #270); direct library calls need about 17 KiB (#268)". When fixing the stale #270 text that #174 already tracks, fold this into the same edit.

Related: new. #174 notes only that #181 still carries the DerivePQCKey known-limitation bullet and the "#270 is not part of this release" text. Those are known: #174 and still present at 261d1b71eb: lines 15-17 of the summary, and lines 492-497.

Activity

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

    @kiwidream
    MemberAuthor

    Fixed on 1.x.x by #181 (29c0ec9b6c): doc/subtrees/libbitcoinpqc.md and the v1.0.1 release notes now say that a call made directly to the library needs about 17 KiB of free stack, and that each CPQCKey::MakeNewKey(), CPQCKey::Set(), CPQCKey::Sign() and DerivePQCKey() call needs at least 32 KiB plus its own frames (#270). doc/release-notes-268.md is folded into the notes and deleted, and the "#270 is not part of this release" text is gone.

    Closing by hand, because a merge into 1.x.x does not close issues automatically.

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