Skip to content

fuzz: fix stale pqc_sign_refused coverage anchor after signing refactor #173

Closed

Description

@kiwidream

Is there an existing issue for this?

  • Existing issues were searched. #154 and #164 introduced the fuzz work; this is a later source-anchor mismatch after #163.

Current behaviour

At 1.x.x commit c4b254e2d39f3a430b8b4a85798dd03ed47c3d98, the qbit fuzz coverage checker fails while resolving the pqc_sign_refused anchor. It cannot evaluate the required named-seed coverage until this mismatch is corrected.

The anchor definition expects:

if (!IsValid() || counter_inout >= PQC_MAX_SIGNATURES) return false;

The current signing code, changed by #163, is:

if (!IsValid() || counter_inout >= PQC_MAX_SIGNATURES) return finish(false);

The checker requires a unique textual match, so it raises an assertion before coverage evaluation. This is a test-tool failure; it does not demonstrate a PQC verification or signing-correctness failure.

Expected behaviour

The refusal-path anchor resolves uniquely to the current refusal branch, and the coverage checker continues to enforce its existing named-seed hit/miss expectations.

Steps to reproduce

From the repository root at the commit above:

python3 test/fuzz/test_qbit_fuzz_coverage.py --anchors-only

This reproduction does not need a node, wallet, or coverage-instrumented executable.

Relevant log output

AssertionError: anchor Anchor(file='src/crypto/pqc.cpp', lines=('if (!IsValid() || counter_inout >= PQC_MAX_SIGNATURES) return false;',), token='return') matched 0 times in src/crypto/pqc.cpp

Verified on September 23, 2026, on native Apple Silicon macOS 26.4 against the source checkout. The mismatch is in repository text, not a macOS command-compatibility issue.

Proposed scope and acceptance

  • Update pqc_sign_refused to the current refusal branch without removing or relaxing the coverage expectation.
  • --anchors-only exits successfully and all named anchors resolve uniquely. Missing or ambiguous matches must still fail.
  • Run the checker's documented coverage-instrumented path with the named corpus; verify the refusal region is mapped to the intended branch and the existing expected hits/misses pass.
  • Retain the instrumentation/corpus results as release evidence, including replay/mutation evidence from the corresponding fuzz runner. A passing anchor-only check must not be presented as proof of measured coverage or mutation.
  • Existing fuzz runner/corpus contract tests continue to pass.

Keep the change in fuzz tooling unless investigation identifies a separate defect. No consensus, signing behavior, wallet format, or published release artifact changes are required by this issue.

How did you obtain qbit?

Compiled from source. Tested source is the full commit above; the binary version string remains v1.0.0.

Release tracking

Tracked by #174 — v1.0.1 release readiness.

Activity

  1. added
    bug
    on Sep 23, 2026
  2. kiwidream commented on Sep 25, 2026

    @kiwidream
    MemberAuthor

    Instrumented coverage and mutation evidence for the #173 acceptance items. It was produced on the PR #176 head b617ceb1e4 (the anchor fix on top of 1.x.x c4b254e2) with the official LLVM 20.1.8 release. The toolchain's SHA-256 and sigstore attestation were verified.

    • llvm-cov checker: the documented test_qbit_fuzz_coverage.py --fuzz-binary path exited 0, and every hit, miss and at-least expectation in all 17 CASES was met.
      • pqc_sign_refused is a HIT on legacy-import-corrupted-secret at pqc.cpp:132:60.
      • An independent llvm-cov export shows the refusal-return region is separate from its condition region, and that the slh_dsa_sign-failure return on line 139 is never taken by any seed.
      • A negative control with inverted expectations makes the checker exit 1.
    • libFuzzer (ASan+UBSan), with --require_qbit_corpus:
      • Replay: 53/53 inputs across the six qbit targets.
      • Mutation: 120 s per target, plus a supplementary 600 s on p2mr_script and pqc. No crashes or sanitizer reports.
    • Runner contract tests: 16 unit and 18 libFuzzer integration tests pass.
    • Not covered:
      • Mutation depth under ASan is shallow for p2mr_script and pqc: at most 532 and 271 mutated execs, because SLH-DSA is slow.
      • No multi-hour campaign or libfuzzer-nosan run, and no macOS or other LLVM versions.
      • The CI nightly / qa-assets overlay path was not exercised.

    #173 should close once #176 merges into 1.x.x. The evidence applies to that source; if #176 changes, re-run it on the final release source (#174).

    Full evidence record (LLVM-EVIDENCE.md)

    #173 evidence: llvm-cov coverage + libFuzzer replay/mutation for qbit fuzz targets

    Host: minidev-alex1 (Linux 7.0.0-31-generic x86_64, glibc 2.43, Python 3.14.4, cmake 4.2.3). Date: 2026-09-25.
    Source: b617ceb (PR #176, branch kiwidream/fix-pqc-sign-refused-anchor,
    the pqc_sign_refused anchor fix on top of 1.x.x c4b254e). Worktree clean (git status --short empty;
    only the gitignored build-fuzz-llvm/ and build-fuzzcov-llvm/ dirs were added). No repository changes, no commit.
    Logs and helper scripts are in evidence-173/llvm/. This supersedes section 4 ("NOT RUN") and the
    mutation part of section 6 of EVIDENCE.md.

    Result summary

    Step Result
    1. LLVM toolchain (official release, SHA-256 + sigstore attestation verified) PASS
    2. Coverage build (-fprofile-instr-generate -fcoverage-mapping, BUILD_FOR_FUZZING) PASS
    3. test_qbit_fuzz_coverage.py with llvm-profdata/llvm-cov: all 17 CASES, incl. pqc_sign_refused HIT PASS (exit 0)
    3a. Refusal region maps to the intended branch (independent llvm-cov export, all 16 pqc seeds) PASS
    3b. Negative control: inverted pqc_sign_refused expectations make the checker fail PASS (checker exit 1 as expected)
    4a. libFuzzer (ASan+UBSan) replay, --require_qbit_corpus, 6 targets PASS: 53/53 inputs
    4b. libFuzzer mutation, 120 s/target, --require_qbit_corpus PASS, 0 crashes
    4c. Supplementary mutation, 600 s, p2mr_script + pqc PASS, 0 crashes
    4d. Runner/corpus contract tests (unit 16 tests; --build-dir libFuzzer 18 tests) PASS

    1. Toolchain

    • LLVM 20.1.8 official release: https://github.com/llvm/llvm-project/releases/download/llvmorg-20.1.8/LLVM-20.1.8-Linux-X64.tar.xz
      (2 021 269 412 bytes), extracted to ~/.local/opt/LLVM-20.1.8-Linux-X64. No sudo, apt or Docker.
    • sha256sum: 1ead36b3dfcb774b57be530df42bec70ab2d239fbce9889447c7a29a4ddc1ae6. Matches the GitHub release asset digest.
    • Provenance: gh attestation verify LLVM-20.1.8-Linux-X64.tar.xz --bundle LLVM-20.1.8-Linux-X64.tar.xz.jsonl --repo llvm/llvm-project
      → rc 0 (gh 2.101.0). Sigstore bundle (sha256 00beee3c…a75d) is from the release. The verified subject digest is the tarball's.
      Signer: https://github.com/llvm/llvm-project/.github/workflows/release-binaries.yml@refs/tags/llvmorg-20.1.8, source digest
      87f0227cb60147a26a1eeb4fb06e3b505e9c7261 (llvm/attestation-verify.json).
    • clang --version: clang version 20.1.8 (https://github.com/llvm/llvm-project 87f0227cb60147a26a1eeb4fb06e3b505e9c7261).
      llvm-cov/llvm-profdata/llvm-symbolizer 20.1.8 come from the same tarball. libclang_rt fuzzer/profile/asan/ubsan
      are under lib/clang/20/lib/x86_64-unknown-linux-gnu/. The C++ standard library is the system libstdc++ (GCC 15).

    2. Builds

    Both builds used export PATH=$HOME/.local/opt/LLVM-20.1.8-Linux-X64/bin:$PATH and TMPDIR=<build>/tmp, with ccache ON.

    Coverage build, exactly as documented in doc/development/developer-notes.md "Compiling for Fuzz Coverage".
    The default build type gives -O2 -g, and there is no sanitizer, so the native fuzz engine is used:

    cmake -B build-fuzzcov-llvm -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ \
      -DCMAKE_C_FLAGS="-fprofile-instr-generate -fcoverage-mapping" \
      -DCMAKE_CXX_FLAGS="-fprofile-instr-generate -fcoverage-mapping" -DBUILD_FOR_FUZZING=ON   # cov-configure.log
    cmake --build build-fuzzcov-llvm -j6        # rc 0, 2m57s, cov-build.log
    sha256 build-fuzzcov-llvm/bin/fuzz = 52fce15a8120188896173c5e81ab2f92772d17edeff96e8e08cb302587ff7901 (70 __llvm_profile symbols)
    

    libFuzzer build for replay and mutation. It uses the libfuzzer preset (ASan+UBSan+fuzzer and -ftrivial-auto-var-init=pattern)
    with the binary dir overridden:

    cmake --preset=libfuzzer -B build-fuzz-llvm   # fuzz-configure.log
    cmake --build build-fuzz-llvm -j6             # rc 0, 4m05s, fuzz-build.log
    sha256 build-fuzz-llvm/bin/fuzz = b9fbe389bf3a85256a91ea2233f0e5ef11bd3f7202b4da09b2755003300245dc
    

    3. Coverage checker (the documented llvm-cov path)

    L=$HOME/.local/opt/LLVM-20.1.8-Linux-X64/bin
    python3 test/fuzz/test_qbit_fuzz_coverage.py --fuzz-binary build-fuzzcov-llvm/bin/fuzz \
      --llvm-profdata $L/llvm-profdata --llvm-cov $L/llvm-cov          # EXIT 0, 15.5 s, coverage-checker.log
    

    --path-equivalence was not needed. -fdebug-prefix-map does not rewrite coverage-mapping filenames.
    Ran 6 tests, OK: 5 AnchorResolutionTest cases plus CoverageContractTest over all 17 named seeds.
    Every hit, miss and at-least expectation passed. Per-case counts:

    p2mr_script/legacy-checksigpqc-default-valid: p2mr_checksig_call=1, p2mr_execute_leaf=1, p2mr_fixture_sign=0, p2mr_harness_keygen=1, p2mr_harness_sign=1, p2mr_harness_verify=1, p2mr_hashtype_pop=0, p2mr_verify_accept=1, p2mr_verify_call=1, p2mr_verify_reject=0, pqc_sign_accept=1, pqc_sign_call=1, pqc_verify_call=1, sign_pqc_append_hashtype=0, sign_pqc_provider=1, witness_script_accept=1
    p2mr_script/legacy-checksigpqc-all-valid: p2mr_checksig_call=1, p2mr_execute_leaf=1, p2mr_fixture_sign=0, p2mr_harness_keygen=1, p2mr_harness_sign=1, p2mr_harness_verify=1, p2mr_hashtype_pop=1, p2mr_verify_accept=1, p2mr_verify_call=1, p2mr_verify_reject=0, pqc_sign_accept=1, pqc_sign_call=1, pqc_verify_call=1, sign_pqc_append_hashtype=1, sign_pqc_provider=1, witness_script_accept=1
    p2mr_script/legacy-ctv-checksigpqc-all-valid: ctv_match=1, ctv_mismatch=0, p2mr_checksig_call=1, p2mr_execute_leaf=1, p2mr_fixture_sign=0, p2mr_harness_keygen=1, p2mr_harness_sign=1, p2mr_harness_verify=1, p2mr_verify_accept=1, p2mr_verify_call=1, p2mr_verify_reject=0, pqc_sign_accept=1, pqc_sign_call=1, pqc_verify_call=1, sign_pqc_provider=1, witness_script_accept=1
    p2mr_script/legacy-signature-bit-flip: p2mr_fixture_sign=0, p2mr_harness_keygen=1, p2mr_harness_sign=1, p2mr_harness_verify=1, p2mr_verify_accept=0, p2mr_verify_reject=1, pqc_sign_accept=1, pqc_sign_call=1, pqc_verify_call=1, sign_pqc_provider=1, witness_script_accept=0
    p2mr_script/legacy-signature-truncated: p2mr_fixture_sign=0, p2mr_harness_keygen=1, p2mr_harness_sign=1, p2mr_harness_verify=1, p2mr_sig_size_reject=1, p2mr_verify_accept=0, pqc_sign_accept=1, pqc_sign_call=1, pqc_verify_call=0, sign_pqc_provider=1
    p2mr_script/legacy-invalid-hashtype-appended: p2mr_fixture_sign=0, p2mr_harness_keygen=1, p2mr_harness_sign=1, p2mr_harness_verify=1, p2mr_hashtype_invalid=1, pqc_sign_accept=1, pqc_sign_call=1, pqc_verify_call=0, sign_pqc_provider=1
    p2mr_script/legacy-control-block-bit0-cleared: p2mr_control_bit0_reject=1, p2mr_execute_leaf=0, p2mr_fixture_sign=0, p2mr_harness_keygen=1, p2mr_harness_sign=1, p2mr_harness_verify=1, pqc_sign_accept=1, pqc_sign_call=1, sign_pqc_provider=1
    p2mr_script/legacy-control-block-truncated: p2mr_control_size_reject=1, p2mr_execute_leaf=0, p2mr_fixture_sign=0, p2mr_harness_keygen=1, p2mr_harness_sign=1, p2mr_harness_verify=1, pqc_sign_accept=1, pqc_sign_call=1, sign_pqc_provider=1
    p2mr_script/generation-checksigpqc-default-valid: p2mr_checksig_call=1, p2mr_execute_leaf=1, p2mr_fixture_sign=0, p2mr_harness_keygen=1, p2mr_harness_sign=1, p2mr_harness_verify=1, p2mr_verify_accept=1, p2mr_verify_call=1, p2mr_verify_reject=0, pqc_sign_accept=1, pqc_sign_call=1, pqc_verify_call=1, sign_pqc_provider=1, witness_script_accept=1
    p2mr_script/fixture-checksigpqc-default-untouched: p2mr_fixture_sign=6, p2mr_fixture_verify=1, p2mr_harness_keygen=0, p2mr_harness_sign=0, p2mr_harness_verify=0, p2mr_verify_accept=7
    p2mr_script/fixture-ctv-checksigpqc-all-untouched: ctv_match=3, p2mr_fixture_verify=1, p2mr_verify_accept=7
    p2mr_script/fixture-ctv-locktime-changed: ctv_mismatch=1, p2mr_fixture_verify=1, p2mr_harness_sign=0
    pqc/legacy-generated-valid-sign-verify: pqc_fixture_sign=0, pqc_harness_import_sign=1, pqc_harness_keygen=2, pqc_set_accept=3, pqc_set_reject=0, pqc_sign_accept=3, pqc_sign_call=3, pqc_verify_call=4
    pqc/legacy-import-corrupted-secret: pqc_fixture_sign=0, pqc_harness_keygen=2, pqc_set_reject=1, pqc_sign_call=2, pqc_sign_refused=1
    pqc/generation-valid-sign-verify: pqc_fixture_sign=0, pqc_harness_keygen=2, pqc_sign_call=3, pqc_verify_call=4
    pqc/fixture-untouched-key0-msg0: pqc_fixture_final_verify=1, pqc_fixture_sign=4, pqc_harness_keygen=0, pqc_verify_call=6
    pqc/fixture-signature-bit-flip: pqc_fixture_final_verify=1, pqc_harness_keygen=0, pqc_verify_call=6
    

    The at-least bounds are met exactly: p2mr_fixture_sign=6 (≥6), p2mr_verify_accept=7 (≥7), ctv_match=3 (≥3),
    pqc_fixture_sign=4 (≥4), pqc_verify_call=6 (≥6).

    3a. Refusal region mapping (independent of the checker)

    llvm/refusal_regions.py runs each of the 16 pqc seeds alone. For each seed it exports src/crypto/pqc.cpp with llvm-cov
    and prints the raw segments for lines 132 and 136–139 (refusal-regions.log). The anchor resolves to pqc.cpp:132:60,
    the return of if (!IsValid() || counter_inout >= PQC_MAX_SIGNATURES) return finish(false);.
    Results for legacy-import-corrupted-secret:

    (132,9,3) condition   (132,23,2) counter check   (132,59,1)/(132,60,1) refusal return   (132,81,2) fall-through
    (136,9,2) slh_dsa_sign call   (137,32,0)…(137,33,0) body of the slh_dsa_sign-failure branch, i.e. line 139 `return finish(false);` = 0
    
    • The column-precise refusal region has count 1. The condition region has count 3, so a line-level count would have
      given the wrong answer.
    • The second return finish(false); (line 139) is 0 for every seed, so the anchor cannot be confused with it.
    • The refusal region is 1 for legacy-import-corrupted-secret, generation-import-corrupted-secret, legacy-short-secret-import
      and legacy-counter-exhausted. It is 0 for both valid sign/verify seeds and all 10 fixture seeds.
    • For the corrupted and short secrets the refusal comes from !IsValid() (the 132:23 counter check runs 2 of 3 times).
      For counter-exhausted it comes from the counter check (132:23 runs 3 of 3 times).

    This matches the gcov substitute in EVIDENCE.md §5.

    3b. Negative control

    llvm/negative_control.py loads the unmodified checker module and replaces CASES in memory with two inverted expectations:
    legacy-import-corrupted-secret pqc_sign_refused: MISS and legacy-generated-valid-sign-verify pqc_sign_refused: HIT.
    It then runs the checker's own main() against the same binary. Both subtests failed with
    pqc_sign_refused executed 1 times and pqc_sign_refused not executed, and the checker exited 1 as expected
    (negative-control.log). This shows the checker is not vacuous on real llvm-cov data.

    4. libFuzzer replay and mutation (build-fuzz-llvm, ASan+UBSan)

    Runs used LLVM_SYMBOLIZER_PATH=$L/llvm-symbolizer. The runner sets the UBSAN_OPTIONS/ASAN_OPTIONS used in CI
    (ubsan suppressions, halt_on_error=1, detect_leaks=1). The working directory was evidence-173/llvm/artifacts/,
    where libFuzzer writes crash artifacts; it is still empty.

    python3 build-fuzz-llvm/test/fuzz/test_runner.py --par 6 --loglevel DEBUG --require_qbit_corpus \
      test/fuzz/qbit_corpora asert_chain_transition asert_edge_cases asert_math auxpow p2mr_script pqc
    # EXIT 0, 24 s, replay-libfuzzer.log. "Check if using libFuzzer ... True"
    

    Replay (files present / inputs replayed): asert_chain_transition 5/5, asert_edge_cases 5/5, asert_math 5/5, auxpow 6/6,
    p2mr_script 16/16, pqc 16/16.

    ... same with --mutate_min_time=120        # EXIT 0, 2m09s wall, mutation-libfuzzer.log
    
    target rng seed seed inputs init runs runs after init total runs time
    asert_chain_transition 197625877 5 6 75 153 75 159 121 s
    asert_edge_cases 197625883 5 6 1 554 697 1 554 703 121 s
    asert_math 197625884 5 6 1 509 135 1 509 141 121 s
    auxpow 197633350 6 7 1 094 540 1 094 547 121 s
    p2mr_script 197636427 16 18 78 96 121 s
    pqc 197633718 16 18 68 86 128 s

    Under ASan, SLH-DSA keygen and signing are slow: seed initialization took about 21–23 s and each later execution took roughly 1–2 s.
    The 120 s budget therefore gave p2mr_script and pqc under 100 mutated executions. A supplementary longer run followed:

    python3 build-fuzz-llvm/test/fuzz/test_runner.py --par 2 --loglevel DEBUG --mutate_min_time=600 test/fuzz/qbit_corpora p2mr_script pqc
    # EXIT 0, 10m05s, mutation-libfuzzer-600s.log
    p2mr_script: rng seed 335568899, 16 seed inputs, 18 init runs, 532 runs after init, 550 runs in 604s
    pqc:         rng seed 335566005, 16 seed inputs, 18 init runs, 271 runs after init, 289 runs in 602s
    

    Crashes: none. The logs contain 0 matches for ERROR: (AddressSanitizer|libFuzzer|LeakSanitizer)|runtime error|deadly signal|SUMMARY: in the replay and both mutation logs,
    and no crash, leak or timeout artifacts were written.

    Contract tests:

    python3 test/fuzz/test_qbit_fuzz_runner.py                              # 16 tests OK (runner-unit.log)
    python3 test/fuzz/test_qbit_fuzz_runner.py --build-dir build-fuzz-llvm  # 18 tests OK, 2m34s (runner-integration-libfuzzer.log;
                                                                            # includes a real 120 s/target mutation via the libFuzzer build)
    

    Not verified / caveats

    • The mutation depth for p2mr_script and pqc is shallow: at most 532 and 271 mutated executions under ASan.
      This is evidence that the mutation phase runs and does not crash on these inputs. It is not evidence of meaningful exploration of the
      PQC paths. A longer campaign (hours) or a libfuzzer-nosan build would be needed for that and was not run.
    • Coverage was measured with the documented native-engine coverage build (BUILD_FOR_FUZZING, no SANITIZERS=fuzzer),
      not under libFuzzer, as the checker's docstring and developer-notes.md describe. It was not repeated with a libFuzzer+coverage build.
    • Only LLVM 20.1.8 on Linux x86_64 with libstdc++ (GCC 15) was used. Other LLVM versions and macOS were not tested.
    • The CI nightly path (ci/test/03_test_script.sh with QBIT_FUZZ_MUTATE_MIN_TIME, qa-assets overlay) was not run. The runner was
      pointed directly at test/fuzz/qbit_corpora.
    • Rerunning the checker in a fresh clone was not tested. It used this worktree, whose source tree matches the build paths.
  3. kiwidream commented on Sep 25, 2026

    @kiwidream
    MemberAuthor

    Fixed by #176, merged into 1.x.x as a9e1554. The acceptance items are met:

    • Anchor: pqc_sign_refused resolves uniquely to the refusal branch at pqc.cpp:132:60. Missing, ambiguous and token-less anchors still fail, and new resolution tests cover that.
    • Coverage and fuzzing: the llvm-cov checker, libFuzzer replay and libFuzzer mutation all pass. The evidence is in the comment above. It was produced on fuzz: repair stale pqc_sign_refused coverage anchor #176's head b617ceb1e4, and the merged source differs from that commit only in doc/release-trust-1.0.0.md, so it applies unchanged.
    • Contract tests: the runner and corpus contract tests pass.

    Caveat for the release record (#174): mutation depth under ASan was shallow for p2mr_script and pqc. No multi-hour campaign was run.

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

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions