Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,22 @@

- Added `prove_dummy` APIs on `LocalTransactionProver` ([#1674](https://github.com/0xMiden/miden-base/pull/1674)).
- Added `add_signature` helper to simplify loading signatures into advice map ([#1725](https://github.com/0xMiden/miden-base/pull/1725)).
- Enable lazy loading of assets during transaction execution ([#1848](https://github.com/0xMiden/miden-base/pull/1848)).
- Added `prove_dummy` APIs on `LocalBatchProver` and `LocalBlockProver` ([#1811](https://github.com/0xMiden/miden-base/pull/1811)).
- Added `get_native_id` and `get_native_nonce` procedures to the `miden` library ([#1844](https://github.com/0xMiden/miden-base/pull/1844)).
- Enable lazy loading of assets during transaction execution ([#1848](https://github.com/0xMiden/miden-base/pull/1848)).
- Lazy load the native asset ([#1855](https://github.com/0xMiden/miden-base/pull/1855)).
- Added `prove_dummy` APIs on `LocalBatchProver` and `LocalBlockProver` ([#1811](https://github.com/0xMiden/miden-base/pull/1811)).

### Changes

- [BREAKING] Incremented MSRV to 1.89.
- [BREAKING] Remove some of the `note` kernel procedures and use `input_note` procedures instead ([#1834](https://github.com/0xMiden/miden-base/pull/1834)).
- [BREAKING] Remove versioning of the transaction kernel, leaving only one latest version ([#1793](https://github.com/0xMiden/miden-base/pull/1793)).
- [BREAKING] Move `miden::asset::{create_fungible_asset, create_non_fungible_asset}` procedures to `miden::faucet` ([#1850](https://github.com/0xMiden/miden-base/pull/1850)).
- [BREAKING] Removed versioning of the transaction kernel, leaving only one latest version ([#1793](https://github.com/0xMiden/miden-base/pull/1793)).
- Added `AccountComponent::from_package()` method to create components from `miden-mast-package::Package` ([#1802](https://github.com/0xMiden/miden-base/pull/1802)).
- [BREAKING] Removed some of the `note` kernel procedures and use `input_note` procedures instead ([#1834](https://github.com/0xMiden/miden-base/pull/1834)).
- [BREAKING] Replaced `Account` with `PartialAccount` in `TransactionInputs` ([#1840](https://github.com/0xMiden/miden-base/pull/1840)).
- [BREAKING] Renamed `Account::init_commitment` to `Account::initial_commitment` ([#1840](https://github.com/0xMiden/miden-base/pull/1840)).
- [BREAKING] Rename the `is_onchain` method to `has_public_state` for `AccountId`, `AccountIdPrefix`, `Account`, `AccountInterface` and `AccountStorageMode` ([#1846](https://github.com/0xMiden/miden-base/pull/1846)).
- [BREAKING] Move `NetworkId` from account ID to address module ([#1851](https://github.com/0xMiden/miden-base/pull/1851)).
- [BREAKING] Renamed the `is_onchain` method to `has_public_state` for `AccountId`, `AccountIdPrefix`, `Account`, `AccountInterface` and `AccountStorageMode` ([#1846](https://github.com/0xMiden/miden-base/pull/1846)).
- [BREAKING] Moved `miden::asset::{create_fungible_asset, create_non_fungible_asset}` procedures to `miden::faucet` ([#1850](https://github.com/0xMiden/miden-base/pull/1850)).
- [BREAKING] Moved `NetworkId` from account ID to address module ([#1851](https://github.com/0xMiden/miden-base/pull/1851)).

## 0.11.2 (2025-09-08)

Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

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

17 changes: 9 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,15 @@ miden-tx = { default-features = false, path = "crates/miden-tx", ve
miden-tx-batch-prover = { default-features = false, path = "crates/miden-tx-batch-prover", version = "0.12" }

# Miden dependencies
miden-assembly = { default-features = false, version = "0.17" }
miden-core = { default-features = false, version = "0.17" }
miden-crypto = { default-features = false, version = "0.15.6" }
miden-processor = { default-features = false, version = "0.17" }
miden-prover = { default-features = false, version = "0.17" }
miden-stdlib = { default-features = false, version = "0.17" }
miden-utils-sync = { default-features = false, version = "0.17" }
miden-verifier = { default-features = false, version = "0.17" }
miden-assembly = { default-features = false, version = "0.17" }
miden-core = { default-features = false, version = "0.17" }
miden-crypto = { default-features = false, version = "0.15.6" }
miden-mast-package = { default-features = false, version = "0.17" }
miden-processor = { default-features = false, version = "0.17" }
miden-prover = { default-features = false, version = "0.17" }
miden-stdlib = { default-features = false, version = "0.17" }
miden-utils-sync = { default-features = false, version = "0.17" }
miden-verifier = { default-features = false, version = "0.17" }

# External dependencies
anyhow = { default-features = false, version = "1.0" }
Expand Down
15 changes: 8 additions & 7 deletions crates/miden-objects/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,14 @@ testing = ["dep:rand", "dep:rand_xoshiro", "dep:winter-rand-utils"]

[dependencies]
# Miden dependencies
miden-assembly = { workspace = true }
miden-core = { workspace = true }
miden-crypto = { workspace = true }
miden-processor = { workspace = true }
miden-utils-sync = { workspace = true }
miden-verifier = { workspace = true }
winter-rand-utils = { optional = true, version = "0.13" }
miden-assembly = { workspace = true }
miden-core = { workspace = true }
miden-crypto = { workspace = true }
miden-mast-package = { workspace = true }
miden-processor = { workspace = true }
miden-utils-sync = { workspace = true }
miden-verifier = { workspace = true }
winter-rand-utils = { optional = true, version = "0.13" }

# External dependencies
bech32 = { default-features = false, features = ["alloc"], version = "0.11" }
Expand Down
173 changes: 173 additions & 0 deletions crates/miden-objects/src/account/component/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ use alloc::vec::Vec;

use miden_assembly::ast::QualifiedProcedureName;
use miden_assembly::{Assembler, Library, Parse};
use miden_core::utils::Deserializable;
use miden_mast_package::Package;
use miden_processor::MastForest;

mod template;
Expand All @@ -11,6 +13,35 @@ pub use template::*;
use crate::account::{AccountType, StorageSlot};
use crate::{AccountError, Word};

// IMPLEMENTATIONS
// ================================================================================================

impl TryFrom<Package> for AccountComponentTemplate {
type Error = AccountError;

fn try_from(package: Package) -> Result<Self, Self::Error> {
let library = package.unwrap_library().as_ref().clone();

// Extract metadata - require explicit account component metadata
let metadata = match package.account_component_metadata_bytes.as_deref() {
Some(metadata_bytes) => AccountComponentMetadata::read_from_bytes(metadata_bytes)
.map_err(|err| {
AccountError::other_with_source(
"failed to deserialize account component metadata",
err,
)
})?,
None => {
return Err(AccountError::other(
"package does not contain account component metadata - packages without explicit metadata may be intended for other purposes (e.g., note scripts, transaction scripts)",
));
},
};

Ok(AccountComponentTemplate::new(metadata, library))
}
}

/// An [`AccountComponent`] defines a [`Library`] of code and the initial value and types of
/// the [`StorageSlot`]s it accesses.
///
Expand Down Expand Up @@ -112,6 +143,31 @@ impl AccountComponent {
.with_supported_types(template.metadata().supported_types().clone()))
}

/// Creates an [`AccountComponent`] from a [`Package`] using [`InitStorageData`].
///
/// This method provides type safety by leveraging the component's metadata to validate
/// storage initialization data. The package must contain explicit account component metadata.
///
/// # Arguments
///
/// * `package` - The package containing the library and account component metadata
/// * `init_storage_data` - The initialization data for storage slots
///
/// # Errors
///
/// Returns an error if:
/// - The package does not contain account component metadata
/// - The package cannot be converted to an [`AccountComponentTemplate`]
/// - The storage initialization fails due to invalid or missing data
/// - The component creation fails
pub fn from_package_with_init_data(
package: &Package,
init_storage_data: &InitStorageData,
) -> Result<Self, AccountError> {
let template = AccountComponentTemplate::try_from(package.clone())?;
Self::from_template(&template, init_storage_data)
}

// ACCESSORS
// --------------------------------------------------------------------------------------------

Expand Down Expand Up @@ -205,3 +261,120 @@ impl From<AccountComponent> for Library {
component.library
}
}

#[cfg(test)]
mod tests {
use alloc::collections::BTreeSet;
use alloc::string::ToString;
use alloc::sync::Arc;

use miden_assembly::Assembler;
use miden_core::utils::Serializable;
use miden_mast_package::{MastArtifact, Package, PackageManifest};
use semver::Version;

use super::*;
use crate::testing::account_code::CODE;

#[test]
fn test_try_from_package_for_template() {
// Create a simple library for testing
let library = Assembler::default().assemble_library([CODE]).unwrap();

// Test with metadata
let metadata = AccountComponentMetadata::new(
"test_component".to_string(),
"A test component".to_string(),
Version::new(1, 0, 0),
BTreeSet::from_iter([AccountType::RegularAccountImmutableCode]),
vec![],
)
.unwrap();

let metadata_bytes = metadata.to_bytes();
let package_with_metadata = Package {
name: "test_package".to_string(),
mast: MastArtifact::Library(Arc::new(library.clone())),
manifest: PackageManifest::new(None),
account_component_metadata_bytes: Some(metadata_bytes),
};

let template = AccountComponentTemplate::try_from(package_with_metadata).unwrap();
assert_eq!(template.metadata().name(), "test_component");
assert!(
template
.metadata()
.supported_types()
.contains(&AccountType::RegularAccountImmutableCode)
);

// Test without metadata - should fail
let package_without_metadata = Package {
name: "test_package_no_metadata".to_string(),
mast: MastArtifact::Library(Arc::new(library)),
manifest: PackageManifest::new(None),
account_component_metadata_bytes: None,
};

let result = AccountComponentTemplate::try_from(package_without_metadata);
assert!(result.is_err());
let error_msg = result.unwrap_err().to_string();
assert!(error_msg.contains("package does not contain account component metadata"));
}

#[test]
fn test_from_package_with_init_data() {
// Create a simple library for testing
let library = Assembler::default().assemble_library([CODE]).unwrap();

// Create metadata for the component
let metadata = AccountComponentMetadata::new(
"test_component".to_string(),
"A test component".to_string(),
Version::new(1, 0, 0),
BTreeSet::from_iter([
AccountType::RegularAccountImmutableCode,
AccountType::RegularAccountUpdatableCode,
]),
vec![],
)
.unwrap();

// Serialize the metadata
let metadata_bytes = metadata.to_bytes();

// Create a package with metadata
let package = Package {
name: "test_package_init_data".to_string(),
mast: MastArtifact::Library(Arc::new(library.clone())),
manifest: PackageManifest::new(None),
account_component_metadata_bytes: Some(metadata_bytes),
};

// Test with empty init data - this tests the complete workflow:
// Package -> AccountComponentTemplate -> AccountComponent
let init_data = InitStorageData::default();
let component =
AccountComponent::from_package_with_init_data(&package, &init_data).unwrap();

// Verify the component was created correctly
assert_eq!(component.storage_size(), 0);
assert!(component.supports_type(AccountType::RegularAccountImmutableCode));
assert!(component.supports_type(AccountType::RegularAccountUpdatableCode));
assert!(!component.supports_type(AccountType::FungibleFaucet));

// Test without metadata - should fail
let package_without_metadata = Package {
name: "test_package_no_metadata".to_string(),
mast: MastArtifact::Library(Arc::new(library)),
manifest: PackageManifest::new(None),
account_component_metadata_bytes: None,
};

let result =
AccountComponent::from_package_with_init_data(&package_without_metadata, &init_data);
assert!(result.is_err());
let error_msg = result.unwrap_err().to_string();
assert!(error_msg.contains("package does not contain account component metadata"));
}
}
1 change: 1 addition & 0 deletions crates/miden-objects/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ pub mod utils {
pub mod vm {
pub use miden_core::sys_events::SystemEvent;
pub use miden_core::{AdviceMap, Program, ProgramInfo};
pub use miden_mast_package::Package;
pub use miden_processor::{AdviceInputs, FutureMaybeSend, RowIndex, StackInputs, StackOutputs};
pub use miden_verifier::ExecutionProof;
}
Loading