sentri_core/traits.rs
1//! Core traits defining the analyzer/generator/simulator interface.
2
3use crate::error::Result;
4use crate::model::{GenerationOutput, Invariant, ProgramModel, SimulationReport};
5use std::path::Path;
6
7/// Analyzes a smart contract program and extracts its model.
8///
9/// Implementations must be chain-specific but return a chain-agnostic `ProgramModel`.
10pub trait ChainAnalyzer: Send + Sync {
11 /// Analyze a program at the given path.
12 ///
13 /// # Errors
14 ///
15 /// Returns an error if:
16 /// - The file cannot be read
17 /// - The syntax is invalid for the target chain
18 /// - Unsupported patterns are encountered
19 fn analyze(&self, path: &Path) -> Result<ProgramModel>;
20
21 /// Chain identifier: "solana", "evm", "move".
22 fn chain(&self) -> &str;
23}
24
25/// Generates instrumented code with invariant checks.
26///
27/// Implementations inject assertions after state mutations.
28pub trait CodeGenerator: Send + Sync {
29 /// Generate instrumented code.
30 ///
31 /// # Errors
32 ///
33 /// Returns an error if:
34 /// - Invariant expressions reference undefined state
35 /// - Type mismatches are detected
36 /// - Code generation fails
37 fn generate(
38 &self,
39 program: &ProgramModel,
40 invariants: &[Invariant],
41 ) -> Result<GenerationOutput>;
42
43 /// Chain identifier.
44 fn chain(&self) -> &str;
45}
46
47/// Simulates program execution to find invariant violations.
48///
49/// Implementations provide deterministic, fuzzing-based simulation.
50pub trait Simulator: Send + Sync {
51 /// Simulate execution against invariants.
52 ///
53 /// # Errors
54 ///
55 /// Returns an error if simulation setup fails.
56 fn simulate(
57 &self,
58 program: &ProgramModel,
59 invariants: &[Invariant],
60 ) -> Result<SimulationReport>;
61
62 /// Chain identifier.
63 fn chain(&self) -> &str;
64}