miden_tx/host/
script_mast_forest_store.rs1use alloc::collections::BTreeMap;
2use alloc::sync::Arc;
3
4use miden_objects::Word;
5use miden_objects::assembly::mast::MastForest;
6use miden_objects::note::NoteScript;
7use miden_objects::transaction::TransactionScript;
8use miden_objects::vm::AdviceMap;
9use miden_processor::MastForestStore;
10
11pub struct ScriptMastForestStore {
16 mast_forests: BTreeMap<Word, Arc<MastForest>>,
17 advice_map: AdviceMap,
18}
19
20impl ScriptMastForestStore {
21 pub fn new(
23 tx_script: Option<&TransactionScript>,
24 note_scripts: impl Iterator<Item = impl AsRef<NoteScript>>,
25 ) -> Self {
26 let mut mast_store = ScriptMastForestStore {
27 mast_forests: BTreeMap::new(),
28 advice_map: AdviceMap::default(),
29 };
30
31 for note_script in note_scripts {
32 mast_store.insert(note_script.as_ref().mast());
33 }
34
35 if let Some(tx_script) = tx_script {
36 mast_store.insert(tx_script.mast());
37 }
38 mast_store
39 }
40
41 fn insert(&mut self, mast_forest: Arc<MastForest>) {
43 for proc_digest in mast_forest.local_procedure_digests() {
45 self.mast_forests.insert(proc_digest, mast_forest.clone());
46 }
47
48 for (key, values) in mast_forest.advice_map().clone() {
50 self.advice_map.insert((*key).into(), values);
51 }
52 }
53
54 pub fn advice_map(&self) -> &AdviceMap {
56 &self.advice_map
57 }
58}
59
60impl MastForestStore for ScriptMastForestStore {
64 fn get(&self, procedure_root: &Word) -> Option<Arc<MastForest>> {
65 self.mast_forests.get(procedure_root).cloned()
66 }
67}