miden_core/
lib.rs

1#![no_std]
2
3#[macro_use]
4extern crate alloc;
5
6#[cfg(feature = "std")]
7extern crate std;
8
9/// This is an implementation of `std::assert_matches::assert_matches`
10/// so it can be removed when that feature stabilizes upstream
11#[macro_export]
12macro_rules! assert_matches {
13    ($left:expr, $(|)? $( $pattern:pat_param )|+ $( if $guard: expr )? $(,)?) => {
14        match $left {
15            $( $pattern )|+ $( if $guard )? => {}
16            ref left_val => {
17                panic!(r#"
18assertion failed: `(left matches right)`
19    left: `{:?}`,
20    right: `{}`"#, left_val, stringify!($($pattern)|+ $(if $guard)?));
21            }
22        }
23    };
24
25    ($left:expr, $(|)? $( $pattern:pat_param )|+ $( if $guard: expr )?, $msg:literal $(,)?) => {
26        match $left {
27            $( $pattern )|+ $( if $guard )? => {}
28            ref left_val => {
29                panic!(concat!(r#"
30assertion failed: `(left matches right)`
31    left: `{:?}`,
32    right: `{}`
33"#, $msg), left_val, stringify!($($pattern)|+ $(if $guard)?));
34            }
35        }
36    };
37
38    ($left:expr, $(|)? $( $pattern:pat_param )|+ $( if $guard: expr )?, $msg:literal, $($arg:tt)+) => {
39        match $left {
40            $( $pattern )|+ $( if $guard )? => {}
41            ref left_val => {
42                panic!(concat!(r#"
43assertion failed: `(left matches right)`
44    left: `{:?}`,
45    right: `{}`
46"#, $msg), left_val, stringify!($($pattern)|+ $(if $guard)?), $($arg)+);
47            }
48        }
49    }
50}
51
52pub mod chiplets;
53pub mod errors;
54
55mod program;
56pub use program::{Program, ProgramInfo};
57
58mod kernel;
59pub use kernel::Kernel;
60pub use miden_crypto::{EMPTY_WORD, ONE, WORD_SIZE, Word, ZERO, word::LexicographicWord};
61pub mod crypto {
62    pub mod merkle {
63        pub use miden_crypto::merkle::{
64            EmptySubtreeRoots, InnerNodeInfo, LeafIndex, MerkleError, MerklePath, MerkleStore,
65            MerkleTree, Mmr, MmrPeaks, NodeIndex, PartialMerkleTree, SMT_DEPTH, SimpleSmt, Smt,
66            SmtProof, SmtProofError, StoreNode,
67        };
68    }
69
70    pub mod hash {
71        pub use miden_crypto::hash::{
72            Digest, ElementHasher, Hasher,
73            blake::{Blake3_160, Blake3_192, Blake3_256, Blake3Digest},
74            poseidon2::Poseidon2,
75            rpo::Rpo256,
76            rpx::Rpx256,
77        };
78    }
79
80    pub mod random {
81        pub use miden_crypto::rand::{
82            RandomCoin, RandomCoinError, RpoRandomCoin, RpxRandomCoin, WinterRandomCoin,
83        };
84    }
85
86    pub mod dsa {
87        pub use miden_crypto::dsa::rpo_falcon512;
88    }
89}
90
91pub mod mast;
92
93pub use winter_math::{
94    ExtensionOf, FieldElement, StarkField, ToElements,
95    fields::{QuadExtension, f64::BaseElement as Felt},
96    polynom,
97};
98pub type QuadFelt = QuadExtension<Felt>;
99
100pub mod prettier {
101    pub use miden_formatting::{prettier::*, pretty_via_display, pretty_via_to_string};
102
103    /// Pretty-print a list of [PrettyPrint] values as comma-separated items.
104    pub fn pretty_print_csv<'a, T>(items: impl IntoIterator<Item = &'a T>) -> Document
105    where
106        T: PrettyPrint + 'a,
107    {
108        let mut doc = Document::Empty;
109        for (i, item) in items.into_iter().enumerate() {
110            if i > 0 {
111                doc += const_text(", ");
112            }
113            doc += item.render();
114        }
115        doc
116    }
117}
118
119mod operations;
120pub use operations::{
121    AssemblyOp, DebugOptions, Decorator, DecoratorList, Operation, opcode_constants::*,
122};
123
124pub mod stack;
125pub use stack::{StackInputs, StackOutputs};
126
127mod event_id;
128pub use event_id::{EventId, EventName};
129
130pub mod sys_events;
131
132mod advice;
133pub use advice::map::AdviceMap;
134
135pub mod precompile;
136pub mod utils;
137
138// Re-export indexing functionality from the new standalone crate
139pub use miden_utils_indexing::{
140    DenseIdMap, Idx, IndexVec, IndexedVecError, LookupByIdx, newtype_id,
141};
142
143// CONSTANTS
144// ================================================================================================
145
146/// The initial value for the frame pointer, corresponding to the start address for procedure
147/// locals.
148pub const FMP_INIT_VALUE: Felt = Felt::new(2_u64.pow(31));
149
150/// The address where the frame pointer is stored in memory.
151pub const FMP_ADDR: Felt = Felt::new(u32::MAX as u64 - 1_u64);