SUPERSEDED: The previous v1 plan has been revised into bin_datalog/plan-v2.md based on critical review. Key changes: added MLIL-SSA-centric extraction, added Phase 0 spike, cut v1 scope (BN-only, no provenance, 3 rule modules), identified MCP text parsing as the core engineering challenge, added competitor framing (Joern, CodeQL), grounded in 5 concrete user queries.
Original plan below kept for reference.
Steps
-
Phase 1 - Problem framing and query contract
-
Define a strict query contract (supported property classes, query template language, expected outputs, error modes).
-
Define out-of-scope queries for v1 (e.g., symbolic-execution-level constraints, whole-program pointer alias precision beyond selected rules).
-
Decide canonical result model: relation rows + provenance explanation + confidence/coverage metadata.
-
Phase 2 - Backend abstraction and fact schema (blocks phase 3+)
-
Create a backend capability matrix for BN MCP vs Ghidra MCP: function listing, decompilation, xrefs, type queries, CFG/basic blocks, stack vars, imports/exports.
-
Define a backend-agnostic fact schema (Datalog relations) with normalized identifiers: function_id, block_id, instr_id, var_id, type_id.
-
Define relation families for full interprocedural def-use target, staged by confidence:
-
Core structural: Function, Calls, CFGEdge, Entry, Exit.
-
Dataflow seed: Def, Use, MemoryRead, MemoryWrite, ArgMap, RetMap.
-
Interprocedural links: ActualToFormal, FormalToReturn, HeapObjAliasApprox.
-
Add provenance fields on facts (source backend, extraction tool, timestamp, optional confidence) to support explainability.
-
Phase 3 - Fact extraction pipeline
-
Implement BN extractor first using isolated MCP sessions per worker and chunked parallel extraction.
-
Add deterministic fact serialization to CSV/TSV files per relation with stable sorting for reproducibility.
-
Implement extraction checkpoints and caching (per binary hash + backend + schema version).
-
Implement Ghidra adapter mapping into the same schema; unsupported capability should emit explicit partial-coverage metadata, not silent omission.
-
Phase 4 - Datalog rule system and generation
-
Build a curated rule library first (handwritten baseline rules) for call reachability, taint-ish flow approximation, and resource lifecycle checks.
-
Introduce LLM-assisted rule generation behind guardrails:
-
Generate candidate rules from user intent into a sandbox file.
-
Run static validation (allowed predicates, recursion limits, stratification constraints).
-
Fallback to nearest curated template if validation fails.
-
Keep user-facing query-to-rule mapping traceable (which template/rules executed).
-
Phase 5 - Souffle execution and result interpretation
-
Run Souffle via subprocess with timeout/memory controls and per-run temp workspace.
-
Parse structured outputs (prefer output-dir artifacts over stdout scraping).
-
Post-process result relations into:
-
Human markdown report (primary).
-
Optional JSON artifact (secondary, for future automation).
-
Add interpretation layer that explains why each result row exists using provenance edges and rule traces where available.
-
Phase 6 - Interactive loop and UX
-
Implement ask-refine loop: if answer confidence/coverage is low, propose concrete follow-up queries or narrower scope.
-
Show explicit backend coverage summary (BN vs Ghidra parity, missing predicates).
-
Support “direct MCP answer” shortcut for trivial questions where Datalog is unnecessary.
-
Phase 7 - Evaluation and hardening
-
Build a benchmark set of query tasks (structural, dataflow, vulnerability-oriented).
-
Measure correctness (manual oracle or known ground truth), latency, and failure classes (syntax, timeout, incomplete facts).
-
Add regression fixtures for schema evolution and backend parity.
-
Document threat model for prompt-injected rule abuse and subprocess safety.
Relevant files
-
/media/sanjay/f574986f-8197-4e72-a69d-87ddf200a6a9/sanjay/research/tii/tii24/repos/dev-claude/bin_datalog/research.md — source concept and goals to refine into a formal architecture doc.
-
/media/sanjay/f574986f-8197-4e72-a69d-87ddf200a6a9/sanjay/research/tii/tii24/repos/dev-claude/vuln_analysis_6step/agent.py — reusable MCP toolset isolation, async orchestration, staged agent pipeline patterns.
-
/media/sanjay/f574986f-8197-4e72-a69d-87ddf200a6a9/sanjay/research/tii/tii24/repos/dev-claude/fuzz_harness_adv/agent.py — subprocess execution and timeout/error-handling patterns applicable to Souffle runs.
-
/memories/session/datalog_references_summary.md — distilled patterns from MATE, cclyzer++, and ddisasm; canonical input for schema and rule-library design discussions.
Verification
- Contract tests: same query over same binary with same schema version must produce byte-identical fact files and stable result ordering.
- Backend parity tests: run a minimal predicate suite on BN and Ghidra; compare overlap and report deltas explicitly.
- Rule validation tests: malformed/generated rules must fail safely and route to curated fallback.
- Performance tests: enforce max extraction and solve time budgets for small/medium binaries.
- End-to-end acceptance: at least 10 non-trivial queries (including interprocedural def-use) answered with markdown explanations and traceable provenance.
Decisions
- Included: dual-backend architecture with BN-first implementation and Ghidra compatibility path.
- Included: full interprocedural def-use as target capability, but delivered incrementally via staged relation families.
- Included: markdown as primary human output, JSON as optional secondary artifact.
- Excluded (v1): high-precision alias analysis, SMT-backed path feasibility, full symbolic execution.
Further Considerations
- Souffle relation design choice: normalized wide schema (fewer predicates, more columns) vs narrow semantic schema (more predicates, easier rule readability). Recommendation: start narrow semantic schema for explainability and easier LLM rule control.
- LLM rule generation policy: optional-by-default vs always-on. Recommendation: default to curated library and enable generation only when no template matches.
- Backend strategy: strict parity vs graceful degradation. Recommendation: graceful degradation with explicit coverage reporting, then iterate toward parity on high-value predicates.