Skip to main content

miden_protocol/errors/
mod.rs

1use alloc::boxed::Box;
2use alloc::string::String;
3use alloc::vec::Vec;
4use core::error::Error;
5
6use miden_assembly::Report;
7use miden_assembly::diagnostics::reporting::PrintDiagnostic;
8use miden_core::mast::MastForestError;
9use miden_crypto::merkle::mmr::MmrError;
10use miden_crypto::merkle::smt::{SmtLeafError, SmtProofError};
11use miden_crypto::utils::HexParseError;
12use miden_processor::ExecutionError;
13use miden_verifier::VerificationError;
14use thiserror::Error;
15
16use super::account::{AccountId, RoleSymbol};
17use super::asset::{Asset, AssetComposition, AssetId, FungibleAsset, TokenSymbol};
18use super::crypto::merkle::MerkleError;
19use super::note::NoteId;
20use super::{
21    MAX_ACCOUNTS_PER_BLOCK,
22    MAX_BATCHES_PER_BLOCK,
23    MAX_INPUT_NOTES_PER_BLOCK,
24    MAX_OUTPUT_NOTES_PER_BATCH,
25    Word,
26};
27use crate::account::component::{SchemaTypeError, StorageValueName, StorageValueNameError};
28use crate::account::delta::AssetDeltaOperation;
29use crate::account::{
30    AccountCode,
31    AccountHeader,
32    AccountIdPrefix,
33    AccountProcedureRoot,
34    AccountStorage,
35    AccountVaultDelta,
36    StorageMapKey,
37    StorageSlotId,
38    StorageSlotName,
39};
40use crate::address::AddressType;
41use crate::asset::AssetClass;
42use crate::batch::BatchId;
43use crate::block::{BlockNumber, ValidatorConfig};
44use crate::note::{
45    NoteAssets,
46    NoteAttachment,
47    NoteAttachmentScheme,
48    NoteAttachments,
49    NoteTag,
50    NoteType,
51    Nullifier,
52};
53use crate::protocol_config::KernelConfig;
54use crate::script::MastForestScriptError;
55use crate::transaction::TransactionId;
56use crate::utils::serde::DeserializationError;
57use crate::vm::EventId;
58use crate::{
59    ACCOUNT_UPDATE_MAX_SIZE,
60    Felt,
61    MAX_ACCOUNTS_PER_BATCH,
62    MAX_INPUT_NOTES_PER_BATCH,
63    MAX_INPUT_NOTES_PER_TX,
64    MAX_NOTE_STORAGE_ITEMS,
65    MAX_OUTPUT_NOTES_PER_TX,
66    NOTE_MAX_SIZE,
67};
68
69#[cfg(any(feature = "testing", test))]
70mod masm_error;
71#[cfg(any(feature = "testing", test))]
72pub use masm_error::MasmError;
73
74/// The errors from the MASM code of the transaction kernel.
75#[cfg(any(feature = "testing", test))]
76pub mod tx_kernel {
77    include!(concat!(env!("OUT_DIR"), "/tx_kernel_errors.rs"));
78}
79
80/// The errors from the MASM code of the Miden protocol library.
81#[cfg(any(feature = "testing", test))]
82pub mod protocol {
83    include!(concat!(env!("OUT_DIR"), "/protocol_errors.rs"));
84}
85
86// ACCOUNT COMPONENT TEMPLATE ERROR
87// ================================================================================================
88
89#[derive(Debug, Error)]
90pub enum ComponentMetadataError {
91    #[error("storage slot name `{0}` is duplicate")]
92    DuplicateSlotName(StorageSlotName),
93    #[error("storage init value name `{0}` is duplicate")]
94    DuplicateInitValueName(StorageValueName),
95    #[error("storage value name is incorrect: {0}")]
96    IncorrectStorageValueName(#[source] StorageValueNameError),
97    #[error("invalid storage schema: {0}")]
98    InvalidSchema(String),
99    #[error("type `{0}` is not valid for `{1}` slots")]
100    InvalidType(String, String),
101    #[error("error deserializing component metadata: {0}")]
102    MetadataDeserializationError(String),
103    #[error("init storage value `{0}` was not provided")]
104    InitValueNotProvided(StorageValueName),
105    #[error("invalid init storage value for `{0}`: {1}")]
106    InvalidInitStorageValue(StorageValueName, String),
107    #[error("error converting value into expected type: {0}")]
108    StorageValueParsingError(#[source] SchemaTypeError),
109    #[error("storage map contains duplicate keys")]
110    StorageMapHasDuplicateKeys(#[source] Box<dyn Error + Send + Sync + 'static>),
111    #[cfg(feature = "std")]
112    #[error("error trying to deserialize from toml")]
113    TomlDeserializationError(#[source] toml::de::Error),
114    #[cfg(feature = "std")]
115    #[error("error trying to deserialize from toml")]
116    TomlSerializationError(#[source] toml::ser::Error),
117}
118
119// ACCOUNT ERROR
120// ================================================================================================
121
122#[derive(Debug, Error)]
123pub enum AccountError {
124    #[error("account code does not contain an auth component")]
125    AccountCodeNoAuthComponent,
126    #[error("account code contains multiple auth components")]
127    AccountCodeMultipleAuthComponents,
128    #[error("account code must contain at least one non-auth procedure")]
129    AccountCodeNoProcedures,
130    #[error("account procedure {0} is not contained in the provided mast forest")]
131    AccountCodeProcedureNotInMastForest(AccountProcedureRoot),
132    #[error("account code contains {0} procedures but it may contain at most {max} procedures", max = AccountCode::MAX_NUM_PROCEDURES)]
133    AccountCodeTooManyProcedures(usize),
134    #[error("account code contains a duplicate procedure with root {0}")]
135    AccountCodeDuplicateProcedureRoot(AccountProcedureRoot),
136    #[error(
137        "account code procedures following the authentication procedure are not sorted in ascending order"
138    )]
139    AccountCodeProceduresUnsorted,
140    #[error("failed to assemble account component:\n{}", PrintDiagnostic::new(.0))]
141    AccountComponentAssemblyError(Report),
142    #[error("failed to merge components into one account code mast forest")]
143    AccountComponentMastForestMergeError(#[source] MastForestError),
144    #[error("account component contains multiple authentication procedures")]
145    AccountComponentMultipleAuthProcedures,
146    #[error(
147        "storage of account {0} contains an asset callback slot but its asset callback flag is disabled, so the callback would never be invoked"
148    )]
149    AssetCallbackSlotWithDisabledFlag(AccountId),
150    #[error("failed to update asset vault")]
151    AssetVaultUpdateError(#[source] AssetVaultError),
152    #[error("account build error: {0}")]
153    BuildError(String, #[source] Option<Box<AccountError>>),
154    #[error("failed to parse account ID from final account header")]
155    FinalAccountHeaderIdParsingFailed(#[source] AccountIdError),
156    #[error("account header data has length {actual} but it must be of length {expected}",
157        expected = AccountHeader::NUM_ELEMENTS
158    )]
159    UnexpectedHeaderLength { actual: usize },
160    #[error("account has an unsupported version {0}")]
161    UnsupportedAccountVersion(u64),
162    #[error("final nonce {new} is not strictly greater than current account nonce {current}")]
163    NonceMustIncrease { current: Felt, new: Felt },
164    #[error(
165        "digest of the seed has {actual} trailing zeroes but must have at least {expected} trailing zeroes"
166    )]
167    SeedDigestTooFewTrailingZeros { expected: u32, actual: u32 },
168    #[error("account ID {actual} computed from seed does not match ID {expected} on account")]
169    AccountIdSeedMismatch { actual: AccountId, expected: AccountId },
170    #[error("account ID seed was provided for an existing account")]
171    ExistingAccountWithSeed,
172    #[error("account ID seed was not provided for a new account")]
173    NewAccountMissingSeed,
174    #[error(
175        "an account with a seed cannot be converted into a delta since it represents an unregistered account"
176    )]
177    DeltaFromAccountWithSeed,
178    #[error(
179        "an account with a seed cannot be converted into a patch since it represents an unregistered account"
180    )]
181    PatchFromAccountWithSeed,
182    #[error("seed converts to an invalid account ID")]
183    SeedConvertsToInvalidAccountId(#[source] AccountIdError),
184    #[error("storage map root {0} not found in the account storage")]
185    StorageMapRootNotFound(Word),
186    #[error("storage slot {0} is not of type map")]
187    StorageSlotNotMap(StorageSlotName),
188    #[error("storage slot {0} is not of type value")]
189    StorageSlotNotValue(StorageSlotName),
190    #[error("storage slot name {0} is assigned to more than one slot")]
191    DuplicateStorageSlotName(StorageSlotName),
192    #[error("storage does not contain a slot with name {slot_name}")]
193    StorageSlotNameNotFound { slot_name: StorageSlotName },
194    #[error("storage does not contain a slot with ID {slot_id}")]
195    StorageSlotIdNotFound { slot_id: StorageSlotId },
196    #[error("storage slots must be sorted by slot ID")]
197    UnsortedStorageSlots,
198    #[error("reserved element of a storage slot must be zero but was {0}")]
199    StorageSlotReservedElementNotZero(Felt),
200    #[error("number of storage slots is {0} but max possible number is {max}", max = AccountStorage::MAX_NUM_STORAGE_SLOTS)]
201    StorageTooManySlots(u64),
202    #[error(
203        "failed to apply full state patch to existing account; full state patches can be converted to accounts directly"
204    )]
205    ApplyFullStatePatchToAccount,
206    #[error("patch is for account ID {patch_id} but is being applied to account {account_id}")]
207    PatchAccountIdMismatch {
208        account_id: AccountId,
209        patch_id: AccountId,
210    },
211    #[error("only account deltas representing a full account can be converted to a full account")]
212    PartialStateDeltaToAccount,
213    #[error("assets cannot be removed from a new account with an empty asset vault")]
214    AssetsRemovedFromNewAccount,
215    #[error("only account patches representing a full account can be converted to a full account")]
216    PartialStatePatchToAccount,
217    #[error("maximum number of storage map leaves exceeded")]
218    MaxNumStorageMapLeavesExceeded(#[source] MerkleError),
219    #[error("unknown storage patch operation tag {0}")]
220    UnknownStoragePatchOperation(u8),
221    /// This variant can be used by methods that are not inherent to the account but want to return
222    /// this error type.
223    #[error("{error_msg}")]
224    Other {
225        error_msg: Box<str>,
226        // thiserror will return this when calling Error::source on AccountError.
227        source: Option<Box<dyn Error + Send + Sync + 'static>>,
228    },
229}
230
231impl AccountError {
232    /// Creates a custom error using the [`AccountError::Other`] variant from an error message.
233    pub fn other(message: impl Into<String>) -> Self {
234        let message: String = message.into();
235        Self::Other { error_msg: message.into(), source: None }
236    }
237
238    /// Creates a custom error using the [`AccountError::Other`] variant from an error message and
239    /// a source error.
240    pub fn other_with_source(
241        message: impl Into<String>,
242        source: impl Error + Send + Sync + 'static,
243    ) -> Self {
244        let message: String = message.into();
245        Self::Other {
246            error_msg: message.into(),
247            source: Some(Box::new(source)),
248        }
249    }
250}
251
252/// Error returned when account update details are incompatible with an account ID.
253#[derive(Debug)]
254pub(crate) enum AccountUpdateDetailsValidationError {
255    PrivateAccountWithDetails(AccountId),
256    PublicStateAccountMissingDetails(AccountId),
257    AccountIdMismatch {
258        account_id: AccountId,
259        patch_account_id: AccountId,
260    },
261}
262
263/// Error returned when serialized account update details exceed the size limit.
264#[derive(Debug)]
265pub(crate) struct AccountUpdateSizeValidationError {
266    pub(crate) account_id: AccountId,
267    pub(crate) update_size: usize,
268}
269
270/// Error returned when a new public account cannot be reconstructed from its update details.
271#[derive(Debug)]
272pub(crate) enum NewPublicAccountValidationError {
273    RequiresFullStatePatch {
274        id: AccountId,
275        source: AccountError,
276    },
277    FinalCommitmentMismatch {
278        final_state_commitment: Word,
279        account_commitment: Word,
280    },
281}
282
283// ACCOUNT ID ERROR
284// ================================================================================================
285
286#[derive(Debug, Error)]
287pub enum AccountIdError {
288    #[error("failed to convert bytes into account ID prefix field element")]
289    AccountIdInvalidPrefixFieldElement(#[source] DeserializationError),
290    #[error("failed to convert bytes into account ID suffix field element")]
291    AccountIdInvalidSuffixFieldElement(#[source] DeserializationError),
292    #[error("`{0}` is not a known account type")]
293    UnknownAccountType(Box<str>),
294    #[error("failed to parse hex string into account ID")]
295    AccountIdHexParseError(#[source] HexParseError),
296    #[error("`{0}` is not a known account ID version")]
297    UnknownAccountIdVersion(u8),
298    #[error("most significant bit of account ID suffix must be zero")]
299    AccountIdSuffixMostSignificantBitMustBeZero,
300    #[error("least significant byte of account ID suffix must be zero")]
301    AccountIdSuffixLeastSignificantByteMustBeZero,
302    #[error("failed to decode bech32 string into account ID")]
303    Bech32DecodeError(#[source] Bech32Error),
304}
305
306// SLOT NAME ERROR
307// ================================================================================================
308
309#[derive(Debug, Error)]
310pub enum StorageSlotNameError {
311    #[error("slot name must only contain characters a..z, A..Z, 0..9, double colon or underscore")]
312    InvalidCharacter,
313    #[error("slot names must be separated by double colons")]
314    UnexpectedColon,
315    #[error("slot name components must not start with an underscore")]
316    UnexpectedUnderscore,
317    #[error(
318        "slot names must contain at least {} components separated by double colons",
319        StorageSlotName::MIN_NUM_COMPONENTS
320    )]
321    TooShort,
322    #[error("slot names must contain at most {} characters", StorageSlotName::MAX_LENGTH)]
323    TooLong,
324}
325
326// ACCOUNT CODE INTERFACE ERROR
327// ================================================================================================
328
329#[derive(Debug, Error)]
330pub enum AccountCodeInterfaceError {
331    #[error(
332        "account code interface must contain at least {} procedures, but only {actual} were given",
333        AccountCode::MIN_NUM_PROCEDURES
334    )]
335    TooFewProcedures { actual: usize },
336    #[error(
337        "account code interface contains {actual} procedures but it may contain at most {} procedures",
338        AccountCode::MAX_NUM_PROCEDURES
339    )]
340    TooManyProcedures { actual: usize },
341}
342
343// ACCOUNT COMPONENT NAME ERROR
344// ================================================================================================
345
346#[derive(Debug, Error)]
347pub enum AccountComponentNameError {
348    #[error(
349        "account component name must only contain characters a..z, A..Z, 0..9, double colon or underscore"
350    )]
351    InvalidCharacter,
352    #[error("account component names must be separated by double colons")]
353    UnexpectedColon,
354    #[error("account component name components must not start with an underscore")]
355    UnexpectedUnderscore,
356    #[error(
357        "account component names must contain at least {} components separated by double colons",
358        StorageSlotName::MIN_NUM_COMPONENTS
359    )]
360    TooShort,
361    #[error(
362        "account component names must contain at most {} characters",
363        StorageSlotName::MAX_LENGTH
364    )]
365    TooLong,
366}
367
368// ACCOUNT TREE ERROR
369// ================================================================================================
370
371#[derive(Debug, Error)]
372pub enum AccountTreeError {
373    #[error(
374        "account tree contains multiple account IDs that share the same prefix {duplicate_prefix}"
375    )]
376    DuplicateIdPrefix { duplicate_prefix: AccountIdPrefix },
377    #[error(
378        "entries passed to account tree contain multiple state commitments for the same account ID prefix {prefix}"
379    )]
380    DuplicateStateCommitments { prefix: AccountIdPrefix },
381    #[error("untracked account ID {id} used in partial account tree")]
382    UntrackedAccountId { id: AccountId, source: MerkleError },
383    #[error("new tree root after account witness insertion does not match previous tree root")]
384    TreeRootConflict(#[source] MerkleError),
385    #[error("failed to apply mutations to account tree")]
386    ApplyMutations(#[source] MerkleError),
387    #[error("failed to compute account tree mutations")]
388    ComputeMutations(#[source] MerkleError),
389    #[error("provided smt contains an invalid account ID in key {key}")]
390    InvalidAccountIdKey { key: Word, source: AccountIdError },
391    #[error("smt leaf's index is not a valid account ID prefix")]
392    InvalidAccountIdPrefix(#[source] AccountIdError),
393    #[error("account witness merkle path depth {0} does not match AccountTree::DEPTH")]
394    WitnessMerklePathDepthDoesNotMatchAccountTreeDepth(usize),
395}
396
397// ADDRESS ERROR
398// ================================================================================================
399
400#[derive(Debug, Error)]
401pub enum AddressError {
402    #[error("tag length {0} is too large, must be less than or equal to {max}",
403        max = NoteTag::MAX_ACCOUNT_TARGET_TAG_LENGTH
404    )]
405    TagLengthTooLarge(u8),
406    #[error("unknown address interface `{0}`")]
407    UnknownAddressInterface(u16),
408    #[error("failed to decode account ID")]
409    AccountIdDecodeError(#[source] AccountIdError),
410    #[error("address separator must not be included without routing parameters")]
411    TrailingSeparator,
412    #[error("failed to decode bech32 string into an address")]
413    Bech32DecodeError(#[source] Bech32Error),
414    #[error("{error_msg}")]
415    DecodeError {
416        error_msg: Box<str>,
417        // thiserror will return this when calling Error::source on AddressError.
418        source: Option<Box<dyn Error + Send + Sync + 'static>>,
419    },
420    #[error("found unknown routing parameter key {0}")]
421    UnknownRoutingParameterKey(u8),
422}
423
424impl AddressError {
425    /// Creates an [`AddressError::DecodeError`] variant from an error message.
426    pub fn decode_error(message: impl Into<String>) -> Self {
427        let message: String = message.into();
428        Self::DecodeError { error_msg: message.into(), source: None }
429    }
430
431    /// Creates an [`AddressError::DecodeError`] variant from an error message and
432    /// a source error.
433    pub fn decode_error_with_source(
434        message: impl Into<String>,
435        source: impl Error + Send + Sync + 'static,
436    ) -> Self {
437        let message: String = message.into();
438        Self::DecodeError {
439            error_msg: message.into(),
440            source: Some(Box::new(source)),
441        }
442    }
443}
444
445// BECH32 ERROR
446// ================================================================================================
447
448#[derive(Debug, Error)]
449pub enum Bech32Error {
450    #[error(transparent)]
451    DecodeError(Box<dyn Error + Send + Sync + 'static>),
452    #[error("found unknown address type {0} which is not the expected {account_addr} account ID address type",
453      account_addr = AddressType::AccountId as u8
454    )]
455    UnknownAddressType(u8),
456    #[error("expected bech32 data to be of length {expected} but it was of length {actual}")]
457    InvalidDataLength { expected: usize, actual: usize },
458}
459
460// NETWORK ID ERROR
461// ================================================================================================
462
463#[derive(Debug, Error)]
464pub enum NetworkIdError {
465    #[error("failed to parse string into a network ID")]
466    NetworkIdParseError(#[source] Box<dyn Error + Send + Sync + 'static>),
467}
468
469// ACCOUNT DELTA ERROR
470// ================================================================================================
471
472#[derive(Debug, Error)]
473pub enum AccountDeltaError {
474    #[error("storage slot {0} was used as different slot types")]
475    StorageSlotUsedAsDifferentTypes(StorageSlotName),
476    #[error("asset {0} is changed by more than one asset delta")]
477    DuplicateAssetDelta(AssetId),
478    #[error(
479        "number of {delta_op} operations in account vault delta is {num_ops} but max is {max}",
480        max = AccountVaultDelta::MAX_ASSETS_PER_DELTA_OP
481    )]
482    TooManyVaultAssetDeltas {
483        delta_op: AssetDeltaOperation,
484        num_ops: usize,
485    },
486    #[error(
487        "account update of type `{left_update_type}` cannot be merged with account update of type `{right_update_type}`"
488    )]
489    IncompatibleAccountUpdates {
490        left_update_type: &'static str,
491        right_update_type: &'static str,
492    },
493    #[error("account delta could not be applied to account {account_id}")]
494    AccountDeltaApplicationFailed {
495        account_id: AccountId,
496        source: AccountError,
497    },
498    #[error("non-empty account storage or vault delta with zero nonce delta is not allowed")]
499    NonEmptyStorageOrVaultDeltaWithZeroNonceDelta,
500    #[error("cannot merge two full state deltas")]
501    MergingFullStateDeltas,
502    #[error("a full state delta must only contain storage create operations")]
503    FullStateDeltaContainsNonCreateOp,
504}
505
506#[derive(Debug, Error)]
507pub enum AccountPatchError {
508    #[error("final nonce can never be set to zero")]
509    FinalNonceIsZero,
510
511    #[error(
512        "state change to an account (store, vault or code) require that the final nonce is incremented"
513    )]
514    StateChangeRequiresNonceUpdate,
515
516    #[error("account code must be provided for new accounts (with nonce = 1)")]
517    CodeMustBeProvidedForNewAccounts,
518
519    #[error("a full state patch must only contain storage create operations")]
520    FullStatePatchContainsNonCreateStorageOp,
521
522    #[error("storage slot {0} was used as different slot types")]
523    StorageSlotUsedAsDifferentTypes(StorageSlotName),
524
525    #[error("storage slot name {0} is assigned to more than one slot patch")]
526    DuplicateStorageSlotName(StorageSlotName),
527
528    #[error("number of storage slot patches is {0} but max possible number is {max}", max = AccountStorage::MAX_NUM_STORAGE_SLOTS)]
529    TooManyStorageSlotPatches(usize),
530
531    #[error(
532        "a full state patch cannot be merged on top of another patch; it must be the merge base"
533    )]
534    MergeIncomingFullStatePatch,
535
536    #[error("failed to merge storage patch for slot {0}: cannot create a slot twice")]
537    StoragePatchMergeDoubleCreate(StorageSlotName),
538
539    #[error(
540        "failed to merge storage patch for slot {0}: cannot create a slot after it was updated, which indicates it already exists"
541    )]
542    StoragePatchMergeCreateAfterUpdate(StorageSlotName),
543
544    #[error("failed to merge storage patch for slot {0}: cannot update slot after it was removed")]
545    StoragePatchMergeUpdateAfterRemove(StorageSlotName),
546
547    #[error("failed to merge storage patch for slot {0}: cannot remove a slot twice")]
548    StoragePatchMergeDoubleRemove(StorageSlotName),
549
550    #[error(
551        "nonce in the patch being merged is {new} which is not exactly one greater than current patch nonce {current}"
552    )]
553    NonceMustIncrementByOne { current: Felt, new: Felt },
554
555    #[error(
556        "patch is for account ID {actual} but is being merged into patch for account {expected}"
557    )]
558    AccountIdMismatch { expected: AccountId, actual: AccountId },
559
560    #[error(
561        "account update of type `{left_update_type}` cannot be merged with account update of type `{right_update_type}`"
562    )]
563    IncompatibleAccountUpdates {
564        left_update_type: &'static str,
565        right_update_type: &'static str,
566    },
567}
568
569// STORAGE MAP ERROR
570// ================================================================================================
571
572#[derive(Debug, Error)]
573pub enum StorageMapError {
574    #[error("map entries contain key {key} twice with values {value0} and {value1}")]
575    DuplicateKey {
576        key: StorageMapKey,
577        value0: Word,
578        value1: Word,
579    },
580    #[error("map key {key} is not present in provided SMT proof")]
581    MissingKey { key: StorageMapKey },
582}
583
584// BATCH ACCOUNT UPDATE ERROR
585// ================================================================================================
586
587#[derive(Debug, Error)]
588pub enum BatchAccountUpdateError {
589    #[error(
590        "account update of size {update_size} for account {account_id} exceeds maximum update size of {ACCOUNT_UPDATE_MAX_SIZE}"
591    )]
592    AccountUpdateSizeLimitExceeded {
593        account_id: AccountId,
594        update_size: usize,
595    },
596    #[error("private account {0} should not have account details")]
597    PrivateAccountWithDetails(AccountId),
598    #[error("account {0} with public state is missing its account details")]
599    PublicStateAccountMissingDetails(AccountId),
600    #[error(
601        "batch account update's account ID {account_id} and account patch ID {patch_account_id} must match"
602    )]
603    AccountIdMismatch {
604        account_id: AccountId,
605        patch_account_id: AccountId,
606    },
607    #[error("new account {id} with public state must be accompanied by a full state patch")]
608    NewPublicStateAccountRequiresFullStatePatch { id: AccountId, source: AccountError },
609    #[error(
610        "batch account update's final commitment {final_state_commitment} and reconstructed account commitment {account_commitment} must match"
611    )]
612    AccountFinalCommitmentMismatch {
613        final_state_commitment: Word,
614        account_commitment: Word,
615    },
616    #[error(
617        "account update for account {expected_account_id} cannot be merged with update from transaction {transaction} which was executed against account {actual_account_id}"
618    )]
619    AccountUpdateIdMismatch {
620        transaction: TransactionId,
621        expected_account_id: AccountId,
622        actual_account_id: AccountId,
623    },
624    #[error(
625        "final state commitment in account update from transaction {0} does not match initial state of current update"
626    )]
627    AccountUpdateInitialStateMismatch(TransactionId),
628    #[error("failed to merge account patch from transaction {0}")]
629    TransactionUpdateMergeError(TransactionId, #[source] Box<AccountPatchError>),
630}
631
632// BLOCK ACCOUNT UPDATE ERROR
633// ================================================================================================
634
635#[derive(Debug, Error)]
636pub enum BlockAccountUpdateError {
637    #[error("private account {0} should not have account details")]
638    PrivateAccountWithDetails(AccountId),
639    #[error("account {0} with public state is missing its account details")]
640    PublicStateAccountMissingDetails(AccountId),
641    #[error(
642        "block account update's account ID {account_id} and account patch ID {patch_account_id} must match"
643    )]
644    AccountIdMismatch {
645        account_id: AccountId,
646        patch_account_id: AccountId,
647    },
648    #[error("new account {id} with public state must be accompanied by a full state patch")]
649    NewPublicStateAccountRequiresFullStatePatch { id: AccountId, source: AccountError },
650    #[error(
651        "block account update's final commitment {final_state_commitment} and reconstructed account commitment {account_commitment} must match"
652    )]
653    AccountFinalCommitmentMismatch {
654        final_state_commitment: Word,
655        account_commitment: Word,
656    },
657}
658
659// BLOCK BODY ERROR
660// ================================================================================================
661
662#[derive(Debug, Error)]
663pub enum BlockBodyError {
664    #[error("block has {0} account updates but at most {MAX_ACCOUNTS_PER_BLOCK} are allowed")]
665    TooManyAccountUpdates(usize),
666    #[error("block has {0} nullifiers but at most {MAX_INPUT_NOTES_PER_BLOCK} are allowed")]
667    TooManyNullifiers(usize),
668    #[error("block has {0} output note batches but at most {MAX_BATCHES_PER_BLOCK} are allowed")]
669    TooManyOutputNoteBatches(usize),
670    #[error(
671        "output note batch {batch_index} has {note_count} notes but at most {MAX_OUTPUT_NOTES_PER_BATCH} are allowed"
672    )]
673    TooManyOutputNotes { batch_index: usize, note_count: usize },
674    #[error("output note batch {batch_index} contains invalid note index {note_index}")]
675    InvalidOutputNoteIndex { batch_index: usize, note_index: usize },
676    #[error("output note batch {batch_index} contains note index {note_index} twice")]
677    DuplicateOutputNoteIndex { batch_index: usize, note_index: usize },
678    #[error("output note {0} appears twice in the block body")]
679    DuplicateOutputNote(NoteId),
680    #[error("account update for {0} appears twice in the block body")]
681    DuplicateAccountUpdate(AccountId),
682    #[error("nullifier {0} appears twice in the block body")]
683    DuplicateNullifier(Nullifier),
684    #[error("transaction {0} appears twice in the block body")]
685    DuplicateTransaction(TransactionId),
686}
687
688// ASSET ERROR
689// ================================================================================================
690
691#[derive(Debug, Error)]
692pub enum AssetError {
693    #[error(
694      "fungible asset amount {0} exceeds the max allowed amount of {max_amount}",
695      max_amount = FungibleAsset::MAX_AMOUNT
696    )]
697    FungibleAssetAmountTooBig(u64),
698    #[error("subtracting {subtrahend} from fungible asset amount {minuend} would underflow")]
699    FungibleAssetAmountNotSufficient { minuend: u64, subtrahend: u64 },
700    #[error(
701        "cannot combine fungible assets with different asset IDs: {original_id} and {other_id}"
702    )]
703    FungibleAssetInconsistentIds { original_id: AssetId, other_id: AssetId },
704    #[error("faucet account ID in asset is invalid")]
705    InvalidFaucetAccountId(#[source] Box<dyn Error + Send + Sync + 'static>),
706    #[error(
707        "asset class prefix and suffix in a non-fungible asset ID must match indices 0 and 1 in the value, but asset class was {asset_class} and value was {value}"
708    )]
709    NonFungibleAssetClassMustMatchValue { asset_class: AssetClass, value: Word },
710    #[error("asset class prefix and suffix in a fungible asset ID must be zero but was {0}")]
711    FungibleAssetClassMustBeZero(AssetClass),
712    #[error(
713        "the three most significant elements in a fungible asset's value must be zero but provided value was {0}"
714    )]
715    FungibleAssetValueMostSignificantElementsMustBeZero(Word),
716    #[error("smt proof in asset witness contains invalid ID or value")]
717    AssetWitnessInvalid(#[source] Box<AssetError>),
718    #[error("asset ID {id} is not present in the provided asset witness SMT proof")]
719    AssetWitnessMissingId { id: AssetId },
720    #[error("unknown asset composition encoding: {0}")]
721    UnknownAssetComposition(u8),
722    #[error("unknown asset delta operation encoding: {0}")]
723    UnknownAssetDeltaOperation(u8),
724    #[error("asset composition {0:?} is not supported at this operational site")]
725    UnsupportedAssetComposition(AssetComposition),
726    #[error(
727        "asset composition mismatch for faucet {faucet_id}: expected {expected:?}, found {actual:?}"
728    )]
729    AssetCompositionMismatch {
730        faucet_id: AccountId,
731        expected: AssetComposition,
732        actual: AssetComposition,
733    },
734    #[error("asset metadata byte 0x{0:02x} has reserved bits set to non-zero values")]
735    ReservedAssetMetadata(u8),
736    #[error("unknown asset ID version: {0}")]
737    UnknownAssetIdVersion(u8),
738}
739
740// TOKEN SYMBOL ERROR
741// ================================================================================================
742
743#[derive(Debug, Error)]
744pub enum TokenSymbolError {
745    #[error("token symbol value {0} cannot exceed {max}", max = TokenSymbol::MAX_ENCODED_VALUE)]
746    ValueTooLarge(u64),
747    #[error(
748        "token symbol value {0} cannot be less than {min}",
749        min = TokenSymbol::MIN_ENCODED_VALUE
750    )]
751    ValueTooSmall(u64),
752    #[error("token symbol should have length between 1 and 12 characters, but {0} was provided")]
753    InvalidLength(usize),
754    #[error("token symbol contains a character that is not uppercase ASCII")]
755    InvalidCharacter,
756    #[error("token symbol data left after decoding the specified number of characters")]
757    DataNotFullyDecoded,
758}
759
760impl From<ShortCapitalStringError> for TokenSymbolError {
761    fn from(value: ShortCapitalStringError) -> Self {
762        match value {
763            ShortCapitalStringError::ValueTooLarge(v) => Self::ValueTooLarge(v),
764            ShortCapitalStringError::ValueTooSmall(v) => Self::ValueTooSmall(v),
765            ShortCapitalStringError::InvalidLength(v) => Self::InvalidLength(v),
766            ShortCapitalStringError::InvalidCharacter => Self::InvalidCharacter,
767            ShortCapitalStringError::DataNotFullyDecoded => Self::DataNotFullyDecoded,
768        }
769    }
770}
771
772// ROLE ERROR
773// ================================================================================================
774
775#[derive(Debug, Error)]
776pub enum RoleSymbolError {
777    #[error("role symbol value {0} cannot exceed {max}", max = RoleSymbol::MAX_ENCODED_VALUE)]
778    ValueTooLarge(u64),
779    #[error("role symbol value {0} cannot be less than {min}", min = RoleSymbol::MIN_ENCODED_VALUE)]
780    ValueTooSmall(u64),
781    #[error("role symbol should have length between 1 and 12 characters, but {0} was provided")]
782    InvalidLength(usize),
783    #[error("role symbol contains a character that is not uppercase ASCII or underscore")]
784    InvalidCharacter,
785    #[error("role symbol data left after decoding the specified number of characters")]
786    DataNotFullyDecoded,
787}
788
789impl From<ShortCapitalStringError> for RoleSymbolError {
790    fn from(value: ShortCapitalStringError) -> Self {
791        match value {
792            ShortCapitalStringError::ValueTooLarge(v) => Self::ValueTooLarge(v),
793            ShortCapitalStringError::ValueTooSmall(v) => Self::ValueTooSmall(v),
794            ShortCapitalStringError::InvalidLength(v) => Self::InvalidLength(v),
795            ShortCapitalStringError::InvalidCharacter => Self::InvalidCharacter,
796            ShortCapitalStringError::DataNotFullyDecoded => Self::DataNotFullyDecoded,
797        }
798    }
799}
800
801// SHORT CAPITAL STRING ERROR
802// ================================================================================================
803
804#[derive(Debug, Error)]
805pub(crate) enum ShortCapitalStringError {
806    #[error("short capital string value {0} is too large")]
807    ValueTooLarge(u64),
808    #[error("short capital string value {0} is too small")]
809    ValueTooSmall(u64),
810    #[error(
811        "short capital string should have length between 1 and 12 characters, but {0} was provided"
812    )]
813    InvalidLength(usize),
814    #[error("short capital string contains an invalid character")]
815    InvalidCharacter,
816    #[error("short capital string data left after decoding the specified number of characters")]
817    DataNotFullyDecoded,
818}
819
820// ASSET VAULT ERROR
821// ================================================================================================
822
823#[derive(Debug, Error)]
824pub enum AssetVaultError {
825    #[error("adding fungible asset amounts would exceed maximum allowed amount")]
826    AddFungibleAssetBalanceError(#[source] AssetError),
827    #[error("provided assets contain duplicates")]
828    DuplicateAsset(#[source] MerkleError),
829    #[error("non fungible asset {0} already exists in the vault")]
830    DuplicateNonFungibleAsset(Asset),
831    #[error("fungible asset {0} does not exist in the vault")]
832    FungibleAssetNotFound(FungibleAsset),
833    #[error("non fungible asset {0} does not exist in the vault")]
834    NonFungibleAssetNotFound(Asset),
835    #[error("subtracting fungible asset amounts would underflow")]
836    SubtractFungibleAssetBalanceError(#[source] AssetError),
837    #[error("maximum number of asset vault leaves exceeded")]
838    MaxLeafEntriesExceeded(#[source] MerkleError),
839}
840
841// PARTIAL ASSET VAULT ERROR
842// ================================================================================================
843
844#[derive(Debug, Error)]
845pub enum PartialAssetVaultError {
846    #[error("duplicate asset ID {0} in partial vault")]
847    DuplicateAssetId(AssetId),
848    #[error("partial vault contains invalid asset value {value} at ID {id}")]
849    InvalidAssetForId {
850        id: AssetId,
851        value: Word,
852        #[source]
853        source: AssetError,
854    },
855    #[error("failed to add asset proof")]
856    FailedToAddProof(#[source] MerkleError),
857    #[error("asset is not tracked in the partial vault")]
858    UntrackedAsset(#[source] MerkleError),
859}
860
861// NOTE ERROR
862// ================================================================================================
863
864#[derive(Debug, Error)]
865pub enum NoteError {
866    #[error("error while creating note script: {0}")]
867    MastForestScript(#[source] MastForestScriptError),
868    #[error("note tag length {0} exceeds the maximum of {max}", max = NoteTag::MAX_ACCOUNT_TARGET_TAG_LENGTH)]
869    NoteTagLengthTooLarge(u8),
870    #[error("duplicate fungible asset from issuer {0} in note")]
871    DuplicateFungibleAsset(AccountId),
872    #[error("duplicate non fungible asset {0} in note")]
873    DuplicateNonFungibleAsset(Asset),
874    #[error("note type {0} is inconsistent with note tag {1}")]
875    InconsistentNoteTag(NoteType, u64),
876    #[error("adding fungible asset amounts would exceed maximum allowed amount")]
877    AddFungibleAssetBalanceError(#[source] AssetError),
878    #[error("note sender is not a valid account ID")]
879    NoteSenderInvalidAccountId(#[source] AccountIdError),
880    #[error("note execution hint after block variant cannot contain u32::MAX")]
881    NoteExecutionHintAfterBlockCannotBeU32Max,
882    #[error("invalid note execution hint payload {1} for tag {0}")]
883    InvalidNoteExecutionHintPayload(u8, u32),
884    #[error(
885    "note type {0} does not match any of the valid note types {public} or {private}",
886    public = NoteType::Public,
887    private = NoteType::Private,
888    )]
889    UnknownNoteType(Box<str>),
890    #[error("block note tree index {block_note_tree_index} is out of bounds 0..={highest_index}")]
891    BlockNoteTreeIndexOutOfBounds {
892        block_note_tree_index: u16,
893        highest_index: usize,
894    },
895    #[error("note network execution requires a public note but note is of type {0}")]
896    NetworkExecutionRequiresPublicNote(NoteType),
897    #[error("failed to assemble note script:\n{}", PrintDiagnostic::new(.0))]
898    NoteScriptAssemblyError(Report),
899    #[error("failed to deserialize note script")]
900    NoteScriptDeserializationError(#[source] DeserializationError),
901    #[error("note contains {0} assets which exceeds the maximum of {max}", max = NoteAssets::MAX_NUM_ASSETS)]
902    TooManyAssets(usize),
903    #[error("note contains {0} storage items which exceeds the maximum of {max}", max = MAX_NOTE_STORAGE_ITEMS)]
904    TooManyStorageItems(usize),
905    #[error("invalid note storage length: expected {expected} items, got {actual}")]
906    InvalidNoteStorageLength { expected: usize, actual: usize },
907    #[error("note tag requires a public note but the note is of type {0}")]
908    PublicNoteRequired(NoteType),
909    #[error("note attachment content must have at least one word")]
910    NoteAttachmentContentEmpty,
911    #[error(
912        "note attachment content contains {0} words, but the maximum is {max} words",
913        max = NoteAttachment::MAX_NUM_WORDS
914    )]
915    NoteAttachmentContentTooManyWords(usize),
916    #[error(
917        "note attachments contain a total of {0} words, but the maximum allowed is {max} words",
918        max = NoteAttachments::MAX_NUM_WORDS
919    )]
920    NoteAttachmentsTooManyWords(usize),
921    #[error(
922        "attachment size {0} exceeds maximum {max}",
923        max = NoteAttachment::MAX_NUM_WORDS
924    )]
925    NoteAttachmentHeaderSizeExceeded(u8),
926    #[error("{0} attachments were provided but maximum is {max}", max = NoteAttachments::MAX_COUNT)]
927    TooManyAttachments(usize),
928    #[error("attachment scheme {0} exceeds maximum value of {max}", max = NoteAttachmentScheme::MAX)]
929    NoteAttachmentSchemeExceeded(u32),
930    #[error("attachment scheme value 0 is reserved")]
931    NoteAttachmentSchemeZeroReserved,
932    #[error("{error_msg}")]
933    Other {
934        error_msg: Box<str>,
935        // thiserror will return this when calling Error::source on NoteError.
936        source: Option<Box<dyn Error + Send + Sync + 'static>>,
937    },
938}
939
940impl NoteError {
941    /// Creates a custom error using the [`NoteError::Other`] variant from an error message.
942    pub fn other(message: impl Into<String>) -> Self {
943        let message: String = message.into();
944        Self::Other { error_msg: message.into(), source: None }
945    }
946
947    /// Creates a custom error using the [`NoteError::Other`] variant from an error message and
948    /// a source error.
949    pub fn other_with_source(
950        message: impl Into<String>,
951        source: impl Error + Send + Sync + 'static,
952    ) -> Self {
953        let message: String = message.into();
954        Self::Other {
955            error_msg: message.into(),
956            source: Some(Box::new(source)),
957        }
958    }
959}
960
961// PARTIAL BLOCKCHAIN ERROR
962// ================================================================================================
963
964#[derive(Debug, Error)]
965pub enum PartialBlockchainError {
966    #[error(
967        "block num {block_num} exceeds chain length {chain_length} implied by the partial blockchain"
968    )]
969    BlockNumTooBig {
970        chain_length: usize,
971        block_num: BlockNumber,
972    },
973
974    #[error("duplicate block {block_num} in partial blockchain")]
975    DuplicateBlock { block_num: BlockNumber },
976
977    #[error("partial blockchain does not track authentication paths for block {block_num}")]
978    UntrackedBlock { block_num: BlockNumber },
979
980    #[error(
981        "provided block header with number {block_num} and commitment {block_commitment} is not tracked by partial MMR"
982    )]
983    BlockHeaderCommitmentMismatch {
984        block_num: BlockNumber,
985        block_commitment: Word,
986        source: MmrError,
987    },
988}
989
990impl PartialBlockchainError {
991    pub fn block_num_too_big(chain_length: usize, block_num: BlockNumber) -> Self {
992        Self::BlockNumTooBig { chain_length, block_num }
993    }
994
995    pub fn duplicate_block(block_num: BlockNumber) -> Self {
996        Self::DuplicateBlock { block_num }
997    }
998
999    pub fn untracked_block(block_num: BlockNumber) -> Self {
1000        Self::UntrackedBlock { block_num }
1001    }
1002}
1003
1004// TRANSACTION INPUT ERROR
1005// ================================================================================================
1006
1007#[derive(Debug, Error)]
1008pub enum TransactionInputError {
1009    #[error("transaction input note with nullifier {0} is a duplicate")]
1010    DuplicateInputNote(Nullifier),
1011    #[error("partial blockchain has length {actual} which does not match block number {expected}")]
1012    InconsistentChainLength {
1013        expected: BlockNumber,
1014        actual: BlockNumber,
1015    },
1016    #[error(
1017        "partial blockchain has commitment {actual} which does not match the block header's chain commitment {expected}"
1018    )]
1019    InconsistentChainCommitment { expected: Word, actual: Word },
1020    #[error(
1021        "protocol config has commitment {actual} which does not match the block header's protocol config commitment {expected}"
1022    )]
1023    InconsistentProtocolConfig { expected: Word, actual: Word },
1024    #[error("block in which input note with id {0} was created is not in partial blockchain")]
1025    InputNoteBlockNotInPartialBlockchain(NoteId),
1026    #[error("input note with id {0} was not created in block {1}")]
1027    InputNoteNotInBlock(NoteId, BlockNumber),
1028    #[error(
1029        "total number of input notes is {0} which exceeds the maximum of {MAX_INPUT_NOTES_PER_TX}"
1030    )]
1031    TooManyInputNotes(usize),
1032}
1033
1034// TRANSACTION INPUTS EXTRACTION ERROR
1035// ===============================================================================================
1036
1037#[derive(Debug, Error)]
1038pub enum TransactionInputsExtractionError {
1039    #[error("specified foreign account id matches the transaction input's account id")]
1040    AccountNotForeign,
1041    #[error("foreign account data not found in advice map for account {0}")]
1042    ForeignAccountNotFound(AccountId),
1043    #[error("foreign account code not found for account {0}")]
1044    ForeignAccountCodeNotFound(AccountId),
1045    #[error("storage header data not found in advice map for account {0}")]
1046    StorageHeaderNotFound(AccountId),
1047    #[error("failed to handle account data")]
1048    AccountError(#[from] AccountError),
1049    #[error("failed to handle merkle data")]
1050    MerkleError(#[from] MerkleError),
1051    #[error("failed to handle account tree data")]
1052    AccountTreeError(#[from] AccountTreeError),
1053    #[error("missing vault root from Merkle store")]
1054    MissingVaultRoot,
1055    #[error("missing storage map root from Merkle store")]
1056    MissingMapRoot,
1057    #[error("failed to construct SMT proof")]
1058    SmtProofError(#[from] SmtProofError),
1059    #[error("failed to construct an asset")]
1060    AssetError(#[from] AssetError),
1061    #[error("failed to handle storage map data")]
1062    StorageMapError(#[from] StorageMapError),
1063    #[error("failed to convert elements to leaf index: {0}")]
1064    LeafConversionError(String),
1065    #[error("failed to construct SMT leaf")]
1066    SmtLeafError(#[from] SmtLeafError),
1067}
1068
1069// TRANSACTION OUTPUT ERROR
1070// ===============================================================================================
1071
1072#[derive(Debug, Error)]
1073pub enum TransactionOutputError {
1074    #[error("transaction output note with id {0} is a duplicate")]
1075    DuplicateOutputNote(NoteId),
1076    #[error("final account commitment is not in the advice map")]
1077    FinalAccountCommitmentMissingInAdviceMap,
1078    #[error("failed to parse final account header")]
1079    FinalAccountHeaderParseFailure(#[source] AccountError),
1080    #[error(
1081        "output notes commitment {expected} from kernel does not match computed commitment {actual}"
1082    )]
1083    OutputNotesCommitmentInconsistent { expected: Word, actual: Word },
1084    #[error("transaction kernel output stack is invalid: {0}")]
1085    OutputStackInvalid(String),
1086    #[error(
1087        "total number of output notes is {0} which exceeds the maximum of {MAX_OUTPUT_NOTES_PER_TX}"
1088    )]
1089    TooManyOutputNotes(usize),
1090    #[error("failed to process account update commitment: {0}")]
1091    AccountUpdateCommitment(Box<str>),
1092}
1093
1094// OUTPUT NOTE ERROR
1095// ================================================================================================
1096
1097/// Errors that can occur when creating a
1098/// [`PublicOutputNote`](crate::transaction::PublicOutputNote) or
1099/// [`PrivateOutputNote`](crate::transaction::PrivateOutputNote).
1100#[derive(Debug, Error)]
1101pub enum OutputNoteError {
1102    #[error("attachment headers do not match attachments for private note with id {0}")]
1103    AttachmentHeadersMismatch(NoteId),
1104    #[error("attachments commitment does not match attachments for private note with id {0}")]
1105    AttachmentsCommitmentMismatch(NoteId),
1106    #[error("note with id {0} is private but expected a public note")]
1107    NoteIsPrivate(NoteId),
1108    #[error("note with id {0} is public but expected a private note")]
1109    NoteIsPublic(NoteId),
1110    #[error(
1111        "public note with id {note_id} has size {note_size} bytes which exceeds maximum note size of {NOTE_MAX_SIZE}"
1112    )]
1113    NoteSizeLimitExceeded { note_id: NoteId, note_size: usize },
1114}
1115
1116// TRANSACTION SUMMARY ERROR
1117// ================================================================================================
1118
1119#[derive(Debug, Error)]
1120pub enum TransactionSummaryError {
1121    #[error(
1122        "transaction summary preimage contains {actual} elements but expected {expected} elements"
1123    )]
1124    InvalidPreimageLength { actual: usize, expected: usize },
1125    #[error("transaction summary metadata element {0} sets bits above the packed fields")]
1126    MetadataOutOfRange(Felt),
1127    #[error(
1128        "transaction summary layout version is {actual} but only version {expected} is supported"
1129    )]
1130    UnsupportedVersion { actual: Felt, expected: u8 },
1131}
1132
1133// TRANSACTION EVENT PARSING ERROR
1134// ================================================================================================
1135
1136#[derive(Debug, Error)]
1137pub enum TransactionEventError {
1138    #[error("event id {0} is not a valid transaction event")]
1139    InvalidTransactionEvent(EventId),
1140}
1141
1142// TRANSACTION TRACE PARSING ERROR
1143// ================================================================================================
1144
1145#[derive(Debug, Error)]
1146pub enum TransactionTraceParsingError {
1147    #[error("trace id {0} is an unknown transaction kernel trace")]
1148    UnknownTransactionTrace(u32),
1149}
1150
1151// PROVEN TRANSACTION ERROR
1152// ================================================================================================
1153
1154#[derive(Debug, Error)]
1155pub enum ProvenTransactionError {
1156    #[error(
1157        "proven transaction's final account commitment {tx_final_commitment} and account details commitment {details_commitment} must match"
1158    )]
1159    AccountFinalCommitmentMismatch {
1160        tx_final_commitment: Word,
1161        details_commitment: Word,
1162    },
1163    #[error(
1164        "proven transaction's final account ID {tx_account_id} and account details id {details_account_id} must match"
1165    )]
1166    AccountIdMismatch {
1167        tx_account_id: AccountId,
1168        details_account_id: AccountId,
1169    },
1170    #[error("failed to construct input notes for proven transaction")]
1171    InputNotesError(TransactionInputError),
1172    #[error("private account {0} should not have account details")]
1173    PrivateAccountWithDetails(AccountId),
1174    #[error("account {0} with public state is missing its account details")]
1175    PublicStateAccountMissingDetails(AccountId),
1176    #[error("new account {id} with public state must be accompanied by a full state patch")]
1177    NewPublicStateAccountRequiresFullStatePatch { id: AccountId, source: AccountError },
1178    #[error(
1179        "existing account {0} with public state should only provide delta updates instead of full details"
1180    )]
1181    ExistingPublicStateAccountRequiresDeltaDetails(AccountId),
1182    #[error("failed to construct output notes for proven transaction")]
1183    OutputNotesError(#[source] TransactionOutputError),
1184    #[error(
1185        "account update of size {update_size} for account {account_id} exceeds maximum update size of {ACCOUNT_UPDATE_MAX_SIZE}"
1186    )]
1187    AccountUpdateSizeLimitExceeded {
1188        account_id: AccountId,
1189        update_size: usize,
1190    },
1191    #[error("proven transaction neither changed the account state, nor consumed any notes")]
1192    EmptyTransaction,
1193    #[error(
1194        "expected account patch commitment {expected_patch_commitment} but found {actual_patch_commitment}"
1195    )]
1196    AccountPatchCommitmentMismatch {
1197        expected_patch_commitment: Word,
1198        actual_patch_commitment: Word,
1199    },
1200    #[error("note with id {0} is both created and consumed by the transaction")]
1201    NoteCreatedAndConsumed(NoteId),
1202}
1203
1204// TRANSACTION HEADER ERROR
1205// ================================================================================================
1206
1207/// Error returned when constructing an invalid transaction header.
1208#[derive(Debug, Error)]
1209#[non_exhaustive]
1210pub enum TransactionHeaderError {
1211    #[error("input note with nullifier {0} appears twice in the transaction header")]
1212    DuplicateInputNote(Nullifier),
1213    #[error("output note {0} appears twice in the transaction header")]
1214    DuplicateOutputNote(NoteId),
1215    #[error("note with id {0} is both created and consumed by the transaction header")]
1216    NoteCreatedAndConsumed(NoteId),
1217}
1218
1219impl From<AccountUpdateDetailsValidationError> for ProvenTransactionError {
1220    fn from(error: AccountUpdateDetailsValidationError) -> Self {
1221        match error {
1222            AccountUpdateDetailsValidationError::PrivateAccountWithDetails(account_id) => {
1223                Self::PrivateAccountWithDetails(account_id)
1224            },
1225            AccountUpdateDetailsValidationError::PublicStateAccountMissingDetails(account_id) => {
1226                Self::PublicStateAccountMissingDetails(account_id)
1227            },
1228            AccountUpdateDetailsValidationError::AccountIdMismatch {
1229                account_id,
1230                patch_account_id,
1231            } => Self::AccountIdMismatch {
1232                tx_account_id: account_id,
1233                details_account_id: patch_account_id,
1234            },
1235        }
1236    }
1237}
1238
1239impl From<AccountUpdateSizeValidationError> for ProvenTransactionError {
1240    fn from(error: AccountUpdateSizeValidationError) -> Self {
1241        Self::AccountUpdateSizeLimitExceeded {
1242            account_id: error.account_id,
1243            update_size: error.update_size,
1244        }
1245    }
1246}
1247
1248impl From<AccountUpdateSizeValidationError> for BatchAccountUpdateError {
1249    fn from(error: AccountUpdateSizeValidationError) -> Self {
1250        Self::AccountUpdateSizeLimitExceeded {
1251            account_id: error.account_id,
1252            update_size: error.update_size,
1253        }
1254    }
1255}
1256
1257impl From<AccountUpdateDetailsValidationError> for BatchAccountUpdateError {
1258    fn from(error: AccountUpdateDetailsValidationError) -> Self {
1259        match error {
1260            AccountUpdateDetailsValidationError::PrivateAccountWithDetails(account_id) => {
1261                Self::PrivateAccountWithDetails(account_id)
1262            },
1263            AccountUpdateDetailsValidationError::PublicStateAccountMissingDetails(account_id) => {
1264                Self::PublicStateAccountMissingDetails(account_id)
1265            },
1266            AccountUpdateDetailsValidationError::AccountIdMismatch {
1267                account_id,
1268                patch_account_id,
1269            } => Self::AccountIdMismatch { account_id, patch_account_id },
1270        }
1271    }
1272}
1273
1274impl From<AccountUpdateDetailsValidationError> for BlockAccountUpdateError {
1275    fn from(error: AccountUpdateDetailsValidationError) -> Self {
1276        match error {
1277            AccountUpdateDetailsValidationError::PrivateAccountWithDetails(account_id) => {
1278                Self::PrivateAccountWithDetails(account_id)
1279            },
1280            AccountUpdateDetailsValidationError::PublicStateAccountMissingDetails(account_id) => {
1281                Self::PublicStateAccountMissingDetails(account_id)
1282            },
1283            AccountUpdateDetailsValidationError::AccountIdMismatch {
1284                account_id,
1285                patch_account_id,
1286            } => Self::AccountIdMismatch { account_id, patch_account_id },
1287        }
1288    }
1289}
1290
1291impl From<NewPublicAccountValidationError> for ProvenTransactionError {
1292    fn from(error: NewPublicAccountValidationError) -> Self {
1293        match error {
1294            NewPublicAccountValidationError::RequiresFullStatePatch { id, source } => {
1295                Self::NewPublicStateAccountRequiresFullStatePatch { id, source }
1296            },
1297            NewPublicAccountValidationError::FinalCommitmentMismatch {
1298                final_state_commitment,
1299                account_commitment,
1300            } => Self::AccountFinalCommitmentMismatch {
1301                tx_final_commitment: final_state_commitment,
1302                details_commitment: account_commitment,
1303            },
1304        }
1305    }
1306}
1307
1308impl From<NewPublicAccountValidationError> for BatchAccountUpdateError {
1309    fn from(error: NewPublicAccountValidationError) -> Self {
1310        match error {
1311            NewPublicAccountValidationError::RequiresFullStatePatch { id, source } => {
1312                Self::NewPublicStateAccountRequiresFullStatePatch { id, source }
1313            },
1314            NewPublicAccountValidationError::FinalCommitmentMismatch {
1315                final_state_commitment,
1316                account_commitment,
1317            } => Self::AccountFinalCommitmentMismatch {
1318                final_state_commitment,
1319                account_commitment,
1320            },
1321        }
1322    }
1323}
1324
1325impl From<NewPublicAccountValidationError> for BlockAccountUpdateError {
1326    fn from(error: NewPublicAccountValidationError) -> Self {
1327        match error {
1328            NewPublicAccountValidationError::RequiresFullStatePatch { id, source } => {
1329                Self::NewPublicStateAccountRequiresFullStatePatch { id, source }
1330            },
1331            NewPublicAccountValidationError::FinalCommitmentMismatch {
1332                final_state_commitment,
1333                account_commitment,
1334            } => Self::AccountFinalCommitmentMismatch {
1335                final_state_commitment,
1336                account_commitment,
1337            },
1338        }
1339    }
1340}
1341
1342// PROPOSED BATCH ERROR
1343// ================================================================================================
1344
1345#[derive(Debug, Error)]
1346pub enum ProposedBatchError {
1347    #[error("failed to verify transaction {transaction_id} in transaction batch")]
1348    TransactionVerificationFailed {
1349        transaction_id: TransactionId,
1350        source: TransactionVerifierError,
1351    },
1352
1353    #[error(
1354        "transaction batch has {0} input notes but at most {MAX_INPUT_NOTES_PER_BATCH} are allowed"
1355    )]
1356    TooManyInputNotes(usize),
1357
1358    #[error(
1359        "transaction batch has {0} output notes but at most {MAX_OUTPUT_NOTES_PER_BATCH} are allowed"
1360    )]
1361    TooManyOutputNotes(usize),
1362
1363    #[error(
1364        "transaction batch has {0} account updates but at most {MAX_ACCOUNTS_PER_BATCH} are allowed"
1365    )]
1366    TooManyAccountUpdates(usize),
1367
1368    #[error(
1369        "transaction {transaction_id} expires at block number {transaction_expiration_num} which is not greater than the number of the batch's reference block {reference_block_num}"
1370    )]
1371    ExpiredTransaction {
1372        transaction_id: TransactionId,
1373        transaction_expiration_num: BlockNumber,
1374        reference_block_num: BlockNumber,
1375    },
1376
1377    #[error("transaction batch must contain at least one transaction")]
1378    EmptyTransactionBatch,
1379
1380    #[error("transaction {transaction_id} appears twice in the proposed batch input")]
1381    DuplicateTransaction { transaction_id: TransactionId },
1382
1383    #[error(
1384        "transaction {second_transaction_id} consumes the note with nullifier {note_nullifier} that is also consumed by another transaction {first_transaction_id} in the batch"
1385    )]
1386    DuplicateInputNote {
1387        note_nullifier: Nullifier,
1388        first_transaction_id: TransactionId,
1389        second_transaction_id: TransactionId,
1390    },
1391
1392    #[error(
1393        "transaction {second_transaction_id} creates the note with id {note_id} that is also created by another transaction {first_transaction_id} in the batch"
1394    )]
1395    DuplicateOutputNote {
1396        note_id: NoteId,
1397        first_transaction_id: TransactionId,
1398        second_transaction_id: TransactionId,
1399    },
1400
1401    #[error(
1402        "transaction {consumed_by} that consumes the note with ID {note_id} must be ordered before transaction {created_by} that creates the note"
1403    )]
1404    NoteConsumedBeforeCreated {
1405        note_id: NoteId,
1406        consumed_by: TransactionId,
1407        created_by: TransactionId,
1408    },
1409
1410    #[error("failed to merge transaction patch into account {account_id}")]
1411    AccountUpdateError {
1412        account_id: AccountId,
1413        source: BatchAccountUpdateError,
1414    },
1415
1416    #[error(
1417        "unable to prove unauthenticated note inclusion because block {block_number} in which note with id {note_id} was created is not in partial blockchain"
1418    )]
1419    UnauthenticatedInputNoteBlockNotInPartialBlockchain {
1420        block_number: BlockNumber,
1421        note_id: NoteId,
1422    },
1423
1424    #[error(
1425        "unable to prove unauthenticated note inclusion of note {note_id} in block {block_num}"
1426    )]
1427    UnauthenticatedNoteAuthenticationFailed {
1428        note_id: NoteId,
1429        block_num: BlockNumber,
1430        source: MerkleError,
1431    },
1432
1433    #[error("partial blockchain has length {actual} which does not match block number {expected}")]
1434    InconsistentChainLength {
1435        expected: BlockNumber,
1436        actual: BlockNumber,
1437    },
1438
1439    #[error(
1440        "partial blockchain has root {actual} which does not match block header's root {expected}"
1441    )]
1442    InconsistentChainRoot { expected: Word, actual: Word },
1443
1444    #[error(
1445        "block {block_num} referenced by transaction {transaction_id} is not in the partial blockchain"
1446    )]
1447    MissingTransactionReferenceBlock {
1448        transaction_id: TransactionId,
1449        block_num: BlockNumber,
1450    },
1451
1452    #[error(
1453        "transaction {transaction_id} references block {block_num} with commitment {actual_block_commitment}, but the block in the chain with the same number has commitment {expected_block_commitment}"
1454    )]
1455    TransactionReferenceBlockCommitmentMismatch {
1456        transaction_id: TransactionId,
1457        block_num: BlockNumber,
1458        expected_block_commitment: Word,
1459        actual_block_commitment: Word,
1460    },
1461}
1462
1463// PROVEN BATCH ERROR
1464// ================================================================================================
1465
1466#[derive(Debug, Error)]
1467pub enum ProvenBatchError {
1468    #[error("transaction batch must contain at least one transaction")]
1469    EmptyTransactionBatch,
1470    #[error("transaction {0} appears twice in the proven batch")]
1471    DuplicateTransaction(TransactionId),
1472    #[error(
1473        "transaction batch has {0} input notes but at most {MAX_INPUT_NOTES_PER_BATCH} are allowed"
1474    )]
1475    TooManyInputNotes(usize),
1476    #[error("input note with nullifier {0} appears twice in the proven batch")]
1477    DuplicateInputNote(Nullifier),
1478    #[error(
1479        "transaction batch has {0} output notes but at most {MAX_OUTPUT_NOTES_PER_BATCH} are allowed"
1480    )]
1481    TooManyOutputNotes(usize),
1482    #[error(
1483        "transaction batch has at least {0} account updates but at most {MAX_ACCOUNTS_PER_BATCH} are allowed"
1484    )]
1485    TooManyAccountUpdates(usize),
1486    #[error("output note {0} appears twice in the proven batch")]
1487    DuplicateOutputNote(NoteId),
1488    #[error("note with id {0} is both created and consumed by the proven batch")]
1489    NoteCreatedAndConsumed(NoteId),
1490    #[error("account {0} is updated more than once in the proven batch")]
1491    DuplicateAccountUpdate(AccountId),
1492    #[error("account update for {0} is missing from the proven batch")]
1493    MissingAccountUpdate(AccountId),
1494    #[error("account update for {0} has no corresponding transaction in the proven batch")]
1495    UnexpectedAccountUpdate(AccountId),
1496    #[error(
1497        "transaction {transaction_id} for account {account_id} starts from state {actual_initial_state_commitment}, but the previous transaction ends at state {expected_initial_state_commitment}"
1498    )]
1499    TransactionAccountStateMismatch {
1500        account_id: AccountId,
1501        transaction_id: TransactionId,
1502        expected_initial_state_commitment: Word,
1503        actual_initial_state_commitment: Word,
1504    },
1505    #[error(
1506        "account update for {account_id} starts from state {actual}, but its first transaction starts from state {expected}"
1507    )]
1508    AccountUpdateInitialStateMismatch {
1509        account_id: AccountId,
1510        expected: Word,
1511        actual: Word,
1512    },
1513    #[error(
1514        "account update for {account_id} ends at state {actual}, but its last transaction ends at state {expected}"
1515    )]
1516    AccountUpdateFinalStateMismatch {
1517        account_id: AccountId,
1518        expected: Word,
1519        actual: Word,
1520    },
1521    #[error(
1522        "batch expiration block number {batch_expiration_block_num} is not greater than the reference block number {reference_block_num}"
1523    )]
1524    InvalidBatchExpirationBlockNum {
1525        batch_expiration_block_num: BlockNumber,
1526        reference_block_num: BlockNumber,
1527    },
1528    #[error("batch kernel execution failed")]
1529    BatchKernelExecutionFailed(#[source] ExecutionError),
1530    #[error("batch kernel proving failed")]
1531    BatchKernelProvingFailed(#[source] ExecutionError),
1532    #[error("precompile proving failed")]
1533    PrecompileProvingFailed(#[source] ExecutionError),
1534    #[error("batch proof contains precompiles")]
1535    BatchProofContainsPrecompiles,
1536    #[error("batch kernel produced an invalid output stack")]
1537    BatchKernelOutputInvalid(#[source] BatchOutputError),
1538}
1539
1540// BATCH OUTPUT ERROR
1541// ================================================================================================
1542
1543#[derive(Debug, Error)]
1544pub enum BatchOutputError {
1545    #[error("batch kernel output stack is invalid: {0}")]
1546    OutputStackInvalid(String),
1547    #[error("batch expiration block number {0} does not fit into a u32")]
1548    ExpirationBlockNumberTooLarge(Felt),
1549}
1550
1551// BLOCK OUTPUT ERROR
1552// ================================================================================================
1553
1554#[derive(Debug, Error)]
1555pub enum BlockOutputError {
1556    #[error(
1557        "block kernel output stack has a non-zero element at index {index}, but everything past the nullifier commitment must be zero padding"
1558    )]
1559    PaddingNotZero { index: usize },
1560}
1561
1562// PROPOSED BLOCK ERROR
1563// ================================================================================================
1564
1565#[derive(Debug, Error)]
1566pub enum ProposedBlockError {
1567    #[error("block must contain at least one transaction batch")]
1568    EmptyBlock,
1569
1570    #[error("block must contain at most {MAX_BATCHES_PER_BLOCK} transaction batches")]
1571    TooManyBatches,
1572
1573    #[error(
1574        "batch {batch_id} expired at block {batch_expiration_block_num} but the current block number is {current_block_num}"
1575    )]
1576    ExpiredBatch {
1577        batch_id: BatchId,
1578        batch_expiration_block_num: BlockNumber,
1579        current_block_num: BlockNumber,
1580    },
1581
1582    #[error("batch {batch_id} appears twice in the block inputs")]
1583    DuplicateBatch { batch_id: BatchId },
1584
1585    #[error(
1586        "batch {second_batch_id} consumes the note with nullifier {note_nullifier} that is also consumed by another batch {first_batch_id} in the block"
1587    )]
1588    DuplicateInputNote {
1589        note_nullifier: Nullifier,
1590        first_batch_id: BatchId,
1591        second_batch_id: BatchId,
1592    },
1593
1594    #[error(
1595        "batch {second_batch_id} creates the note with ID {note_id} that is also created by another batch {first_batch_id} in the block"
1596    )]
1597    DuplicateOutputNote {
1598        note_id: NoteId,
1599        first_batch_id: BatchId,
1600        second_batch_id: BatchId,
1601    },
1602
1603    #[error(
1604        "batch {consumed_by} that consumes the note with ID {note_id} must be ordered before batch {created_by} that creates the note"
1605    )]
1606    NoteConsumedBeforeCreated {
1607        note_id: NoteId,
1608        consumed_by: BatchId,
1609        created_by: BatchId,
1610    },
1611
1612    #[error(
1613        "timestamp {provided_timestamp} does not increase monotonically compared to timestamp {previous_timestamp} from the previous block header"
1614    )]
1615    TimestampDoesNotIncreaseMonotonically {
1616        provided_timestamp: u32,
1617        previous_timestamp: u32,
1618    },
1619
1620    #[error(
1621        "account {account_id} is updated from the same initial state commitment {initial_state_commitment} by multiple conflicting batches with IDs {first_batch_id} and {second_batch_id}"
1622    )]
1623    ConflictingBatchesUpdateSameAccount {
1624        account_id: AccountId,
1625        initial_state_commitment: Word,
1626        first_batch_id: BatchId,
1627        second_batch_id: BatchId,
1628    },
1629
1630    #[error(
1631        "partial blockchain has length {chain_length} which does not match the block number {prev_block_num} of the previous block referenced by the to-be-built block"
1632    )]
1633    ChainLengthNotEqualToPreviousBlockNumber {
1634        chain_length: BlockNumber,
1635        prev_block_num: BlockNumber,
1636    },
1637
1638    #[error(
1639        "partial blockchain has commitment {chain_commitment} which does not match the chain commitment {prev_block_chain_commitment} of the previous block {prev_block_num}"
1640    )]
1641    ChainRootNotEqualToPreviousBlockChainCommitment {
1642        chain_commitment: Word,
1643        prev_block_chain_commitment: Word,
1644        prev_block_num: BlockNumber,
1645    },
1646
1647    #[error(
1648        "partial blockchain is missing block {reference_block_num} referenced by batch {batch_id} in the block"
1649    )]
1650    BatchReferenceBlockMissingFromChain {
1651        reference_block_num: BlockNumber,
1652        batch_id: BatchId,
1653    },
1654
1655    #[error(
1656        "failed to prove unauthenticated note inclusion because block {block_number} in which note with id {note_id} was created is not in partial blockchain"
1657    )]
1658    UnauthenticatedInputNoteBlockNotInPartialBlockchain {
1659        block_number: BlockNumber,
1660        note_id: NoteId,
1661    },
1662
1663    #[error(
1664        "failed to prove unauthenticated note inclusion of note {note_id} in block {block_num}"
1665    )]
1666    UnauthenticatedNoteAuthenticationFailed {
1667        note_id: NoteId,
1668        block_num: BlockNumber,
1669        source: MerkleError,
1670    },
1671
1672    #[error(
1673        "unauthenticated note with nullifier {nullifier} was not created in the same block and no inclusion proof to authenticate it was provided"
1674    )]
1675    UnauthenticatedNoteConsumed { nullifier: Nullifier },
1676
1677    #[error("block inputs do not contain a proof of inclusion for account {0}")]
1678    MissingAccountWitness(AccountId),
1679
1680    #[error(
1681        "account {account_id} with state {state_commitment} cannot transition to any of the remaining states {}",
1682        remaining_state_commitments.iter().map(Word::to_hex).collect::<Vec<_>>().join(", ")
1683    )]
1684    InconsistentAccountStateTransition {
1685        account_id: AccountId,
1686        state_commitment: Word,
1687        remaining_state_commitments: Vec<Word>,
1688    },
1689
1690    #[error("no proof for nullifier {0} was provided")]
1691    NullifierProofMissing(Nullifier),
1692
1693    #[error("note with nullifier {0} is already spent")]
1694    NullifierSpent(Nullifier),
1695
1696    #[error("failed to merge transaction patch into account {account_id}")]
1697    AccountUpdateError {
1698        account_id: AccountId,
1699        source: Box<AccountPatchError>,
1700    },
1701
1702    #[error("failed to track account witness")]
1703    AccountWitnessTracking { source: AccountTreeError },
1704
1705    #[error(
1706        "account tree root of the previous block header is {prev_block_account_root} but the root of the partial tree computed from account witnesses is {stale_account_root}, indicating that the witnesses are stale"
1707    )]
1708    StaleAccountTreeRoot {
1709        prev_block_account_root: Word,
1710        stale_account_root: Word,
1711    },
1712
1713    #[error("account ID prefix already exists in the tree")]
1714    AccountIdPrefixDuplicate { source: AccountTreeError },
1715
1716    #[error(
1717        "nullifier tree root of the previous block header is {prev_block_nullifier_root} but the root of the partial tree computed from nullifier witnesses is {stale_nullifier_root}, indicating that the witnesses are stale"
1718    )]
1719    StaleNullifierTreeRoot {
1720        prev_block_nullifier_root: Word,
1721        stale_nullifier_root: Word,
1722    },
1723
1724    #[error("nullifier witness has a different root than the current nullifier tree root")]
1725    NullifierWitnessRootMismatch(NullifierTreeError),
1726}
1727
1728// PROTOCOL CONFIG ERROR
1729// ================================================================================================
1730
1731/// Error returned when constructing an invalid protocol configuration.
1732#[derive(Debug, thiserror::Error)]
1733#[non_exhaustive]
1734pub enum ProtocolConfigError {
1735    #[error("fee asset composition {0:?} is not supported, it must be fungible")]
1736    FeeAssetMustBeFungible(AssetComposition),
1737    #[error("minimum proof security must be at least one bit")]
1738    MinimumSecurityBitsMustBeNonZero,
1739    #[error("next protocol config cannot become effective at the genesis block")]
1740    NextConfigEffectiveAtGenesis,
1741    #[error(
1742        "kernel config contains {count} procedures but must contain at most {max}",
1743        max = KernelConfig::MAX_NUM_KERNEL_PROCEDURES,
1744    )]
1745    TooManyKernelProcedures { count: usize },
1746}
1747
1748// VALIDATOR CONFIG ERROR
1749// ================================================================================================
1750
1751/// Error returned when constructing an invalid [`ValidatorConfig`].
1752#[derive(Debug, thiserror::Error)]
1753#[non_exhaustive]
1754pub enum ValidatorConfigError {
1755    #[error("validator set must contain at least one key")]
1756    EmptySet,
1757    #[error(
1758        "validator set contains {count} keys but must contain at most {max}",
1759        max = ValidatorConfig::MAX_VALIDATORS,
1760    )]
1761    TooManyKeys { count: usize },
1762    #[error("validator set contains duplicate public keys")]
1763    DuplicateKey,
1764    #[error("quorum is {quorum} but must equal the validator count of {count}")]
1765    QuorumMustEqualValidatorCount { quorum: u16, count: usize },
1766}
1767
1768// NULLIFIER TREE ERROR
1769// ================================================================================================
1770
1771#[derive(Debug, Error)]
1772pub enum NullifierTreeError {
1773    #[error(
1774        "entries passed to nullifier tree contain multiple block numbers for the same nullifier"
1775    )]
1776    DuplicateNullifierBlockNumbers(#[source] MerkleError),
1777
1778    #[error("attempt to mark nullifier {0} as spent but it is already spent")]
1779    NullifierAlreadySpent(Nullifier),
1780
1781    #[error("maximum number of nullifier tree leaves exceeded")]
1782    MaxLeafEntriesExceeded(#[source] MerkleError),
1783
1784    #[error("nullifier {nullifier} is not tracked by the partial nullifier tree")]
1785    UntrackedNullifier {
1786        nullifier: Nullifier,
1787        source: MerkleError,
1788    },
1789
1790    #[error("new tree root after nullifier witness insertion does not match previous tree root")]
1791    TreeRootConflict(#[source] MerkleError),
1792
1793    #[error("failed to compute nullifier tree mutations")]
1794    ComputeMutations(#[source] MerkleError),
1795
1796    #[error("invalid nullifier block number")]
1797    InvalidNullifierBlockNumber(Word),
1798}
1799
1800// AUTH SCHEME ERROR
1801// ================================================================================================
1802
1803#[derive(Debug, Error)]
1804pub enum AuthSchemeError {
1805    #[error("auth scheme identifier `{0}` is not valid")]
1806    InvalidAuthSchemeIdentifier(String),
1807}
1808
1809// TRANSACTION VERIFIER ERROR
1810// ================================================================================================
1811
1812#[derive(Debug, Error)]
1813pub enum TransactionVerifierError {
1814    #[error("failed to verify transaction")]
1815    TransactionVerificationFailed(#[source] VerificationError),
1816    #[error("transaction proof contains settled precompile work")]
1817    TransactionProofContainsPrecompiles,
1818    #[error("transaction proof security level is {actual} but must be at least {expected_minimum}")]
1819    InsufficientProofSecurityLevel { actual: u32, expected_minimum: u32 },
1820}