Skip to content
Merged
Show file tree
Hide file tree
Changes from 18 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
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@
- [BREAKING] Migrated to `miden-vm` v0.20 and `miden-crypto` v0.19 ([#2158](https://github.com/0xMiden/miden-base/pull/2158)).
- [BREAKING] Refactored `AccountStorageDelta` to use a new `StorageSlotDelta` type ([#2182](https://github.com/0xMiden/miden-base/pull/2182)).
- [BREAKING] Removed OLD_MAP_ROOT from being returned when calling [`native_account::set_map_item`](crates/miden-lib/asm/miden/native_account.masm) ([#2194](https://github.com/0xMiden/miden-base/pull/2194)).
- [BREAKING] Refactored account component templates into `AccountStorageSchema` ([#2193](https://github.com/0xMiden/miden-base/pull/2193)).
- [BREAKING] Refactored account component templates into `StorageSchema` ([#2193](https://github.com/0xMiden/miden-base/pull/2193)).
- [BREAKING] Refactored `InitStorageData` to support native types ([#2230](https://github.com/0xMiden/miden-base/pull/2230)).
- Added `StorageSchema::commitment()` ([#2244](https://github.com/0xMiden/miden-base/pull/2244)).

## 0.12.4 (2025-11-26)

Expand Down
54 changes: 32 additions & 22 deletions crates/miden-protocol/src/account/component/metadata/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use miden_mast_package::{Package, SectionId};
use miden_processor::DeserializationError;
use semver::Version;

use super::{AccountStorageSchema, AccountType, SchemaRequirement, StorageValueName};
use super::{AccountType, SchemaRequirement, StorageSchema, StorageValueName};
use crate::AccountError;

// ACCOUNT COMPONENT METADATA
Expand All @@ -27,10 +27,10 @@ use crate::AccountError;
///
/// - The metadata's storage schema does not contain duplicate slot names.
/// - The schema cannot contain protocol-reserved slot names.
/// - Each init-time value name uniquely identifies a single value. The expected init-time
/// requirements can be retrieved with [AccountComponentMetadata::schema_requirements()], which
/// returns a map from keys to [SchemaRequirement] (which indicates the expected value type and
/// optional defaults).
/// - Each init-time value name uniquely identifies a single value. The expected init-time metadata
/// can be retrieved with [AccountComponentMetadata::schema_requirements()], which returns a map
/// from keys to [SchemaRequirement] (which indicates the expected value type and optional
/// defaults).
///
/// # Example
///
Expand All @@ -40,14 +40,15 @@ use crate::AccountError;
/// use miden_protocol::account::StorageSlotName;
/// use miden_protocol::account::component::{
/// AccountComponentMetadata,
/// AccountStorageSchema,
/// FeltSchema,
/// InitStorageData,
/// SchemaTypeId,
/// StorageSchema,
/// StorageSlotSchema,
/// StorageValueName,
/// ValueSlotSchema,
/// WordSchema,
/// WordValue,
/// };
/// use semver::Version;
///
Expand All @@ -60,7 +61,7 @@ use crate::AccountError;
/// FeltSchema::new_typed(SchemaTypeId::native_felt(), "foo"),
/// ]);
///
/// let storage_schema = AccountStorageSchema::new([(
/// let storage_schema = StorageSchema::new([(
/// slot_name.clone(),
/// StorageSlotSchema::Value(ValueSlotSchema::new(Some("demo slot".into()), word)),
/// )])?;
Expand All @@ -74,10 +75,9 @@ use crate::AccountError;
/// );
///
/// // Init value keys are derived from slot name: `demo::test_value.foo`.
/// let init_storage_data = InitStorageData::new(
/// [(StorageValueName::from_slot_name(&slot_name).with_suffix("foo")?, "300".into())],
/// [],
/// );
/// let value_name = StorageValueName::from_slot_name_with_suffix(&slot_name, "foo")?;
/// let mut init_storage_data = InitStorageData::default();
/// init_storage_data.set_value(value_name, WordValue::Atomic("300".into()))?;
///
/// let storage_slots = metadata.storage_schema().build_storage_slots(&init_storage_data)?;
/// assert_eq!(storage_slots.len(), 1);
Expand All @@ -102,7 +102,7 @@ pub struct AccountComponentMetadata {

/// Storage schema defining the component's storage layout, defaults, and init-supplied values.
#[cfg_attr(feature = "std", serde(rename = "storage"))]
storage_schema: AccountStorageSchema,
storage_schema: StorageSchema,
}

impl AccountComponentMetadata {
Expand All @@ -112,7 +112,7 @@ impl AccountComponentMetadata {
description: String,
version: Version,
targets: BTreeSet<AccountType>,
storage_schema: AccountStorageSchema,
storage_schema: StorageSchema,
) -> Self {
Self {
name,
Expand All @@ -123,7 +123,7 @@ impl AccountComponentMetadata {
}
}

/// Returns the init-time value requirements for this schema.
/// Returns the init-time values requirements for this schema.
///
/// These values are used for initializing storage slot values or storage map entries. For a
/// full example, refer to the docs for [AccountComponentMetadata].
Expand Down Expand Up @@ -154,7 +154,7 @@ impl AccountComponentMetadata {
}

/// Returns the storage schema of the component.
pub fn storage_schema(&self) -> &AccountStorageSchema {
pub fn storage_schema(&self) -> &StorageSchema {
&self.storage_schema
}
}
Expand Down Expand Up @@ -200,14 +200,24 @@ impl Serializable for AccountComponentMetadata {

impl Deserializable for AccountComponentMetadata {
fn read_from<R: ByteReader>(source: &mut R) -> Result<Self, DeserializationError> {
let name = String::read_from(source)?;
let description = String::read_from(source)?;
if !description.is_ascii() {
return Err(DeserializationError::InvalidValue(
"description must contain only ASCII characters".to_string(),
));
}
let version = semver::Version::from_str(&String::read_from(source)?)
.map_err(|err: semver::Error| DeserializationError::InvalidValue(err.to_string()))?;
let supported_types = BTreeSet::<AccountType>::read_from(source)?;
let storage_schema = StorageSchema::read_from(source)?;

Ok(Self {
name: String::read_from(source)?,
description: String::read_from(source)?,
version: semver::Version::from_str(&String::read_from(source)?).map_err(
|err: semver::Error| DeserializationError::InvalidValue(err.to_string()),
)?,
supported_types: BTreeSet::<AccountType>::read_from(source)?,
storage_schema: AccountStorageSchema::read_from(source)?,
name,
description,
version,
supported_types,
storage_schema,
})
}
}
4 changes: 2 additions & 2 deletions crates/miden-protocol/src/account/component/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ mod tests {
"A test component".to_string(),
Version::new(1, 0, 0),
BTreeSet::from_iter([AccountType::RegularAccountImmutableCode]),
AccountStorageSchema::default(),
StorageSchema::default(),
);

let metadata_bytes = metadata.to_bytes();
Expand Down Expand Up @@ -329,7 +329,7 @@ mod tests {
AccountType::RegularAccountImmutableCode,
AccountType::RegularAccountUpdatableCode,
]),
AccountStorageSchema::default(),
StorageSchema::default(),
);

// Test with empty init data - this tests the complete workflow:
Expand Down
Loading