Repository Public
1# QYVORA fuzzing23Fuzzing of every parser, decoder and verifier of the engine that takes untrusted input. This is part of the4internal security audit (see `security/README.md`); it is not an independent review.56## What this is, and what it is not78- **No libFuzzer.** `swiftc -sanitize=fuzzer` is refused by the Xcode toolchain ("unsupported option9 '-sanitize=fuzzer' for target arm64-apple-macosx"), checked on the laptop (Swift 6.4.2) and on the cluster nodes10 (Swift 6.3.3). The fuzzer here, `qyfuzz`, is our own engine, written in Swift (`security/tests/Sources/qyfuzz`,11 `security/tests/Sources/FuzzTargets`).12- **Two builds, two kinds of feedback.**13 - *plain*: the release build, as the engine ships. Mutation-based with a seeded generator. The only feedback is14 the *outcome class* a harness reports (accepted, or which error case): **this build is not coverage-guided.**15 It is the fastest and it traps exactly where a release build of the application would.16 - *coverage*: release build with AddressSanitizer and LLVM SanitizerCoverage inline 8-bit counters17 (`--sanitize=address -Xswiftc -sanitize-coverage=edge,inline-8bit-counters`, accepted by the toolchain).18 The instrumented modules register one counter per control-flow edge through19 `__sanitizer_cov_8bit_counters_init` (defined in `Coverage.swift`); the engine zeroes the counters before an20 execution and keeps the input when it reached a new edge or a new hit-count bucket (1, 2, 3, 4–7, 8–15, 16–31,21 32–127, 128+). This is edge-coverage guidance over the engine modules and the harnesses, done by our own loop:22 no value profile, no comparison tracing, no libFuzzer mutators or minimisation. About ten times slower.23- A campaign without a crash shows that no trap was found in the executions made. It proves nothing beyond that.2425## Targets2627`qyfuzz list` prints the targets (93 after the multi-chain extension of 2026-12-05). A target is a harness `(Bytes) -> Void`. A harness must return for every28input: a Swift trap (index out of range, arithmetic overflow, forced unwrap, `precondition`, `fatalError`) kills29the worker and is recorded as a crash. Harnesses also check invariants and stop with `FUZZ-INVARIANT: …`:3031| Area | Targets | Invariants beyond "no trap" |32|---|---|---|33| Encodings | `hex`, `base58check`, `bech32`, `base64url`, `uint256`, `bip39`, `extended-key`, `byte-reader` | decode ∘ encode round trips, canonical forms, checked arithmetic inverses, `isValid` agrees with the parser |34| Bitcoin | `bitcoin-transaction`, `psbt`, `psbt-text`, `descriptor`, `bitcoin-address`, `bitcoin-script`, `bitcoin-wif`, `psbt-sign` | strict parser ⇒ re-serialisation equals the input; PSBT serialisation idempotent; descriptor print/parse; address ⇄ script; a PSBT finalized after signing always extracts and never changes the unsigned transaction |35| Ethereum | `rlp`, `eip1559-unsigned`, `eip1559-signed`, `ethereum-address`, `erc20-abi`, `personal-message` | canonical RLP; decoded payload re-encodes to the same bytes (what is shown is what is signed); EIP-55 |36| secp256k1 | `secp256k1-pubkey`, `secp256k1-der`, `secp256k1-ecdsa-verify`, `secp256k1-schnorr-verify`, `secp256k1-sign` | only the committed valid signatures verify; recovered key verifies; private/public tweak agreement; strict DER |37| Post-quantum | `mlkem-keys`, `mlkem-decaps`, `mldsa-verify`, `mldsa-sign-mutate`, `slhdsa-verify` | validation agrees with use; decapsulation never throws for well-sized input; implicit rejection never returns the real secret; a mutated signature, message or key never verifies |38| Symmetric, X25519 | `aead-open`, `kmac-verify`, `x25519` | only the committed boxes open and the committed tags verify; no tag below the minimum length; no all-zero shared secret |39| Files and packages | `vault-file`, `vault-open`, `backup-file`, `backup-authenticated`, `identity-public`, `identity-signature`, `identity-rotation`, `hybrid-envelope`, `identity-private`, `qr-frames` | canonical re-encoding; an envelope opens only when its signature verifies; record counts match the authenticated header |40| Ed25519 | `ed25519-verify`, `ed25519-point`, `ed25519-sign`, `slip10-ed25519`, `ed25519-arithmetic` | only the committed signatures verify, and an accepted input satisfies every rule of the strict policy; strict decoding ⇒ canonical re-encoding, lenient decoding agrees with `isOnCurve`; a signature verifies, is deterministic and stops verifying after one flipped bit; path derivation equals step-by-step derivation; field, scalar and group identities on arbitrary bytes |41| Solana | `solana-compact-u16`, `solana-address`, `solana-message`, `solana-transaction`, `solana-instructions`, `solana-review`, `solana-planner`, `solana-json`, `solana-json-rpc`, `solana-history`, `solana-base64` | strict decoder ⇒ canonical re-encoding; a reviewed message re-encodes to the bytes that are signed; only the committed signed transactions verify; planner arithmetic on hostile balances, rent and fees never traps; bounds on what the parsers keep |42| TRON | `tron-protobuf`, `tron-raw-data`, `tron-signed-transaction`, `tron-address`, `tron-json`, `tron-abi`, `tron-review` | strict protobuf decoder ⇒ canonical re-encoding (any non-canonical form refused); a decoded transaction re-encodes to the bytes whose SHA-256 is its identifier; signature shape and signer recovery; only the Base58Check address form is accepted |43| Litecoin, Dogecoin, Bitcoin Cash | `cashaddr`, `utxo-coin-address`, `utxo-legacy-transaction`, `psbt-prevtx`, `json-blockbook`, `json-bitcore`, `utxo-indexer-normalise`, `utxo-coin-sign` | CashAddr round trip and checksum; no address accepted by two coins; no witness data on Dogecoin and Bitcoin Cash; the fee of a PSBT comes from authenticated previous outputs; value conservation and signatures valid under the coin's own digest; bounds on what indexer answers leave in the wallet |44| EVM networks | `evm-fee-quotes`, `opstack-oracle`, `json-evm-indexer-dialects`, `endpoint-config`, `network-table` | max fee ≥ priority fee, ceilings, no overflow on hostile fee figures; oracle answers of exactly one bounded word; canonical endpoint configuration; explorer links only from validated identifiers |45| Multi-chain service | `cold-envelope`, `watch-only-v2`, `chain-snapshot`, `check-address`, `account-binding-v2`, `utxo-coin-snapshot`, `hidden-tokens`, and `wallet-sync` extended to Solana, TRON, a UTXO coin and an OP-Stack network against hostile endpoints | envelope parse ∘ print identity and family/network binding; hostile persisted files through the real loader; address checks never trap and never cross families silently |46| Server responses | `json-esplora`, `json-ethereum-rpc`, `json-indexer`, `wallet-payloads`, `wallet-sync` (the wallet service itself, one wallet per process, synchronised against a routing stub) | bounds on what the wallet keeps (monetary range, decimals, counts). The transport is a stub: nothing reaches the network |4748The vault and backup files end with a SHA-256 checksum that a blind mutation would never satisfy: those harnesses49run the input as given and again with the checksum recomputed. Password key derivation is run only when the50file asks for tiny parameters (the format accepts up to 2 GiB of Argon2 memory).5152`backup-authenticated` covers the case blind mutation cannot reach: a backup that decrypts under the password but53carries hostile records (a file or a device transfer prepared by an attacker who also gives the password). The54harness seals the fuzz input itself, opens the file and restores it into a new vault.5556Two rules every harness follows, both learned the hard way (see `validation/`):5758- **Results are consumed.** In a release build the optimiser deletes a computation whose result is unused,59 together with the overflow or bounds trap inside it. `_ = value` hides defects; harnesses pass such values to60 `fuzzUse(_:)`.61- **Selectors are letters.** A target that picks one of several parsers reads a leading letter, not a digit, so62 the mutations that rewrite numbers do not change which parser runs.6364Dictionaries (format tokens, boundary integers, curve constants) are declared with each target in65`Targets+*.swift`.6667## Corpus and crashes6869- `corpus/<target>/` — committed seeds, named by SHA-256. Written by `qyfuzz seed` from valid objects (keys,70 signatures, transactions, files built with the engine) and from the official vectors quoted in the engine's71 tests. Identity material in these seeds is public (public identities, signatures, sealed envelopes of a72 throw-away identity). The private-identity target takes its seeds at run time and commits none.73- `work/` — git-ignored: inputs found during runs (`work/<run>/corpus/<target>/`), worker status files.74- `crashes/<target>/<sha256>.bin` — inputs that stopped a harness, each with a `.txt` note (message, site, seed,75 host, input in hexadecimal, tail of stderr, crashed thread from the macOS crash report). They are committed:76 `FuzzReplayTests` replays every corpus and crash file, so a fixed crash stays fixed.77 `crashes/identity-private/*.bin` holds the private encoding of a throw-away identity generated by the fuzzer78 (reproducer of finding QYV-FUZ-001); it protects nothing.79- `campaigns/<date>-<host>.json` — summaries of the long campaigns that were really run (machine, duration,80 executions, crashes), each with the commit it ran on.8182## Does it find real defects?8384`validation/2026-12-04-known-defects.json` records one experiment: the harnesses were run against the engine as85it was before the service review fixed its findings (commit `3ff9505~1`). In 240 seconds on one node (14 workers,86plain build, 1.2e9 executions) the fuzzer found four of the trap defects the review had fixed (QYV-SVC-001, 002,87005, 006). It did not find QYV-SVC-003 (inside the wallet service's synchronisation, which no harness drives),88QYV-SVC-004 (needs a 500 kB PSBT, above the 8 kB input cap), QYV-SVC-007 (not a trap) and QYV-SVC-01589(quadratic time on very long text, above the caps). Inputs are capped (80 bytes to 56 kB depending on the target):90defects that need larger inputs are out of reach, and so is everything behind the wallet service actor.9192## Commands9394```sh95# build (the harnesses use @testable import, hence -enable-testing in release)96swift build -c release -Xswiftc -enable-testing --product qyfuzz --package-path security/tests --scratch-path /tmp/qy-audit-fuzz97# coverage build98swift build -c release -Xswiftc -enable-testing --sanitize=address -Xswiftc -sanitize-coverage=edge,inline-8bit-counters \99 --product qyfuzz --package-path security/tests --scratch-path /tmp/qy-audit-fuzz-cov100101Q=/tmp/qy-audit-fuzz/release/qyfuzz102$Q list103$Q run --target all --seconds 600 --workers 8 --json /tmp/fuzz.json # workers cycle through the targets in slices104$Q run --target psbt,rlp --iterations 1000000 --seed 42 # reproducible: same seed, same inputs105$Q repro psbt security/fuzzing/crashes/psbt/<sha256>.bin # run one input in this process106$Q minimize psbt <file> --out <file>.min # shrink a crashing input107$Q seed # (re)write the committed seeds108109security/fuzzing/campaign.sh 1800 16 # both builds side by side on this machine, summaries in work/campaign/110python3 security/audit/runners/fuzz.py --full --nodes "M3U96a M3U96b M2U64" --seconds 1800111```112113The audit orchestrator calls `security/audit/runners/fuzz.py`: quick mode = plain build, about 25 seconds on the114local machine; full mode = both builds locally and `campaign.sh` on every node given with `--nodes`.115116## How a crash is handled1171181. The worker copies each input into a memory-mapped status file before executing it. When the worker dies or119 stops making progress (`--timeout`, 30 s), the driver saves that input and starts a new worker.1202. A release build traps without a message. The driver reads the crashed thread from the report macOS writes121 (`~/Library/Logs/DiagnosticReports/qyfuzz-*.ips`) to say where; the system throttles these reports, so a site122 can be missing — then `qyfuzz repro` under a debugger, or a debug build, gives it.1233. The runner turns each distinct (target, site) into a finding, **high** until triaged124 (`security/policies/triage.json`), and the release gate fails.1254. Fix the engine (or the harness when the invariant was wrong), keep the input in `crashes/`, add the regression126 test, record the fix in the findings register.127128## Sanitizers129130`security/audit/runners/sanitizers.py` (full mode) rebuilds and runs the fuzz-replay tests and selected engine131suites under AddressSanitizer, the actor services and the concurrent SLH-DSA suite under ThreadSanitizer, and a132small subset under UBSan (which instruments C-family code only and says almost nothing about Swift).133