Repository Public
1# QYVORA — security audit engine23The permanent audit infrastructure required by the owner's instruction of 2026-12-04 (`CLAUDE.md`,4"MANDATORY — full wallet security audit"). One command re-runs the whole audit and regenerates the5reports:67```8./scripts/security-audit.sh # quick: every check, reduced counts (about 3 minutes on the laptop)9./scripts/security-audit.sh --full --nodes "M3U96a M3U96b M2U64" --timing-node M4M64a10```1112**What this is.** An internal, automated technical audit run on the project's own machines. **What it13is not:** an independent certification, a proof of security, or a substitute for the independent14cryptographic review required before any recommendation to use the wallet with real funds. A tool that15cannot run is recorded as NOT RUN with its reason, never as passed; every number in a report comes from16the results file produced by the run.1718Post-quantum cryptography in QYVORA protects the local vault, backups, transfers and the separate19identity. It does not make Bitcoin or Ethereum transactions quantum-resistant; the audit rates the two20separately everywhere.2122## Layout2324| Path | Content |25|---|---|26| `Scripts/security-audit.sh` | Entry point. The repository's script directory is `Scripts/`; `./scripts/security-audit.sh` is the same file on the case-insensitive volumes macOS uses by default (on a case-sensitive volume call `Scripts/security-audit.sh`). |27| `security/audit/orchestrator.py` | Runs the steps in three concurrent lanes, merges tool results with the findings register, evaluates the release gate, writes the results file, calls the report generator. Python standard library only. |28| `security/audit/runners/` | One runner per tool: each returns a *tool result* (status RUN / NOT RUN / FAILED, version, coverage statement, metrics, test records, findings) in the common schema of `lib/common.py`. Each runs standalone (`python3 security/audit/runners/<name>.py`). |29| `security/audit/lib/` | Shared helpers: schema (`common.py`), Swift builds and cluster helpers (`build.py`), disassembly and branch counting (`machinecode.py`). |30| `security/audit/report/generate.py` | Markdown, self-contained HTML and PDF reports from the results file (PDF rendered locally with WeasyPrint; headless Chrome or wkhtmltopdf as fallbacks). |31| `security/audit/findings/` | The findings register: one JSON file per finding (root cause, severity, CVSS, CWE, MASVS, location, status, fix commit, regression test). Prefixes: `QYV-CRY` primitives review, `QYV-SVC` service layer, `QYV-APP` application and design, `QYV-BIN` binary, `QYV-FUZ` fuzzing, `QYV-AUD` found by the audit tests. |32| `security/audit/review/` | Registers of the manual source reviews (constant-time verdicts, parser traps, memory hygiene). |33| `security/audit/install-tools.sh` | Installs the pinned tools under `security/.tools` (git-ignored). |34| `security/audit/install-hooks.sh`, `security/audit/ci/` | Pre-push hook and server-side integration (below). |35| `security/tests/` | Swift package `QyvoraSecurityAudit`, depending on the engine by path (production targets untouched): conformance replay, Wycheproof, differential, property tests, fuzz-corpus replay, the fuzzer `qyfuzz`, the timing tool `qytiming`. |36| `security/tests/oracles/` | Python reference oracle and its pinned requirements (test environment only). `mc/` holds the oracles of the multi-chain tests (Ed25519, Solana, TRON, UTXO coins, EVM), run in a second environment `security/.tools/venv-mc` (`requirements-multichain.txt`: PyNaCl, cryptography, solders, tronpy, eth-account, bip-utils, bitcash…). |37| `security/vectors/` | Third-party vectors (Wycheproof, BIP) at pinned revisions with `MANIFEST.json`; see its README. |38| `security/fuzzing/` | Seed corpus, crash reproducers, campaign summaries, sanitizer run records; see its README. |39| `security/policies/` | Severity policy, release gate, tool pins, Semgrep rules, Gitleaks configuration, framework mappings (MASVS, MASTG, Coinspect, wallet audit, Dontrust), triage decisions; see its README. |40| `security/reports/` | Generated: `SECURITY_AUDIT_RESULTS.json`, `SECURITY_AUDIT_REPORT.{md,html,pdf}`, `CRYPTOGRAPHIC_VALIDATION_REPORT.{html,pdf}`. `raw/` (tool output, logs) is git-ignored. |41| `SECURITY.md`, `docs/THREAT_MODEL.md` | Disclosure address, supported versions, honest status; threat model with the audit-status section. |4243## Installation4445```46security/audit/install-tools.sh # idempotent; --check lists what is installed47```4849Creates `security/.tools/venv` (Python) with the pinned Semgrep, mobsfscan and the reference oracle's50requirements (coincurve/libsecp256k1, pycryptodome, argon2-cffi, embit, mnemonic), a second environment51`security/.tools/venv-mc` with the references of the multi-chain tests (kept apart because some of them52require older versions of the same packages), checks Gitleaks53(Homebrew), caches the Semgrep registry packs, and copies the `spbqc` tool and `libspb_pqc.dylib` of the54owner's Rust library when a release build exists. Pins: `security/policies/tools.json`. Dontrust is55installed separately (`python3 security/audit/runners/frameworks.py --install-dontrust`, needs Node and56pnpm). MobSF needs Docker on the configured host (`security/policies/mobsf.json`, default BHS128). Xcode,57xcodegen and WeasyPrint are expected on the machine.5859Nothing leaves the project's machines: Semgrep and mobsfscan run with the network denied60(`sandbox-exec`), MobSF runs in a container without network on the project's own server and is removed61after each run, the only downloads are public rule packs, tools and vector files.6263## What the command does6465| Step | Tools reported | Quick | Full |66|---|---|---|---|67| `vectors` | `vectors` | SHA-256 of the third-party vector files against the manifest | same |68| `engine-tests` | `engine-tests` | every test target of the root package, release build | + large-data hash vectors (`QYVORA_LDT=1`) |69| `swift-audit` | `swift-audit` | ACVP/CAVP/BIP replay with counts per parameter set, Wycheproof, differential tests, property tests, corpus replay — reduced random counts | ten times the counts, complete SLH-DSA ACVP files when present, all twelve SLH-DSA sets |70| `timing` | `ct-machine-code`, `dudect-timing` | conditional branches in the compiled code of the secret-handling functions (secp256k1, ML-KEM, AES, Ed25519, SHA-512…); dudect test on this machine at 15 % of the sample counts, on the production build and, for the Ed25519 internals with chosen scalars, on a second build with testability | timing on `--timing-node` (or the first of `--nodes`), full counts |71| `fuzz` | `qyfuzz` | about one minute over the targets (93 since the multi-chain extension), local | long campaigns on `--nodes`, coverage-guided build |72| `sanitizers` | `sanitizers` | NOT RUN (recorded) | AddressSanitizer / UndefinedBehavior / ThreadSanitizer builds of selected suites (the Ed25519, Solana and TRON suites under both AddressSanitizer and ThreadSanitizer) |73| `semgrep`, `gitleaks`, `mobsfscan`, `static-checks` | same names | run | run |74| `frameworks` | `coinspect-wsf`, `owasp-masvs`, `owasp-mastg`, `wallet-audit`, `dontrust` | run (evidence references re-verified at each run) | run |75| `ipa-build`, `mobsf`, `binary-checks` | same names | NOT RUN (recorded) unless `--with-app` | unsigned Release archive, MobSF on the project's server, own binary checks |76| `ct-ios` | `ct-machine-code-ios` | NOT RUN (recorded) unless `--with-app` | the branch-count check repeated on the iOS application binary of the archive (symbols from its dSYM) |7778Options: `--no-mobsf`, `--with-app`, `--nodes "A B"`, `--timing-node N`, `--only a,b`, `--skip a,b`,79`--jobs N`, `--no-report`, `--list`. Environment: `QY_AUDIT_SCRATCH` (build directories, default80`/tmp/qy-audit-build`), `QY_AUDIT_REPORTS` (write results elsewhere than `security/reports`),81`QY_AUDIT_SEED` (deterministic random campaigns), `QY_AUDIT_REPLAY_SEED` (replay one recorded campaign).8283Cluster use: the working tree is copied with rsync to `<node>:qyvora-build/audit/` (timing) and84`<node>:qyvora-build/audit-fuzz/` (fuzzing) — only those directories are written on a node, nothing is85killed by name, and each runner records machine, duration, executions and crashes.8687Exit status: 0 release gate passed · 1 gate failed · 2 usage error · 3 report generation failed.8889## Release gate9091`security/policies/release-gate.json`. Publication is blocked by: an unresolved critical or high finding;92a failed case in an executed test (vectors, engine suites, audit tests, machine-code check, fuzzing,93sanitizers); a fuzzing crash; an untriaged secret; a required tool that failed or did not run (the full94list of required tools applies to `--full`). Everything else is a warning (open medium findings, tools95not run, checks not run, quick mode). Severity rules: `security/policies/severity-policy.md` — the96severity is the higher of the CVSS v3.1 band and the wallet-impact class; an agent never accepts a risk97on the owner's behalf.9899## Findings workflow1001011. A problem found by a person, a review or a test gets one file in `security/audit/findings/` with the102 fields of `lib/common.py: finding()`. Tool findings are produced at run time and triaged in103 `security/policies/triage.json` (keyed by fingerprint; every entry carries its justification).1042. A fix is a minimal change with a regression test; the finding then records `status: fixed`, the fix105 commit and the test. Fixes in the engine must pass on the laptop's toolchain.1063. The orchestrator merges register and tool findings by identifier (the live tool status wins), so a107 finding that a tool no longer reports is shown as resolved at that commit.108109## Reproducing a result110111- A failed random campaign prints its seed and stores it in the results file:112 `QY_AUDIT_REPLAY_SEED=<seed> swift test -c release --package-path security/tests --filter <test>`.113- One target group of the test package only (faster iteration):114 `QY_AUDIT_ONLY=PropertyAuditTests swift test -c release --package-path security/tests`.115- Timing: `swift build -c release --package-path security/tests --product qytiming`, then116 `qytiming --only <target> --scale 5 [--dit]` on a quiet machine. `--dit` sets the processor's117 data-independent-timing flag for the measurement. Two properties of the harness matter as much as the118 code under test (QYV-AUD-005, a timing "leak" that was a measurement artefact). (1) Both classes of a119 target keep their inputs in one block of memory whose slots are dealt to the classes at random120 (`ClassStore`): a class kept in its own buffers differs from the other by a constant 1 to 3 ns per run121 whatever the contents. (2) The timed region is separated from the preparation of the inputs by a122 serialising barrier (`dsb sy; isb`): without it the processor is still finishing the copy of the input123 when the clock is read. `--no-barrier` restores the former timed region:124 `qytiming --only info-former-preparation-ML-KEM-768 --scale 10 --no-barrier` reproduces the reported125 artefact (|t| ≈ 6 to 12); that target keeps the former asymmetric preparation as a record and has no126 verdict. Controls run every time: `control-leaky-compare` and `control-positive-mlkem-leak-ML-KEM-768`127 must be detected; `control-same-class`, `control-negative-aes-random-keys` and128 `control-negative-mlkem-ciphertexts-*` (same distribution in both classes) must not.129 The targets `diag-*` only run when named (`diag-<case>-<parameter set>` with the cases130 `same-single-vs-copies`, `copies-vs-pool`, `pool-vs-pool`, `single-vs-single`, `u-only`, `v-only`,131 `single-touch-vs-copies`; `diag-branch-ML-KEM-768`; `diag-aes-null`, `diag-aes-zero-vs-zero`,132 `diag-aes-random-vs-random`, `diag-aes-fixed-vs-random`, `diag-aes-zero-single-vs-random`): they keep each133 class in its own buffers, as before the correction, to reproduce and localise the artefacts. `--pool N`134 changes the number of values per class (default 512).135- Timing of the Ed25519 internals (scalar chosen directly, which the public interface does not allow):136 `QY_TIMING_INTERNALS=1 swift build -c release -Xswiftc -enable-testing --package-path security/tests --scratch-path /tmp/qy-timing-internals --product qytiming`,137 then `qytiming --internals --dit --scale 10`. The verdict is taken with `--dit`, because the production entry138 points set the data-independent-timing flag before reaching these functions; without `--dit` the same targets139 are reported as `info-nodit-…` (no verdict). `info-public-…` targets measure the variable-base multiplication,140 which serves verification only. The campaigns that found and closed QYV-AUD-006 are in141 `security/audit/review/ed25519-timing-2026-12-05.json`.142- Multi-chain differential tests: `QY_AUDIT_ONLY=DifferentialAuditTests swift test -c release --package-path security/tests --filter Ed25519Differential`143 (or `Solana`, `Tron`, `UTXOCoins`, `EVMChains`); a campaign whose reference is not installed is recorded NOT RUN.144- Fuzzing: `qyfuzz list`, `qyfuzz run …`, `qyfuzz repro <target> <file>` (see `security/fuzzing/README.md`).145- Machine code: `python3 security/audit/runners/timing.py` prints the branch counts of the functions146 listed in `security/policies/constant-time-functions.json`.147148## CI/CD149150The forge is self-hosted (spbgit: bare repositories on the gateway M1M32); there is no hosted runner.151Three pieces are provided.152153**(a) Pre-push hook (local).**154155```156security/audit/install-hooks.sh # install; --remove to uninstall157```158159Before a push that touches `Sources/`, `Tests/`, `App/`, `security/`, `Package.swift` or the entry script,160the hook runs the quick audit with its output redirected to a scratch directory (the committed reports161are not rewritten) and refuses the push when the release gate fails. `QY_SKIP_AUDIT=1 git push` skips it162and says so. An existing `pre-push` hook is kept as `pre-push.local` and runs first.163164**(b) Server-side integration (ready, NOT installed).** `security/audit/ci/post-receive-audit.sh` is165meant to be called from the bare repository's `post-receive` hook. For each pushed `refs/heads/main` it166clones the pushed revision into a scratch directory on a build node, runs167`Scripts/security-audit.sh --quick` there, and writes `~/qyvora-audit-status/<sha>.json` and168`latest-main.json` on the gateway (commit, node, start and end, exit status, gate result, blockers,169summary, path of the log). The push is never blocked: the audit runs detached. It was tested against a170local bare clone with `QY_CI_BUILD_NODE=local` (clone, checkout, run, status file, clean-up); it has not171been run on M1M32, and nothing was installed there.172173Installation, to be approved and run by the owner (one command from the laptop; it copies the script next174to the hooks of the bare repository `gitsrv:srv/git/qyvora.git` and appends one line to `post-receive`):175176```177scp security/audit/ci/post-receive-audit.sh gitsrv:srv/git/qyvora.git/hooks/qyvora-audit.sh && ssh gitsrv 'chmod +x srv/git/qyvora.git/hooks/qyvora-audit.sh && printf "%s\n" "tee >(QY_CI_BUILD_NODE=M3U96b \"\$(dirname \"\$0\")/qyvora-audit.sh\") >/dev/null" >> srv/git/qyvora.git/hooks/post-receive'178```179180The appended line is181182```183tee >(QY_CI_BUILD_NODE=M3U96b "$(dirname "$0")/qyvora-audit.sh") >/dev/null184```185186It hands a copy of the hook's standard input (the pushed references) to the script. It needs a `post-receive`187written for bash (process substitution); if the hook does not exist yet, create it with `#!/usr/bin/env bash`188as first line and make it executable. To remove: delete that line and `hooks/qyvora-audit.sh`.189190Before enabling it: check how the existing `post-receive` of spbgit uses its standard input (if it191already reads it, place the line before that command), run `security/audit/install-tools.sh` once on the build node192(the script keeps a persistent tool directory `qyvora-build/ci/tools` there and installs on first use),193and note that the Rust oracle and Dontrust are absent on a node unless installed (their campaigns are194then NOT RUN and reported as such). Settings are environment variables documented at the top of the195script (`QY_CI_BUILD_NODE`, `QY_CI_BRANCHES`, `QY_CI_AUDIT_ARGS`, `QY_CI_STATUS_DIR`…).196197**(c) `.github/workflows/security-audit.yml`.** An example of the equivalent for a mirror on a forge198with macOS runners. Unused, never run, clearly marked as such.199200## Limits (summary; the reports give the complete list)201202- Internal audit; no independent review of the cryptography or of this engine.203- Fuzzing is our own engine (mutation-based; edge-coverage feedback only in the instrumented build);204 libFuzzer is not available in the Xcode toolchain.205- Timing tests are statistical evidence on one machine and one build (macOS build of the package). The206 iOS application binary is disassembled for branch counts in full runs, but not timed on a device.207- Static tools have limited Swift support; framework mappings are self-assessments by source review.208- MobSF and the binary checks analyse an unsigned archive statically; no dynamic test on a device.209- No real funds, no live network in the audit.210- Multi-chain extension (2026-12-05): the new families were audited by source review, vectors, differential211 tests against independent libraries, property tests and fuzzing on stub transports. No transaction built by212 the wallet was broadcast to a real node of the new chains: acceptance by the networks rests on byte identity213 with the references and with public transactions. The application screens of the new chains were not214 reviewed by this extension (open `QYV-APP-0xx` items).215