Skip to content

feat: Implement named storage slots in the transaction kernel#1987

Merged
PhilippGackstatter merged 45 commits intonextfrom
pgackst-named-storage-slots
Dec 9, 2025
Merged

feat: Implement named storage slots in the transaction kernel#1987
PhilippGackstatter merged 45 commits intonextfrom
pgackst-named-storage-slots

Conversation

@PhilippGackstatter
Copy link
Contributor

Implements named storage slots. The main changes:

  • Change storage slot memory layout to:
    [[0, slot_type, name_id_suffix, name_id_prefix], SLOT_VALUE]
    
    Previously, the SLOT_VALUE was the first WORD. This change allows using std::collections::sorted_array helpers to search for the name without having to reimplement its complex logic. In order to use sorted_array, we need a sorted array, and for that reason, SlotName can be turned into a SlotNamedId (which will eventually be the hash of the name).
  • Builds on feat: Allow searching for a partial key in sorted_array miden-vm#2268, so we can search for the slot where name_id_suffix, name_id_prefix match, rather than the entire key (including the slot type). See that PR for the motivation.
    • We don't absolutely need this VM PR to be merged for named storage slots. We can instead also temporarily include the slot type in the lookup, but eventually we should probably find a way to not require a match on the entire WORD.
  • Leaves the index API in place. This PR essentially changes the underlying slot implementation to named slots, but translates access to index 0 into a lookup of name miden::0, index 1 into miden::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.
  • The primary impact of this PR is on $kernel::account and AccountStorage, AccountStorageHeader and StorageSlotHeader.
  • The doc-related TODOs can be done in this PR or in the next, but I would probably do them in the next one when the full impact on the API has become clear. In any case, a deep check on the account storage docs is necessary, because we have used slot indices a lot and those docs will probably have to be rewritten.
  • Also not that $kernel::account contains get_item_init_by_index / get_item_by_index which are equivalent to the current APIs and they are intended to stay for use in the account delta.

part of #1724

Copy link
Collaborator

@mmagician mmagician left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for now just a very surface-level review.

I'm looking forward to using named storage slots when fully ready!

Copy link
Collaborator

@mmagician mmagician left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 NamedStorageSlot wrapper that associates each storage slot with a SlotName and cached SlotNameId
  • 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.

Copy link
Contributor

@bobbinth bobbinth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Thank you! I left some comments inline - most of them are related to naming.

Comment on lines +5 to +6
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct NamedStorageSlot {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the plan to eventually rename this to just StorageSlot?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@PhilippGackstatter
Copy link
Contributor Author

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.

@PhilippGackstatter PhilippGackstatter merged commit 004e99c into next Dec 9, 2025
17 checks passed
@PhilippGackstatter PhilippGackstatter deleted the pgackst-named-storage-slots branch December 9, 2025 06:16
sergerad pushed a commit that referenced this pull request Dec 10, 2025
* 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>
sergerad pushed a commit that referenced this pull request Dec 10, 2025
* 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>
sergerad pushed a commit that referenced this pull request Dec 10, 2025
* 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants