miden_protocol/
protocol.rs1use alloc::sync::Arc;
2
3use crate::assembly::Library;
4use crate::assembly::mast::MastForest;
5use crate::utils::serde::Deserializable;
6use crate::utils::sync::LazyLock;
7
8const PROTOCOL_LIB_BYTES: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/assets/protocol.masl"));
12
13#[derive(Clone)]
17pub struct ProtocolLib(Library);
18
19impl ProtocolLib {
20 pub fn mast_forest(&self) -> &Arc<MastForest> {
22 self.0.mast_forest()
23 }
24}
25
26impl AsRef<Library> for ProtocolLib {
27 fn as_ref(&self) -> &Library {
28 &self.0
29 }
30}
31
32impl From<ProtocolLib> for Library {
33 fn from(value: ProtocolLib) -> Self {
34 value.0
35 }
36}
37
38impl Default for ProtocolLib {
39 fn default() -> Self {
40 static PROTOCOL_LIB: LazyLock<ProtocolLib> = LazyLock::new(|| {
41 let contents = Library::read_from_bytes(PROTOCOL_LIB_BYTES)
42 .expect("protocol lib masl should be well-formed");
43 ProtocolLib(contents)
44 });
45 PROTOCOL_LIB.clone()
46 }
47}
48
49#[cfg(all(test, feature = "std"))]
54mod tests {
55 use super::ProtocolLib;
56 use crate::assembly::Path;
57
58 #[test]
59 fn test_compile() {
60 let path = Path::new("::miden::protocol::active_account::get_id");
61 let miden = ProtocolLib::default();
62 let exists = miden.0.module_infos().any(|module| {
63 module
64 .procedures()
65 .any(|(_, proc)| module.path().join(&proc.name).as_path() == path)
66 });
67
68 assert!(exists);
69 }
70}