Skip to main content

miden_processor/host/advice/
errors.rs

1// Allow unused assignments - required by miette::Diagnostic derive macro
2#![allow(unused_assignments)]
3
4use alloc::vec::Vec;
5
6use miden_core::deferred::PrecompileError;
7use miden_utils_diagnostics::{Diagnostic, miette};
8
9use crate::{Felt, Word, crypto::merkle::MerkleError};
10
11#[derive(Debug, thiserror::Error, Diagnostic)]
12pub enum AdviceError {
13    #[error(
14        "value for key {} already present in the advice map: previous values were '{prev_values:?}', attempted replacement values were '{new_values:?}'",
15        key.to_hex()
16    )]
17    MapKeyAlreadyPresent {
18        key: Word,
19        prev_values: Vec<Felt>,
20        new_values: Vec<Felt>,
21    },
22    #[error("value for key {} not present in the advice map", .key.to_hex())]
23    MapKeyNotFound { key: Word },
24    #[error("advice stack read failed")]
25    StackReadFailed,
26    #[error(
27        "advice stack size exceeded: pushing {push_count} elements would exceed the maximum of {max}"
28    )]
29    StackSizeExceeded { push_count: usize, max: usize },
30    #[error("advice map value size of {size} exceeds the maximum of {max}")]
31    AdvMapValueSizeExceeded { size: usize, max: usize },
32    #[error(
33        "advice map element budget exceeded: adding {added} elements to the current {current} would exceed the maximum of {max}"
34    )]
35    AdvMapElementBudgetExceeded { current: usize, added: usize, max: usize },
36    #[error(
37        "Merkle store node budget exceeded: adding {added} nodes to the current {current} would exceed the maximum of {max}"
38    )]
39    MerkleStoreNodeBudgetExceeded { current: usize, added: usize, max: usize },
40    #[error("failed to initialize deferred state with the built-in precompile registry")]
41    DeferredStateInitializationFailed(#[source] PrecompileError),
42    #[error(
43        "provided merkle tree {depth} is out of bounds and cannot be represented as an unsigned 8-bit integer"
44    )]
45    InvalidMerkleTreeDepth { depth: Felt },
46    #[error("provided node index {index} is out of bounds for a merkle tree node at depth {depth}")]
47    InvalidMerkleTreeNodeIndex { depth: Felt, index: Felt },
48    #[error("failed to lookup value in Merkle store")]
49    MerkleStoreLookupFailed(#[source] MerkleError),
50    /// Note: This error currently never occurs, since `MerkleStore::merge_roots()` never fails.
51    #[error("Merkle store backend merge failed")]
52    MerkleStoreMergeFailed(#[source] MerkleError),
53    #[error("Merkle store backend update failed")]
54    MerkleStoreUpdateFailed(#[source] MerkleError),
55}