4.8 KiB
Project Graph Reasoning
UltrafastSecp256k1 ships with a SQLite-backed project graph at:
.project_graph.db
This is not only a code index. It is a cryptographic engineering knowledge base used by humans and AI agents to reason about:
- subsystem boundaries
- constant-time and secret-bearing paths
- parser boundaries
- audit coverage
- optimization opportunity vs. audit risk
- CPU-to-GPU candidate selection
- change-history-sensitive review targets
Rebuild
python3 scripts/build_project_graph.py --rebuild
What The Graph Contains
Core structural layers:
- source files
- include dependencies
- C ABI functions
- ABI routing
- C++ methods
- test targets
- audit modules
- docs
- call graph
- function-to-test map
Reasoning layers:
semantic_tagsentity_tagssymbol_semanticssymbol_securitysymbol_performancesymbol_audit_coveragesymbol_historysymbol_scoresv_symbol_reasoning
Semantic Classification
Symbols and files are tagged with higher-level meaning, for example:
field_arithmeticscalar_arithmeticpoint_arithmeticmodinvecdsaschnorrecdhbip352hashingffi_abiwallet_flowgpu_accelerationconstant_timeparser_boundaryaudit_evidence
This allows graph queries to operate on intent, not only filenames.
Security Metadata
Each symbol may carry reasoning fields such as:
uses_secret_inputmust_be_constant_timepublic_data_onlydevice_secret_uploadrequires_zeroizationinvalid_input_sensitive
This makes it possible to separate:
- public verification code
- secret-bearing signing / derivation code
- parser-boundary code
- GPU/offload-sensitive flows
Performance Metadata
Each symbol also gets estimated engineering metadata:
hotness_scoreestimated_costbatchablevectorizablegpu_candidatememory_boundcompute_boundduplicated_backends
This is heuristic, not a benchmark replacement. It is meant to guide review and optimization triage.
Audit Coverage Metadata
The graph records whether a symbol is covered by:
- unit tests
- fuzzing
- invalid-vector style tests
- CT tests
- cross-implementation differential checks
- GPU-equivalence style checks
- regression-style tests
It also stores:
last_audit_resulttimes_failed_historicallyknown_fragile
History Layer
The graph uses git history to derive:
times_modifiedrecently_modifiedbug_fix_countperformance_tuning_countaudit_related_changes
This helps prioritize review on recently changing, fragile, or heavily tuned paths.
Risk And Gain Scoring
Every symbol gets:
risk_scoregain_scoreoptimization_priority
The current scoring is heuristic and intended for triage, not for automated proof of correctness. It is useful for answering:
- which optimization candidates are high-gain and relatively lower-risk
- which secret-bearing or parser-sensitive symbols deserve review first
- which CPU paths look like strong GPU-offload candidates
Query Commands
Structural
python3 scripts/query_graph.py context cpu/src/ct_sign.cpp
python3 scripts/query_graph.py impact cpu/src/ecdh.cpp
python3 scripts/query_graph.py callgraph pippenger_msm
python3 scripts/query_graph.py coverage ecdsa_sign
Semantic
python3 scripts/query_graph.py tags
python3 scripts/query_graph.py tag constant_time
python3 scripts/query_graph.py symbol ecdsa_sign
Optimization / Audit Triage
python3 scripts/query_graph.py optimize 20
python3 scripts/query_graph.py risk 20
python3 scripts/query_graph.py gpuwork 20
python3 scripts/query_graph.py fragile 20
Recommended Workflow
Before editing a file
python3 scripts/query_graph.py context <file>
python3 scripts/query_graph.py impact <file>
Before touching secret-bearing code
python3 scripts/query_graph.py security <file>
python3 scripts/query_graph.py fragile 20
python3 scripts/query_graph.py tag constant_time
Before changing the C ABI
python3 scripts/query_graph.py routing <name>
python3 scripts/query_graph.py bindings
python3 scripts/query_graph.py tag ffi_surface
Before proposing an optimization
python3 scripts/query_graph.py optimize 20
python3 scripts/query_graph.py gpuwork 20
python3 scripts/query_graph.py risk 20
Machine-Readable Export
The reasoning graph is exported through:
python3 scripts/export_assurance.py -o assurance_report.json
The exported JSON includes:
- semantic tag inventory
- reasoning summary by category/backend
- optimization candidates
- risk hotspots
Notes
- The reasoning layer is intentionally heuristic.
- It should guide review and AI assistance, not replace cryptographic judgment.
- If graph builder logic changes, rebuild the DB before relying on query output.