feat: Implement named storage slots in the transaction kernel#1987
feat: Implement named storage slots in the transaction kernel#1987PhilippGackstatter merged 45 commits intonextfrom
Conversation
mmagician
left a comment
There was a problem hiding this comment.
for now just a very surface-level review.
I'm looking forward to using named storage slots when fully ready!
mmagician
left a comment
There was a problem hiding this comment.
Overall I'm happy to proceed with the current changes.
I foresee a bunch of changes still happening to the interface as we make the shift from using index-based names to actual unique slot names. It's a bit hard to reason about those already in this PR (related to some of the questions I left) so it probably makes sense to unblock you.
Speaking of unblocking: should we proceed w/o 0xMiden/miden-vm#2268 for now?
There was a problem hiding this comment.
Pull Request Overview
This PR refactors the account storage system to access storage slots by names instead of indices, introducing a new NamedStorageSlot abstraction and updating the storage commitment computation to include slot name identifiers.
- Introduced
NamedStorageSlotwrapper that associates each storage slot with aSlotNameand cachedSlotNameId - Updated storage commitment format to include name IDs in the header:
[[0, slot_type, name_id_suffix, name_id_prefix], SLOT_VALUE] - Refactored assembly code to use sorted array binary search for slot lookup by name instead of direct indexing
Reviewed Changes
Copilot reviewed 29 out of 29 changed files in this pull request and generated 15 comments.
Show a summary per file
| File | Description |
|---|---|
| crates/miden-objects/src/account/storage/slot/slot_name.rs | Added serialization, Display implementation, and length validation for slot names |
| crates/miden-objects/src/account/storage/slot/slot_name_id.rs | New file defining SlotNameId struct for cached name identifiers |
| crates/miden-objects/src/account/storage/slot/named_slot.rs | New file defining NamedStorageSlot wrapper combining name and slot |
| crates/miden-objects/src/account/storage/mod.rs | Refactored AccountStorage to use NamedStorageSlot internally with binary search lookup |
| crates/miden-objects/src/account/storage/header.rs | Updated StorageSlotHeader to include name_id and changed commitment format |
| crates/miden-objects/src/account/storage/slot/type.rs | Changed StorageSlotType to use repr(u8) and simplified TryFrom implementation |
| crates/miden-tx/src/host/storage_delta_tracker.rs | Updated to destructure new tuple format with slot names |
| crates/miden-testing/src/kernel_tests/tx/*.rs | Updated test code to use renamed methods (commitment() → to_commitment(), as_elements() → to_elements()) |
| crates/miden-lib/asm/kernels/transaction/lib/account.masm | Added slot lookup procedures using sorted array binary search |
| CHANGELOG.md | Added entry for breaking change |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
bobbinth
left a comment
There was a problem hiding this comment.
Looks good! Thank you! I left some comments inline - most of them are related to naming.
| #[derive(Debug, Clone, PartialEq, Eq)] | ||
| pub struct NamedStorageSlot { |
There was a problem hiding this comment.
Is the plan to eventually rename this to just StorageSlot?
There was a problem hiding this comment.
That would be nice, but I'm not sure what a better name for the current StorageSlot enum would be then. Except for not being prefixed with Storage, I like the naming because NamedStorageSlot is just a StorageSlot with a SlotName. I'm open to other suggestions, though.
|
I consider this PR ready to be merged, and while we could merge it, I'm leaning towards keeping it open, until #2025 is ready to merge as well. This PR has a few unfinished parts and these PRs are closely related, so merging them together should result in fewer hiccups overall. |
…o pgackst-named-storage-slots
* feat: Implement `NamedStorageSlot` * feat: Use `find_half_key_value` * feat: Implement `AccountStorage::get` * feat: Reimplement account storage APIs * chore: Add compat APIs * feat: Reinstantiate apply_delta and reimpl set_item_raw * fix: get_storage_slot_type * fix: name layout in memory * feat: Implement get_size_hint for named slot and slot name * chore: Reinstantiate commented tests * feat: Implement `SequentialCommit` and make `StorageSlotHeader` private * chore: Various cleanup * fix: toml fmt and `typ` "typo" * chore: Add changelog entry * feat: Enforce max length on `SlotName` * chore: Emit event earlier in `get_map_item_raw` * feat: Update docs of storage slot header and account storage header * chore: Document `NamedStorageSlot` fields * chore: Rename `get_storage_slot_ptr` -> `find_storage_slot` * chore: use branch from VM PR * chore: Bump miden-vm to 0.18.3 * chore: Address post-merge changes * chore: move changelog entry to 0.13 and remove duplicate entries * fix: make format * chore: Use `get_storage_slot_type` instead * chore: Use BTreeSet to check for name uniqueness * chore: Rename `name_id` to `id` * chore: Use `project_name` in slot name example * chore: Remove `SlotName::is_empty` * chore: regengerate kernel procedure files --------- Co-authored-by: Bobbin Threadbare <43513081+bobbinth@users.noreply.github.com>
* feat: Implement `NamedStorageSlot` * feat: Use `find_half_key_value` * feat: Implement `AccountStorage::get` * feat: Reimplement account storage APIs * chore: Add compat APIs * feat: Reinstantiate apply_delta and reimpl set_item_raw * fix: get_storage_slot_type * fix: name layout in memory * feat: Implement get_size_hint for named slot and slot name * chore: Reinstantiate commented tests * feat: Implement `SequentialCommit` and make `StorageSlotHeader` private * chore: Various cleanup * fix: toml fmt and `typ` "typo" * chore: Add changelog entry * feat: Enforce max length on `SlotName` * chore: Emit event earlier in `get_map_item_raw` * feat: Update docs of storage slot header and account storage header * chore: Document `NamedStorageSlot` fields * chore: Rename `get_storage_slot_ptr` -> `find_storage_slot` * chore: use branch from VM PR * chore: Bump miden-vm to 0.18.3 * chore: Address post-merge changes * chore: move changelog entry to 0.13 and remove duplicate entries * fix: make format * chore: Use `get_storage_slot_type` instead * chore: Use BTreeSet to check for name uniqueness * chore: Rename `name_id` to `id` * chore: Use `project_name` in slot name example * chore: Remove `SlotName::is_empty` * chore: regengerate kernel procedure files --------- Co-authored-by: Bobbin Threadbare <43513081+bobbinth@users.noreply.github.com>
* feat: Implement `NamedStorageSlot` * feat: Use `find_half_key_value` * feat: Implement `AccountStorage::get` * feat: Reimplement account storage APIs * chore: Add compat APIs * feat: Reinstantiate apply_delta and reimpl set_item_raw * fix: get_storage_slot_type * fix: name layout in memory * feat: Implement get_size_hint for named slot and slot name * chore: Reinstantiate commented tests * feat: Implement `SequentialCommit` and make `StorageSlotHeader` private * chore: Various cleanup * fix: toml fmt and `typ` "typo" * chore: Add changelog entry * feat: Enforce max length on `SlotName` * chore: Emit event earlier in `get_map_item_raw` * feat: Update docs of storage slot header and account storage header * chore: Document `NamedStorageSlot` fields * chore: Rename `get_storage_slot_ptr` -> `find_storage_slot` * chore: use branch from VM PR * chore: Bump miden-vm to 0.18.3 * chore: Address post-merge changes * chore: move changelog entry to 0.13 and remove duplicate entries * fix: make format * chore: Use `get_storage_slot_type` instead * chore: Use BTreeSet to check for name uniqueness * chore: Rename `name_id` to `id` * chore: Use `project_name` in slot name example * chore: Remove `SlotName::is_empty` * chore: regengerate kernel procedure files --------- Co-authored-by: Bobbin Threadbare <43513081+bobbinth@users.noreply.github.com>
Implements named storage slots. The main changes:
std::collections::sorted_arrayhelpers to search for the name without having to reimplement its complex logic. In order to usesorted_array, we need a sorted array, and for that reason,SlotNamecan be turned into aSlotNamedId(which will eventually be the hash of the name).sorted_arraymiden-vm#2268, so we can search for the slot wherename_id_suffix, name_id_prefixmatch, rather than the entire key (including the slot type). See that PR for the motivation.0into a lookup of namemiden::0, index1intomiden::1, and so on. In a subsequent PR, all the public facing APIs can be changed. Because of that, there are some temporary APIs. These are marked and will be removed in that next PR.$kernel::accountandAccountStorage,AccountStorageHeaderandStorageSlotHeader.$kernel::accountcontainsget_item_init_by_index/get_item_by_indexwhich are equivalent to the current APIs and they are intended to stay for use in the account delta.part of #1724