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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
## v0.16.0 (TBD)

### Changes
- [BREAKING] Moved the initial-state account getters (`get_initial_*`) from `miden::protocol::active_account` to `miden::protocol::native_account`. They now always operate on the native account and panic with `ERR_ACCOUNT_IS_NOT_NATIVE` when invoked from a foreign procedure invocation (FPI) context ([#2034](https://github.com/0xMiden/protocol/issues/2034)).
- Cleaned up `signature.masm` by removing redundant scheme-id validation and duplication, dropping the `neq.0` double-negation in `assert_supported_scheme_word`, and eliminating the unused `NUM_OF_APPROVERS_LOC` slot; also optimized `verify_signatures` to reuse the signer index and approver public key from the operand stack instead of round-tripping them through local memory ([#3230](https://github.com/0xMiden/protocol/pull/3230)).
- Fixed the transaction executor host honoring `AuthRequest` events emitted outside the registered auth procedure, which let untrusted note or transaction scripts force the host to sign; signature production is now restricted to the authentication procedure ([#3233](https://github.com/0xMiden/protocol/pull/3233)).
- Added the `miden::protocol::tx::compute_fee` procedure, which lets account and note code compute the transaction fee during execution ([#3211](https://github.com/0xMiden/protocol/issues/3211)).
Expand Down
99 changes: 15 additions & 84 deletions crates/miden-protocol/asm/kernels/transaction-core/src/account.masm
Original file line number Diff line number Diff line change
Expand Up @@ -217,26 +217,7 @@ end

### ACCOUNT COMMITMENT ###################################################

#! Returns the commitment of the active account at the beginning of the transaction.
#!
#! Inputs: []
#! Outputs: [INIT_COMMITMENT]
#!
#! Where:
#! - INIT_COMMITMENT is the initial account commitment.
pub proc get_initial_commitment
# determine whether the active account is native
exec.memory::is_native_account
# => [is_native_account]

if.true
exec.memory::get_init_account_commitment
else
# for the foreign account current commitment equals to initial
exec.compute_commitment
end
# => [INIT_COMMITMENT]
end
pub use {get_init_account_commitment as get_initial_commitment} from miden::tx_kernel_core::memory

#! Computes commitment to the state of the active account.
#!
Expand Down Expand Up @@ -282,32 +263,7 @@ pub use {get_account_code_commitment as get_code_commitment} from miden::tx_kern

### STORAGE COMMITMENT ###################################################

#! Returns the storage commitment of the active account at the beginning of the transaction.
#!
#! Inputs: []
#! Outputs: [INIT_ACCOUNT_STORAGE_COMMITMENT]
#!
#! Where:
#! - INIT_ACCOUNT_STORAGE_COMMITMENT is the initial account storage commitment.
pub proc get_initial_storage_commitment
# Get the storage commitment of the active account. For the foreign account this commitment will
# be initial.
exec.memory::get_account_storage_commitment
# => [ACTIVE_ACCOUNT_STORAGE_COMMITMENT]

# get the initial storage commitment of the native account
exec.memory::get_init_account_storage_commitment
# => [INIT_NATIVE_ACCOUNT_STORAGE_COMMITMENT, ACTIVE_ACCOUNT_STORAGE_COMMITMENT]

# check whether the active account is native
exec.memory::is_native_account
# => [is_native_account, INIT_NATIVE_ACCOUNT_STORAGE_COMMITMENT, ACTIVE_ACCOUNT_STORAGE_COMMITMENT]

# if the active account is native, keep the INIT_NATIVE_ACCOUNT_STORAGE_COMMITMENT, or
# ACTIVE_ACCOUNT_STORAGE_COMMITMENT otherwise
cdropw
# => [INIT_ACCOUNT_STORAGE_COMMITMENT]
end
pub use {get_init_account_storage_commitment as get_initial_storage_commitment} from miden::tx_kernel_core::memory

#! Computes the storage commitment of the active account.
#!
Expand All @@ -327,32 +283,7 @@ end

### VAULT ROOT ###########################################################

#! Returns the vault root of the active account at the beginning of the transaction.
#!
#! Inputs: []
#! Outputs: [INIT_ACCOUNT_VAULT_ROOT]
#!
#! Where:
#! - INIT_ACCOUNT_VAULT_ROOT is the initial account vault root.
pub proc get_initial_vault_root
# Get the vault root of the active account. For the foreign account this root will be equal to
# the initial one.
exec.memory::get_account_vault_root
# => [ACTIVE_ACCOUNT_VAULT_ROOT]

# get the initial vault root of the native account
exec.memory::get_init_native_account_vault_root
# => [INIT_NATIVE_ACCOUNT_VAULT_ROOT, ACTIVE_ACCOUNT_VAULT_ROOT]

# check whether the active account is native
exec.memory::is_native_account
# => [is_native_account, INIT_NATIVE_ACCOUNT_VAULT_ROOT, ACTIVE_ACCOUNT_VAULT_ROOT]

# if the active account is native, keep the INIT_NATIVE_ACCOUNT_VAULT_ROOT, or
# ACTIVE_ACCOUNT_VAULT_ROOT otherwise
cdropw
# => [INIT_ACCOUNT_VAULT_ROOT]
end
pub use {get_init_native_account_vault_root as get_initial_vault_root} from miden::tx_kernel_core::memory

# STORAGE
# -------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -471,7 +402,7 @@ pub proc get_typed_item
# => [VALUE, slot_type]
end

#! Gets an item from the account storage at its initial state (beginning of transaction).
#! Gets an item from the native account storage at its initial state (beginning of transaction).
#!
#! Inputs: [slot_id_suffix, slot_id_prefix]
#! Outputs: [INIT_VALUE]
Expand All @@ -484,9 +415,9 @@ end
#! Panics if:
#! - a slot with the provided slot ID does not exist in account storage.
pub proc get_initial_item
# get account initial storage slots section offset
exec.memory::get_account_initial_storage_slots_ptr
# => [account_initial_storage_slots_ptr, slot_id_suffix, slot_id_prefix]
# get native account initial storage slots section offset
exec.memory::get_native_account_initial_storage_slots_ptr
# => [native_account_initial_storage_slots_ptr, slot_id_suffix, slot_id_prefix]

exec.get_storage_slot_ptr
# => [slot_ptr]
Expand Down Expand Up @@ -569,7 +500,7 @@ pub proc get_map_item
end

#! Returns the VALUE located under the specified KEY within the map contained in the given
#! account storage slot at its initial state (beginning of transaction).
#! native account storage slot at its initial state (beginning of transaction).
#!
#! Inputs: [slot_id_suffix, slot_id_prefix, KEY]
#! Outputs: [INIT_VALUE]
Expand All @@ -583,8 +514,8 @@ end
#! - a slot with the provided slot ID does not exist in account storage.
#! - the requested storage slot type is not map.
pub proc get_initial_map_item
exec.memory::get_account_initial_storage_slots_ptr
# => [initial_storage_slots_ptr, slot_id_suffix, slot_id_prefix, KEY]
exec.memory::get_native_account_initial_storage_slots_ptr
# => [native_initial_storage_slots_ptr, slot_id_suffix, slot_id_prefix, KEY]

exec.get_map_item_raw
end
Expand Down Expand Up @@ -773,7 +704,7 @@ pub proc get_asset
# => [ASSET_VALUE]
end

#! Returns the ASSET_VALUE associated with the provided asset ID in the active account's vault at
#! Returns the ASSET_VALUE associated with the provided asset ID in the native account's vault at
#! the beginning of the transaction.
#!
#! Inputs: [ASSET_ID]
Expand All @@ -783,8 +714,8 @@ end
#! - ASSET_ID is the asset ID of the asset to fetch.
#! - ASSET_VALUE is the value of the asset from the vault, which can be the EMPTY_WORD if it isn't present.
pub proc get_initial_asset
# get the vault root associated with the initial vault root of the native account
exec.memory::get_account_initial_vault_root_ptr movdn.4
# get the initial vault root ptr of the native account
exec.memory::get_init_native_account_vault_root_ptr movdn.4
# => [ASSET_ID, init_native_vault_root_ptr]

# emit event to signal that an asset is requested
Expand Down Expand Up @@ -1444,8 +1375,8 @@ pub proc get_item_patch
movup.2 exec.get_item_raw
# => [CURRENT_VALUE, slot_id_suffix, slot_id_prefix, offset]

# get account initial storage slots section offset
exec.memory::get_account_initial_storage_slots_ptr
# get native account initial storage slots section offset
exec.memory::get_native_account_initial_storage_slots_ptr
# => [init_storage_slots_ptr, CURRENT_VALUE, slot_id_suffix, slot_id_prefix, offset]

movup.7 add
Expand Down
60 changes: 0 additions & 60 deletions crates/miden-protocol/asm/kernels/transaction-core/src/memory.masm
Original file line number Diff line number Diff line change
Expand Up @@ -1109,36 +1109,6 @@ pub proc set_account_vault_root
mem_storew_le
end

#! Returns the memory pointer to the initial vault root of the active account.
#!
#! For the native account, this returns the pointer to the initial vault root.
#! For foreign accounts, this returns the regular vault root pointer since foreign accounts
#! are read-only and their initial and current vault state always matches.
#!
#! Inputs: []
#! Outputs: [account_initial_vault_root_ptr]
#!
#! Where:
#! - account_initial_vault_root_ptr is the memory pointer to the initial vault root.
pub proc get_account_initial_vault_root_ptr
# for foreign account, use the regular vault root pointer since foreign accounts are read-only
# and initial == current
exec.get_account_vault_root_ptr
# => [account_vault_root_ptr]

# for native account, use the initial vault root pointer
exec.get_init_native_account_vault_root_ptr
# => [native_account_initial_vault_root_ptr, account_vault_root_ptr]

# get the flag indicating whether the active account is native
exec.is_native_account
# => [is_native_account, native_account_initial_vault_root_ptr, account_vault_root_ptr]

# according to the is_native_account flag, return the corresponding pointer
cdrop
# => [account_initial_vault_root_ptr]
end

### ACCOUNT CODE #################################################

#! Returns the code commitment of the account.
Expand Down Expand Up @@ -1380,36 +1350,6 @@ pub proc get_native_account_initial_storage_slots_ptr
push.NATIVE_ACCOUNT_DATA_PTR add.ACCT_INITIAL_STORAGE_SLOTS_SECTION_OFFSET
end

#! Returns the memory pointer to the initial storage slots of the active account.
#!
#! For the native account, this returns the pointer to the initial storage slots section.
#! For foreign accounts, this returns the regular storage slots pointer since foreign accounts
#! are read-only and their initial and current storage state always matches.
#!
#! Inputs: []
#! Outputs: [account_initial_storage_slots_ptr]
#!
#! Where:
#! - account_initial_storage_slots_ptr is the memory pointer to the initial storage slot values.
pub proc get_account_initial_storage_slots_ptr
# for foreign account, use the regular storage slots pointer since foreign accounts are
# read-only and initial == current
exec.get_account_active_storage_slots_section_ptr
# => [account_storage_slots_ptr]

# for native account, use the initial storage slots pointer
exec.get_native_account_initial_storage_slots_ptr
# => [native_account_initial_storage_slots_ptr, account_storage_slots_ptr]

# get the flag indicating whether the active account is native
exec.is_native_account
# => [is_native_account, native_account_initial_storage_slots_ptr, account_storage_slots_ptr]

# according to the is_native_account flag, return the corresponding pointer
cdrop
# => [account_initial_storage_slots_ptr]
end

### ACCOUNT DELTA #################################################

#! Returns the link map pointer to the storage map patch of the storage map in the given slot index.
Expand Down
Loading
Loading