pub struct DeferredState { /* private fields */ }Expand description
In-memory witness for deferred-DAG verification.
The state keeps registered nodes, host-side evaluation memos, and the current deferred root.
Evaluation memos are valid only under the same PrecompileRegistry semantics used to populate
them. The state is intentionally not serialized directly. DeferredStateWire is the retained
low-level transport representation, and Self::from_wire rebuilds this state only after
registry checks, canonical wire checks, and root evaluation.
Implementations§
Source§impl DeferredState
impl DeferredState
pub fn new(registry: Arc<PrecompileRegistry>) -> Result<Self, PrecompileError>
Sourcepub fn extend_precompiles(
&mut self,
precompiles: PrecompileRegistry,
) -> Result<(), PrecompileError>
pub fn extend_precompiles( &mut self, precompiles: PrecompileRegistry, ) -> Result<(), PrecompileError>
Adds precompiles to this state without discarding existing nodes, evaluation memos, root, or budget accounting.
Registration is additive only: duplicate precompile ids panic via
PrecompileRegistry::merge, matching setup-time registry construction behavior. The
state is cloned before mutation so failed precompile initialization leaves self
unchanged.
pub fn registry(&self) -> &PrecompileRegistry
Sourcepub fn root(&self) -> Digest
pub fn root(&self) -> Digest
Returns the current deferred root; super::TRUE_DIGEST means no statements are logged.
pub fn get_node(&self, digest: &Digest) -> Option<&Node>
Sourcepub fn get_canonical_digest(&self, digest: Digest) -> Option<Digest>
pub fn get_canonical_digest(&self, digest: Digest) -> Option<Digest>
Returns the already-memoized canonical digest for digest, if present.
This is strictly read-only: it does not evaluate digest, validate deferred nodes, insert
canonical results, or mutate the memo table. Missing memos and dangling memos whose
canonical node is absent from this state both return None.
Sourcepub fn get_canonical_node(&self, digest: Digest) -> Option<(Digest, &Node)>
pub fn get_canonical_node(&self, digest: Digest) -> Option<(Digest, &Node)>
Returns the already-memoized canonical node for digest, if present.
This is strictly read-only and returns only canonical results that are already memoized and stored in this state.
Sourcepub fn require_canonical_node(
&self,
digest: Digest,
) -> Result<(Digest, &Node), PrecompileError>
pub fn require_canonical_node( &self, digest: Digest, ) -> Result<(Digest, &Node), PrecompileError>
Returns the already-memoized canonical node for digest or
PrecompileError::MissingNode.
This is strictly read-only and never evaluates or mutates deferred state.
pub fn nodes(&self) -> &BTreeMap<Digest, Node>
Sourcepub fn num_elements(&self) -> usize
pub fn num_elements(&self) -> usize
Returns the approximate number of field elements occupied by registered deferred nodes.
pub fn remaining_elements(&self) -> usize
Sourcepub fn decode(&self, tag: Tag) -> Result<NodeType, PrecompileError>
pub fn decode(&self, tag: Tag) -> Result<NodeType, PrecompileError>
Recognizes tag under the installed registry and returns its declared outer payload shape.
This does not inspect a payload, validate structural child references, or evaluate
precompile semantics. Self::register performs those checks for a complete node.
Sourcepub fn register(&mut self, node: Node) -> Result<Digest, PrecompileError>
pub fn register(&mut self, node: Node) -> Result<Digest, PrecompileError>
Registers a PrecompileRegistry-valid node in the DAG and evaluates it immediately.
Registration validates the node shape and child references, stores the original node under its own digest, evaluates it under the current registry, stores the canonical result node, preserves helper nodes registered during evaluation, and records the evaluation memo from original digest to canonical digest. The returned digest is always the original node digest. If evaluation fails, registration returns that error immediately. Re-registering an identical successfully registered node is idempotent and budget-free.
Sourcepub fn log_statement(
&mut self,
statement_digest: Digest,
) -> Result<Digest, PrecompileError>
pub fn log_statement( &mut self, statement_digest: Digest, ) -> Result<Digest, PrecompileError>
Logs a statement commitment after proving the current root and statement evaluate to TRUE.
The statement digest must already be registered (present in nodes), unless it is the
implicit TRUE_DIGEST. On success, this inserts the framework AND node, advances the
deferred root, memoizes the new root as TRUE, and returns the new root.
Sourcepub fn log_verified_statement(
&mut self,
statement_digest: Digest,
expected_new_root: Digest,
) -> Result<Digest, PrecompileError>
pub fn log_verified_statement( &mut self, statement_digest: Digest, expected_new_root: Digest, ) -> Result<Digest, PrecompileError>
Logs a statement only if its constrained transition matches expected_new_root.
The VM constrains log_deferred as a Poseidon2 fold over the previous deferred root and
the statement digest. This helper binds the in-memory deferred DAG to that constrained
transition: it validates the expected root before mutating self, then applies the same
semantic checks as Self::log_statement.
Sourcepub fn evaluate_digest(
&mut self,
digest: Digest,
) -> Result<Digest, PrecompileError>
pub fn evaluate_digest( &mut self, digest: Digest, ) -> Result<Digest, PrecompileError>
Evaluates a registered node addressed by digest and returns the canonical node digest.
Evaluation memoization is an implementation detail: callers receive the canonical digest
whether the result was already known or computed by this call. Use Self::get_node with
the returned digest to inspect the canonical node contents.
Sourcepub fn to_wire(&self) -> Result<DeferredStateWire, IntegrityError>
pub fn to_wire(&self) -> Result<DeferredStateWire, IntegrityError>
Serializes the root-reachable DAG into compact canonical wire form.
Only nodes reachable from root are emitted; registered or memoized orphans are dropped.
The installed PrecompileRegistry determines each node’s shape, so graph edges are never
inferred from opaque payload bytes. Encoding preserves the state representation and does not
establish its validity; failures to materialize canonical wire are returned to the caller.
Sourcepub fn from_wire(
registry: Arc<PrecompileRegistry>,
wire: &DeferredStateWire,
) -> Result<Self, IntegrityError>
pub fn from_wire( registry: Arc<PrecompileRegistry>, wire: &DeferredStateWire, ) -> Result<Self, IntegrityError>
Rebuilds and verifies a deferred state from untrusted wire data.
The wire root is implicit: empty wire opens TRUE_DIGEST, otherwise the root is the
digest of the final entry. Rehydration rejects non-canonical or dangling wire, then
evaluates the implicit root to TRUE under the installed precompiles. The wire remains a
passive transport representation; this supported low-level operation is the explicit seam
that establishes semantic validity under a caller-selected registry.
Trait Implementations§
Source§impl Clone for DeferredState
impl Clone for DeferredState
Source§fn clone(&self) -> DeferredState
fn clone(&self) -> DeferredState
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 DeferredState
impl Debug for DeferredState
Auto Trait Implementations§
impl !RefUnwindSafe for DeferredState
impl !UnwindSafe for DeferredState
impl Freeze for DeferredState
impl Send for DeferredState
impl Sync for DeferredState
impl Unpin for DeferredState
impl UnsafeUnpin for DeferredState
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<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