diff --git a/Cargo.lock b/Cargo.lock index 524951a12..703f3e35c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1073,7 +1073,7 @@ checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" [[package]] name = "miden-air" version = "0.10.5" -source = "git+https://github.com/0xPolygonMiden/miden-vm.git?branch=next#9f9cc63b709d8b7c83841d8e421701dcd33792bb" +source = "git+https://github.com/0xPolygonMiden/miden-vm.git?branch=plafer-1091-dyn-op-rework#3ed930ecbb1600d9d0f77aee3127d027662323f2" dependencies = [ "miden-core", "miden-thiserror", @@ -1084,7 +1084,7 @@ dependencies = [ [[package]] name = "miden-assembly" version = "0.10.5" -source = "git+https://github.com/0xPolygonMiden/miden-vm.git?branch=next#9f9cc63b709d8b7c83841d8e421701dcd33792bb" +source = "git+https://github.com/0xPolygonMiden/miden-vm.git?branch=plafer-1091-dyn-op-rework#3ed930ecbb1600d9d0f77aee3127d027662323f2" dependencies = [ "aho-corasick", "lalrpop", @@ -1115,7 +1115,7 @@ dependencies = [ [[package]] name = "miden-core" version = "0.10.5" -source = "git+https://github.com/0xPolygonMiden/miden-vm.git?branch=next#9f9cc63b709d8b7c83841d8e421701dcd33792bb" +source = "git+https://github.com/0xPolygonMiden/miden-vm.git?branch=plafer-1091-dyn-op-rework#3ed930ecbb1600d9d0f77aee3127d027662323f2" dependencies = [ "lock_api", "loom", @@ -1233,7 +1233,7 @@ dependencies = [ [[package]] name = "miden-processor" version = "0.10.6" -source = "git+https://github.com/0xPolygonMiden/miden-vm.git?branch=next#9f9cc63b709d8b7c83841d8e421701dcd33792bb" +source = "git+https://github.com/0xPolygonMiden/miden-vm.git?branch=plafer-1091-dyn-op-rework#3ed930ecbb1600d9d0f77aee3127d027662323f2" dependencies = [ "miden-air", "miden-core", @@ -1244,7 +1244,7 @@ dependencies = [ [[package]] name = "miden-prover" version = "0.10.5" -source = "git+https://github.com/0xPolygonMiden/miden-vm.git?branch=next#9f9cc63b709d8b7c83841d8e421701dcd33792bb" +source = "git+https://github.com/0xPolygonMiden/miden-vm.git?branch=plafer-1091-dyn-op-rework#3ed930ecbb1600d9d0f77aee3127d027662323f2" dependencies = [ "miden-air", "miden-processor", @@ -1255,7 +1255,7 @@ dependencies = [ [[package]] name = "miden-stdlib" version = "0.10.5" -source = "git+https://github.com/0xPolygonMiden/miden-vm.git?branch=next#9f9cc63b709d8b7c83841d8e421701dcd33792bb" +source = "git+https://github.com/0xPolygonMiden/miden-vm.git?branch=plafer-1091-dyn-op-rework#3ed930ecbb1600d9d0f77aee3127d027662323f2" dependencies = [ "miden-assembly", ] @@ -1327,7 +1327,7 @@ dependencies = [ [[package]] name = "miden-verifier" version = "0.10.5" -source = "git+https://github.com/0xPolygonMiden/miden-vm.git?branch=next#9f9cc63b709d8b7c83841d8e421701dcd33792bb" +source = "git+https://github.com/0xPolygonMiden/miden-vm.git?branch=plafer-1091-dyn-op-rework#3ed930ecbb1600d9d0f77aee3127d027662323f2" dependencies = [ "miden-air", "miden-core", diff --git a/Cargo.toml b/Cargo.toml index 791461397..2e0a591db 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -33,29 +33,28 @@ lto = true [workspace.dependencies] #assembly = { package = "miden-assembly", version = "0.10", default-features = false } -assembly = { package = "miden-assembly", git = "https://github.com/0xPolygonMiden/miden-vm.git", branch = "next", default-features = false } +assembly = { package = "miden-assembly", git = "https://github.com/0xPolygonMiden/miden-vm.git", branch = "plafer-1091-dyn-op-rework", default-features = false } miden-crypto = { version = "0.11", default-features = false } -#miden-crypto = { git = "https://github.com/0xPolygonMiden/miden-vm.git", branch = "next", default-features = false } miden-lib = { path = "miden-lib", version = "0.6", default-features = false } miden-objects = { path = "objects", version = "0.6", default-features = false } #miden-prover = { version = "0.10", default-features = false } -miden-prover = { git = "https://github.com/0xPolygonMiden/miden-vm.git", branch = "next", default-features = false } +miden-prover = { git = "https://github.com/0xPolygonMiden/miden-vm.git", branch = "plafer-1091-dyn-op-rework", default-features = false } #miden-stdlib = { version = "0.10", default-features = false } -miden-stdlib = { git = "https://github.com/0xPolygonMiden/miden-vm.git", branch = "next", default-features = false } +miden-stdlib = { git = "https://github.com/0xPolygonMiden/miden-vm.git", branch = "plafer-1091-dyn-op-rework", default-features = false } miden-tx = { path = "miden-tx", version = "0.6", default-features = false } #miden-verifier = { version = "0.10", default-features = false } -miden-verifier = { git = "https://github.com/0xPolygonMiden/miden-vm.git", branch = "next", default-features = false } +miden-verifier = { git = "https://github.com/0xPolygonMiden/miden-vm.git", branch = "plafer-1091-dyn-op-rework", default-features = false } rand = { version = "0.8", default-features = false } #vm-core = { package = "miden-core", version = "0.10", default-features = false } -vm-core = { package = "miden-core", git = "https://github.com/0xPolygonMiden/miden-vm.git", branch = "next", default-features = false } +vm-core = { package = "miden-core", git = "https://github.com/0xPolygonMiden/miden-vm.git", branch = "plafer-1091-dyn-op-rework", default-features = false } #vm-processor = { package = "miden-processor", version = "0.10", default-features = false } -vm-processor = { package = "miden-processor", git = "https://github.com/0xPolygonMiden/miden-vm.git", branch = "next", default-features = false } +vm-processor = { package = "miden-processor", git = "https://github.com/0xPolygonMiden/miden-vm.git", branch = "plafer-1091-dyn-op-rework", default-features = false } diff --git a/docs/architecture/transactions/kernel.md b/docs/architecture/transactions/kernel.md index f1ebbd602..c94cbc903 100644 --- a/docs/architecture/transactions/kernel.md +++ b/docs/architecture/transactions/kernel.md @@ -91,7 +91,7 @@ If a transaction script is provided, its root is stored at a pre-defined memory ## Note processing -Input notes are consumed in a loop. +Input notes are consumed in a loop. For every note, the [MAST root](https://0xpolygonmiden.github.io/miden-vm/design/programs.html) of the note script is loaded onto the stack. Then, by calling a [`dyncall`](https://0xpolygonmiden.github.io/miden-vm/user_docs/assembly/code_organization.html?highlight=dyncall#dynamic-procedure-invocation) the note script is executed in a new context which prevents unwanted memory access. @@ -102,6 +102,10 @@ For every note, the [MAST root](https://0xpolygonmiden.github.io/miden-vm/design exec.note::prepare_note # => [NOTE_SCRIPT_HASH] + # store the NOTE_SCRIPT_HASH to the memory to be able to call it dynamically + loc_storew.0 dropw locaddr.0 + # => [note_script_hash_addr] + # invoke the note script using the dyncall instruction dyncall # => [OUTPUT_3, OUTPUT_2, OUTPUT_1, OUTPUT_0] diff --git a/miden-lib/asm/kernels/transaction/api.masm b/miden-lib/asm/kernels/transaction/api.masm index b11660c66..5aa974650 100644 --- a/miden-lib/asm/kernels/transaction/api.masm +++ b/miden-lib/asm/kernels/transaction/api.masm @@ -66,35 +66,17 @@ proc.authenticate_account_origin # => [storage_offset, storage_size] end -#! Verifies that the procedure to be invoked against the foreign account is part of its code. -#! TODO: it is a temporary solution. This and other `*_foreign` procedures should be removed after -#! the refactoring of the `DYN` operation (see miden-vm/#1091) and the fix of the CALLER operation. -#! -#! Stack: [FOREIGN_PROC_ROOT] -#! Output: [storage_offset, storage_size, ...] -#! -#! Panics if: -#! - the invocation of the kernel procedure does not originate from the account context. -proc.authenticate_account_origin_foreign - # assert that the caller is from the user context - exec.account::authenticate_procedure - # => [storage_offset, storage_size, ...] -end - # KERNEL PROCEDURES # ================================================================================================= #! Returns the account id. #! -#! Stack: [KERNEL_PROCEDURE_HASH, 0] +#! Stack: [0] #! Output: [acct_id] #! #! Where: #! - acct_id is the account id. export.get_account_id - # drop the procedure's hash - dropw - # get the account id exec.account::get_id # => [acct_id, 0] @@ -105,15 +87,12 @@ end #! Returns the account nonce. #! -#! Stack: [KERNEL_PROCEDURE_HASH, 0] +#! Stack: [0] #! Output: [nonce] #! #! Where: #! - nonce is the account nonce. export.get_account_nonce - # drop the procedure's hash - dropw - # get the account nonce exec.account::get_nonce # => [0, nonce] @@ -124,15 +103,12 @@ end #! Returns the initial account hash. #! -#! Stack: [KERNEL_PROCEDURE_HASH, 0, 0, 0, 0] +#! Stack: [0, 0, 0, 0] #! Output: [H] #! #! Where: #! - H is the initial account hash. export.get_initial_account_hash - # drop the procedure's hash - dropw - # get the initial account hash exec.account::get_initial_hash # => [H, 0, 0, 0, 0] @@ -143,15 +119,12 @@ end #! Computes and returns the account hash from account data stored in memory. #! -#! Stack: [KERNEL_PROCEDURE_HASH, 0, 0, 0, 0] +#! Stack: [0, 0, 0, 0] #! Output: [ACCT_HASH] #! #! Where: #! - ACCT_HASH is the hash of the account data. export.get_current_account_hash - # drop the procedure's hash - dropw - # get the current account hash exec.account::get_current_hash # => [ACCT_HASH, 0, 0, 0, 0] @@ -162,7 +135,7 @@ end #! Increments the account nonce by the provided value. #! -#! Stack: [KERNEL_PROCEDURE_HASH, value] +#! Stack: [value] #! Output: [0] #! #! Where: @@ -175,9 +148,6 @@ export.incr_account_nonce # check that this procedure was executed against the native account exec.memory::assert_native_account - # drop the procedure's hash - dropw - # authenticate that the procedure invocation originates from the account context exec.authenticate_account_origin drop drop # => [value] @@ -193,7 +163,7 @@ end #! Gets an item from the account storage. #! -#! Stack: [KERNEL_PROCEDURE_HASH, index, 0, 0, 0] +#! Stack: [index, 0, 0, 0] #! Output: [VALUE] #! #! Where: @@ -203,9 +173,6 @@ end #! Panics if: #! - the index is out of bounds. export.get_account_item - # drop the procedure's hash - dropw - # authenticate that the procedure invocation originates from the account context exec.authenticate_account_origin # => [storage_offset, storage_size, index, 0, 0, 0] @@ -223,40 +190,9 @@ export.get_account_item # => [VALUE] end -#! Gets an item from the account storage. -#! -#! Stack: [KERNEL_PROCEDURE_HASH, FOREIGN_PROC_ROOT, index, pad(10)] -#! Output: [VALUE, pad(10)] -#! -#! Where: -#! - KERNEL_PROCEDURE_HASH is the hash of this procedure. -#! - FOREIGN_PROC_ROOT is the hash of the foreign procedure which called this procedure. -#! - index is the index of the item to get. -#! - VALUE is the value of the item. -#! -#! Panics if: -#! - the index is out of bounds. -export.get_account_item_foreign - # drop the kernel procedure's hash - dropw - # => [FOREIGN_PROC_ROOT, index, pad(10)] - - # authenticate that the procedure invocation originates from the account context - exec.authenticate_account_origin_foreign - # => [storage_offset, storage_size, index, pad(10)] - - # apply offset to storage slot index - exec.account::apply_storage_offset - # => [index_with_offset, pad(10)] - - # fetch the account storage item - exec.account::get_item - # => [VALUE, pad(10)] -end - #! Sets an item in the account storage. #! -#! Stack: [KERNEL_PROCEDURE_HASH, index, V', 0, 0, 0] +#! Stack: [index, V', 0, 0, 0] #! Output: [R', V] #! #! Where: @@ -272,9 +208,6 @@ export.set_account_item # check that this procedure was executed against the native account exec.memory::assert_native_account - # drop the procedure's hash - dropw - # if the transaction is being executed against a faucet account then assert # index != FAUCET_STORAGE_DATA_SLOT (reserved slot) dup exec.account::get_faucet_storage_data_slot eq @@ -301,7 +234,7 @@ end #! Returns VALUE located under specified KEY in map in specified account storage slot. #! -#! Stack: [KERNEL_PROCEDURE_HASH, index, KEY, ...] +#! Stack: [index, KEY, ...] #! Output: [VALUE, 0] #! #! Where: @@ -312,9 +245,6 @@ end #! - the index is out of bounds (>255). #! - the requested storage slot type is not map export.get_account_map_item - # drop the procedure's hash - dropw - # check if storage type is map dup exec.account::get_storage_slot_type # => [slot_type, index, KEY, ...] @@ -344,55 +274,9 @@ export.get_account_map_item # => [VALUE, 0] end -#! Returns VALUE located under specified KEY in map in specified account storage slot. -#! -#! Stack: [KERNEL_PROCEDURE_HASH, FOREIGN_PROC_ROOT, index, KEY, pad(6)] -#! Output: [VALUE, pad(6)] -#! -#! Where: -#! - index is the index of the item to get. -#! - VALUE is the value of the item. -#! -#! Panics if: -#! - the index is out of bounds (>255). -#! - the requested storage slot type is not map -export.get_account_map_item_foreign - # drop the procedure's hash - dropw - # => [FOREIGN_PROC_ROOT, index, KEY, pad(6)] - - # check if storage type is map - movup.4 dup exec.account::get_storage_slot_type - # => [slot_type, index, FOREIGN_PROC_ROOT, KEY, pad(6)] - - # check if type == map - exec.constants::get_storage_slot_type_map eq assert.err=ERR_ACCOUNT_READING_MAP_VALUE_FROM_NON_MAP_SLOT - # => [index, FOREIGN_PROC_ROOT, KEY, pad(6)] - - # authenticate that the procedure invocation originates from the account context - movdn.4 exec.authenticate_account_origin_foreign - # => [storage_offset, storage_size, index, KEY, pad(6)] - - # apply offset to storage slot index - exec.account::apply_storage_offset - # => [index_with_offset, KEY, pad(6)] - - # fetch the account storage item, which is ROOT of the map - exec.account::get_item swapw - # => [KEY, ROOT, pad(6)] - - # fetch the VALUE located under KEY in the tree - exec.smt::get - # => [VALUE, ROOT, pad(6)] - - # prepare the stack for return - swapw dropw - # => [VALUE, pad(6)] -end - #! Inserts specified NEW_VALUE under specified KEY in map in specified account storage slot. #! -#! Stack: [KERNEL_PROCEDURE_HASH, index, KEY, NEW_VALUE, ...] +#! Stack: [index, KEY, NEW_VALUE, ...] #! Output: [OLD_MAP_ROOT, OLD_MAP_VALUE, 0] #! #! Where: @@ -412,9 +296,6 @@ export.set_account_map_item.1 # check that this procedure was executed against the native account exec.memory::assert_native_account - # drop the procedure's hash - dropw - # authenticate that the procedure invocation originates from the account context exec.authenticate_account_origin # => [storage_offset, storage_size, index, KEY, NEW_VALUE, ...] @@ -444,7 +325,7 @@ end #! This procedure can only be executed on regular accounts with updatable code. Otherwise, this #! procedure fails. #! -#! Stack: [KERNEL_PROCEDURE_HASH, CODE_COMMITMENT] +#! Stack: [CODE_COMMITMENT] #! Output: [0, 0, 0, 0] #! #! Where: @@ -456,9 +337,6 @@ export.set_account_code # check that this procedure was executed against the native account exec.memory::assert_native_account - # drop the procedure's hash - dropw - # authenticate that the procedure invocation originates from the account context exec.authenticate_account_origin drop drop # => [CODE_COMMITMENT] @@ -474,7 +352,7 @@ end #! Returns the balance of a fungible asset associated with a faucet_id. #! -#! Stack: [KERNEL_PROCEDURE_HASH, faucet_id] +#! Stack: [faucet_id] #! Output: [balance] #! #! Where: @@ -484,9 +362,6 @@ end #! Panics if: #! - the asset is not a fungible asset. export.account_vault_get_balance - # drop the procedure's hash - dropw - # get the vault root exec.memory::get_acct_vault_root_ptr swap # => [faucet_id, acct_vault_root_ptr] @@ -498,7 +373,7 @@ end #! Returns a boolean indicating whether the non-fungible asset is present in the vault. #! -#! Stack: [KERNEL_PROCEDURE_HASH, ASSET] +#! Stack: [ASSET] #! Output: [has_asset, 0, 0, 0] #! #! Where: @@ -508,9 +383,6 @@ end #! Panics if: #! - the ASSET is a fungible asset. export.account_vault_has_non_fungible_asset - # drop the procedure's hash - dropw - # arrange stack and get the vault root push.0 movdn.4 push.0 movdn.4 push.0 movdn.4 exec.memory::get_acct_vault_root_ptr movdn.4 # => [ASSET, 0, 0, 0] @@ -522,7 +394,7 @@ end #! Add the specified asset to the vault. #! -#! Stack: [KERNEL_PROCEDURE_HASH, ASSET] +#! Stack: [ASSET] #! Output: [ASSET'] #! #! Where: @@ -541,9 +413,6 @@ export.account_vault_add_asset # check that this procedure was executed against the native account exec.memory::assert_native_account - # drop the procedure's hash - dropw - # authenticate that the procedure invocation originates from the account context exec.authenticate_account_origin drop drop # => [ASSET] @@ -573,7 +442,7 @@ end #! Remove the specified asset from the vault. #! -#! Stack: [KERNEL_PROCEDURE_HASH, ASSET] +#! Stack: [ASSET] #! Output: [ASSET] #! #! Where: @@ -588,9 +457,6 @@ export.account_vault_remove_asset # check that this procedure was executed against the native account exec.memory::assert_native_account - # drop the procedure's hash - dropw - # authenticate that the procedure invocation originates from the account context exec.authenticate_account_origin drop drop # => [ASSET] @@ -615,7 +481,7 @@ end #! Returns the number of assets and the assets hash of the note currently being processed. #! -#! Inputs: [KERNEL_PROCEDURE_HASH, 0, 0, 0, 0, 0] +#! Inputs: [0, 0, 0, 0, 0] #! Outputs: [ASSETS_HASH, num_assets] #! #! Where: @@ -625,9 +491,6 @@ end #! Panics if: #! - a note is not being processed. export.get_note_assets_info - # drop the procedure's hash - dropw - # get the assets info exec.note::get_assets_info # => [ASSETS_HASH, num_assets, 0, 0, 0, 0, 0] @@ -639,15 +502,12 @@ end #! Returns the current note's inputs hash. #! -#! Inputs: [KERNEL_PROCEDURE_HASH, EMPTY_WORD] +#! Inputs: [EMPTY_WORD] #! Outputs: [NOTE_INPUTS_HASH] #! #! Where: #! - NOTE_INPUTS_HASH is the current note's inputs hash. export.get_note_inputs_hash - # drop the procedure's hash - dropw - exec.note::get_note_inputs_hash # => [NOTE_INPUTS_HASH, EMPTY_WORD] @@ -657,7 +517,7 @@ end #! Returns the sender of the note currently being processed. #! -#! Inputs: [KERNEL_PROCEDURE_HASH, 0] +#! Inputs: [0] #! Outputs: [sender] #! #! Where: @@ -666,24 +526,18 @@ end #! Panics if: #! - a note is not being processed. export.get_note_sender - # drop the procedure's hash - dropw - exec.note::get_sender swap drop # => [sender] end #! Returns the block number of the last known block at the time of transaction execution. #! -#! Inputs: [KERNEL_PROCEDURE_HASH, 0] +#! Inputs: [0] #! Outputs: [num] #! #! Where: #! - num is the last known block number. export.get_block_number - # drop the procedure's hash - dropw - # get the block number exec.tx::get_block_number # => [num, 0] @@ -695,15 +549,12 @@ end #! Returns the block hash of the reference block. #! -#! Stack: [KERNEL_PROCEDURE_HASH, EMPTY_WORD] +#! Stack: [EMPTY_WORD] #! Output: [BLOCK_HASH] #! #! Where: #! - BLOCK_HASH is the reference block for the transaction execution. export.get_block_hash - # drop the procedure's hash - dropw - dropw exec.tx::get_block_hash # => [BLOCK_HASH] end @@ -716,15 +567,12 @@ end #! be delayed to the batch/block kernel. The delayed authentication allows a transaction to consume a #! public note that is not yet included to a block. #! -#! Inputs: [KERNEL_PROCEDURE_HASH, 0, 0, 0, 0] +#! Inputs: [0, 0, 0, 0] #! Outputs: [INPUT_NOTES_COMMITMENT] #! #! Where: #! - INPUT_NOTES_COMMITMENT is the input notes commitment hash. export.get_input_notes_commitment - # drop the procedure's hash - dropw - exec.tx::get_input_notes_commitment # => [COM, 0, 0, 0, 0] @@ -735,15 +583,12 @@ end #! Returns the output notes hash. This is computed as a sequential hash of (note_id, note_metadata) #! tuples over all output notes. #! -#! Inputs: [KERNEL_PROCEDURE_HASH, 0, 0, 0, 0] +#! Inputs: [0, 0, 0, 0] #! Outputs: [COM] #! #! Where: #! - COM is the output notes hash. export.get_output_notes_hash - # drop the procedure's hash - dropw - # get the output notes hash exec.tx::get_output_notes_hash # => [COM, 0, 0, 0, 0] @@ -755,7 +600,7 @@ end #! Creates a new note and returns the index of the note. #! -#! Inputs: [KERNEL_PROCEDURE_HASH, tag, aux, note_type, execution_hint, RECIPIENT, pad(4)] +#! Inputs: [tag, aux, note_type, execution_hint, RECIPIENT, pad(4)] #! Outputs: [note_idx, pad(15)] #! #! Where: @@ -773,9 +618,6 @@ export.create_note # check that this procedure was executed against the native account exec.memory::assert_native_account - # drop the procedure's hash - dropw - # authenticate that the procedure invocation originates from the account context exec.authenticate_account_origin drop drop # => [tag, aux, note_type, execution_hint, RECIPIENT, pad(8)] @@ -786,7 +628,7 @@ end #! Adds the ASSET to the note specified by the index. #! -#! Inputs: [KERNEL_PROCEDURE_HASH, note_idx, ASSET, pad(7)] +#! Inputs: [note_idx, ASSET, pad(7)] #! Outputs: [note_idx, ASSET, pad(11)] #! #! Where: @@ -800,9 +642,6 @@ export.add_asset_to_note # check that this procedure was executed against the native account exec.memory::assert_native_account - # drop the procedure's hash - dropw - # authenticate that the procedure invocation originates from the account context exec.authenticate_account_origin drop drop # => [note_idx, ASSET] @@ -817,15 +656,12 @@ end #! Returns a commitment to the account vault the transaction is being executed against. #! -#! Stack: [KERNEL_PROCEDURE_HASH, 0, 0, 0, 0] +#! Stack: [0, 0, 0, 0] #! Outputs: [COM] #! #! Where: #! - COM is the commitment to the account vault. export.get_account_vault_commitment - # drop the procedure's hash - dropw - # fetch the account vault root exec.memory::get_acct_vault_root # => [COM, 0, 0, 0, 0] @@ -837,7 +673,7 @@ end #! Mint an asset from the faucet the transaction is being executed against. #! -#! Stack: [KERNEL_PROCEDURE_HASH, ASSET] +#! Stack: [ASSET] #! Outputs: [ASSET] #! #! Where: @@ -857,9 +693,6 @@ export.mint_asset # check that this procedure was executed against the native account exec.memory::assert_native_account - # drop the procedure's hash - dropw - # authenticate that the procedure invocation originates from the account context exec.authenticate_account_origin drop drop # => [ASSET] @@ -871,7 +704,7 @@ end #! Burn an asset from the faucet the transaction is being executed against. #! -#! Stack: [KERNEL_PROCEDURE_HASH, ASSET] +#! Stack: [ASSET] #! Outputs: [ASSET] #! #! Where: @@ -892,9 +725,6 @@ export.burn_asset # check that this procedure was executed against the native account exec.memory::assert_native_account - # drop the procedure's hash - dropw - # authenticate that the procedure invocation originates from the account context exec.authenticate_account_origin drop drop # => [ASSET] @@ -906,7 +736,7 @@ end #! Returns the total issuance of the fungible faucet the transaction is being executed against. #! -#! Stack: [KERNEL_PROCEDURE_HASH, 0] +#! Stack: [0] #! Outputs: [total_issuance] #! #! Where: @@ -916,9 +746,6 @@ end #! Panics if: #! - the transaction is not being executed against a fungible faucet. export.get_fungible_faucet_total_issuance - # drop the procedure's hash - dropw - # assert that we are executing a transaction against a fungible faucet (access checks) exec.account::get_id exec.account::is_fungible_faucet assert.err=ERR_ACCOUNT_TOTAL_ISSUANCE_PROC_CAN_ONLY_BE_CALLED_ON_FUNGIBLE_FAUCET # => [0] @@ -934,7 +761,7 @@ end #! Returns the serial number of the note currently being processed. #! -#! Inputs: [KERNEL_PROCEDURE_HASH] +#! Inputs: [] #! Outputs: [SERIAL_NUMBER] #! #! Where: @@ -943,9 +770,6 @@ end #! Panics if: #! - no note is not being processed. export.get_note_serial_number - # drop the procedure's hash - dropw - exec.note::get_serial_number # => [SERIAL_NUMBER] @@ -960,7 +784,7 @@ end #! Moves the account pointer to the currently accessing foreign account. #! #! Inputs: -#! Operand stack: [KERNEL_PROCEDURE_HASH, foreign_account_id, pad(11)] +#! Operand stack: [foreign_account_id, pad(11)] #! Advice map: { #! FOREIGN_ACCOUNT_ID: [[foreign_account_id, 0, 0, account_nonce], VAULT_ROOT, STORAGE_ROOT, CODE_ROOT], #! STORAGE_ROOT: [[STORAGE_SLOT_DATA]], @@ -987,10 +811,6 @@ end export.start_foreign_context # check that this procedure was executed against the native account exec.memory::assert_native_account - # OS => [KERNEL_PROCEDURE_HASH, foreign_account_id] - - # drop the procedure's hash - dropw # OS => [foreign_account_id] # get the memory address and a flag whether this account was already loaded. @@ -1058,16 +878,13 @@ end #! Tells the transaction kernel that we are done executing a procedure on a foreign account. #! -#! Inputs: [KERNEL_PROCEDURE_HASH, ...] +#! Inputs: [...] #! Outputs: [...] #! #! Panics if: #! - the current context is a native context. export.end_foreign_context exec.memory::set_current_account_data_ptr_to_native_account - - # drop the procedure's hash - dropw end #! Updates the transaction expiration time delta. @@ -1076,29 +893,23 @@ end #! The input block height delta is added to the reference block in order to output an upper limit #! up until which the transaction will be considered valid (not expired). #! -#! Inputs: [KERNEL_PROCEDURE_HASH, block_height_delta, ...] +#! Inputs: [block_height_delta, ...] #! Output: [...] #! #! Where: #! - block_height_delta is the desired expiration time delta (1 to 0xFFFF). export.update_expiration_block_num - # drop the procedure's hash - dropw - exec.tx::update_expiration_block_num end #! Gets the transaction expiration delta. #! #! Inputs: [...] -#! Output: [KERNEL_PROCEDURE_HASH, block_height_delta, ...] +#! Output: [block_height_delta, ...] #! #! Where: #! - block_height_delta is the stored expiration time delta (1 to 0xFFFF). export.get_expiration_delta - # drop the procedure's hash - dropw - exec.tx::get_expiration_delta end @@ -1135,6 +946,10 @@ export.exec_kernel_proc mem_loadw # => [KERNEL_PROCEDURE_HASH, , ] + # store the KERNEL_PROCEDURE_HASH to the memory to be able to call it dynamically + exec.memory::store_dyn_proc_root + # => [kernel_procedure_hash_addr, , ] + # execute loaded procedure dynexec # => [, ] diff --git a/miden-lib/asm/kernels/transaction/lib/memory.masm b/miden-lib/asm/kernels/transaction/lib/memory.masm index 316d45c14..7c9dbb1ad 100644 --- a/miden-lib/asm/kernels/transaction/lib/memory.masm +++ b/miden-lib/asm/kernels/transaction/lib/memory.masm @@ -144,6 +144,13 @@ const.ACCT_PROCEDURES_SECTION_OFFSET=8 const.NUM_ACCT_STORAGE_SLOTS_OFFSET=521 const.ACCT_STORAGE_SLOTS_SECTION_OFFSET=522 +# DYNAMIC EXECUTION DATA SLOT +# ------------------------------------------------------------------------------------------------- + +# The memory address which should be used to store the root of the dynamically called/executed +# procedure. +const.DYN_PROC_ROOT_ADDR=133120 + # INPUT NOTES DATA # ------------------------------------------------------------------------------------------------- @@ -976,6 +983,23 @@ export.get_acct_storage_slots_section_ptr exec.get_current_account_data_ptr push.ACCT_STORAGE_SLOTS_SECTION_OFFSET add end +# DYNAMIC EXECUTION DATA +# ------------------------------------------------------------------------------------------------- + +#! Stores the provided procedure root to the dedicated memory address, returning this address as a +#! result. +#! +#! Stack: [DYN_PROC_ROOT] +#! Output: [dyn_proc_root_addr] +#! +#! Where: +#! - DYN_PROC_ROOT is the root of the procedure which will be called/executed dynamically. +#! - dyn_proc_root_addr is the memory address where this proc root is stored. +export.store_dyn_proc_root + mem_storew.DYN_PROC_ROOT_ADDR dropw + push.DYN_PROC_ROOT_ADDR +end + # INPUT NOTES # ------------------------------------------------------------------------------------------------- diff --git a/miden-lib/asm/kernels/transaction/main.masm b/miden-lib/asm/kernels/transaction/main.masm index 91f5a3e2f..29f34fd27 100644 --- a/miden-lib/asm/kernels/transaction/main.masm +++ b/miden-lib/asm/kernels/transaction/main.masm @@ -95,6 +95,10 @@ proc.main.1 exec.note::prepare_note # => [NOTE_SCRIPT_HASH, NOTE_ARGS] + # store the NOTE_SCRIPT_HASH to the memory to be able to call it dynamically + exec.memory::store_dyn_proc_root + # => [note_script_hash_addr, NOTE_ARGS] + # run note's script dyncall # => [X, X, X, X] @@ -134,6 +138,10 @@ proc.main.1 # => [has_tx_script, TX_SCRIPT_ROOT] if.true + # store the TX_SCRIPT_ROOT to the memory to be able to call it dynamically + exec.memory::store_dyn_proc_root + # => [tx_script_root_addr] + # execute the transaction script dyncall # => [OUTPUT_3, OUTPUT_2, OUTPUT_1, OUTPUT_0] diff --git a/miden-lib/asm/miden/account.masm b/miden-lib/asm/miden/account.masm index 265cac70d..6753c0354 100644 --- a/miden-lib/asm/miden/account.masm +++ b/miden-lib/asm/miden/account.masm @@ -376,74 +376,6 @@ export.get_vault_commitment # => [COM] end -# FOREIGN ACCOUNT PROCEDURES -# ================================================================================================= - -# NOTE -# ------------------------------------------------------------------------------------------------- -# Procedures listed in this section are supposed to be `dyncall`ed, so it is assumed that the top # -# word on the stack is occupied by the procedure hash. # -# ------------------------------------------------------------------------------------------------- - -#! Gets an item from the foreign account storage. -#! -#! Stack: [PROC_HASH, index] -#! Output: [VALUE] -#! -#! Where: -#! - PROC_HASH is the hash of this procedure. -#! - index is the index of the item to get. -#! - VALUE is the value of the item. -#! -#! Panics if: -#! - the item index is out of bounds. -export.get_item_foreign - exec.kernel_proc_offsets::get_account_item_foreign_offset - # => [offset, PROC_HASH, index] - - # pad the stack - push.0.0 movdn.7 movdn.7 - padw padw swapdw - # => [offset, PROC_HASH, index, pad(10)] - - syscall.exec_kernel_proc - # => [VALUE, pad(12)] - - # clean the stack - swapdw dropw dropw swapw dropw - # => [VALUE] -end - -#! Gets a map item from the account storage. -#! -#! Stack: [PROC_HASH, index, KEY] -#! Output: [VALUE] -#! -#! Where: -#! - PROC_HASH is the hash of this procedure. -#! - index is the index of the map where the KEY VALUE should be read. -#! - KEY is the key of the item to get. -#! - VALUE is the value of the item. -#! -#! Panics if: -#! - the index for the map is out of bounds, means >255 -#! - the slot item at index is not a map -export.get_map_item_foreign - exec.kernel_proc_offsets::get_account_map_item_foreign_offset - # => [offset, PROC_HASH, index, KEY] - - # pad the stack - push.0.0 movdn.11 movdn.11 padw movdnw.3 - # => [offset, PROC_HASH, index, KEY, pad(6)] - - syscall.exec_kernel_proc - # => [VALUE, PAD(12)] - - # clean the stack - swapdw dropw dropw swapw dropw - # => [VALUE] -end - # PROCEDURES COPIED FROM KERNEL (TODO: get rid of this duplication) # ================================================================================================= diff --git a/miden-lib/asm/miden/kernel_proc_offsets.masm b/miden-lib/asm/miden/kernel_proc_offsets.masm index a1f6024f6..a7d256c07 100644 --- a/miden-lib/asm/miden/kernel_proc_offsets.masm +++ b/miden-lib/asm/miden/kernel_proc_offsets.masm @@ -17,31 +17,29 @@ const.INCR_ACCOUNT_NONCE_OFFSET=11 const.SET_ACCOUNT_CODE_OFFSET=12 const.SET_ACCOUNT_ITEM_OFFSET=13 const.SET_ACCOUNT_MAP_ITEM_OFFSET=14 -const.GET_ACCOUNT_ITEM_FOREIGN_OFFSET=15 -const.GET_ACCOUNT_MAP_ITEM_FOREIGN_OFFSET=16 # Current faucet -const.BURN_ASSET_OFFSET=17 -const.GET_FUNGIBLE_FAUCET_TOTAL_ISSUANCE_OFFSET=18 -const.MINT_ASSET_OFFSET=19 +const.BURN_ASSET_OFFSET=15 +const.GET_FUNGIBLE_FAUCET_TOTAL_ISSUANCE_OFFSET=16 +const.MINT_ASSET_OFFSET=17 # Current note -const.ADD_ASSET_TO_NOTE_OFFSET=20 -const.CREATE_NOTE_OFFSET=21 -const.GET_INPUT_NOTES_COMMITMENT_OFFSET=22 -const.GET_NOTE_ASSETS_INFO_OFFSET=23 -const.GET_NOTE_INPUTS_HASH_OFFSET=24 -const.GET_NOTE_SENDER_OFFSET=25 -const.GET_NOTE_SERIAL_NUMBER_OFFSET=26 -const.GET_OUTPUT_NOTES_HASH_OFFSET=27 +const.ADD_ASSET_TO_NOTE_OFFSET=18 +const.CREATE_NOTE_OFFSET=19 +const.GET_INPUT_NOTES_COMMITMENT_OFFSET=20 +const.GET_NOTE_ASSETS_INFO_OFFSET=21 +const.GET_NOTE_INPUTS_HASH_OFFSET=22 +const.GET_NOTE_SENDER_OFFSET=23 +const.GET_NOTE_SERIAL_NUMBER_OFFSET=24 +const.GET_OUTPUT_NOTES_HASH_OFFSET=25 # Transaction -const.GET_BLOCK_HASH_OFFSET=28 -const.GET_BLOCK_NUMBER_OFFSET=29 -const.START_FOREIGN_CONTEXT_OFFSET=30 -const.END_FOREIGN_CONTEXT_OFFSET=31 -const.UPDATE_EXPIRATION_BLOCK_NUM_OFFSET=32 -const.GET_EXPIRATION_DELTA_OFFSET=33 +const.GET_BLOCK_HASH_OFFSET=26 +const.GET_BLOCK_NUMBER_OFFSET=27 +const.START_FOREIGN_CONTEXT_OFFSET=28 +const.END_FOREIGN_CONTEXT_OFFSET=29 +const.UPDATE_EXPIRATION_BLOCK_NUM_OFFSET=30 +const.GET_EXPIRATION_DELTA_OFFSET=31 # ACCESSORS # ------------------------------------------------------------------------------------------------- @@ -429,27 +427,3 @@ end export.end_foreign_context_offset push.END_FOREIGN_CONTEXT_OFFSET end - -#! Returns an offset of the `get_account_item_foreign` kernel procedure. -#! -#! Stack: [] -#! Output: [proc_offset] -#! -#! Where: -#! - proc_offset is the offset of the `get_account_item_foreign` kernel procedure required to get -#! the address where this procedure is stored. -export.get_account_item_foreign_offset - push.GET_ACCOUNT_ITEM_FOREIGN_OFFSET -end - -#! Returns an offset of the `get_account_map_item_foreign` kernel procedure. -#! -#! Stack: [] -#! Output: [proc_offset] -#! -#! Where: -#! - proc_offset is the offset of the `get_account_map_item_foreign` kernel procedure required to -#! get the address where this procedure is stored. -export.get_account_map_item_foreign_offset - push.GET_ACCOUNT_MAP_ITEM_FOREIGN_OFFSET -end diff --git a/miden-lib/asm/miden/tx.masm b/miden-lib/asm/miden/tx.masm index b5331e3ab..64cb75a6a 100644 --- a/miden-lib/asm/miden/tx.masm +++ b/miden-lib/asm/miden/tx.masm @@ -163,17 +163,17 @@ end #! Executes the provided procedure against the foreign account. #! -#! WARNING: the procedure to be invoked can not have more than 12 inputs and it can not return more -#! than 12 elements back. Otherwise exceeding elements will not be provided to the procedure and +#! WARNING: the procedure to be invoked can not have more than 15 inputs and it can not return more +#! than 15 elements back. Otherwise exceeding elements will not be provided to the procedure and #! will not be returned from it. #! #! Inputs: [foreign_account_id, FOREIGN_PROC_ROOT, , pad(n), ...] #! Outputs: [] #! #! Where: -#! - pad(n) is the exact number of pads needed to set the number of procedure inputs to 16 at the moment of the foreign procedure execution -#! (n = 16 - WORD_SIZE - foreign_inputs_len) -export.execute_foreign_procedure +#! - pad(n) is the exact number of pads needed to set the number of procedure inputs to 16 at the +#! moment of the foreign procedure execution (n = 16 - mem_addr_size - foreign_inputs_len) +export.execute_foreign_procedure.1 # pad the stack before the syscall push.0.0 movup.2 exec.kernel_proc_offsets::start_foreign_context_offset @@ -188,6 +188,10 @@ export.execute_foreign_procedure dropw dropw dropw dropw # => [FOREIGN_PROC_ROOT, , pad(n), ...] + # store the foreign procedure root to the <...> memory address + loc_storew.0 dropw locaddr.0 + # => [foreign_proc_root_addr, , pad(n), ...] + # execute the foreign procedure dyncall # => [] diff --git a/miden-lib/src/transaction/memory.rs b/miden-lib/src/transaction/memory.rs index 58c56831b..24422c23b 100644 --- a/miden-lib/src/transaction/memory.rs +++ b/miden-lib/src/transaction/memory.rs @@ -20,6 +20,7 @@ pub type StorageSlot = u8; // | Chain MMR | 300 | 332? | // | Kernel data | 400 | 429 | // | Accounts data | 2048 | 133_119 | 64 foreign accounts max +// | Dyn proc root | 133_120 | 133_120 | // | Input notes | 1_048_576 | ? | // | Output notes | 4_194_304 | ? | @@ -254,6 +255,13 @@ pub const NATIVE_ACCT_STORAGE_SLOTS_SECTION_PTR: MemoryAddress = /// The size of the memory segment allocated to each note. pub const NOTE_MEM_SIZE: MemoryAddress = 512; +// DYNAMIC EXECUTION DATA SLOT +// ================================================================================================ + +/// The memory address which should be used to store the root of the dynamically called/executed +/// procedure. +pub const DYN_PROC_ROOT: MemoryAddress = 133120; + #[rustfmt::skip] // INPUT NOTES DATA // ------------------------------------------------------------------------------------------------ diff --git a/miden-lib/src/transaction/procedures/kernel_v0.rs b/miden-lib/src/transaction/procedures/kernel_v0.rs index c79219b4c..b5adc37e1 100644 --- a/miden-lib/src/transaction/procedures/kernel_v0.rs +++ b/miden-lib/src/transaction/procedures/kernel_v0.rs @@ -6,73 +6,69 @@ use miden_objects::{digest, Digest, Felt}; // ================================================================================================ /// Hashes of all dynamically executed procedures from the kernel 0. -pub const KERNEL0_PROCEDURES: [Digest; 34] = [ +pub const KERNEL0_PROCEDURES: [Digest; 32] = [ // account_vault_add_asset - digest!(0x6a4c5744379b0cfe, 0x57e40daef3cec08, 0x8417b2b9ec21d9c6, 0x20bad9b26d301d51), + digest!(0xa9fe41a58d609bc6, 0xca49c09c352213a4, 0x30f55868815fc5, 0x84f2f2540b3d335e), // account_vault_get_balance - digest!(0x473133967d0cd8c3, 0xa9b39da8971ba187, 0xf35e31679a6e8ba6, 0xb2b5a0eb135d9642), + digest!(0xc9f641c7cb28c537, 0x5f1835b4bc0216d8, 0x67a3595a70ec1e47, 0xe80706963236ef04), // account_vault_has_non_fungible_asset - digest!(0xcbb00af70f96ae4, 0x1b15725d50b2ad4d, 0x4366b2d4c5ef9d68, 0x11c5ed76e02dcf5b), + digest!(0xea8a34165d532089, 0x59a926dbd5aa3ff2, 0xe5115a03af1df001, 0x76389bdaf65efbe7), // account_vault_remove_asset - digest!(0x63983686cfc3e338, 0x49ac24bbe5da2222, 0x95fc53e8d4175df6, 0x186bd5fd84eeef81), + digest!(0x50d3cb33cd1418ba, 0x7557071cd1d80348, 0x15bf59b92f4acbf0, 0xe5b38d70ced94a21), // get_account_id - digest!(0x3bb2b1ebd4b93ba4, 0x3573acd91765a430, 0xaf0dbcbc764df097, 0x31af3e18b39589c0), + digest!(0x6aced4e086435d59, 0xba76f46e942cef62, 0xb200b248f2dcd162, 0x1157061dd5f0d46f), // get_account_item - digest!(0x92ea96dea9736b41, 0x80fa0e2803b876e8, 0x4de592d9b418369f, 0x73bb3aeef016eda4), + digest!(0x17eb77c44f50731a, 0xf3a47bd9edfcc9c9, 0x18ff2a567c82c997, 0x18dae9f808fda222), // get_account_map_item - digest!(0xdeeccc19456a9bee, 0x365a1f03bbfb89f8, 0x4605e18f262ea21, 0x27a8b916b81272b3), + digest!(0xe8bc7c2fc9d43a2b, 0x3161e056efe3ea43, 0xbdc7cd1661a4417b, 0x23852218531bdad9), // get_account_nonce - digest!(0x706a7e6f01eaca6c, 0x128418b35adc4bae, 0x575071abfd7c7891, 0x19e10dfdd93b6689), + digest!(0xacdebda374aa5674, 0x8a0b1304eb02cffb, 0xeb0a5fb1b57207ea, 0xf76bd169121bf949), // get_account_vault_commitment - digest!(0x1eb5ab08eee78202, 0x24b4209938be234a, 0x225cdf131b90a8f0, 0x1091ab9649c7923b), + digest!(0x3c4f947b6f95a1bf, 0x50ce4a4edb6f4e8e, 0x2034c3ca943fa0cd, 0x1c98390c7ae9b7c8), // get_current_account_hash - digest!(0xcf814d60948e4f31, 0xf37c6365975649ff, 0xdfb3c81a7d8f401a, 0xe0f48c13bdc2fc00), + digest!(0x802c0790eeeabe44, 0xd88044083d9bf1ff, 0x516b86ae7774a2e, 0x79fc0a0193b24fd7), // get_initial_account_hash - digest!(0x7200982d1270fde9, 0x17344f71b88e42c1, 0xe416d03b6e170405, 0xc3d6fa95b3fca8a6), + digest!(0xef64acfbf231cccf, 0x1cb9c8cf93a1b0ae, 0x72f5eee9bd238830, 0x326baec63364b9be), // incr_account_nonce - digest!(0x153f7f40fe898961, 0x3e5759b18d548091, 0x98fa30818b06e761, 0x7c3a93fea3ee1f85), + digest!(0xb0dfaaa97c2b4ce5, 0x2bd39c4c6176fc56, 0xd96082a492f92d0a, 0x8db29879a967bd2d), // set_account_code - digest!(0xd9020751acc4d18f, 0x5197b566ce35dc5b, 0xd814905dec6794d3, 0x7fe8ebc8ee735bed), + digest!(0xfe85c2bde64f0700, 0x8aa763adc38d6662, 0xe3f29524e6f8a6d9, 0x653dea6b152cba52), // set_account_item - digest!(0x9e5a9241d5e7a337, 0x9fc135b73381fc2d, 0xa7de64699a803ddf, 0x95af6772e92e304a), + digest!(0x499f79c1362b9a07, 0x1b92269850061e98, 0x796953b19ee46adc, 0xe72dd36a7b0ddcbb), // set_account_map_item - digest!(0xe8a35ef683860239, 0xaad59ad5a062d811, 0x7b41eda353be1f2f, 0x71fe819e5134a208), - // get_account_item_foreign - digest!(0x3391cd1c53071c21, 0xafae0c1886ac7fd0, 0x39c7e7faf40c27df, 0xe920b566887a70b9), - // get_account_map_item_foreign - digest!(0xb184cda9c0b74acd, 0xfe92bb45c26872eb, 0x5ac336124a3e5c05, 0x675f5660f797b940), + digest!(0xb725af2709828550, 0xb7ba61b264bdcb95, 0x46fb74585d83ff7a, 0xa5f4990bf3f25698), // burn_asset - digest!(0x434615ce6d6f4511, 0x20a46199d43a7396, 0xe428d5590463d800, 0xa403f97c29382f0c), + digest!(0xe04d74db39cc3b5b, 0x9cc09131a411012b, 0x1359ac8f13bfaf7c, 0xaa61f025022959d9), // get_fungible_faucet_total_issuance - digest!(0x5ea05f3e3e4f81ca, 0x8496fd279dddd738, 0xc3ff22442bbdc3ec, 0xac33ea50669bc0aa), + digest!(0x9dc9fa65171ea10b, 0x3f7735402fe315d6, 0x7cedd24bf19310ad, 0x197e0ba67054fa98), // mint_asset - digest!(0x64c37e09b9b2bb75, 0xbc76d5845d6c439d, 0x25442aa97dff8d5e, 0x57f86b308e3a34c8), + digest!(0x5f1b1ef4632de4c1, 0xde69adb0010e558b, 0x6c034d21e74f265b, 0x22e4b88e992799a0), // add_asset_to_note - digest!(0x1c6316d7664eedfe, 0x2a412f16c5221694, 0xeebb83464618d7cd, 0xfb1e445be3826578), + digest!(0xa64a1ece11db2897, 0x892200d8bf530f42, 0x9d03e9da185baad3, 0xebcb1e54b2e23e3c), // create_note - digest!(0xa2f8729e6c4f40d6, 0x8bc5b479884d82d, 0x20a8f7f3e27b7ea3, 0x3e60ddb9d387325e), + digest!(0xabde835730b7c0f3, 0x29f54d09ca7fe6ea, 0xc1799a2c33024aa0, 0x9d95083bf6532962), // get_input_notes_commitment - digest!(0xf9def388fed463af, 0xd4cc0c28bbfb3e3b, 0x34214c6db961ab94, 0x6c7d08842f0d3f05), + digest!(0x7e3ca0c93364a844, 0x56ed10c6b049de9, 0xb676b1eb055f27df, 0xb5e8ea2972209301), // get_note_assets_info - digest!(0xc964001fcc716747, 0x85b6192367ebbb6b, 0x130316a2b2012aaa, 0x689eab2646670883), + digest!(0x98dddf82d366a2cc, 0x5c5278df4b88d10a, 0x9d83d6f405fe90c0, 0x2f0e122b3867f01d), // get_note_inputs_hash - digest!(0xb0023a2d6db766f2, 0xfb3f03e1ceab2acf, 0x2cf90c72a460cbd8, 0xcccbf0ce7510d3d6), + digest!(0xade126b7999e20e6, 0xfabc302b719eb825, 0xdc817bb4fe45ad3b, 0xdacb0d2bb050a651), // get_note_sender - digest!(0x313121b59e628727, 0xed392737df4eb374, 0x73e1162d04f6e183, 0xff2c13eca489cbb4), + digest!(0x967b8f2b43a079c5, 0xfb8a3cf7b33ac140, 0xfa3c4ab109a40a6f, 0xfda24ed0606e53ff), // get_note_serial_number - digest!(0x2d2dc403ffe37a4, 0x19fa079fae6767b3, 0x9906641edeb7c6dc, 0x73cf6ad64959ad7c), + digest!(0x627519c20e1391ad, 0xde388aafdecac613, 0xc3b70c620ce56887, 0xb654604c8731c547), // get_output_notes_hash - digest!(0xa26981efeeaf8832, 0x58c074710a5846cf, 0x6562ef6dacb0d009, 0xac19ed60ff18d663), + digest!(0xaf7e3e2ce3a65a5d, 0xd20c093c6816dda7, 0x9d029901984dc860, 0x8a9968ec5c7dea98), // get_block_hash - digest!(0x7ac96b85d3264a44, 0x728be44578702285, 0xadc7955452ed46b0, 0x64e57a26836003a2), + digest!(0xccc964fdf761d004, 0xd919b4cb05cb160, 0xda45a051c1bc0ab9, 0x8ea560fbf3191913), // get_block_number - digest!(0x4ae44b38c3cbdb03, 0x90cb608a6097a8b4, 0x697db8ae9980cc61, 0xdc101e2fb18546fc), + digest!(0x88278b8772ada17, 0x69b99e5f2bffbf54, 0xf4978f996ae7e2a4, 0x7c4396761a2b7b96), // start_foreign_context - digest!(0x562e2acd1d18037c, 0x6c27192cdd634a9d, 0x3e5d3fa8ddaae4b4, 0x200701203fc97777), + digest!(0xfc26cc8cc1a4d7b4, 0xeb50a928de2c5222, 0x7930027d939740e3, 0x4218d117620f4664), // end_foreign_context - digest!(0xf95632fd4a6467c2, 0xf1559b93b6790054, 0x3b5180597c08a1cd, 0xee23ca99d5420d5d), + digest!(0xc1ce8ecafe502b13, 0x73590c6440c73709, 0x4c30d8c1893e643e, 0x28047ae2203152f4), // update_expiration_block_num - digest!(0xd678d5b25cb7394, 0x660a9b25e0733930, 0x5831851f6ffb1b2d, 0xfddab52d7183c806), + digest!(0xfd51bff9ff681633, 0x8075745cbe89f84c, 0xebecbce5a2c97df9, 0xad195ad3e589976f), // get_expiration_delta - digest!(0x83f22fdecb98f87, 0xee7d669b37e6e740, 0x6ecf3b01115a6724, 0xe8fa1ba45c87b953), + digest!(0x60d571bf3cbe4ca0, 0x1969d046d6e5e007, 0x5f97e0173f503c60, 0x8064d7deb54c2f13), ]; diff --git a/miden-tx/src/tests/kernel_tests/test_tx.rs b/miden-tx/src/tests/kernel_tests/test_tx.rs index a1cf4d464..3abcc305b 100644 --- a/miden-tx/src/tests/kernel_tests/test_tx.rs +++ b/miden-tx/src/tests/kernel_tests/test_tx.rs @@ -641,30 +641,45 @@ fn test_load_foreign_account_basic() { .advice_inputs(advice_inputs.clone()) .build(); + let get_item_foreign_hash = { + let foreign_account_code_source = " + use.miden::account + export.get_item + exec.account::get_item + movup.8 drop movup.8 drop movup.8 drop + end + "; + *AccountCode::mock_with_code( + foreign_account_code_source, + TransactionKernel::testing_assembler(), + ) + .procedures()[0] + .mast_root() + }; + let code = format!( " use.std::sys use.kernel::prologue use.miden::tx - use.miden::account begin exec.prologue::prepare_transaction # pad the stack for the `execute_foreign_procedure`execution - padw padw push.0.0.0 - # => [pad(11)] + padw padw padw push.0.0 + # => [pad(14)] # push the index of desired storage item push.0 - # get the hash of the `get_item_foreign` account procedure - procref.account::get_item_foreign + # get the hash of the `get_item` account procedure + push.{get_item_foreign_hash} # push the foreign account id push.{account_id} - # => [foreign_account_id, FOREIGN_PROC_ROOT, storage_item_index, pad(11)] + # => [foreign_account_id, FOREIGN_PROC_ROOT, storage_item_index, pad(14)] exec.tx::execute_foreign_procedure # => [STORAGE_VALUE_1] @@ -716,8 +731,8 @@ fn test_load_foreign_account_basic() { exec.prologue::prepare_transaction # pad the stack for the `execute_foreign_procedure`execution - padw push.0.0.0 - # => [pad(7)] + padw padw push.0.0 + # => [pad(10)] # push the key of desired storage item push.{map_key} @@ -725,12 +740,12 @@ fn test_load_foreign_account_basic() { # push the index of desired storage item push.0 - # get the hash of the `get_map_item_foreign` account procedure - procref.account::get_map_item_foreign + # get the hash of the `get_map_item` account procedure + procref.account::get_map_item # push the foreign account id push.{account_id} - # => [foreign_account_id, FOREIGN_PROC_ROOT, storage_item_index, MAP_ITEM_KEY, pad(7)] + # => [foreign_account_id, FOREIGN_PROC_ROOT, storage_item_index, MAP_ITEM_KEY, pad(10)] exec.tx::execute_foreign_procedure # => [MAP_VALUE] @@ -774,49 +789,64 @@ fn test_load_foreign_account_twice() { .advice_inputs(advice_inputs.clone()) .build(); + let get_item_foreign_hash = { + let foreign_account_code_source = " + use.miden::account + export.get_item + exec.account::get_item + movup.8 drop movup.8 drop movup.8 drop + end + "; + *AccountCode::mock_with_code( + foreign_account_code_source, + TransactionKernel::testing_assembler(), + ) + .procedures()[0] + .mast_root() + }; + let code = format!( " use.std::sys use.kernel::prologue use.miden::tx - use.miden::account begin exec.prologue::prepare_transaction ### Get the storage item at index 0 ##################### # pad the stack for the `execute_foreign_procedure`execution - padw padw push.0.0.0 - # => [pad(11)] + padw padw padw push.0.0 + # => [pad(14)] # push the index of desired storage item push.0 - # get the hash of the `get_item_foreign` account procedure - procref.account::get_item_foreign + # get the hash of the `get_item` account procedure + push.{get_item_foreign_hash} # push the foreign account id push.{account_id} - # => [foreign_account_id, FOREIGN_PROC_ROOT, storage_item_index, pad(11)] + # => [foreign_account_id, FOREIGN_PROC_ROOT, storage_item_index, pad(14)] exec.tx::execute_foreign_procedure dropw # => [] ### Get the storage item at index 0 again ############### # pad the stack for the `execute_foreign_procedure`execution - padw padw push.0.0.0 - # => [pad(11)] + padw padw padw push.0.0 + # => [pad(14)] # push the index of desired storage item push.0 - # get the hash of the `get_item_foreign` account procedure - procref.account::get_item_foreign + # get the hash of the `get_item` account procedure + push.{get_item_foreign_hash} # push the foreign account id push.{account_id} - # => [foreign_account_id, FOREIGN_PROC_ROOT, storage_item_index, MAP_ITEM_KEY, pad(11)] + # => [foreign_account_id, FOREIGN_PROC_ROOT, storage_item_index, pad(14)] exec.tx::execute_foreign_procedure diff --git a/objects/src/testing/account_code.rs b/objects/src/testing/account_code.rs index 24d00e456..f2782062b 100644 --- a/objects/src/testing/account_code.rs +++ b/objects/src/testing/account_code.rs @@ -49,9 +49,6 @@ impl AccountCode { export.::miden::contracts::wallets::basic::create_note export.::miden::contracts::wallets::basic::move_asset_to_note - export.::miden::account::get_item_foreign - export.::miden::account::get_map_item_foreign - export.incr_nonce push.0 swap # => [value, 0]