SPB Git

Repository Public

README.md 12.6 KB

# QYVORA fuzzing

Fuzzing of every parser, decoder and verifier of the engine that takes untrusted input. This is part of the internal security audit (see security/README.md); it is not an independent review.

# What this is, and what it is not

  • No libFuzzer. swiftc -sanitize=fuzzer is refused by the Xcode toolchain ("unsupported option '-sanitize=fuzzer' for target arm64-apple-macosx"), checked on the laptop (Swift 6.4.2) and on the cluster nodes (Swift 6.3.3). The fuzzer here, qyfuzz, is our own engine, written in Swift (security/tests/Sources/qyfuzz, security/tests/Sources/FuzzTargets).
  • Two builds, two kinds of feedback.
    • plain: the release build, as the engine ships. Mutation-based with a seeded generator. The only feedback is the outcome class a harness reports (accepted, or which error case): this build is not coverage-guided. It is the fastest and it traps exactly where a release build of the application would.
    • coverage: release build with AddressSanitizer and LLVM SanitizerCoverage inline 8-bit counters (--sanitize=address -Xswiftc -sanitize-coverage=edge,inline-8bit-counters, accepted by the toolchain). The instrumented modules register one counter per control-flow edge through __sanitizer_cov_8bit_counters_init (defined in Coverage.swift); the engine zeroes the counters before an 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, 32–127, 128+). This is edge-coverage guidance over the engine modules and the harnesses, done by our own loop: no value profile, no comparison tracing, no libFuzzer mutators or minimisation. About ten times slower.
  • A campaign without a crash shows that no trap was found in the executions made. It proves nothing beyond that.

# Targets

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 every input: a Swift trap (index out of range, arithmetic overflow, forced unwrap, precondition, fatalError) kills the worker and is recorded as a crash. Harnesses also check invariants and stop with FUZZ-INVARIANT: …:

Area Targets Invariants beyond "no trap"
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
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
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
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
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
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
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
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
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
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
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
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
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
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

The vault and backup files end with a SHA-256 checksum that a blind mutation would never satisfy: those harnesses run the input as given and again with the checksum recomputed. Password key derivation is run only when the file asks for tiny parameters (the format accepts up to 2 GiB of Argon2 memory).

backup-authenticated covers the case blind mutation cannot reach: a backup that decrypts under the password but carries hostile records (a file or a device transfer prepared by an attacker who also gives the password). The harness seals the fuzz input itself, opens the file and restores it into a new vault.

Two rules every harness follows, both learned the hard way (see validation/):

  • Results are consumed. In a release build the optimiser deletes a computation whose result is unused, together with the overflow or bounds trap inside it. _ = value hides defects; harnesses pass such values to fuzzUse(_:).
  • Selectors are letters. A target that picks one of several parsers reads a leading letter, not a digit, so the mutations that rewrite numbers do not change which parser runs.

Dictionaries (format tokens, boundary integers, curve constants) are declared with each target in Targets+*.swift.

# Corpus and crashes

  • corpus/<target>/ — committed seeds, named by SHA-256. Written by qyfuzz seed from valid objects (keys, signatures, transactions, files built with the engine) and from the official vectors quoted in the engine's tests. Identity material in these seeds is public (public identities, signatures, sealed envelopes of a throw-away identity). The private-identity target takes its seeds at run time and commits none.
  • work/ — git-ignored: inputs found during runs (work/<run>/corpus/<target>/), worker status files.
  • crashes/<target>/<sha256>.bin — inputs that stopped a harness, each with a .txt note (message, site, seed, host, input in hexadecimal, tail of stderr, crashed thread from the macOS crash report). They are committed: FuzzReplayTests replays every corpus and crash file, so a fixed crash stays fixed. crashes/identity-private/*.bin holds the private encoding of a throw-away identity generated by the fuzzer (reproducer of finding QYV-FUZ-001); it protects nothing.
  • campaigns/<date>-<host>.json — summaries of the long campaigns that were really run (machine, duration, executions, crashes), each with the commit it ran on.

# Does it find real defects?

validation/2026-12-04-known-defects.json records one experiment: the harnesses were run against the engine as it was before the service review fixed its findings (commit 3ff9505~1). In 240 seconds on one node (14 workers, plain build, 1.2e9 executions) the fuzzer found four of the trap defects the review had fixed (QYV-SVC-001, 002, 005, 006). It did not find QYV-SVC-003 (inside the wallet service's synchronisation, which no harness drives), QYV-SVC-004 (needs a 500 kB PSBT, above the 8 kB input cap), QYV-SVC-007 (not a trap) and QYV-SVC-015 (quadratic time on very long text, above the caps). Inputs are capped (80 bytes to 56 kB depending on the target): defects that need larger inputs are out of reach, and so is everything behind the wallet service actor.

# Commands

sh
# build (the harnesses use @testable import, hence -enable-testing in release)
swift build -c release -Xswiftc -enable-testing --product qyfuzz --package-path security/tests --scratch-path /tmp/qy-audit-fuzz
# coverage build
swift build -c release -Xswiftc -enable-testing --sanitize=address -Xswiftc -sanitize-coverage=edge,inline-8bit-counters \
  --product qyfuzz --package-path security/tests --scratch-path /tmp/qy-audit-fuzz-cov

Q=/tmp/qy-audit-fuzz/release/qyfuzz
$Q list
$Q run --target all --seconds 600 --workers 8 --json /tmp/fuzz.json     # workers cycle through the targets in slices
$Q run --target psbt,rlp --iterations 1000000 --seed 42                 # reproducible: same seed, same inputs
$Q repro psbt security/fuzzing/crashes/psbt/<sha256>.bin                # run one input in this process
$Q minimize psbt <file> --out <file>.min                                # shrink a crashing input
$Q seed                                                                 # (re)write the committed seeds

security/fuzzing/campaign.sh 1800 16          # both builds side by side on this machine, summaries in work/campaign/
python3 security/audit/runners/fuzz.py --full --nodes "M3U96a M3U96b M2U64" --seconds 1800

The audit orchestrator calls security/audit/runners/fuzz.py: quick mode = plain build, about 25 seconds on the local machine; full mode = both builds locally and campaign.sh on every node given with --nodes.

# How a crash is handled

  1. The worker copies each input into a memory-mapped status file before executing it. When the worker dies or stops making progress (--timeout, 30 s), the driver saves that input and starts a new worker.
  2. A release build traps without a message. The driver reads the crashed thread from the report macOS writes (~/Library/Logs/DiagnosticReports/qyfuzz-*.ips) to say where; the system throttles these reports, so a site can be missing — then qyfuzz repro under a debugger, or a debug build, gives it.
  3. The runner turns each distinct (target, site) into a finding, high until triaged (security/policies/triage.json), and the release gate fails.
  4. Fix the engine (or the harness when the invariant was wrong), keep the input in crashes/, add the regression test, record the fix in the findings register.

# Sanitizers

security/audit/runners/sanitizers.py (full mode) rebuilds and runs the fuzz-replay tests and selected engine suites under AddressSanitizer, the actor services and the concurrent SLH-DSA suite under ThreadSanitizer, and a small subset under UBSan (which instruments C-family code only and says almost nothing about Swift).

Files main
Menu

Theme