miden_lib/errors/
transaction_errors.rs1use alloc::{boxed::Box, vec::Vec};
2use core::error::Error;
3
4use miden_objects::{AccountDeltaError, AssetError, Digest, Felt, NoteError, note::NoteMetadata};
5use thiserror::Error;
6
7#[derive(Debug, Error)]
11pub enum TransactionKernelError {
12 #[error("failed to add asset to account delta")]
13 AccountDeltaAddAssetFailed(#[source] AccountDeltaError),
14 #[error("failed to remove asset to account delta")]
15 AccountDeltaRemoveAssetFailed(#[source] AccountDeltaError),
16 #[error("failed to add asset to note")]
17 FailedToAddAssetToNote(#[source] NoteError),
18 #[error("note input data has hash {actual} but expected hash {expected}")]
19 InvalidNoteInputs { expected: Digest, actual: Digest },
20 #[error(
21 "storage slot index {actual} is invalid, must be smaller than the number of account storage slots {max}"
22 )]
23 InvalidStorageSlotIndex { max: u64, actual: u64 },
24 #[error("failed to push element {0} to advice stack")]
25 FailedToPushAdviceStack(Felt),
26 #[error("failed to generate signature: {0}")]
27 FailedSignatureGeneration(&'static str),
28 #[error("asset data extracted from the stack by event handler `{handler}` is not well formed")]
29 MalformedAssetInEventHandler {
30 handler: &'static str,
31 source: AssetError,
32 },
33 #[error(
34 "note inputs data extracted from the advice map by the event handler is not well formed"
35 )]
36 MalformedNoteInputs(#[source] NoteError),
37 #[error("note metadata created by the event handler is not well formed")]
38 MalformedNoteMetadata(#[source] NoteError),
39 #[error(
40 "note script data `{data:?}` extracted from the advice map by the event handler is not well formed"
41 )]
42 MalformedNoteScript {
43 data: Vec<Felt>,
44 source: Box<dyn Error + Send + Sync + 'static>,
47 },
48 #[error("recipient data `{0:?}` in the advice provider is not well formed")]
49 MalformedRecipientData(Vec<Felt>),
50 #[error("cannot add asset to note with index {0}, note does not exist in the advice provider")]
51 MissingNote(u64),
52 #[error(
53 "public note with metadata {0:?} and recipient digest {1} is missing details in the advice provider"
54 )]
55 PublicNoteMissingDetails(NoteMetadata, Digest),
56 #[error(
57 "note input data in advice provider contains fewer elements ({actual}) than specified ({specified}) by its inputs length"
58 )]
59 TooFewElementsForNoteInputs { specified: u64, actual: u64 },
60 #[error("account procedure with procedure root {0} is not in the advice provider")]
61 UnknownAccountProcedure(Digest),
62 #[error("code commitment {0} is not in the advice provider")]
63 UnknownCodeCommitment(Digest),
64 #[error("account storage slots number is missing in memory at address {0}")]
65 AccountStorageSlotsNumMissing(u32),
66}
67
68#[derive(Debug, Error)]
72pub enum TransactionEventError {
73 #[error("event id {0} is not a valid transaction event")]
74 InvalidTransactionEvent(u32),
75 #[error("event id {0} is not a transaction kernel event")]
76 NotTransactionEvent(u32),
77 #[error("event id {0} can only be emitted from the root context")]
78 NotRootContext(u32),
79}
80
81#[derive(Debug, Error)]
85pub enum TransactionTraceParsingError {
86 #[error("trace id {0} is an unknown transaction kernel trace")]
87 UnknownTransactionTrace(u32),
88}
89
90#[cfg(test)]
91mod error_assertions {
92 use super::*;
93
94 fn _assert_error_is_send_sync_static<E: core::error::Error + Send + Sync + 'static>(_: E) {}
96
97 fn _assert_transaction_kernel_error_bounds(err: TransactionKernelError) {
98 _assert_error_is_send_sync_static(err);
99 }
100}