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()?;For maximum protection against denial-of-service attacks from malicious input, use
UntrustedMastForest::read_from_bytes_with_budget which limits memory consumption:
ⓘ
use miden_core::mast::UntrustedMastForest;
// Budget limits pre-allocation sizes and total bytes consumed
let forest = UntrustedMastForest::read_from_bytes_with_budget(&bytes, bytes.len())?
.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).
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.
- 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. - 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
Decorator Ids - A two-level compressed sparse row (CSR) representation for indexing decorator IDs per operation per node.
- 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.
- 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§
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.