Skip to main content

truent_analyzer_move/
lib.rs

1#![deny(unsafe_code)]
2#![allow(missing_docs)]
3
4//! Move (Aptos/Sui) program analyzer.
5
6pub mod analyzer;
7/// Vulnerability detectors for Move modules
8pub mod detectors;
9pub mod move_manual_overflow_check;
10pub mod move_resource_destruction;
11pub mod move_type_safety_violation;
12/// Chain-agnostic semantic-model extraction (Epic 6.1 shared IR)
13pub mod semantic_model;
14/// Real structural parsing via a vendored Sui Move tree-sitter grammar
15pub mod tree_sitter_grammar;
16
17pub use analyzer::MoveAnalyzer;
18pub use detectors::*;
19pub use move_manual_overflow_check::detect_move_manual_overflow_check;
20pub use move_resource_destruction::detect_move_resource_destruction;
21pub use move_type_safety_violation::detect_move_type_safety_violation;
22pub use semantic_model::build_semantic_model;
23
24/// Run every live Move detector against the given source text.
25///
26/// This is the single entry point the CLI should use for Move analysis: each
27/// detector operates directly on raw source text, no Move AST parse is required.
28pub fn run_all_detectors(source: &str, file_path: &str) -> Vec<truent_core::Finding> {
29    let mut findings = detectors::detect_all(source, file_path);
30
31    findings.extend(detect_move_resource_destruction(source, file_path));
32    findings.extend(detect_move_type_safety_violation(source, file_path));
33    findings.extend(detect_move_manual_overflow_check(source, file_path));
34
35    // Chain-agnostic shared-IR rule (Epic 6.1): flags privileged mutations
36    // with no authorization guard, using the same rule EVM and Solana share.
37    let model = build_semantic_model(source, file_path);
38    findings.extend(truent_ir::rules::find_unauthorized_privileged_mutations(
39        &model,
40    ));
41
42    let mut seen = std::collections::HashSet::new();
43    findings.retain(|f| seen.insert(f.dedup_key()));
44
45    findings.sort_by(|a, b| match b.severity.cmp(&a.severity) {
46        std::cmp::Ordering::Equal => a.line.cmp(&b.line),
47        other => other,
48    });
49
50    findings
51}