truent_analyzer_solana/
lib.rs1#![deny(unsafe_code)]
2#![allow(missing_docs)]
3
4pub mod analyzer;
7pub mod anchor_model;
9pub mod anchor_parser;
11pub mod detectors;
13pub mod semantic_model;
15pub mod solana_durable_nonce;
16pub mod solana_fake_sysvar_instruction;
17pub mod solana_pda_authority_validation;
18pub mod solana_rent_exemption;
19pub mod solana_unchecked_token_account;
20
21pub use analyzer::SolanaAnalyzer;
22pub use anchor_model::{
23 AccountSecurity, AnchorAccountField, AnchorAccountStruct, AnchorConstraint,
24};
25pub use anchor_parser::parse_anchor_accounts;
26pub use detectors::*;
27pub use semantic_model::build_semantic_model;
28pub use solana_durable_nonce::detect_solana_durable_nonce_validation;
29pub use solana_fake_sysvar_instruction::detect_fake_sysvar_instruction_account;
30pub use solana_pda_authority_validation::detect_solana_pda_authority_validation;
31pub use solana_rent_exemption::detect_solana_rent_exemption;
32pub use solana_unchecked_token_account::detect_unchecked_token_account_type;
33
34pub fn run_all_detectors(source: &str, file_path: &str) -> Vec<truent_core::Finding> {
39 let mut findings = detectors::detect_all(source, file_path);
40
41 findings.extend(detect_solana_durable_nonce_validation(source, file_path));
42 findings.extend(detect_solana_pda_authority_validation(source, file_path));
43 findings.extend(detect_solana_rent_exemption(source, file_path));
44 findings.extend(detect_unchecked_token_account_type(source, file_path));
45 findings.extend(detect_fake_sysvar_instruction_account(source, file_path));
46
47 if let Ok(model) = build_semantic_model(source, file_path) {
52 findings.extend(truent_ir::rules::find_unauthorized_privileged_mutations(
53 &model,
54 ));
55 }
56
57 let mut seen = std::collections::HashSet::new();
58 findings.retain(|f| seen.insert(f.dedup_key()));
59
60 findings.sort_by(|a, b| match b.severity.cmp(&a.severity) {
61 std::cmp::Ordering::Equal => a.line.cmp(&b.line),
62 other => other,
63 });
64
65 findings
66}