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_options with
UntrustedMastForestReadOptions to tune the wire byte budget. This limits allocations driven
directly by wire counts while reading the payload. A separate validation helper budget is
derived from it for later allocations needed to materialize and check hashless payloads.
use miden_core::mast::{UntrustedMastForest, UntrustedMastForestReadOptions};
let options = UntrustedMastForestReadOptions::new()
.with_wire_byte_budget(bytes.len());
let forest = UntrustedMastForest::read_from_bytes_with_options(&bytes, options)?
.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. MastForestWireView::new: trusted wire-backed cache access; scans only the layout needed for random access and rejects hashless payloads.UntrustedMastForest::read_from_bytesandUntrustedMastForest::read_from_bytes_with_options: untrusted paths; parse with bounded readers and requireUntrustedMastForest::validatebefore use.
Structs§
- Advice
MapView - Read-only view over forest advice.
- Advice
Value View - Read-only view over a value from forest advice.
- Basic
Block Node - Block for a linear sequence of operations (i.e., no branching or loops).
- Basic
Block Node Builder - Builder for creating
BasicBlockNodeinstances. - 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. - DynNode
- A Dyn node specifies that the node to be executed next is defined dynamically via the stack.
- DynNode
Builder - Builder for creating
DynNodeinstances. - External
Node - Node for referencing procedures not present in a given
MastForest(hence “external”). - External
Node Builder - Builder for creating
ExternalNodeinstances. - 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. - 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``, except for the encounter which it executes unconditionally.
- Loop
Node Builder - Builder for creating
LoopNodeinstances. - Mast
Forest - Represents one or more procedures, represented as a collection of
MastNodes. - Mast
Forest Id - Mast
Forest Root Map - A mapping for the new location of the roots of a
MastForestafter a merge. - Mast
Forest Wire View - A trusted wire-backed view over serialized MAST forest bytes.
- 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.
- OpBatch
- A batch of operations in a span block.
- Sparse
Mast Forest - A sparse replay view over a single source
MastForest’sMastNodeIdspace, retaining only the nodes visited during execution. - Sparse
Mast Forest Builder - Incrementally builds a
SparseMastForestby collecting theMastNodeIds of nodes visited during execution of a single sourceMastForest. - 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. - 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. - Untrusted
Mast Forest Read Options - Options for reading an
UntrustedMastForestfrom bytes.
Enums§
- Mast
Forest Error - Represents the types of errors that can occur when dealing with MAST forest.
- Mast
Forest Read Mode - Trusted read backing mode for read-only MAST forest access.
- Mast
Forest Read View - Read-only trusted MAST forest handle.
- 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. - Visit
Kind - Describes how a node referenced during execution should be represented in the resulting
SparseMastForest.
Constants§
- OP_
BATCH_ SIZE - Maximum number of groups per batch.
- OP_
GROUP_ SIZE - Maximum number of operations per group.
Traits§
- Executable
Mast Forest - A MAST forest that can be used as the source of nodes during program execution.
- 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 using the provided mapping.
- 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§
- Remapping
- Operations that mutate a MAST often produce this mapping between old and new NodeIds.