pub struct UntrustedMastForest { /* private fields */ }Expand description
A MastForest deserialized from untrusted input that has not yet been validated.
This type wraps a serialized-backed, decoded MAST representation that has not had its node
hashes verified. Before using the forest, callers must call validate() to
materialize and verify structural integrity and node hashes.
§Usage
// Deserialize from untrusted bytes
let untrusted = UntrustedMastForest::read_from_bytes(&bytes)?;
// Validate structure and hashes
let forest = untrusted.validate()?;
// Now safe to use
let root = forest.procedure_roots()[0];§Security
This type exists to provide type-level safety for untrusted deserialization. The validation
performed by validate() includes:
- Structural validation: Checks that basic block batch invariants are satisfied and procedure names reference valid roots.
- Topological ordering: Verifies that all node references point to nodes that appear earlier in the forest (no forward references).
- Hash recomputation: Recomputes the digest for every node and verifies it matches the stored digest.
Implementations§
Source§impl UntrustedMastForest
impl UntrustedMastForest
Sourcepub fn validate(self) -> Result<MastForest, MastForestError>
pub fn validate(self) -> Result<MastForest, MastForestError>
Validates the forest by checking structural invariants and recomputing all node hashes.
This method performs a complete validation of the deserialized forest:
- If wire node hashes are present, recomputes all non-external node hashes and requires them to match the serialized digests.
- If the payload is hashless, uses the digests rebuilt during materialization.
- Validates structural invariants, topological ordering, and procedure-name roots.
§Returns
Ok(MastForest)if validation succeedsErr(MastForestError)with details about the first validation failure
§Errors
Returns an error if:
- Deferred materialization from serialized form fails (
MastForestError::Deserialization) - Any basic block has invalid batch structure (
MastForestError::InvalidBatchPadding) - Any procedure name references a non-root digest
(
MastForestError::InvalidProcedureNameDigest) - Any node references a child that appears later in the forest
(
MastForestError::ForwardReference) - Any non-external wire digest does not match the recomputed digest
(
MastForestError::HashMismatch) - Any node’s digest cannot be recomputed because structural validation fails first
Security convention:
- Hashless payloads rebuild non-external digests from structure during materialization.
- If wire node hashes are present, validation recomputes them and requires them to match.
- External node digests are marshaled as opaque values and are not semantically resolved here.
Sourcepub fn read_from_bytes(
bytes: &[u8],
) -> Result<UntrustedMastForest, DeserializationError>
pub fn read_from_bytes( bytes: &[u8], ) -> Result<UntrustedMastForest, DeserializationError>
Deserializes an UntrustedMastForest from bytes.
This method uses a BudgetedReader plus a bounded validation-allocation budget derived
from the input size to protect against denial-of-service attacks from malicious input.
The default validation budget includes room for the retained serialized copy used by the
deferred-validation path, in addition to stripped/hashless helper allocations. Concretely,
the default is bytes.len() for parsing and bytes.len() * 7 for validation allocations.
That * 7 factor is a coarse convenience bound, not an exact peak-memory formula.
For explicit parsing and validation limits, use
read_from_bytes_with_budgets.
§Example
// Read from untrusted source
let untrusted = UntrustedMastForest::read_from_bytes(&bytes)?;
// Validate before use
let forest = untrusted.validate()?;Sourcepub fn read_from_bytes_with_flags(
bytes: &[u8],
) -> Result<(UntrustedMastForest, u8), DeserializationError>
pub fn read_from_bytes_with_flags( bytes: &[u8], ) -> Result<(UntrustedMastForest, u8), DeserializationError>
Deserializes an UntrustedMastForest from bytes and returns the raw wire flags.
This enables callers to inspect serializer intent flags (e.g., HASHLESS) without affecting the untrusted deserialization path.
Sourcepub fn read_from_bytes_with_budget(
bytes: &[u8],
budget: usize,
) -> Result<UntrustedMastForest, DeserializationError>
pub fn read_from_bytes_with_budget( bytes: &[u8], budget: usize, ) -> Result<UntrustedMastForest, DeserializationError>
Deserializes an UntrustedMastForest from bytes with a byte budget.
This method uses a BudgetedReader to limit memory consumption during deserialization,
protecting against denial-of-service attacks from malicious input that claims to contain
an excessive number of elements.
§Arguments
bytes- The serialized forest bytesbudget- Maximum bytes to consume while parsing the wire payload and pre-sizing wire-driven collections viaBudgetedReader
§Example
// Read from untrusted source with an explicit parsing budget
let untrusted = UntrustedMastForest::read_from_bytes_with_budget(&bytes, bytes.len())?;
// Validate before use
let forest = untrusted.validate()?;§Security
The budget limits:
- Pre-allocation sizes when deserializing collections (via
max_alloc) - Total bytes consumed during deserialization
This prevents attacks where malicious input claims an unrealistic number of elements
(e.g., len = 2^60), causing excessive memory allocation before any data is read.
To also cap stripped/hashless validation helper allocations, use
read_from_bytes_with_budgets.
Sourcepub fn read_from_bytes_with_budget_and_flags(
bytes: &[u8],
budget: usize,
) -> Result<(UntrustedMastForest, u8), DeserializationError>
pub fn read_from_bytes_with_budget_and_flags( bytes: &[u8], budget: usize, ) -> Result<(UntrustedMastForest, u8), DeserializationError>
Deserializes an UntrustedMastForest from bytes with a byte budget and returns flags.
Sourcepub fn read_from_bytes_with_budgets(
bytes: &[u8],
parsing_budget: usize,
validation_budget: usize,
) -> Result<UntrustedMastForest, DeserializationError>
pub fn read_from_bytes_with_budgets( bytes: &[u8], parsing_budget: usize, validation_budget: usize, ) -> Result<UntrustedMastForest, DeserializationError>
Deserializes an UntrustedMastForest from bytes with separate parsing and validation
budgets.
parsing_budget limits wire-driven parsing and collection pre-sizing. validation_budget
additionally caps tracked stripped/hashless helper allocations such as digest slot tables,
empty debug-info scaffolding, and rebuilt digest tables.
Sourcepub fn read_from_bytes_with_budgets_and_flags(
bytes: &[u8],
parsing_budget: usize,
validation_budget: usize,
) -> Result<(UntrustedMastForest, u8), DeserializationError>
pub fn read_from_bytes_with_budgets_and_flags( bytes: &[u8], parsing_budget: usize, validation_budget: usize, ) -> Result<(UntrustedMastForest, u8), DeserializationError>
Deserializes an UntrustedMastForest from bytes with separate parsing and validation
budgets and returns flags.
Trait Implementations§
Source§impl Clone for UntrustedMastForest
impl Clone for UntrustedMastForest
Source§fn clone(&self) -> UntrustedMastForest
fn clone(&self) -> UntrustedMastForest
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 UntrustedMastForest
impl Debug for UntrustedMastForest
Source§impl Deserializable for UntrustedMastForest
impl Deserializable for UntrustedMastForest
Source§fn read_from<R>(
source: &mut R,
) -> Result<UntrustedMastForest, DeserializationError>where
R: ByteReader,
fn read_from<R>(
source: &mut R,
) -> Result<UntrustedMastForest, DeserializationError>where
R: ByteReader,
Deserializes an super::UntrustedMastForest from a byte reader.
Note: This method does not apply budgeting. For untrusted input, prefer using
read_from_bytes which applies budgeted deserialization.
After deserialization, callers should use super::UntrustedMastForest::validate()
to verify structural integrity and recompute all node hashes before using
the forest.
Source§fn read_from_bytes(
bytes: &[u8],
) -> Result<UntrustedMastForest, DeserializationError>
fn read_from_bytes( bytes: &[u8], ) -> Result<UntrustedMastForest, DeserializationError>
Deserializes an super::UntrustedMastForest from bytes using budgeted deserialization.
This method uses the default untrusted wire/validation budget from
super::UntrustedMastForest::read_from_bytes.
After deserialization, callers should use super::UntrustedMastForest::validate()
to verify structural integrity and recompute all node hashes before using
the forest.
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 moreAuto Trait Implementations§
impl Freeze for UntrustedMastForest
impl RefUnwindSafe for UntrustedMastForest
impl Send for UntrustedMastForest
impl Sync for UntrustedMastForest
impl Unpin for UntrustedMastForest
impl UnsafeUnpin for UntrustedMastForest
impl UnwindSafe for UntrustedMastForest
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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