Commit graph

29 commits

Author SHA1 Message Date
trvon
bcdcb3036b
feat(analysis): harden quality and solver pipelines 2026-07-29 20:46:51 -04:00
trvon
8d85829481
docs: document convergence contracts 2026-07-29 00:58:19 -04:00
trvon
374aa7475d
many good updates for binary and SAST / DAST scanning 2026-06-02 12:39:03 -04:00
trvon
5152d0c9f7
feat(binary): vendor Ghidra 12.1 decompiler + validate P-Code lifting (Phase 0-1)
Foundation for replacing fold's dead/abstract binary encoder with a real
SSA P-Code frontend. Verified root-cause gap: serializeBinaryIR() emits only
data-discovery nodes (sections/strings/imports/exports); the control-flow
BinaryExprKind values (BasicBlock/CallSite/...) are never constructed, so the
Z3-BB encoder's encodable filter is always empty and encodeBinaryBBs never
runs — hence 0 binary Z3 findings. The P-Code pipeline supersedes that path.

Phase 0 — docs/internal/ghidra-pcode-integration-research.md: P-Code opcode
core, the decompiler C++ embedding API (LoadImage/SleighArchitecture/Funcdata),
the CORE+DECCORE+SLEIGH source sets, no-bison finding, and pypcode as build
reference.

Phase 1 — vendored Ghidra decompiler at pinned commit (Ghidra_12.1_build,
7e89d94e34...) under third_party/ghidra-decompiler/ (cpp + AArch64 specs +
Apache-2.0 LICENSE + VENDOR.md + .gitignore for build artifacts). Validated by
hand on this clang-21/macOS toolchain:
  - full SSA engine (CORE+DECCORE+SLEIGH, 80 files incl. heritage/funcdata/
    action) compiles clean, -std=c++11 -O2, NO BFD, NO bison (generated
    parsers are committed upstream; ruleparse isn't in the lib set);
  - sleigh compiler builds; AArch64 .slaspec -> .sla compiles;
  - tools/pcode_dump.cpp (custom LoadImage, no BFD) lifts the real arm64
    sym._div_by_zero_direct to correct P-Code: `mov w9,#0 -> COPY(const 0)`,
    `sdiv -> INT_SDIV(w8,w9)` — divisor zero-ness explicit in the data flow,
    so the Phase-3 encoder proves div-by-zero trivially, multi-arch.

Not yet meson-wired (next step) and no fold-side IR/encoder yet (Phase 2-3);
this commit is the validated vendor + smoke tool.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-05-31 17:32:47 -04:00
trvon
dd98730988
docs: remaining loop-IR work + cross-frontend architecture finding
Record that rust_ir_encoder and binary_bb_encoder do not route through
SecurityWalker/unrollLoop and have no loop handling, so "cross-frontend
ir::Loop reuse" is gated on a shared clang-free loop-walk core rather than
being a standalone slice. Lay out the realistic sequencing (clang-free CFG
foundation -> rust/binary lowering -> recall-preserving while(1) acceleration)
and note no safe small gate-validatable slice exists short of starting the
foundation. Clang counted+affine summarization is complete.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-05-31 13:44:48 -04:00
trvon
b693d8a038
bench: tracked precision baseline + enforcing local drift gate
The old fp-baseline.json lived under gitignored bench/results/, so it had
no history and nothing compared against it — precision drift went unnoticed.

- Move the committed baseline to a tracked path (bench/fp-baseline.json)
  regenerated from the current build.
- Add `score_fp.py --gate`: diff per-detector P/R/F1 vs the baseline and
  exit non-zero on any drop beyond --tolerance (default 0.02).
- Add `--max-files-per-cwe` deterministic stride sampling so huge CWEs are
  tractable; restrict gold to the scanned subset so recall stays meaningful.
- Document the gate (local, not CI) in bench/README.md.
- docs/internal/loop-summarization-research.md: Workstream B research + the
  null-deref drift root-cause appendix.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-05-30 18:04:16 -04:00
trvon
6348820f92
audit: binary scan timeout root cause — repeated aaa per session
- Each R2Session construction runs full auto-analysis
- 4-6 aaa runs on a single binary → 60-90s timeout
- Fix: share one R2Session across all extraction calls
- Progressive analysis levels: aa (quick), aaa (full), aaaa (experimental)
2026-05-30 00:26:15 -04:00
trvon
0d63dbbd7e
research+feat: interprocedural buffer-bound threading — pre-pass architecture
- SafetyObserver::seedInterproceduralContext() called before function walks
- OOBObserver override scans all call sites for ConstantArrayType args
- Seeds param_buffer_sizes_ from any caller, regardless of decl order
- Research doc covers Inferbo/ARCHER/FunFrog approaches and fold's infrastructure
2026-05-29 23:49:56 -04:00
trvon
95a5ddb462
audit: CTF binary detector gap analysis — 5 gaps, projected 7%→70%
- #1 fortified import _chk strip (+4 CWE-121, S effort)
- #2 binary format-string xref (+3 CWE-134, S effort)
- #3 hardcoded-string re-enable (+2 CWE-798, S effort)
- #4 BB encoder per-instruction granularity (+6 CWE-369/190/476, M)
- #5 binary UAF observer (+2 CWE-416, M)
2026-05-29 22:54:17 -04:00
trvon
eb85913f6e
eval: CTF loop 2 — 3.7%→7.4% detection, 2x improvement
- dangerous-import correctly flags gets() and system() imports
- Hardcoded-string FP fix too aggressive (drops real findings)
- CWE gaps: buffer overflow, format string, UAF, div-zero still missed
- Next: wire binary_bb_encoder into pipeline for Z3-proved findings
2026-05-29 21:30:38 -04:00
trvon
5a4d27d60e
audit: loop 2 priorities — top 5 by ROI across all backends
- #1: wire binary BB Z3 encoder into scan pipeline (binary 50%→70%)
- #2: Juliet benchmark scoring (standardized recall/precision)
- #3: Rust OSS benchmark formalization (ripgrep 49 findings)
- #4: binary BB encoder pipeline wiring
- #5: watch mode + CI/CD integration
2026-05-29 21:25:10 -04:00
trvon
8af924dd47
research: binary analysis tools — Ghidra P-code, angr, r2 levels
- Ghidra P-code: 25-op arch-neutral IR → BinaryIR design
- angr: symbolic path exploration → basic block to Z3
- r2 aaaa: function signature recovery → fix default params=3
- 6 recommended features ordered by effort/impact
2026-05-29 20:24:00 -04:00
trvon
f4e3d32fcb
audit: binary backend test coverage — 35% coverage, 8 failure points
- Only 5/15 functions tested; extractCalls/extractXrefs/pdbj untested
- CTF failures mapped to specific r2_backend.cpp code paths
- Top fix: flag dangerous imports + hardcoded strings (S effort, +12 findings)
- Full basic block analysis needed for div-by-zero/null-deref (L effort, +6)
2026-05-29 20:22:37 -04:00
trvon
d40707c6a7
design: BinaryIR + BinaryDetector pipeline v2
- BinaryExprKind enum (8 kinds): HardcodedString, CallSite, VtableEntry...
- 8 BinaryFindingKind values for binary-specific vulnerabilities
- Detector pipeline mirrors source architecture (standalone functions)
- Phase plan: 4 phases, target 3.7% → 40%+ detection
2026-05-29 20:22:02 -04:00
trvon
592a6b4acd
docs: fold runtime performance profile — Z3 is not the bottleneck
- Z3 solver <0.01% of wall time (74 queries, ~0ms)
- Real bottleneck: AST walkers + CFG traversal (~85%)
- Top optimization: TU pre-filter (skip files with no security ops)
- Bitwuzla multi-solver would not help — SMT queries are already fast
2026-05-29 14:05:03 -04:00
trvon
e9e23227cb
docs: fold expansion roadmap — 4 sprints, security + performance + utility
- Sprint 1: 4 syntactic detectors (deprecated API, weak crypto, format string, creds)
- Sprint 2: 3 Z3-powered (use-after-move, iterator invalidation, SQL injection)
- Sprint 3: Bitwuzla multi-solver, TU pre-filter, clone cache
- Sprint 4: watch mode, pre-commit hooks, GitHub Code Scanning SARIF
2026-05-29 13:20:34 -04:00
trvon
706c86013e
docs: CTF binary validation corpus — 7 challenges to test fold binary analysis
- picoCTF, CSAW, DEF CON, Flare-On, HackTheBox challenges
- Tests: string extraction, xrefs, heap UAF, ARM64 ABI, ObjC routing
- Gaps identified: packed binaries, fat Mach-O, PE IAT, encrypted strings
2026-05-29 13:19:39 -04:00
trvon
d7258c4021
docs: Z3 multi-solver portfolio research — Bitwuzla 5.1x faster on BV
- Bitwuzla BV solver is 5.1x faster than Z3 (SMT-COMP 2023)
- ESBMC pattern: dispatch to 6 solvers, race for first result
- Proposal: add --solver bitwuzla | z3 | portfolio-all flag
- Expected 2-5x speedup on fold's BV-64 queries
2026-05-29 10:10:53 -04:00
trvon
ec8492431c
docs: Semgrep C/C++ gap matrix — ~80 rules vs fold 11 detectors
- Banned functions: 15 rules, 0 fold detectors — largest gap
- Crypto misuse: 8 rules completely uncovered
- Phase 1: 9 syntactic detectors covering 30+ Semgrep rules
- What fold does better: Z3 proofs, CFG analysis, type-aware checking
2026-05-29 10:06:52 -04:00
trvon
a598e9dd96
docs: Facebook Infer gap matrix — ~30 checkers vs fold 10 detectors
- Concurrency: 7 Infer checkers, 0 in fold — biggest gap
- C++ lifetime: 4 Infer, 0 fold (dangling refs, ownership)
- Resource mgmt: file/socket leak missing from fold's memory-leak
- Performance: vector reallocation, loop invariants
2026-05-29 10:06:12 -04:00
trvon
5d81aa5b98
docs: CodeQL C/C++ gap matrix — ~200 queries vs fold 29 detectors
- Memory safety: 7/30 covered (7 new detectors added this session)
- Injection/taint: 1/25 covered — high-impact gap
- Phase 1: 8 syntactic detectors (deprecated APIs, format strings, weak crypto)
- Phase 2: 5 Z3-powered (path/command/SQL injection, tainted format, process)
- What fold does better: Z3-proved findings, semantic equivalence, binary scanning
2026-05-29 10:04:26 -04:00
trvon
27bb4d807f
docs: code quality detector opportunities — API misuse, exception safety, concurrency, deprecated APIs
- 12 detector ideas across 4 categories
- Phase 1 (S effort): deprecated APIs, throwing dtors, missing noexcept
- Phase 2 (M-L): use-after-move, iterator invalidation, lock inversion
- All phase 1 detectors are syntactic (RecursiveASTVisitor, no Z3 needed)
2026-05-29 10:03:25 -04:00
trvon
04642c46af
docs: rustc internals research for HIR/MIR analysis in fold-rust
- rustc_driver Callbacks, TyCtxt, HIR ExprKind, MIR BasicBlock/Rvalue
- TyKind type system: bit-width queries via LayoutS
- Borrow checker: BorrowKind, loan scopes, BorrowTracker usage
2026-05-28 20:09:14 -04:00
trvon
585ae4e4ab
docs: clang API research, multi-language IR patterns, Rust-Clang parity gap analysis
- clang-analysis-api-research.md: AST nodes, CFG, type system, constant folding
- multi-language-ir-patterns.md: CodeQL shared engine, Infer SIL, Kani MIR→Goto-C
- rust-clang-scanning-parity.md: 9-component comparison table, 8 priority fixes
2026-05-28 20:08:38 -04:00
trvon
18ce5a6050
docs: Swift/C++ ABI, fuzzing, IR, MIR research for multi-language pipeline
- Swift ABI: tagged pointers, garbage-input abort path, ObjC bridging
- C++ fuzz: libFuzzer dlopen coverage limits, AFL++ QEMU mode, vtable seeding
- Cross-language IR: CodeQL/Infer/Joern patterns, Swift SIL gaps in fold IR
- MIR verification: Kani/Prusti/Creusot approaches, BorrowTracker wiring
2026-05-28 10:28:41 -04:00
trvon
811aab5254
docs: Z3 symbolic encoder robustness audit (31 files, 7 fixes ranked by ROI)
- H1: &&/|| short-circuit not forked → 30-40% null-deref FP reduction
- H3: Rust IR incomplete (Member, Conditional, signedness, path)
- 7 recommended fixes ordered by effort/impact
- Precision gaps mapped per detector family
2026-05-27 21:15:38 -04:00
trvon
56550a93a1
feat: symex-fuzz landscape, SWAN SIL parser, Juliet expansion, FP scoring
- docs/internal/symex-fuzz-landscape.md: 11 tools across 6 categories
- tools/fold-swift/swan_sil_parser: 75 SIL operator kinds, JSON converter
- bench/juliet/expansion/: 118-CWE catalog, gold generator, runner
- bench/score_fp.py: precision/recall/F1 per detector
2026-05-27 18:00:06 -04:00
trvon
ffc7917957
feat: symbolic IR, swift backend, binary-to-fuzz pipeline, SARIF fixes
- Rust IR encoder (encodeRustIr): walks HIR expr trees, fires SafetyObserver hooks
- Swift SIL frontend (fold-swift): swiftc -emit-sil parser, demangling, NDJSON output
- SwiftBackend: --mode swift CLI routing, shells out to fold-swift
- Binary-to-fuzz: Mach-O export discovery, ARM64 ABI param-count inference, dlopen harness generation
- Language-agnostic IR: json_keys canonical constants, Call/Member/ArraySubscript/Cast/HeapNew nodes
- Dogfood fixes: SARIF kind field, cross-detector dedup, harness_file in predictions, Swift stoi safety
- Corpuses: swift-sil-z3-corpus.md, binary-fuzz-corpus.md
- AGENTS.md: cross-language wire format rule
2026-05-27 15:29:14 -04:00
trvon
ce1c353847
feat: harden security scanner routing 2026-05-27 10:36:57 -04:00