Skip to content

Commit

Permalink
chore: Merge
Browse files Browse the repository at this point in the history
  • Loading branch information
igamigo committed Jan 17, 2025
2 parents 0a30796 + 3326306 commit 3bee78a
Show file tree
Hide file tree
Showing 29 changed files with 300 additions and 188 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

### Changes

- Added health check endpoints to the prover service (#1006).
- Implemented serialization for `AccountHeader` (#996).
- Updated Pingora crates to 0.4 and added polling time to the configuration file (#997).
- Added support for `miden-tx-prover` proxy to update workers on a running proxy (#989).
Expand All @@ -17,11 +16,13 @@
- Added conversion from `Account` to `AccountDelta` for initial account state representation as delta (#983).
- [BREAKING] Added `miden::note::get_script_hash` procedure (#995).
- [BREAKING] Refactor error messages in `miden-lib` and `miden-tx` and use `thiserror` 2.0 (#1005).
- Added health check endpoints to the prover service (#1006).
- [BREAKING] Extend `AccountId` to two `Felt`s and require block hash in derivation (#982).
- Removed workers list from the proxy configuration file (#1018).
- Added tracing to the `miden-tx-prover` CLI (#1014).
- Added metrics to the `miden-tx-prover` proxy (#1017).
- Implemented `to_hex` for `AccountIdPrefix` and `epoch_block_num` for `BlockHeader` (#1039).
- Add `BlockNumber` struct (#1043).
- Introduce `AccountIdBuilder` to simplify `AccountId` generation in tests (#1045).
- Introduced `AccountComponentTemplate` with TOML serialization and templating (#1015, #1027).
- [BREAKING] Updated the names and values of the kernel procedure offsets and corresponding kernel procedures (#1037).
Expand Down
41 changes: 8 additions & 33 deletions miden-lib/asm/kernels/transaction/api.masm
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use.std::collections::smt
use.std::sys

use.kernel::account
Expand Down Expand Up @@ -27,9 +26,6 @@ const.ERR_FAUCET_STORAGE_DATA_SLOT_IS_RESERVED=0x00020000
# The get_fungible_faucet_total_issuance procedure can only be called on a fungible faucet
const.ERR_ACCOUNT_TOTAL_ISSUANCE_PROC_CAN_ONLY_BE_CALLED_ON_FUNGIBLE_FAUCET=0x00020001

# Failed to read an account map item from a non-map storage slot
const.ERR_ACCOUNT_READING_MAP_VALUE_FROM_NON_MAP_SLOT=0x00020002

# Provided kernel procedure offset is out of bounds
const.ERR_KERNEL_PROCEDURE_OFFSET_OUT_OF_BOUNDS=0x00020003

Expand Down Expand Up @@ -298,30 +294,22 @@ export.account_set_item
# => [R', V, pad(8)]
end

#! Returns VALUE located under specified KEY in map in specified account storage slot.
#! Returns the VALUE located under the specified KEY within the map contained in the given
#! account storage slot.
#!
#! Inputs: [index, KEY, pad(11)]
#! Outputs: [VALUE, pad(12)]
#!
#! Where:
#! - index is the index of the item to get.
#! - VALUE is the value of the item.
#! - index is the index of the storage slot that contains the the map root.
#! - VALUE is the value of the map item at KEY.
#!
#! Panics if:
#! - the index is out of bounds (>255).
#! - the requested storage slot type is not map.
#!
#! Invocation: dynexec
export.account_get_map_item
# check if storage type is map
dup exec.account::get_storage_slot_type
# => [slot_type, index, KEY, pad(11)]

# check if type == map
exec.constants::get_storage_slot_type_map eq
assert.err=ERR_ACCOUNT_READING_MAP_VALUE_FROM_NON_MAP_SLOT
# => [index, KEY, pad(11)]

# authenticate that the procedure invocation originates from the account context
exec.authenticate_account_origin
# => [storage_offset, storage_size, index, KEY, pad(11)]
Expand All @@ -330,31 +318,22 @@ export.account_get_map_item
exec.account::apply_storage_offset
# => [index_with_offset, KEY, pad(11)]

# fetch the account storage item, which is ROOT of the map
exec.account::get_item swapw
# => [KEY, ROOT, pad(11)]

# fetch the VALUE located under KEY in the tree
exec.smt::get
# => [VALUE, ROOT, pad(11)]

# remove the ROOT from the stack
swapw dropw
# fetch the map item from account storage
exec.account::get_map_item
# => [VALUE, pad(12)]
end

#! Inserts specified NEW_VALUE under specified KEY in map in specified account storage slot.
#! Stores NEW_VALUE under the specified KEY within the map contained in the given account storage slot.
#!
#! Inputs: [index, KEY, NEW_VALUE, pad(7)]
#! Outputs: [OLD_MAP_ROOT, OLD_MAP_VALUE, pad(8)]
#!
#! Where:
#! - index is the index of the item to get.
#! - index is the index of the storage slot which contains the map root.
#! - NEW_VALUE is the value of the new map item for the respective KEY.
#! - OLD_VALUE is the value of the old map item for the respective KEY.
#! - KEY is the key of the new item.
#! - OLD_MAP_ROOT is the root of the old map before insertion
#! - NEW_MAP_ROOT is the root of the new map after insertion.
#!
#! Panics if:
#! - the index is out of bounds (>255).
Expand Down Expand Up @@ -436,7 +415,6 @@ export.account_add_asset
exec.authenticate_account_origin drop drop
# => [ASSET, pad(12)]

push.19891 drop # TODO: remove line, see miden-vm/#1122
emit.ACCOUNT_VAULT_BEFORE_ADD_ASSET_EVENT
# => [ASSET, pad(12)]

Expand All @@ -454,7 +432,6 @@ export.account_add_asset

# emit event to signal that an asset is being added to the account vault
swapw
push.21383 drop # TODO: remove line, see miden-vm/#1122
emit.ACCOUNT_VAULT_AFTER_ADD_ASSET_EVENT dropw
# => [ASSET', pad(12)]
end
Expand Down Expand Up @@ -483,7 +460,6 @@ export.account_remove_asset
exec.authenticate_account_origin drop drop
# => [ASSET, pad(12)]

push.20071 drop # TODO: remove line, see miden-vm/#1122
emit.ACCOUNT_VAULT_BEFORE_REMOVE_ASSET_EVENT
# => [ASSET, pad(12)]

Expand All @@ -496,7 +472,6 @@ export.account_remove_asset
# => [ASSET, pad(12)]

# emit event to signal that an asset is being removed from the account vault
push.20149 drop # TODO: remove line, see miden-vm/#1122
emit.ACCOUNT_VAULT_AFTER_REMOVE_ASSET_EVENT
# => [ASSET, pad(12)]
end
Expand Down
76 changes: 55 additions & 21 deletions miden-lib/asm/kernels/transaction/lib/account.masm
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ const.ERR_ACCOUNT_ID_EPOCH_MUST_BE_LESS_THAN_U16_MAX=0x00020058
# Unknown account storage mode in account ID.
const.ERR_ACCOUNT_ID_UNKNOWN_STORAGE_MODE=0x00020059

# Failed to read an account map item from a non-map storage slot
const.ERR_ACCOUNT_READING_MAP_VALUE_FROM_NON_MAP_SLOT=0x00020002

# CONSTANTS
# =================================================================================================

Expand Down Expand Up @@ -235,13 +238,11 @@ export.incr_nonce
u32assert.err=ERR_ACCOUNT_NONCE_INCREASE_MUST_BE_U32

# emit event to signal that account nonce is being incremented
push.20261 drop # TODO: remove line, see miden-vm/#1122
emit.ACCOUNT_BEFORE_INCREMENT_NONCE_EVENT

exec.memory::get_acct_nonce add
exec.memory::set_acct_nonce

push.20357 drop # TODO: remove line, see miden-vm/#1122
emit.ACCOUNT_AFTER_INCREMENT_NONCE_EVENT
end

Expand Down Expand Up @@ -528,7 +529,6 @@ end
#! Panics if:
#! - the storage slot type is not value.
export.set_item
push.20443 drop # TODO: remove line, see miden-vm/#1122
emit.ACCOUNT_STORAGE_BEFORE_SET_ITEM_EVENT
# => [index, V']

Expand All @@ -552,25 +552,63 @@ export.set_item

# emit event to signal that an account storage item is being updated
swapw movup.8
push.20551 drop # TODO: remove line, see miden-vm/#1122
emit.ACCOUNT_STORAGE_AFTER_SET_ITEM_EVENT drop dropw
# => [V]
end

#! Sets an item in the specified account storage map.
#! Returns the VALUE located under the specified KEY within the map contained in the given
#! account storage slot.
#!
#! Inputs: [index, KEY]
#! Outputs: [VALUE]
#!
#! Note:
#! - We assume that index has been validated and is within bounds.
#!
#! Where:
#! - index is the index of the storage slot that contains the the map root.
#! - VALUE is the value of the map item at KEY.
#!
#! Panics if:
#! - the requested storage slot type is not map.
export.get_map_item
# check if storage slot type is map
dup exec.get_storage_slot_type
# => [slot_type, index, KEY]

# check if type == map
exec.constants::get_storage_slot_type_map eq
assert.err=ERR_ACCOUNT_READING_MAP_VALUE_FROM_NON_MAP_SLOT
# => [index, KEY]

# fetch the account storage item, which is ROOT of the map
exec.get_item swapw
# => [KEY, ROOT]

# fetch the VALUE located under KEY in the tree
exec.smt::get
# => [VALUE, ROOT]

# remove the ROOT from the stack
swapw dropw
# => [VALUE]
end

#! Stores NEW_VALUE under the specified KEY within the map contained in the given account storage slot.
#!
#! Note:
#! - We assume that index has been validated and is within bounds.
#!
#! Inputs: [index, KEY, NEW_VALUE, OLD_ROOT]
#! Outputs: [OLD_VALUE, NEW_ROOT]
#! Outputs: [OLD_MAP_ROOT, OLD_MAP_VALUE]
#!
#! Where:
#! - index is the index of the storage slot which contains the map root.
#! - OLD_ROOT is the root of the map to set the KEY NEW_VALUE pair.
#! - NEW_VALUE is the value to set under KEY.
#! - KEY is the key to set.
#! - OLD_VALUE is the previous value of the item.
#! - NEW_ROOT is the new root of the map.
#! - OLD_MAP_VALUE is the previous value of the item.
#! - OLD_MAP_ROOT is the root of the old map before insertion
#!
#! Panics if:
#! - the storage slot type is not map.
Expand All @@ -585,11 +623,10 @@ export.set_map_item.3
# => [slot_type, index, KEY, NEW_VALUE, OLD_ROOT]

# check if slot_type == map
exec.constants::get_storage_slot_type_map eq
exec.constants::get_storage_slot_type_map eq
assert.err=ERR_ACCOUNT_SETTING_MAP_ITEM_ON_NON_MAP_SLOT
# => [index, KEY, NEW_VALUE, OLD_ROOT]

push.20693 drop # TODO: remove line, see miden-vm/#1122
emit.ACCOUNT_STORAGE_BEFORE_SET_MAP_ITEM_EVENT
# => [index, KEY, NEW_VALUE, OLD_ROOT]

Expand All @@ -601,25 +638,24 @@ export.set_map_item.3
# set the NEW_VALUE under KEY in the tree
# note smt::set expects the stack to be [NEW_VALUE, KEY, OLD_ROOT, ...]
swapw exec.smt::set
# => [OLD_VALUE, NEW_ROOT, KEY, NEW_VALUE, index, ...]
# => [OLD_MAP_VALUE, NEW_ROOT, KEY, NEW_VALUE, index, ...]

# store OLD_VALUE and NEW_ROOT until the end of the procedure
# store OLD_MAP_VALUE and NEW_ROOT until the end of the procedure
loc_storew.1 dropw loc_storew.2 dropw
# => [KEY, NEW_VALUE, index, ...]

# emit event to signal that an account storage item is being updated
movup.8
push.20771 drop # TODO: remove line, see miden-vm/#1122
emit.ACCOUNT_STORAGE_AFTER_SET_MAP_ITEM_EVENT drop
# => [KEY, NEW_VALUE, ...]

# load OLD_VALUE and NEW_ROOT on the top of the stack
# load OLD_MAP_VALUE and NEW_ROOT on the top of the stack
loc_loadw.2 swapw loc_loadw.1 swapw
# => [NEW_ROOT, OLD_VALUE, ...]
# => [NEW_ROOT, OLD_MAP_VALUE, ...]

# set the root of the map in the respective account storage slot
loc_load.0 exec.set_item_raw
# => [OLD_MAP_ROOT, OLD_VALUE, ...]
# => [OLD_MAP_ROOT, OLD_MAP_VALUE, ...]
end

#! Returns the type of the requested storage slot.
Expand Down Expand Up @@ -691,7 +727,6 @@ end
#! - the procedure root is not part of the account code.
export.authenticate_procedure
# load procedure index
push.20897 drop # TODO: remove line, see miden-vm/#1122
emit.ACCOUNT_PUSH_PROCEDURE_INDEX_EVENT adv_push.1
# => [index, PROC_ROOT]

Expand Down Expand Up @@ -746,8 +781,7 @@ export.validate_seed
# => [0, 0, account_id_prefix, account_id_suffix, ANCHOR_BLOCK_HASH]

# populate first four elements of the rate with the account ID seed
adv.push_mapval push.15263 drop # TODO: remove line, see miden-vm/#1122
adv_loadw
adv.push_mapval adv_loadw
# => [SEED, ANCHOR_BLOCK_HASH]

# pad capacity element of hasher
Expand Down Expand Up @@ -825,7 +859,7 @@ end
#! - the computed account storage commitment does not match the provided account storage commitment
export.save_account_storage_data
# move storage slot data from the advice map to the advice stack
adv.push_mapvaln push.15160 drop # TODO: remove line, see miden-vm/#1122
adv.push_mapvaln
# OS => [STORAGE_COMMITMENT]
# AS => [storage_slot_data_len, [STORAGE_SLOT_DATA]]

Expand Down Expand Up @@ -894,7 +928,7 @@ end
#! - the computed account code commitment does not match the provided account code commitment
export.save_account_procedure_data
# move procedure data from the advice map to the advice stack
adv.push_mapvaln push.15161 drop # TODO: remove line, see miden-vm/#1122
adv.push_mapvaln
# OS => [CODE_COMMITMENT]
# AS => [account_procedure_data_len, [ACCOUNT_PROCEDURE_DATA]]

Expand Down
4 changes: 2 additions & 2 deletions miden-lib/asm/kernels/transaction/lib/asset_vault.masm
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ export.add_fungible_asset
# we therefore overwrite the faucet id with the faucet id from ASSET to account for this edge case
mem_loadw swapw
# => [ASSET_KEY, VAULT_ROOT, faucet_id_prefix, faucet_id_suffix, amount, vault_root_ptr]
adv.push_smtpeek push.15329 drop # TODO: remove line, see miden-vm/#1122
adv.push_smtpeek
adv_loadw
# => [CUR_VAULT_VALUE, VAULT_ROOT, faucet_id_prefix, faucet_id_suffix, amount, vault_root_ptr]
swapw
Expand Down Expand Up @@ -312,7 +312,7 @@ export.remove_fungible_asset
# To account for the edge case in which CUR_VAULT_VALUE is an EMPTY_WORD, we replace the most
# significant element with the faucet_id to construct the CUR_ASSET.
padw dup.14 mem_loadw swapw
adv.push_smtpeek push.15413 drop # TODO: remove line, see miden-vm/#1122
adv.push_smtpeek
adv_loadw dupw movdnw.2 drop movup.11
# => [CUR_ASSET, VAULT_ROOT, CUR_VAULT_VALUE, amount, ASSET, vault_root_ptr]

Expand Down
6 changes: 2 additions & 4 deletions miden-lib/asm/kernels/transaction/lib/epilogue.masm
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ proc.copy_output_notes_to_advice_map
# => [OUTPUT_NOTES_COMMITMENT, output_note_ptr, output_notes_end_ptr]

# insert created data into the advice map
adv.insert_mem push.15511 drop # TODO: remove line, see miden-vm/#1122
adv.insert_mem
# => [OUTPUT_NOTES_COMMITMENT, output_note_ptr, output_notes_end_ptr]

# drop output note pointers
Expand Down Expand Up @@ -274,7 +274,7 @@ export.finalize_transaction
# => [FINAL_ACCOUNT_HASH, acct_data_ptr, acct_data_end_ptr, INIT_ACCT_HASH]

# insert final account data into the advice map
adv.insert_mem push.15619 drop # TODO: remove line, see miden-vm/#1122
adv.insert_mem
# => [FINAL_ACCOUNT_HASH, acct_data_ptr, acct_data_end_ptr, INIT_ACCT_HASH]

# drop account data section pointers
Expand All @@ -295,8 +295,6 @@ export.finalize_transaction
exec.memory::get_acct_nonce
# => [current_nonce, init_nonce, FINAL_ACCOUNT_HASH, INIT_ACCT_HASH]

push.1005 drop # TODO: remove line, see miden-vm/#1122

# assert that initial nonce is less than current nonce
lt assert.err=ERR_ACCOUNT_NONCE_DID_NOT_INCREASE_AFTER_STATE_CHANGE
# => [FINAL_ACCOUNT_HASH, INIT_ACCT_HASH]
Expand Down
3 changes: 1 addition & 2 deletions miden-lib/asm/kernels/transaction/lib/prologue.masm
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,6 @@ proc.validate_new_account
exec.constants::get_empty_smt_root
assert_eqw.err=ERR_PROLOGUE_NEW_NON_FUNGIBLE_FAUCET_RESERVED_SLOT_MUST_BE_VALID_EMPY_SMT
# => []
push.1001 drop # TODO: remove line, see miden-vm/#1122

# get the faucet reserved storage data slot type
exec.account::get_faucet_storage_data_slot exec.account::get_storage_slot_type
Expand Down Expand Up @@ -982,7 +981,7 @@ proc.process_input_notes_data
dup neq.0
if.true
exec.memory::get_input_notes_commitment
adv.push_mapval push.15787 drop # TODO: remove line, see miden-vm/#1122
adv.push_mapval
dropw
end
# => [num_notes]
Expand Down
Loading

0 comments on commit 3bee78a

Please sign in to comment.