Skip to content

refactor: move initial-state getters to native_account#3218

Open
Fumuran wants to merge 4 commits into
nextfrom
fumuran-claude/recategorize-initial-getters
Open

refactor: move initial-state getters to native_account#3218
Fumuran wants to merge 4 commits into
nextfrom
fumuran-claude/recategorize-initial-getters

Conversation

@Fumuran

@Fumuran Fumuran commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Summary

Closes #2034.

Recategorizes the seven initial-state account getters from miden::protocol::active_account to miden::protocol::native_account. Because the concept of an "initial" (beginning-of-transaction) state is only meaningful for the transaction's native account, these procedures now always operate on the native account and panic with ERR_ACCOUNT_IS_NOT_NATIVE when invoked from a foreign procedure invocation (FPI) context, rather than silently branching on native vs. foreign.

Moved procedures:

  • get_initial_commitment
  • get_initial_storage_commitment
  • get_initial_vault_root
  • get_initial_item
  • get_initial_map_item
  • get_initial_asset
  • get_initial_balance

Changes

  • Protocol library: moved the seven wrappers from active_account.masm into native_account.masm (with the required offset/asset imports).
  • Kernel API (api.masm): added exec.memory::assert_native_account to the six initial-getter procs, matching the existing native-only guard pattern (e.g. account_incr_nonce, account_set_item).
  • Kernel core (account.masm): removed the is_native_account branches from the commitment / storage-commitment / vault-root getters, and switched the item / map-item / asset getters (and get_item_patch) to native-only pointers.
  • memory.masm: removed the now-unused branching helpers get_account_initial_storage_slots_ptr and get_account_initial_vault_root_ptr.
  • Callers: retargeted all auth components / standards (singlesig, singlesig_acl, multisig, multisig_smart, signature, note_/tx_script_allowlist, no_auth, network_account) and the mock account code to native_account::, fixing use imports per file.
  • Tests: retargeted test_account.rs; rewrote the two FPI tests so foreign-context calls now assert ERR_ACCOUNT_IS_NOT_NATIVE.
  • Docs / changelog: moved the rows to the native-account table in protocol_library.md and added a [BREAKING] changelog entry.

Design note

Per the discussion, FPI invocation of these getters is now a hard error (via memory::assert_native_account). This technically adds an assert rather than purely removing conditional logic, but it is consistent with how other native-only procedures (set_item, incr_nonce, add_asset) are already guarded, and it removes the dual-behavior branches the issue called out.

Testing

  • cargo build -p miden-protocol -p miden-standards (compiles the MASM kernel and libraries).
  • cargo test -p miden-testing: 30 test_account tests, 12 test_fpi tests (including two new error tests), and 81 auth integration tests — all passing.

🤖 Generated with Claude Code

Move get_initial_commitment, get_initial_storage_commitment,
get_initial_vault_root, get_initial_item, get_initial_map_item,
get_initial_asset and get_initial_balance from the active_account module
to native_account. These procedures operate on the transaction's native
account, so they now assert the active account is native (via
memory::assert_native_account) and panic with ERR_ACCOUNT_IS_NOT_NATIVE
when invoked from a foreign procedure invocation (FPI) context.

Removes the is_native_account conditional logic from the kernel
get_initial_* procedures and the now-unused branching pointer helpers
get_account_initial_storage_slots_ptr and get_account_initial_vault_root_ptr.

Updates all standards/auth callers, the mock account code, kernel and FPI
tests, protocol library docs and the changelog.
Comment thread crates/miden-protocol/asm/kernels/transaction-core/src/account.masm Outdated
Comment thread crates/miden-protocol/asm/kernels/transaction-core/src/account.masm Outdated
Comment thread crates/miden-testing/src/kernel_tests/tx/test_fpi.rs Outdated
Comment thread CHANGELOG.md Outdated
claude and others added 3 commits July 7, 2026 15:49
- Re-export get_initial_commitment/storage_commitment/vault_root as pub use
  aliases of the underlying memory procedures instead of one-line wrappers.
- Remove the redundant 'assumed to be invoked after asserting native' doc
  comments in account.masm.
- Restore the foreign-account read tests to verify correct values via the
  active_account current getters (get_item/get_map_item/get_balance), since
  foreign accounts are immutable.
- Note in protocol_library.md that foreign accounts are immutable and their
  initial values should be read via active_account procedures.
- Shorten the changelog entry to reference get_initial_*.
@Fumuran Fumuran changed the title refactor: move initial-state getters to native_account (#2034) refactor: move initial-state getters to native_account Jul 7, 2026
@Fumuran Fumuran marked this pull request as ready for review July 7, 2026 13:38

@PhilippGackstatter PhilippGackstatter left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good!

Did not re-review the procedures in crates/miden-protocol/asm/protocol/src/native_account.masm in detail, assuming they are copies.

Comment on lines -870 to +874
async fn foreign_account_get_initial_balance() -> anyhow::Result<()> {
async fn foreign_account_get_balance() -> anyhow::Result<()> {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Does this test anything that foreign_account_can_get_balance_and_presence_of_asset does not already test? If not, I would remove foreign_account_get_balance.

Comment on lines -1889 to +1897
async fn test_get_initial_item_and_get_initial_map_item_with_foreign_account() -> anyhow::Result<()>
{
async fn test_get_item_and_get_map_item_with_foreign_account() -> anyhow::Result<()> {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Seems like get_item and get_map_item are also covered by other tests (e.g. test_fpi_memory_single_account), so does this test add anything additional? If not, I'd remove it or repurpose it for some other interesting test case.

@mmagician mmagician left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM modulo the now-incorrect docs

One more general comment, unrelated to this PR: I wonder if executing account would be a better name than native account. I remember the naming had confused me quite a bit in the past: native to what?

Comment on lines +76 to +82
| `get_initial_commitment` | Returns the native account commitment at the beginning of the transaction.<br/><br/>**Inputs:** `[]`<br/>**Outputs:** `[INIT_COMMITMENT]` | Any |
| `get_initial_storage_commitment` | Returns the storage commitment of the native account at the beginning of the transaction.<br/><br/>**Inputs:** `[]`<br/>**Outputs:** `[INIT_STORAGE_COMMITMENT]` | Any |
| `get_initial_item` | Gets the initial item from the native account storage slot as it was at the beginning of the transaction.<br/><br/>**Inputs:** `[slot_id_suffix, slot_id_prefix]`<br/>**Outputs:** `[VALUE]` | Account |
| `get_initial_map_item` | Gets the initial VALUE from the native account storage map as it was at the beginning of the transaction.<br/><br/>**Inputs:** `[slot_id_suffix, slot_id_prefix, KEY]`<br/>**Outputs:** `[VALUE]` | Account |
| `get_initial_asset` | Returns the asset associated with the provided asset ID in the native account's vault at the beginning of the transaction.<br/><br/>**Inputs:** `[ASSET_ID]`<br/>**Outputs:** `[ASSET_VALUE]` | Any |
| `get_initial_balance` | Returns the balance of the fungible asset associated with the provided faucet_id in the native account's vault at the beginning of the transaction.<br/><br/>**Inputs:** `[faucet_id_suffix, faucet_id_prefix]`<br/>**Outputs:** `[init_balance]` | Any |
| `get_initial_vault_root` | Returns the vault root of the native account at the beginning of the transaction.<br/><br/>**Inputs:** `[]`<br/>**Outputs:** `[INIT_VAULT_ROOT]` | Any |

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

the context should be updated - "Any" no longer holds

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.

Recategorize procedures in active_account and native_account

4 participants