Skip to content

Commit

Permalink
Merge pull request #395 from 0xPolygonMiden/dominik_refactor_miden_lib
Browse files Browse the repository at this point in the history
refactor: miden-lib refactoring
  • Loading branch information
Dominik1999 authored Jan 4, 2024
2 parents b698c74 + 5ffe6f0 commit eeef30b
Show file tree
Hide file tree
Showing 48 changed files with 377 additions and 377 deletions.
4 changes: 2 additions & 2 deletions docs/src/network/miden-clients.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ receive_asset(asset)
end
```

In the above, `add_asset` is a kernel procedure `miden::sat::account::add_asset` of the Tx Kernel.
In the above, `add_asset` is a kernel procedure `miden::account::add_asset` of the Tx Kernel.

Note: this method does not increment account nonce. The nonce will be incremented in auth_tx method described below. Thus, receiving assets requires authentication.

Expand All @@ -57,7 +57,7 @@ send_asset(asset, recipient)
end
```

In the above, `remove_asset` is a kernel procedure `miden::sat::account::remove_asset` and `create_note` is a kernel procedure `miden::sat::tx::create_note`, both in the Tx Kernel.
In the above, `remove_asset` is a kernel procedure `miden::account::remove_asset` and `create_note` is a kernel procedure `miden::tx::create_note`, both in the Tx Kernel.

`recipient` is a partial hash of the created note computed outside the VM as `hash(hash(hash(serial_num), script_hash), input_hash)`. This allows computing note hash as `hash(recipient, vault_hash)` where the `vault_hash` can be computed inside the VM based on the specified asset.

Expand Down
14 changes: 7 additions & 7 deletions miden-lib/asm/kernels/transaction.masm
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use.std::utils

use.miden::sat::internal::epilogue
use.miden::sat::internal::layout
use.miden::sat::internal::note
use.miden::sat::internal::prologue
use.miden::kernels::tx::epilogue
use.miden::kernels::tx::memory
use.miden::kernels::tx::note
use.miden::kernels::tx::prologue

#! This is the entrypoint for the transaction kernel program. It is composed of the following
#! program sections:
Expand Down Expand Up @@ -71,12 +71,12 @@ proc.main.1
# ---------------------------------------------------------------------------------------------

# get the total number of consumed notes
exec.layout::get_total_num_consumed_notes
exec.memory::get_total_num_consumed_notes
# => [num_consumed_notes]

# compute the pointer to the consumed note after the last consumed note (i.e. the pointer at
# which the looping should terminate)
dup exec.layout::get_consumed_note_ptr loc_store.0
dup exec.memory::get_consumed_note_ptr loc_store.0
# => [num_consumed_notes]

# check if we have any notes to consume
Expand Down Expand Up @@ -112,7 +112,7 @@ proc.main.1
# ---------------------------------------------------------------------------------------------

# execute the transaction script
exec.layout::get_tx_script_root
exec.memory::get_tx_script_root
# => [TX_SCRIPT_ROOT]

exec.utils::is_empty_word not
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use.miden::sat::internal::account->internal_account
use.miden::sat::internal::asset
use.miden::sat::account
use.miden::kernels::tx::account->internal_account
use.miden::kernels::tx::asset
use.miden::account

# CONSTANTS
# =================================================================================================
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use.miden::sat::account
use.miden::sat::tx
use.miden::account
use.miden::tx
use.std::crypto::dsa::rpo_falcon512

# CONSTANTS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
# - max_supply is the maximum supply of the token.
# - decimals are the decimals of the token.
# - token_symbol as three chars encoded in a Felt.
use.miden::sat::account
use.miden::sat::asset
use.miden::sat::faucet
use.miden::sat::tx
use.miden::auth::basic
use.miden::account
use.miden::asset
use.miden::faucet
use.miden::tx
use.miden::contracts::auth::basic

# CONSTANTS
# =================================================================================================
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use.miden::sat::account
use.miden::sat::tx
use.miden::account
use.miden::tx

#! Adds the provided asset to the current account.
#!
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use.miden::sat::internal::constants
use.miden::sat::internal::layout
use.miden::kernels::tx::constants
use.miden::kernels::tx::memory

# CONSTANTS
# =================================================================================================
Expand Down Expand Up @@ -83,7 +83,7 @@ end
#! - ACCT_HASH is the hash of the account data.
export.get_current_hash
# prepare the stack for computing the account hash
exec.layout::get_acct_data_ptr padw padw padw
exec.memory::get_acct_data_ptr padw padw padw

# stream account data and compute sequential hash. We perform two `mem_stream` operations
# because account data consists of exactly 4 words.
Expand All @@ -105,8 +105,8 @@ end
#! procedure panics.
export.incr_nonce
u32assert
exec.layout::get_acct_nonce add
exec.layout::set_acct_nonce
exec.memory::get_acct_nonce add
exec.memory::set_acct_nonce
end

#! Returns the account id.
Expand All @@ -115,23 +115,23 @@ end
#! Output: [acct_id]
#!
#! - acct_id is the account id.
export.layout::get_acct_id->get_id
export.memory::get_acct_id->get_id

#! Returns the account nonce.
#!
#! Stack: []
#! Output: [nonce]
#!
#! - nonce is the account nonce.
export.layout::get_acct_nonce->get_nonce
export.memory::get_acct_nonce->get_nonce

#! Returns the initial account hash.
#!
#! Stack: []
#! Output: [H]
#!
#! - H is the initial account hash.
export.layout::get_init_acct_hash->get_initial_hash
export.memory::get_init_acct_hash->get_initial_hash

#! Returns the account type of the account id provided via the stack.
#!
Expand Down Expand Up @@ -276,15 +276,15 @@ end
#! - CODE_ROOT is the hash of the code to set.
export.set_code
# get the account id
exec.layout::get_acct_id
exec.memory::get_acct_id
# => [acct_id, CODE_ROOT]

# assert the account is an updatable regular account
exec.is_updatable_account assert
# => [CODE_ROOT]

# set the code root
exec.layout::set_new_acct_code_root
exec.memory::set_new_acct_code_root
# => []
end

Expand All @@ -297,7 +297,7 @@ end
#! - slot_type is the type of the slot.
#! - entry_arity is the arity of the slot.
export.get_storage_slot_type_info
exec.layout::get_acct_storage_slot_type_data u32split
exec.memory::get_acct_storage_slot_type_data u32split
end

#! Gets an item from the account storage. Panics if the index is out of bounds.
Expand All @@ -309,7 +309,7 @@ end
#! - VALUE is the value of the item.
export.get_item
# get the storage root
exec.layout::get_acct_storage_root
exec.memory::get_acct_storage_root
# => [storage_root, index]

# get the item from storage
Expand All @@ -331,15 +331,15 @@ end
#! - V is the previous value of the item.
export.set_item
# get the storage root
exec.layout::get_acct_storage_root
exec.memory::get_acct_storage_root
# => [R, index, V']

# set the item in storage
movup.4 push.STORAGE_TREE_DEPTH mtree_set
# => [V, R']

# set the new storage root
swapw exec.layout::set_acct_storage_root
swapw exec.memory::set_acct_storage_root
# => [V]
end

Expand All @@ -352,7 +352,7 @@ end
#! - PROC_ROOT is the hash of the procedure to authenticate.
export.authenticate_procedure.1
# load the account code root onto the stack
exec.layout::get_acct_code_root swapw
exec.memory::get_acct_code_root swapw
# => [PROC_ROOT, CODE_ROOT]

# load the index of the procedure root onto the advice stack
Expand Down Expand Up @@ -385,11 +385,11 @@ end
#! Output: []
export.validate_seed
# pad capacity elements of hasher and populate first four elements of the rate with the account id seed
padw exec.layout::get_acct_id push.0.0.0 adv.push_mapval adv_loadw
padw exec.memory::get_acct_id push.0.0.0 adv.push_mapval adv_loadw
# => [SEED, 0, 0, 0, 0]

# populate last four elements of the hasher rate with the code root
exec.layout::get_acct_code_root
exec.memory::get_acct_code_root
# => [CODE_ROOT, SEED, 0, 0, 0, 0]

# perform first permutation of seed and code_root (from advice stack) perm(seed, code_root)
Expand All @@ -401,7 +401,7 @@ export.validate_seed
# => [PERM]

# perform second permutation perm(storage_root, 0, 0, 0, 0)
exec.layout::get_acct_storage_root padw hperm
exec.memory::get_acct_storage_root padw hperm
# => [RATE, RATE, CAP]

# extract digest
Expand All @@ -410,14 +410,14 @@ export.validate_seed

# assert the account id matches the account id of the new account and extract pow
# element
movdn.3 drop drop exec.layout::get_acct_id eq assert
movdn.3 drop drop exec.memory::get_acct_id eq assert
# => [pow]

# get acct and facuet modulus to check the min number of trailing zeros required in the pow
exec.constants::get_regular_account_seed_digest_modulus exec.constants::get_faucet_seed_digest_modulus
# => [faucet_modulus, acct_modulus, pow]

exec.layout::get_acct_id
exec.memory::get_acct_id
# => [acct_id, faucet_modulus, acct_modulus, pow]

exec.is_faucet
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use.miden::sat::internal::account
use.miden::kernels::tx::account

# CONSTANTS
# =================================================================================================
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use.std::collections::smt

use.miden::sat::internal::account
use.miden::sat::internal::asset
use.miden::sat::internal::layout
use.miden::kernels::tx::account
use.miden::kernels::tx::asset
use.miden::kernels::tx::memory

# ACCESSORS
# =================================================================================================
Expand Down
Loading

0 comments on commit eeef30b

Please sign in to comment.