Skip to main content

miden_protocol/utils/
mod.rs

1use alloc::vec;
2
3use miden_core::mast::MastNode;
4pub use miden_core::utils::*;
5pub use miden_crypto::utils::{HexParseError, bytes_to_hex_string, hex_to_bytes};
6pub use miden_utils_sync as sync;
7
8use crate::Word;
9use crate::assembly::mast::{ExternalNodeBuilder, MastForest, MastNodeId};
10use crate::vm::AdviceMap;
11
12pub mod serde {
13    pub use miden_crypto::utils::{
14        BudgetedReader,
15        ByteReader,
16        ByteWriter,
17        Deserializable,
18        DeserializationError,
19        Serializable,
20        SliceReader,
21    };
22}
23
24pub mod strings;
25
26pub(crate) use strings::ShortCapitalString;
27
28/// Creates a minimal [MastForest] containing only an external node referencing the given digest.
29///
30/// This is useful for creating lightweight references to procedures without copying entire
31/// libraries. The external reference will be resolved at runtime, assuming the source library
32/// is loaded into the VM's MastForestStore.
33pub(crate) fn create_external_node_forest(digest: Word) -> (MastForest, MastNodeId) {
34    let mut nodes: IndexVec<MastNodeId, MastNode> = IndexVec::new();
35    let node_id = nodes
36        .push(ExternalNodeBuilder::new(digest).build().into())
37        .expect("adding external node to empty forest should not fail");
38    let mast = MastForest::from_raw_parts(nodes, vec![node_id], AdviceMap::default())
39        .expect("single external node forest should be well-formed");
40    (mast, node_id)
41}