pub struct MastForest { /* private fields */ }Expand description
Represents one or more procedures, represented as a collection of MastNodes.
A MastForest does not have an entrypoint, and hence is not executable. A
crate::program::Program can be built from a MastForest to specify an entrypoint.
Implementations§
Source§impl MastForest
impl MastForest
Sourcepub fn read_view_from_bytes(
bytes: &[u8],
mode: MastForestReadMode,
) -> Result<MastForestReadView<'_>, DeserializationError>
pub fn read_view_from_bytes( bytes: &[u8], mode: MastForestReadMode, ) -> Result<MastForestReadView<'_>, DeserializationError>
Reads trusted MAST forest bytes using the requested backing mode.
MastForestReadMode::Materialized is equivalent to Self::read_from_bytes.
MastForestReadMode::WireBacked returns a trusted random-access cache view and rejects
hashless and trailing payloads because trusted cache bytes must be complete execution
payloads.
Source§impl MastForest
Constructors
impl MastForest
Constructors
Sourcepub fn new() -> MastForest
pub fn new() -> MastForest
Creates a new empty MastForest.
Source§impl MastForest
State mutators
impl MastForest
State mutators
Sourcepub fn compact(self) -> (MastForest, MastForestRootMap)
pub fn compact(self) -> (MastForest, MastForestRootMap)
Compacts the forest by merging duplicate nodes.
This operation performs node deduplication by merging the forest with itself. This method consumes the forest and returns a new compacted forest.
The process works by:
- Merging the forest with itself to deduplicate identical nodes
- Updating internal node references and remappings
- Returning the compacted forest and root map
§Examples
use miden_core::mast::MastForest;
let forest = MastForest::new();
// Add nodes to the forest
// Compact the forest (consumes the original)
let (compacted_forest, root_map) = forest.compact();
// compacted_forest is now compacted with duplicate nodes mergedSourcepub fn merge<'forest>(
forests: impl IntoIterator<Item = &'forest MastForest>,
) -> Result<(MastForest, MastForestRootMap), MastForestError>
pub fn merge<'forest>( forests: impl IntoIterator<Item = &'forest MastForest>, ) -> Result<(MastForest, MastForestRootMap), MastForestError>
Merges all forests into a new MastForest.
Merging two forests means combining all their constituent parts, i.e. MastNodes and
roots. During this process, any duplicate or unreachable nodes are removed. Additionally,
MastNodeIds of nodes may change and references to them are remapped to their new
location.
For example, consider this representation of a forest’s nodes with all of these nodes being roots:
[Block(foo), Block(bar)]If we merge another forest into it:
[Block(bar), Call(0)]then we would expect this forest:
[Block(foo), Block(bar), Call(1)]- The
Callto thebarblock was remapped to its new index (now 1, previously 0). - The
Block(bar)was deduplicated any only exists once in the merged forest.
The function also returns a vector of MastForestRootMaps, whose length equals the number
of passed forests. The indices in the vector correspond to the ones in forests. The map
of a given forest contains the new locations of its roots in the merged forest. To
illustrate, the above example would return a vector of two maps:
vec![{0 -> 0, 1 -> 1}
{0 -> 1, 1 -> 2}]- The root locations of the original forest are unchanged.
- For the second forest, the
barblock has moved from index 0 to index 1 in the merged forest, and theCallhas moved from index 1 to 2.
If any forest being merged contains an External(qux) node and another forest contains a
node whose digest is qux, then the external node will be replaced with the qux node,
which is effectively deduplication.
impl MastForest
Helpers
Source§impl MastForest
Public accessors
impl MastForest
Public accessors
Sourcepub fn get_node_by_id(&self, node_id: MastNodeId) -> Option<&MastNode>
pub fn get_node_by_id(&self, node_id: MastNodeId) -> Option<&MastNode>
Returns the MastNode associated with the provided MastNodeId if valid, or else
None.
This is the fallible version of indexing (e.g. mast_forest[node_id]).
Sourcepub fn find_procedure_root(&self, digest: Word) -> Option<MastNodeId>
pub fn find_procedure_root(&self, digest: Word) -> Option<MastNodeId>
Returns the MastNodeId of the procedure associated with a given digest, if any.
Sourcepub fn is_procedure_root(&self, node_id: MastNodeId) -> bool
pub fn is_procedure_root(&self, node_id: MastNodeId) -> bool
Returns true if a node with the specified ID is a root of a procedure in this MAST forest.
Sourcepub fn is_procedure_root_with_exact_digest(
&self,
node_id: MastNodeId,
digest: Word,
) -> bool
pub fn is_procedure_root_with_exact_digest( &self, node_id: MastNodeId, digest: Word, ) -> bool
Returns true if a node with the specified ID is a root of a procedure in this MAST forest,
and the digest of that procedure is digest.
This is primarily intended for use in confirming that procedure exports of a package, which declare their MAST node and digest, actually exist in the MAST.
Sourcepub fn procedure_digests(&self) -> impl Iterator<Item = Word>
pub fn procedure_digests(&self) -> impl Iterator<Item = Word>
Returns an iterator over the digests of all procedures in this MAST forest.
Sourcepub fn local_procedure_digests(&self) -> impl Iterator<Item = Word>
pub fn local_procedure_digests(&self) -> impl Iterator<Item = Word>
Returns an iterator over the digests of local procedures in this MAST forest.
A local procedure is defined as a procedure which is not a single external node.
Sourcepub fn procedure_roots(&self) -> &[MastNodeId]
pub fn procedure_roots(&self) -> &[MastNodeId]
Returns an iterator over the IDs of the procedures in this MAST forest.
Sourcepub fn num_procedures(&self) -> u32
pub fn num_procedures(&self) -> u32
Returns the number of procedures in this MAST forest.
Sourcepub fn compute_nodes_commitment<'a>(
&self,
node_ids: impl IntoIterator<Item = &'a MastNodeId>,
) -> Word
pub fn compute_nodes_commitment<'a>( &self, node_ids: impl IntoIterator<Item = &'a MastNodeId>, ) -> Word
Returns the Word representing the content hash of a subset of MastNodeIds.
§Panics
This function panics if any node_ids is not a node of this forest.
Sourcepub fn commitment(&self) -> Word
pub fn commitment(&self) -> Word
Returns the commitment to this MAST forest.
The commitment is computed as the sequential hash of all procedure roots in the forest.
The commitment uniquely identifies the forest’s structure, as each root’s digest transitively includes all of its descendants. Therefore, a commitment to all roots is a commitment to the entire forest.
pub fn advice_map(&self) -> &AdviceMap
Sourcepub fn with_advice_map(self, advice_map: AdviceMap) -> MastForest
pub fn with_advice_map(self, advice_map: AdviceMap) -> MastForest
Returns this forest with advice_map entries added.
Sourcepub fn write_hashless<W>(&self, target: &mut W)where
W: ByteWriter,
pub fn write_hashless<W>(&self, target: &mut W)where
W: ByteWriter,
Serializes this MastForest with the HASHLESS flag set.
Hashless forest bytes omit rebuildable internal node hashes. External node digests stay on the wire because they cannot be rebuilt from local structure. Trusted deserialization rejects this flag.
Use this when producing data for untrusted validation.
Source§impl MastForest
Validation methods
impl MastForest
Validation methods
Sourcepub fn validate(&self) -> Result<(), MastForestError>
pub fn validate(&self) -> Result<(), MastForestError>
Validates that all BasicBlockNodes in this forest satisfy the core invariants:
- Power-of-two number of groups in each batch
- No operation group ends with an operation requiring an immediate value
- The last operation group in a batch cannot contain operations requiring immediate values
- OpBatch structural consistency (num_groups <= BATCH_SIZE, group size <= GROUP_SIZE, indptr integrity, bounds checking)
This addresses the gap created by PR 2094, where padding NOOPs are now inserted at assembly time rather than dynamically during execution, and adds comprehensive structural validation to prevent deserialization-time panics.
Trait Implementations§
Source§impl Clone for MastForest
impl Clone for MastForest
Source§fn clone(&self) -> MastForest
fn clone(&self) -> MastForest
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for MastForest
impl Debug for MastForest
Source§impl Default for MastForest
impl Default for MastForest
Source§fn default() -> MastForest
fn default() -> MastForest
Source§impl Deserializable for MastForest
impl Deserializable for MastForest
Source§fn read_from<R>(source: &mut R) -> Result<MastForest, DeserializationError>where
R: ByteReader,
fn read_from<R>(source: &mut R) -> Result<MastForest, DeserializationError>where
R: ByteReader,
source, attempts to deserialize these bytes
into Self, and returns the result. Read moreSource§fn read_from_bytes(bytes: &[u8]) -> Result<MastForest, DeserializationError>
fn read_from_bytes(bytes: &[u8]) -> Result<MastForest, DeserializationError>
Source§fn min_serialized_size() -> usize
fn min_serialized_size() -> usize
Source§fn read_from_bytes_with_budget(
bytes: &[u8],
budget: usize,
) -> Result<Self, DeserializationError>
fn read_from_bytes_with_budget( bytes: &[u8], budget: usize, ) -> Result<Self, DeserializationError>
Self from bytes with a byte budget limit. Read moreimpl Eq for MastForest
Source§impl ExecutableMastForest for MastForest
impl ExecutableMastForest for MastForest
Source§fn get_node_by_id(&self, node_id: MastNodeId) -> Option<&MastNode>
fn get_node_by_id(&self, node_id: MastNodeId) -> Option<&MastNode>
Source§fn get_digest_by_id(&self, node_id: MastNodeId) -> Option<Word>
fn get_digest_by_id(&self, node_id: MastNodeId) -> Option<Word>
MastNodeId if present, or
else None. Read moreSource§fn find_procedure_root(&self, digest: Word) -> Option<MastNodeId>
fn find_procedure_root(&self, digest: Word) -> Option<MastNodeId>
MastNodeId of the procedure associated with a given digest, if any.Source§fn advice_map(&self) -> &AdviceMap
fn advice_map(&self) -> &AdviceMap
Source§impl Index<MastNodeId> for MastForest
impl Index<MastNodeId> for MastForest
Source§fn index(
&self,
node_id: MastNodeId,
) -> &<MastForest as Index<MastNodeId>>::Output
fn index( &self, node_id: MastNodeId, ) -> &<MastForest as Index<MastNodeId>>::Output
container[index]) operation. Read moreSource§impl MastForestView for MastForest
impl MastForestView for MastForest
Source§fn node_count(&self) -> usize
fn node_count(&self) -> usize
Source§fn node_entry_at(
&self,
index: usize,
) -> Result<MastNodeEntry, DeserializationError>
fn node_entry_at( &self, index: usize, ) -> Result<MastNodeEntry, DeserializationError>
Source§fn node_digest_at(&self, index: usize) -> Result<Word, DeserializationError>
fn node_digest_at(&self, index: usize) -> Result<Word, DeserializationError>
Source§fn procedure_root_count(&self) -> usize
fn procedure_root_count(&self) -> usize
Source§fn procedure_root_at(
&self,
index: usize,
) -> Result<MastNodeId, DeserializationError>
fn procedure_root_at( &self, index: usize, ) -> Result<MastNodeId, DeserializationError>
Source§fn advice_map(&self) -> AdviceMapView<'_>
fn advice_map(&self) -> AdviceMapView<'_>
Source§fn node_info_at(
&self,
index: usize,
) -> Result<MastNodeInfo, DeserializationError>
fn node_info_at( &self, index: usize, ) -> Result<MastNodeInfo, DeserializationError>
Source§fn all_node_infos(&self) -> Result<Vec<MastNodeInfo>, DeserializationError>
fn all_node_infos(&self) -> Result<Vec<MastNodeInfo>, DeserializationError>
Source§fn procedure_roots(&self) -> Result<Vec<MastNodeId>, DeserializationError>
fn procedure_roots(&self) -> Result<Vec<MastNodeId>, DeserializationError>
Source§impl PartialEq for MastForest
Equality implementations
impl PartialEq for MastForest
Equality implementations
Source§fn eq(&self, other: &MastForest) -> bool
fn eq(&self, other: &MastForest) -> bool
self and other values to be equal, and is used by ==.Source§impl Serializable for MastForest
impl Serializable for MastForest
Source§fn write_into<W>(&self, target: &mut W)where
W: ByteWriter,
fn write_into<W>(&self, target: &mut W)where
W: ByteWriter,
self into bytes and writes these bytes into the target.Source§fn get_size_hint(&self) -> usize
fn get_size_hint(&self) -> usize
Auto Trait Implementations§
impl Freeze for MastForest
impl RefUnwindSafe for MastForest
impl Send for MastForest
impl Sync for MastForest
impl Unpin for MastForest
impl UnsafeUnpin for MastForest
impl UnwindSafe for MastForest
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<D> OwoColorize for D
impl<D> OwoColorize for D
Source§fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
Source§fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
Source§fn black(&self) -> FgColorDisplay<'_, Black, Self>
fn black(&self) -> FgColorDisplay<'_, Black, Self>
Source§fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
Source§fn red(&self) -> FgColorDisplay<'_, Red, Self>
fn red(&self) -> FgColorDisplay<'_, Red, Self>
Source§fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
Source§fn green(&self) -> FgColorDisplay<'_, Green, Self>
fn green(&self) -> FgColorDisplay<'_, Green, Self>
Source§fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
Source§fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
Source§fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
Source§fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
Source§fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
Source§fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
Source§fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
Source§fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
Source§fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
Source§fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
Source§fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
Source§fn white(&self) -> FgColorDisplay<'_, White, Self>
fn white(&self) -> FgColorDisplay<'_, White, Self>
Source§fn on_white(&self) -> BgColorDisplay<'_, White, Self>
fn on_white(&self) -> BgColorDisplay<'_, White, Self>
Source§fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
Source§fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
Source§fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
Source§fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
Source§fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
Source§fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
Source§fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
Source§fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
Source§fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
Source§fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
Source§fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
Source§fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
Source§fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
Source§fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
Source§fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
Source§fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
Source§fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
Source§fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
Source§fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
Source§fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
Source§fn bold(&self) -> BoldDisplay<'_, Self>
fn bold(&self) -> BoldDisplay<'_, Self>
Source§fn dimmed(&self) -> DimDisplay<'_, Self>
fn dimmed(&self) -> DimDisplay<'_, Self>
Source§fn italic(&self) -> ItalicDisplay<'_, Self>
fn italic(&self) -> ItalicDisplay<'_, Self>
Source§fn underline(&self) -> UnderlineDisplay<'_, Self>
fn underline(&self) -> UnderlineDisplay<'_, Self>
Source§fn blink(&self) -> BlinkDisplay<'_, Self>
fn blink(&self) -> BlinkDisplay<'_, Self>
Source§fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
Source§fn reversed(&self) -> ReversedDisplay<'_, Self>
fn reversed(&self) -> ReversedDisplay<'_, Self>
Source§fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
Source§fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::fg or
a color-specific method, such as OwoColorize::green, Read moreSource§fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::bg or
a color-specific method, such as OwoColorize::on_yellow, Read more