Skip to main content

leo_passes/cei_analysis/
mod.rs

1// Copyright (C) 2019-2026 Provable Inc.
2// This file is part of the Leo library.
3
4// The Leo library is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8
9// The Leo library is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13
14// You should have received a copy of the GNU General Public License
15// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
16
17pub(crate) mod cross_layer_taint;
18pub(crate) mod effect_summary;
19pub(crate) mod finalize_visitor;
20
21use crate::Pass;
22
23use effect_summary::AutomatonState;
24
25use leo_ast::UnitVisitor;
26use leo_errors::Result;
27use leo_span::Symbol;
28
29use indexmap::IndexMap;
30
31pub struct CeiAnalyzing;
32
33impl Pass for CeiAnalyzing {
34    type Input = ();
35    type Output = ();
36
37    const NAME: &str = "CeiAnalyzing";
38
39    fn do_pass(_input: Self::Input, state: &mut crate::CompilerState) -> Result<Self::Output> {
40        let ast = std::mem::take(&mut state.ast);
41
42        // Phase 0: Compute effect summaries bottom-up over the call graph.
43        let effect_summaries = effect_summary::compute_effect_summaries(state);
44
45        // Phase 1: Finalize-time CEI analysis.
46        let mut cei_visitor = finalize_visitor::FinalizeCeiVisitor {
47            state,
48            current_program: Symbol::intern(""),
49            effect_summaries,
50            automaton_state: AutomatonState::BeforeInteraction,
51            interaction_span: None,
52            current_variant: None,
53            in_finalize: false,
54        };
55
56        ast.visit(|program| cei_visitor.visit_program(program), |_library| {});
57
58        // Phase 2: Cross-layer taint analysis.
59        let mut taint_visitor = cross_layer_taint::CrossLayerTaintVisitor {
60            state: cei_visitor.state,
61            current_program: Symbol::intern(""),
62            taint_map: IndexMap::new(),
63            in_transition: false,
64            implicit_taint: cross_layer_taint::TaintInfo::default(),
65        };
66
67        ast.visit(|program| taint_visitor.visit_program(program), |_library| {});
68
69        taint_visitor.state.handler.last_err()?;
70        taint_visitor.state.ast = ast;
71
72        Ok(())
73    }
74}