Skip to content

Commit

Permalink
Add error messages to miden-objects errors and implement `core::err…
Browse files Browse the repository at this point in the history
…or::Error` (#974)

* feat: Remove `Clone`, `PartialEq`, `Eq` from errors

* feat: Refactor `AssetError` and `AssetVaultError`

* feat: Use `thiserror` for `BlockError`

* chore: Make `NoteExecutionHint` tags associated constants

* feat: Use `thiserror` for `NoteError`

* feat: Include printed Report in error

* feat: Add error messages for `TransactionInputError`

* feat: Add error messages for `TransactionOutputError`

* feat: Use `thiserror` for `ProvenTransactionError`

* feat: Update `winter-utils` to `0.10.2`

* feat: Add error messages for `AccountDeltaError`

* fix: Build no-std

* feat: Add error messages for `AccountError`

* chore: Add Changelog entry

* chore: Fix formatting

* feat: Replace `std` with `core::error::Error`

* chore: Alphabetize dependency order

* chore: Include only minor version in version string
  • Loading branch information
PhilippGackstatter authored Nov 21, 2024
1 parent 7098c66 commit e31db53
Show file tree
Hide file tree
Showing 44 changed files with 625 additions and 626 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

- [BREAKING] Better error display when queues are full in the prover service (#967).
- [BREAKING] Remove `AccountBuilder::build_testing` and make `Account::initialize_from_components` private (#969).
- [BREAKING] Add error messages to errors and implement `core::error::Error` (#974).

## 0.6.1 (2024-11-08)

Expand Down
45 changes: 37 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ lto = true

[workspace.dependencies]
assembly = { package = "miden-assembly", version = "0.11", default-features = false }
assert_matches = { version = "1.5", default-features = false }
miden-crypto = { version = "0.12", default-features = false }
miden-lib = { path = "miden-lib", version = "0.7", default-features = false }
miden-objects = { path = "objects", version = "0.7", default-features = false }
Expand All @@ -41,5 +42,6 @@ miden-stdlib = { version = "0.11", default-features = false }
miden-tx = { path = "miden-tx", version = "0.7", default-features = false }
miden-verifier = { version = "0.11", default-features = false }
rand = { version = "0.8", default-features = false }
thiserror = { version = "2.0", default-features = false }
vm-core = { package = "miden-core", version = "0.11", default-features = false }
vm-processor = { package = "miden-processor", version = "0.11", default-features = false }
2 changes: 2 additions & 0 deletions bin/tx-prover/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,5 @@ impl std::fmt::Display for RemoteTransactionProverError {
}
}
}

impl core::error::Error for RemoteTransactionProverError {}
31 changes: 18 additions & 13 deletions miden-lib/src/accounts/faucets/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use alloc::string::ToString;

use miden_objects::{
accounts::{
Account, AccountBuilder, AccountComponent, AccountStorageMode, AccountType, StorageSlot,
Expand Down Expand Up @@ -32,17 +30,27 @@ pub struct BasicFungibleFaucet {
}

impl BasicFungibleFaucet {
// CONSTANTS
// --------------------------------------------------------------------------------------------
const MAX_MAX_SUPPLY: u64 = (1 << 63) - 1;
const MAX_DECIMALS: u8 = 12;

// CONSTRUCTORS
// --------------------------------------------------------------------------------------------

/// Creates a new [`BasicFungibleFaucet`] component from the given pieces of metadata.
pub fn new(symbol: TokenSymbol, decimals: u8, max_supply: Felt) -> Result<Self, AccountError> {
// First check that the metadata is valid.
if decimals > MAX_DECIMALS {
return Err(AccountError::FungibleFaucetInvalidMetadata(
"Decimals must be less than 13".to_string(),
));
} else if max_supply.as_int() > MAX_MAX_SUPPLY {
return Err(AccountError::FungibleFaucetInvalidMetadata(
"Max supply must be < 2^63".to_string(),
));
if decimals > Self::MAX_DECIMALS {
return Err(AccountError::FungibleFaucetTooManyDecimals {
actual: decimals,
max: Self::MAX_DECIMALS,
});
} else if max_supply.as_int() > Self::MAX_MAX_SUPPLY {
return Err(AccountError::FungibleFaucetMaxSupplyTooLarge {
actual: max_supply.as_int(),
max: Self::MAX_MAX_SUPPLY,
});
}

Ok(Self { symbol, decimals, max_supply })
Expand All @@ -65,9 +73,6 @@ impl From<BasicFungibleFaucet> for AccountComponent {
// FUNGIBLE FAUCET
// ================================================================================================

const MAX_MAX_SUPPLY: u64 = (1 << 63) - 1;
const MAX_DECIMALS: u8 = 12;

/// Creates a new faucet account with basic fungible faucet interface,
/// account storage type, specified authentication scheme, and provided meta data (token symbol,
/// decimals, max supply).
Expand Down
4 changes: 2 additions & 2 deletions miden-lib/src/accounts/wallets/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ pub fn create_basic_wallet(
account_storage_mode: AccountStorageMode,
) -> Result<(Account, Word), AccountError> {
if matches!(account_type, AccountType::FungibleFaucet | AccountType::NonFungibleFaucet) {
return Err(AccountError::AccountIdInvalidFieldElement(
"Basic wallet accounts cannot have a faucet account type".to_string(),
return Err(AccountError::AssumptionViolated(
"basic wallet accounts cannot have a faucet account type".to_string(),
));
}

Expand Down
15 changes: 6 additions & 9 deletions miden-lib/src/transaction/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use miden_objects::{
// TRANSACTION KERNEL ERROR
// ================================================================================================

#[derive(Debug, Clone, Eq, PartialEq)]
#[derive(Debug)]
pub enum TransactionKernelError {
AccountDeltaError(AccountDeltaError),
FailedToAddAssetToNote(NoteError),
Expand Down Expand Up @@ -117,13 +117,12 @@ impl fmt::Display for TransactionKernelError {
}
}

#[cfg(feature = "std")]
impl std::error::Error for TransactionKernelError {}
impl core::error::Error for TransactionKernelError {}

// TRANSACTION EVENT PARSING ERROR
// ================================================================================================

#[derive(Debug, Clone, Eq, PartialEq)]
#[derive(Debug)]
pub enum TransactionEventParsingError {
InvalidTransactionEvent(u32),
NotTransactionEvent(u32),
Expand All @@ -142,13 +141,12 @@ impl fmt::Display for TransactionEventParsingError {
}
}

#[cfg(feature = "std")]
impl std::error::Error for TransactionEventParsingError {}
impl core::error::Error for TransactionEventParsingError {}

// TRANSACTION TRACE PARSING ERROR
// ================================================================================================

#[derive(Debug, Clone, Eq, PartialEq)]
#[derive(Debug)]
pub enum TransactionTraceParsingError {
InvalidTransactionTrace(u32),
NotTransactionTrace(u32),
Expand All @@ -167,5 +165,4 @@ impl fmt::Display for TransactionTraceParsingError {
}
}

#[cfg(feature = "std")]
impl std::error::Error for TransactionTraceParsingError {}
impl core::error::Error for TransactionTraceParsingError {}
12 changes: 6 additions & 6 deletions miden-lib/src/transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,18 +272,18 @@ impl TransactionKernel {
let final_account_data: &[Word] = group_slice_elements(
adv_map
.get(&final_acct_hash)
.ok_or(TransactionOutputError::FinalAccountDataNotFound)?,
.ok_or(TransactionOutputError::FinalAccountHashMissingInAdviceMap)?,
);
let account = parse_final_account_header(final_account_data)
.map_err(TransactionOutputError::FinalAccountHeaderDataInvalid)?;
.map_err(TransactionOutputError::FinalAccountHeaderParseFailure)?;

// validate output notes
let output_notes = OutputNotes::new(output_notes)?;
if output_notes_hash != output_notes.commitment() {
return Err(TransactionOutputError::OutputNotesCommitmentInconsistent(
output_notes_hash,
output_notes.commitment(),
));
return Err(TransactionOutputError::OutputNotesCommitmentInconsistent {
actual: output_notes.commitment(),
expected: output_notes_hash,
});
}

Ok(TransactionOutputs {
Expand Down
5 changes: 4 additions & 1 deletion miden-lib/src/transaction/outputs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ pub const EXPIRATION_BLOCK_ELEMENT_IDX: usize = 8;
/// Returns a tuple of account ID, vault root, storage commitment, code commitment, and nonce.
pub fn parse_final_account_header(elements: &[Word]) -> Result<AccountHeader, AccountError> {
if elements.len() != ACCT_DATA_MEM_SIZE {
return Err(AccountError::HeaderDataIncorrectLength(elements.len(), ACCT_DATA_MEM_SIZE));
return Err(AccountError::HeaderDataIncorrectLength {
actual: elements.len(),
expected: ACCT_DATA_MEM_SIZE,
});
}

let id = AccountId::try_from(elements[ACCT_ID_AND_NONCE_OFFSET as usize][ACCT_ID_IDX])?;
Expand Down
1 change: 1 addition & 0 deletions miden-tx/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,6 @@ winter-maybe-async = { version = "0.10" }

[dev-dependencies]
assembly = { workspace = true }
assert_matches = { workspace = true }
miden-tx = { path = ".", features = ["testing"] }
rand_chacha = { version = "0.3", default-features = false }
Loading

0 comments on commit e31db53

Please sign in to comment.