Skip to content

Latest commit

 

History

History
78 lines (64 loc) · 6.31 KB

plan.md

File metadata and controls

78 lines (64 loc) · 6.31 KB

Plan: LLM+MCP+Datalog Binary Query Agent (v2)

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

  1. Phase 1 - Problem framing and query contract

  2. Define a strict query contract (supported property classes, query template language, expected outputs, error modes).

  3. Define out-of-scope queries for v1 (e.g., symbolic-execution-level constraints, whole-program pointer alias precision beyond selected rules).

  4. Decide canonical result model: relation rows + provenance explanation + confidence/coverage metadata.

  5. Phase 2 - Backend abstraction and fact schema (blocks phase 3+)

  6. Create a backend capability matrix for BN MCP vs Ghidra MCP: function listing, decompilation, xrefs, type queries, CFG/basic blocks, stack vars, imports/exports.

  7. Define a backend-agnostic fact schema (Datalog relations) with normalized identifiers: function_id, block_id, instr_id, var_id, type_id.

  8. Define relation families for full interprocedural def-use target, staged by confidence:

  9. Core structural: Function, Calls, CFGEdge, Entry, Exit.

  10. Dataflow seed: Def, Use, MemoryRead, MemoryWrite, ArgMap, RetMap.

  11. Interprocedural links: ActualToFormal, FormalToReturn, HeapObjAliasApprox.

  12. Add provenance fields on facts (source backend, extraction tool, timestamp, optional confidence) to support explainability.

  13. Phase 3 - Fact extraction pipeline

  14. Implement BN extractor first using isolated MCP sessions per worker and chunked parallel extraction.

  15. Add deterministic fact serialization to CSV/TSV files per relation with stable sorting for reproducibility.

  16. Implement extraction checkpoints and caching (per binary hash + backend + schema version).

  17. Implement Ghidra adapter mapping into the same schema; unsupported capability should emit explicit partial-coverage metadata, not silent omission.

  18. Phase 4 - Datalog rule system and generation

  19. Build a curated rule library first (handwritten baseline rules) for call reachability, taint-ish flow approximation, and resource lifecycle checks.

  20. Introduce LLM-assisted rule generation behind guardrails:

  21. Generate candidate rules from user intent into a sandbox file.

  22. Run static validation (allowed predicates, recursion limits, stratification constraints).

  23. Fallback to nearest curated template if validation fails.

  24. Keep user-facing query-to-rule mapping traceable (which template/rules executed).

  25. Phase 5 - Souffle execution and result interpretation

  26. Run Souffle via subprocess with timeout/memory controls and per-run temp workspace.

  27. Parse structured outputs (prefer output-dir artifacts over stdout scraping).

  28. Post-process result relations into:

  29. Human markdown report (primary).

  30. Optional JSON artifact (secondary, for future automation).

  31. Add interpretation layer that explains why each result row exists using provenance edges and rule traces where available.

  32. Phase 6 - Interactive loop and UX

  33. Implement ask-refine loop: if answer confidence/coverage is low, propose concrete follow-up queries or narrower scope.

  34. Show explicit backend coverage summary (BN vs Ghidra parity, missing predicates).

  35. Support “direct MCP answer” shortcut for trivial questions where Datalog is unnecessary.

  36. Phase 7 - Evaluation and hardening

  37. Build a benchmark set of query tasks (structural, dataflow, vulnerability-oriented).

  38. Measure correctness (manual oracle or known ground truth), latency, and failure classes (syntax, timeout, incomplete facts).

  39. Add regression fixtures for schema evolution and backend parity.

  40. 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

  1. Contract tests: same query over same binary with same schema version must produce byte-identical fact files and stable result ordering.
  2. Backend parity tests: run a minimal predicate suite on BN and Ghidra; compare overlap and report deltas explicitly.
  3. Rule validation tests: malformed/generated rules must fail safely and route to curated fallback.
  4. Performance tests: enforce max extraction and solve time budgets for small/medium binaries.
  5. 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

  1. 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.
  2. LLM rule generation policy: optional-by-default vs always-on. Recommendation: default to curated library and enable generation only when no template matches.
  3. Backend strategy: strict parity vs graceful degradation. Recommendation: graceful degradation with explicit coverage reporting, then iterate toward parity on high-value predicates.