Expand description
MAST forest: a collection of procedures represented as Merkle trees.
§Deserializing from untrusted sources
When loading a MastForest from bytes you don’t fully trust (network, user upload, etc.),
use UntrustedMastForest instead of calling MastForest::read_from_bytes directly:
use miden_core::mast::UntrustedMastForest;
let forest = UntrustedMastForest::read_from_bytes(&bytes)?
.validate()?;UntrustedMastForest::read_from_bytes applies default parsing and validation budgets derived
from the input size. Use UntrustedMastForest::read_from_bytes_with_budget to tune only the
wire-parsing budget, or UntrustedMastForest::read_from_bytes_with_budgets to tune both:
the parsing budget limits allocations driven directly by wire counts while reading the payload,
and the validation budget limits later helper allocations needed to materialize and check
stripped or hashless payloads.
use miden_core::mast::UntrustedMastForest;
// Parsing budget only
let forest = UntrustedMastForest::read_from_bytes_with_budget(&bytes, bytes.len())?
.validate()?;
// Parsing budget plus explicit validation-allocation budget
let forest = UntrustedMastForest::read_from_bytes_with_budgets(&bytes, bytes.len(), bytes.len() * 7)?
.validate()?;This recomputes all node hashes and checks structural invariants before returning a usable
MastForest. Direct deserialization via MastForest::read_from_bytes trusts the serialized
hashes and should only be used for data from trusted sources (e.g. compiled locally).
In practice, the public entry points split into three policies:
MastForest::read_from_bytes: trusted full deserialization; rejects hashless payloads and trusts serialized non-external digests.SerializedMastForest::new: structural inspection path for local tooling; scans only the layout needed for random access and may accept full, stripped, or hashless payloads, but it is not an untrusted-validation entry point.UntrustedMastForest::read_from_bytesandUntrustedMastForest::read_from_bytes_with_budgets: untrusted paths; parse with bounded readers and requireUntrustedMastForest::validatebefore use.
Structs§
- AsmOpId
- Unique identifier for an
AssemblyOpwithin aMastForest. - Basic
Block Node - Block for a linear sequence of operations (i.e., no branching or loops).
- Basic
Block Node Builder - Builder for creating
BasicBlockNodeinstances with decorators. - Call
Node - A Call node describes a function call such that the callee is executed in a different execution context from the currently executing code.
- Call
Node Builder - Builder for creating
CallNodeinstances with decorators. - Debug
Info - Debug information for a MAST forest, containing decorators and error messages.
- Debug
VarId - An identifier for a debug variable stored in DebugInfo.
- Decorated
Links - Immutable view over all
(op_idx, DecoratorId)pairs for a node. Uses the two-level CSR encoded bynode_indptr_for_op_idxandop_indptr_for_dec_idx. - Decorated
Links Iter - The concrete, zero-alloc iterator over
(relative_op_idx, DecoratorId). - Decorator
Id - An opaque handle to a
Decoratorin someMastForest. It is the responsibility of the user to use a givenDecoratorIdwith the correspondingMastForest. - Decorator
OpLink Iterator - Iterator used to iterate through the op-indexed decorators of a basic block.
- DynNode
- A Dyn node specifies that the node to be executed next is defined dynamically via the stack.
- DynNode
Builder - Builder for creating
DynNodeinstances with decorators. - External
Node - Node for referencing procedures not present in a given
MastForest(hence “external”). - External
Node Builder - Builder for creating
ExternalNodeinstances with decorators. - Join
Node - A Join node describe sequential execution. When the VM encounters a Join node, it executes the first child first and the second child second.
- Join
Node Builder - Builder for creating
JoinNodeinstances with decorators. - Loop
Node - A Loop node defines condition-controlled iterative execution. When the VM encounters a Loop node, it will keep executing the body of the loop as long as the top of the stack is `1``.
- Loop
Node Builder - Builder for creating
LoopNodeinstances with decorators. - Mast
Forest - Represents one or more procedures, represented as a collection of
MastNodes. - Mast
Forest Root Map - A mapping for the new location of the roots of a
MastForestafter a merge. - Mast
Node Fingerprint - Represents the hash used to test for equality between
crate::mast::MastNodes. - Mast
Node Id - An opaque handle to a
MastNodein someMastForest. It is the responsibility of the user to use a givenMastNodeIdwith the correspondingMastForest. - Mast
Node Info - Logical node metadata combining fixed-width structure and a digest value.
- Node
ToDecorator Ids - A CSR (Compressed Sparse Row) representation for storing node-level decorators (before_enter and after_exit).
- OpBatch
- A batch of operations in a span block.
- OpTo
AsmOp Id - CSR storage mapping (NodeId, OpIdx) -> AsmOpId.
- OpTo
Debug VarIds - A two-level compressed sparse row (CSR) representation for indexing debug variable IDs per operation per node.
- OpTo
Decorator Ids - A two-level compressed sparse row (CSR) representation for indexing decorator IDs per operation per node.
- Serialized
Mast Forest - A zero-copy structural view over serialized MAST forest bytes.
- Split
Node - A Split node defines conditional execution. When the VM encounters a Split node it executes
either the
on_truechild oron_falsechild. - Split
Node Builder - Builder for creating
SplitNodeinstances with decorators. - Subtree
Iterator - Iterates over all the nodes a root depends on, in pre-order. The iteration can include other roots in the same forest.
- Untrusted
Mast Forest - A
MastForestdeserialized from untrusted input that has not yet been validated.
Enums§
- AsmOp
Index Error - Error type for AsmOp index mapping operations.
- Decorator
Index Error - Error type for decorator index mapping operations
- Decorator
Store - A data structure for storing decorators for MAST nodes, including both operation-level decorators and node-level decorators (before_enter/after_exit).
- Mast
Forest Error - Represents the types of errors that can occur when dealing with MAST forest.
- Mast
Node - Mast
Node Builder - Enum of all MAST node builders that can be added to a forest. This allows for generic handling of different builder types through enum dispatch.
- Mast
Node Entry - Fixed-width structural metadata for a serialized
MastNode. - Operation
OrDecorator - Encodes either an
Operationor acrate::operations::Decorator.
Constants§
- OP_
BATCH_ SIZE - Maximum number of groups per batch.
- OP_
GROUP_ SIZE - Maximum number of operations per group.
Traits§
- Mast
Forest Contributor - Mast
Forest View - Read-only view over serialization-oriented MAST node metadata.
- Mast
Node Ext
Functions§
- build_
node_ with_ remapped_ ids - Builds a node builder with remapped children and decorators using the provided mappings.
- error_
code_ from_ msg - Derives an error code from an error message by hashing the message and returning the 0th element
of the resulting
Word.
Type Aliases§
- Decorated
OpLink - Decorator
Fingerprint - Remapping
- Operations that mutate a MAST often produce this mapping between old and new NodeIds.