Repository Public
1// =============================================================================2// SP BOUCHER | SOFTWARE & RESEARCH3// ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// Project : QYVORA7// File : security/tests/Sources/FuzzTargets/Registry.swift8// Module : Tests9// Repository : https://git.spboucher.ai/qyvora10// Project Website : Not specified11// Created : 2026-12-0412// Last Modified : 2026-12-0413//14// Author : Simon-Pierre Boucher15// Position : Professor of Finance16// Institution : Université du Québec en Outaouais (UQO)17// Organization : SP Boucher18// Website : https://spboucher.ai19// Git : https://git.spboucher.ai20//21// Preferred Contact: contact@spboucher.ai22// Development : dev@spboucher.ai23// Support : support@spboucher.ai24// Security/Admin : admin@spboucher.ai25//26// Copyright (c) 202627// Simon-Pierre Boucher28// All rights reserved where applicable. This file is governed by the29// applicable project license, copyright notices and relevant law.30// Existing third-party rights and notices remain unaffected.31//32// License : None specified (no license file in this repository)33//34// Do not embed credentials, private keys, access tokens,35// certificates or confidential personal information.36//37// =============================================================================38// END OF SP BOUCHER SOURCE HEADER39// =============================================================================4041import AuditSupport42import Foundation43import QyvoraMath44import QyvoraSymmetric4546/// Every fuzz target of the audit, in a stable order.47public enum FuzzRegistry {48 public static let all: [FuzzTarget] =49 encodingTargets + bitcoinTargets + bitcoinSigningTargets + ethereumTargets + cryptoTargets + storageTargets + networkTargets + walletTargets50 + ed25519Targets + solanaTargets + tronTargets + utxoCoinTargets + evmChainTargets + multichainWalletTargets51 + (ProcessInfo.processInfo.environment["QY_FUZZ_SELFTEST"] == "1" ? [selfTestTarget] : [])5253 /// Not an engine target: a harness with a planted defect (an out-of-range index reached through a two-byte prefix),54 /// present only when QY_FUZZ_SELFTEST=1. It proves that the fuzzer finds, captures and locates a real trap.55 static let selfTestTarget = FuzzTarget(56 "selftest-trap", "Planted trap behind the prefix 51 59 (self-test of crash capture; QY_FUZZ_SELFTEST=1 only)", maxLength: 16,57 seeds: { [[0x51, 0x00, 0x00, 0x00]] }58 ) { input in59 guard input.count >= 3, input[0] == 0x51 else { return }60 FuzzOutcome.note("first")61 guard input[1] == 0x59 else { return }62 FuzzOutcome.note("second")63 _ = input[input.count + Int(input[2])] // planted: always out of range64 }6566 public static func target(_ name: String) -> FuzzTarget? { all.first { $0.name == name } }6768 public static var names: [String] { all.map(\.name) }6970 /// Targets whose runtime seeds contain throw-away private keys: never written to the committed corpus.71 static let privateSeedTargets: Set<String> = ["identity-private"]7273 /// Seeds to commit for a target: the structural seeds, plus the runtime seeds when they are public material.74 public static func committedSeeds(_ target: FuzzTarget) -> [Bytes] {75 var out = target.seeds()76 if !privateSeedTargets.contains(target.name), let more = target.runtimeSeeds { out += more() }77 return out.filter { !$0.isEmpty && $0.count <= target.maxLength }78 }79}8081public enum FuzzFiles {82 /// Lower-case SHA-256 of the input: the name of corpus and crash files.83 public static func name(_ bytes: Bytes) -> String { Hex.encode(SHA256.hash(bytes)) }8485 /// Files of a directory (sorted by name, hidden files and notes skipped), with their names.86 public static func load(_ dir: URL, limit: Int = 20_000) -> [(name: String, bytes: Bytes)] {87 guard let names = try? FileManager.default.contentsOfDirectory(atPath: dir.path) else { return [] }88 var out = [(name: String, bytes: Bytes)]()89 for n in names.sorted() where !n.hasPrefix(".") && !n.hasSuffix(".txt") && !n.hasSuffix(".md") && !n.hasSuffix(".json") {90 if let d = try? Data(contentsOf: dir.appendingPathComponent(n)) { out.append((n, Bytes(d))) }91 if out.count >= limit { break }92 }93 return out94 }9596 @discardableResult97 public static func save(_ bytes: Bytes, in dir: URL, suffix: String = "") -> URL {98 try? FileManager.default.createDirectory(at: dir, withIntermediateDirectories: true)99 let url = dir.appendingPathComponent(name(bytes) + suffix)100 if !FileManager.default.fileExists(atPath: url.path) { try? Data(bytes).write(to: url) }101 return url102 }103}104