Skip to content

Commit

Permalink
refactor: update proc name, update proc comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Fumuran committed Sep 20, 2024
1 parent 13f2dda commit d336af8
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 36 deletions.
64 changes: 37 additions & 27 deletions miden-lib/asm/kernels/transaction/api.masm
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,13 @@ end
#! This procedure will prevent usage of the account procedures which can mutate the account state
#! with the foreign accounts.
#!
#! Panics:
#! - if the invocation of the account procedure does not originate from the native account.
#! Panics if
#! - the invocation of the account procedure does not originate from the native account.
#!
#! Stack: []
#! Output: []
proc.check_native_account
exec.memory::get_account_id
exec.memory::get_native_account_id
assert_eq
proc.assert_native_account
exec.memory::assert_native_account
end

# KERNEL PROCEDURES
Expand Down Expand Up @@ -158,14 +156,16 @@ end

#! Increments the account nonce by the provided value.
#!
#! Panics if
#! - the invocation of this procedure does not originate from the native account.
#! - the value is greater than 2^32 - 1
#! Stack: [KERNEL_PROCEDURE_HASH, value]
#! Output: [0]
#!
#! - value is the value to increment the nonce by. value can be at most 2^32 - 1 otherwise this
#! procedure panics.
#! - value is the value to increment the nonce by.
export.incr_account_nonce
# check that this procedure was executed against the native account
exec.check_native_account
exec.assert_native_account

# drop the procedure's hash
dropw
Expand Down Expand Up @@ -213,6 +213,9 @@ end

#! Sets an item in the account storage. Panics if the index is out of bounds.
#!
#! Panics if
#! - the invocation of this procedure does not originate from the native account.
#!
#! Stack: [KERNEL_PROCEDURE_HASH, index, V', 0, 0, 0]
#! Output: [R', V]
#!
Expand All @@ -222,7 +225,7 @@ end
#! - R' is the new storage commitment.
export.set_account_item
# check that this procedure was executed against the native account
exec.check_native_account
exec.assert_native_account

# drop the procedure's hash
dropw
Expand Down Expand Up @@ -253,8 +256,8 @@ end

#! Returns VALUE located under specified KEY in map in specified account storage slot.
#! Panics if
#! - the index is out of bounds (>255).
#! - the requested storage slot type is not map
#! - the index is out of bounds (>255).
#! - the requested storage slot type is not map
#!
#! Stack: [KERNEL_PROCEDURE_HASH, index, KEY, ...]
#! Output: [VALUE, 0]
Expand Down Expand Up @@ -296,9 +299,10 @@ end

#! Inserts specified NEW_VALUE under specified KEY in map in specified account storage slot.
#! Panics if
#! - the index is out of bounds (>255).
#! - the requested storage slot type is not map
#! - the procedure is called from a non-account context
#! - the index is out of bounds (>255).
#! - the requested storage slot type is not map
#! - the procedure is called from a non-account context
#! - the invocation of this procedure does not originate from the native account.
#!
#! Stack: [KERNEL_PROCEDURE_HASH, index, KEY, NEW_VALUE, ...]
#! Output: [OLD_MAP_ROOT, OLD_MAP_VALUE, 0]
Expand All @@ -311,7 +315,7 @@ end
#! - NEW_MAP_ROOT is the root of the new map after insertion.
export.set_account_map_item.1
# check that this procedure was executed against the native account
exec.check_native_account
exec.assert_native_account

# drop the procedure's hash
dropw
Expand Down Expand Up @@ -344,13 +348,16 @@ end
#! Sets the code of the account the transaction is being executed against. This procedure can only
#! executed on regular accounts with updatable code. Otherwise, this procedure fails.
#!
#! Panics if
#! - the invocation of this procedure does not originate from the native account.
#!
#! Stack: [KERNEL_PROCEDURE_HASH, CODE_COMMITMENT]
#! Output: [0, 0, 0, 0]
#!
#! - CODE_COMMITMENT is the hash of the code to set.
export.set_account_code
# check that this procedure was executed against the native account
exec.check_native_account
exec.assert_native_account

# drop the procedure's hash
dropw
Expand Down Expand Up @@ -412,10 +419,12 @@ end

#! Add the specified asset to the vault.
#!
#! Panics:
#! - If the asset is not valid.
#! - If the total value of two fungible assets is greater than or equal to 2^63.
#! - If the vault already contains the same non-fungible asset.
#! Panics if
#! - the asset is not valid.
#! - the total value of two fungible assets is greater than or equal to 2^63.
#! - the vault already contains the same non-fungible asset.
#! - the invocation of this procedure does not originate from the native account.
#!
#!
#! Stack: [KERNEL_PROCEDURE_HASH, ASSET]
#! Output: [ASSET']
Expand All @@ -427,7 +436,7 @@ end
#! after ASSET was added to it.
export.account_vault_add_asset
# check that this procedure was executed against the native account
exec.check_native_account
exec.assert_native_account

# drop the procedure's hash
dropw
Expand Down Expand Up @@ -461,18 +470,19 @@ end

#! Remove the specified asset from the vault.
#!
#! Panics:
#! - The fungible asset is not found in the vault.
#! - The amount of the fungible asset in the vault is less than the amount to be removed.
#! - The non-fungible asset is not found in the vault.
#! Panics if
#! - the fungible asset is not found in the vault.
#! - the amount of the fungible asset in the vault is less than the amount to be removed.
#! - the non-fungible asset is not found in the vault.
#! - the invocation of this procedure does not originate from the native account.
#!
#! Stack: [KERNEL_PROCEDURE_HASH, ASSET]
#! Output: [ASSET]
#!
#! - ASSET is the asset to remove from the vault.
export.account_vault_remove_asset
# check that this procedure was executed against the native account
exec.check_native_account
exec.assert_native_account

# drop the procedure's hash
dropw
Expand Down
16 changes: 13 additions & 3 deletions miden-lib/asm/kernels/transaction/lib/memory.masm
Original file line number Diff line number Diff line change
Expand Up @@ -610,9 +610,6 @@ end
#!
#! Stack: []
#! Output: []
#!
#! Where:
#! - native_account_data_ptr is the memory address at which the native account data is stored.
export.set_current_account_data_ptr_to_native_account
push.NATIVE_ACCOUNT_DATA_PTR
push.CURRENT_ACCOUNT_DATA_PTR mem_store
Expand Down Expand Up @@ -640,6 +637,19 @@ export.set_current_account_data_ptr
push.CURRENT_ACCOUNT_DATA_PTR mem_store
end

#! Asserts that current account data pointer matches the data pointer of the native account (2048).
#!
#! Stack: []
#! Output: []
#!
#! Panics:
#! - if the current account data pointer is not equal to native account data pointer (2048).
export.assert_native_account
push.CURRENT_ACCOUNT_DATA_PTR mem_load
push.NATIVE_ACCOUNT_DATA_PTR
assert_eq
end

#! Returns a pointer to the end of the core account data section.
#!
#! Stack: []
Expand Down
12 changes: 6 additions & 6 deletions miden-lib/src/transaction/procedures/kernel_v0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ use miden_objects::{digest, Digest, Felt};
/// Hashes of all dynamically executed procedures from the kernel 0.
pub const KERNEL0_PROCEDURES: [Digest; 30] = [
// account_vault_add_asset
digest!(0x8e14028dc2b66552, 0x3578ba0229c01221, 0xe3abf2f8ee61f6f8, 0x86a8f9d42cd1f0da),
digest!(0xb8815bfacbdcb4c2, 0x6c7e694cf4f6a517, 0xf6233da2865ca264, 0xe51463cd0df6e896),
// account_vault_get_balance
digest!(0x92b81d20684fa47, 0x4920ee53425609b9, 0x2f8c32c56898141c, 0x9e4542839e34452f),
// account_vault_has_non_fungible_asset
digest!(0x1b1e6ec92fabca80, 0xbb3847ce15f98cac, 0x7152391739b5e0b3, 0x696aaf2c879c4fde),
// account_vault_remove_asset
digest!(0x61a32bf1196cebb8, 0xd2efcfcae9b76e8b, 0x852ea9c64957517b, 0x5afa1631df475790),
digest!(0xff01966b06c569b, 0x99fc26250c155461, 0xe0293966a4c4c7ae, 0xdec4ef96fca23f11),
// get_account_id
digest!(0x386549d4435f79c1, 0x4a7add2e3b9f1b9e, 0x91c0af1138c14e77, 0xee8a5630e31bc74d),
// get_account_item
Expand All @@ -30,13 +30,13 @@ pub const KERNEL0_PROCEDURES: [Digest; 30] = [
// get_initial_account_hash
digest!(0xe239391d2c860c53, 0x7a9d09c3015d7417, 0x111e9be3640d3848, 0xf2d442cf1e685a89),
// incr_account_nonce
digest!(0x12602399108259ec, 0xb0ddbfee256f2133, 0xa58ea59059d3f095, 0x6cc32449c738f9b7),
digest!(0xb35351c9b87abeb5, 0x3f2607993a20eb41, 0xf50ef0e64bc386e, 0x265ad79a05151c58),
// set_account_code
digest!(0x6cc9d43670ab6e58, 0xef63fbb3ec8cfb9, 0xf63a09ff599ea458, 0x286cd41056278cf6),
digest!(0x6072f5e975697e09, 0x3384af10c011d5f4, 0x93d87a6c749002f2, 0x76b70654a4ac6025),
// set_account_item
digest!(0x6e0ca46fee3e6d20, 0x597e818173bada3e, 0x6da40e8a22241f9b, 0x8cc6088acbbbced3),
digest!(0xd3402811a9171d13, 0xbaea0a2fe8b11ff6, 0xaeefcd9fc67b86af, 0xbaa253e9beb95c01),
// set_account_map_item
digest!(0xf38170b0aa74e599, 0x1b653fb69b163132, 0x96f6204cd7d7815a, 0x8286a29095513621),
digest!(0x3894ffa4dce29ab3, 0xe571cc3c85e40e6e, 0x709275d311d1dc86, 0xa2efbe0b3980e95c),
// burn_asset
digest!(0x321fd17501dd1b7b, 0x5e41674206ccf93c, 0xf718f75b335577a6, 0x939db3229595dc7c),
// get_fungible_faucet_total_issuance
Expand Down

0 comments on commit d336af8

Please sign in to comment.