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_utils_diagnostics::{Diagnostic, miette};
7
8use crate::{Felt, Word, crypto::merkle::MerkleError};
9
10#[derive(Debug, thiserror::Error, Diagnostic)]
11pub enum AdviceError {
12    #[error(
13        "value for key {} already present in the advice map: previous values were '{prev_values:?}', attempted replacement values were '{new_values:?}'",
14        key.to_hex()
15    )]
16    MapKeyAlreadyPresent {
17        key: Word,
18        prev_values: Vec<Felt>,
19        new_values: Vec<Felt>,
20    },
21    #[error("value for key {} not present in the advice map", .key.to_hex())]
22    MapKeyNotFound { key: Word },
23    #[error("advice stack read failed")]
24    StackReadFailed,
25    #[error(
26        "advice stack size exceeded: pushing {push_count} elements would exceed the maximum of {max}"
27    )]
28    StackSizeExceeded { push_count: usize, max: usize },
29    #[error("advice map value size of {size} exceeds the maximum of {max}")]
30    AdvMapValueSizeExceeded { size: usize, max: usize },
31    #[error(
32        "advice map element budget exceeded: adding {added} elements to the current {current} would exceed the maximum of {max}"
33    )]
34    AdvMapElementBudgetExceeded { current: usize, added: usize, max: usize },
35    #[error(
36        "Merkle store node budget exceeded: adding {added} nodes to the current {current} would exceed the maximum of {max}"
37    )]
38    MerkleStoreNodeBudgetExceeded { current: usize, added: usize, max: usize },
39    #[error(
40        "precompile request count budget exceeded: adding {added} requests to the current {current} would exceed the maximum of {max}"
41    )]
42    PrecompileRequestCountExceeded { current: usize, added: usize, max: usize },
43    #[error(
44        "precompile request calldata byte budget exceeded: adding {added} bytes to the current {current} would exceed the maximum of {max}"
45    )]
46    PrecompileRequestCalldataBudgetExceeded { current: usize, added: usize, max: usize },
47    #[error(
48        "provided merkle tree {depth} is out of bounds and cannot be represented as an unsigned 8-bit integer"
49    )]
50    InvalidMerkleTreeDepth { depth: Felt },
51    #[error("provided node index {index} is out of bounds for a merkle tree node at depth {depth}")]
52    InvalidMerkleTreeNodeIndex { depth: Felt, index: Felt },
53    #[error("failed to lookup value in Merkle store")]
54    MerkleStoreLookupFailed(#[source] MerkleError),
55    /// Note: This error currently never occurs, since `MerkleStore::merge_roots()` never fails.
56    #[error("Merkle store backend merge failed")]
57    MerkleStoreMergeFailed(#[source] MerkleError),
58    #[error("Merkle store backend update failed")]
59    MerkleStoreUpdateFailed(#[source] MerkleError),
60}