diff --git a/bin/tx-prover/src/server/mod.rs b/bin/tx-prover/src/server/mod.rs index daeb224f9..370634dc2 100644 --- a/bin/tx-prover/src/server/mod.rs +++ b/bin/tx-prover/src/server/mod.rs @@ -9,6 +9,7 @@ use tokio::{net::TcpListener, sync::Mutex}; use tonic::{Request, Response, Status}; use tracing::info; +#[rustfmt::skip] pub mod generated; pub struct Rpc { diff --git a/miden-lib/asm/kernels/transaction/api.masm b/miden-lib/asm/kernels/transaction/api.masm index b28ed027b..7ae172f5d 100644 --- a/miden-lib/asm/kernels/transaction/api.masm +++ b/miden-lib/asm/kernels/transaction/api.masm @@ -992,7 +992,7 @@ export.start_foreign_context # OS => [foreign_account_id] # get the memory address and a flag whether this account was already loaded. - exec.memory::get_foreign_account_ptr + exec.account::get_foreign_account_ptr # OS => [was_loaded, ptr, foreign_account_id] if.true @@ -1033,7 +1033,7 @@ export.start_foreign_context # AS => [] # save the account procedure data into the memory - exec.memory::save_account_procedure_data + exec.account::save_account_procedure_data # OS => [STORAGE_ROOT] # AS => [] @@ -1043,7 +1043,7 @@ export.start_foreign_context # AS => [] # save the storage slots data into the memory - exec.memory::save_account_storage_data + exec.account::save_account_storage_data # OS => [] # AS => [] end diff --git a/miden-lib/asm/kernels/transaction/lib/account.masm b/miden-lib/asm/kernels/transaction/lib/account.masm index a706aba93..525bcdf11 100644 --- a/miden-lib/asm/kernels/transaction/lib/account.masm +++ b/miden-lib/asm/kernels/transaction/lib/account.masm @@ -1,5 +1,6 @@ use.std::collections::smt use.std::crypto::hashes::native +use.std::mem use.kernel::constants use.kernel::memory @@ -40,6 +41,27 @@ const.ERR_STORAGE_SLOT_INDEX_OUT_OF_BOUNDS=0x0002004E # Storage offset is invalid for a faucet account (0 is prohibited being the faucet reserved data slot) const.ERR_INVALID_FAUCET_STORAGE_OFFSET=0x0002004F +# Computed account code commitment does not match recorded account code commitment +const.ERR_ACCT_CODE_COMMITMENT_MISMATCH=0x0002004C + +# Number of account procedures exceeded the maximum limit of 256 +const.ERR_ACCT_TOO_MANY_PROCEDURES=0x0002004D + +# Computed account storage commitment does not match recorded account storage commitment +const.ERR_ACCT_STORAGE_COMMITMENT_MISMATCH=0x00020050 + +# Number of account storage slots exceeded the maximum limit of 255 +const.ERR_ACCT_TOO_MANY_STORAGE_SLOTS=0x00020058 + +# ID of the provided foreign account equals zero. +const.ERR_FOREIGN_ACCOUNT_ID_IS_ZERO=0x00020056 + +# Maximum allowed number of foreign account to be loaded (64) was exceeded. +const.ERR_MAX_NUM_FOREIGN_ACCOUNTS_EXCEEDED=0x00020057 + +# Provided foreign account ID is equal to the native account ID. +const.ERR_FOREIGN_ACCT_ID_EQUALS_NATIVE_ACCT_ID=0x00020059 + # CONSTANTS # ================================================================================================= @@ -662,6 +684,147 @@ export.validate_seed # => [] end +# DATA LOADERS +# ================================================================================================= + +#! Saves storage slots data into memory and validates that the storage commitment matches the +#! sequential storage hash. +#! +#! Inputs: +#! Operand stack: [STORAGE_COMMITMENT] +#! Advice map: { +#! STORAGE_COMMITMENT: [[STORAGE_SLOT_DATA]], +#! } +#! Outputs: +#! Operand stack: [] +#! +#! Where: +#! - STORAGE_COMMITMENT is the commitment of the foreign account's storage. +#! - STORAGE_SLOT_DATA is the data contained in the storage slot which is constructed as follows: +#! [SLOT_VALUE, slot_type, 0, 0, 0] +#! +#! Panics if: +#! - the number of account storage slots exceeded the maximum limit of 255. +#! - 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 + # OS => [STORAGE_COMMITMENT] + # AS => [storage_slot_data_len, [STORAGE_SLOT_DATA]] + + # push the length of the storage slot data onto the operand stack and compute the number of + # storage slots from it + adv_push.1 div.8 + # OS => [num_storage_slots, STORAGE_COMMITMENT] + # AS => [[STORAGE_SLOT_DATA]] + + # assert that account does not exceed allowed maximum number of storage slots + dup exec.get_max_num_storage_slots lte assert.err=ERR_ACCT_TOO_MANY_STORAGE_SLOTS + # OS => [num_storage_slots, STORAGE_COMMITMENT] + # AS => [[STORAGE_SLOT_DATA]] + + # store number of storage slots in memory + dup exec.memory::set_num_storage_slots + # OS => [num_storage_slots, STORAGE_COMMITMENT] + # AS => [[STORAGE_SLOT_DATA]] + + # setup acct_storage_slots_offset and end_ptr for reading from advice stack + mul.2 exec.memory::get_acct_storage_slots_section_ptr dup movdn.2 add swap + # OS => [acct_storage_slots_offset, end_ptr, STORAGE_COMMITMENT] + # AS => [[STORAGE_SLOT_DATA]] + + # pad stack before reading from advice stack + padw padw padw + # OS => [PAD, PAD, PAD, acct_proc_offset, end_ptr, STORAGE_COMMITMENT] + # AS => [[STORAGE_SLOT_DATA]] + + # read the data from advice stack to memory and hash + exec.mem::pipe_double_words_to_memory + # OS => [PERM, PERM, PERM, end_ptr', STORAGE_COMMITMENT] + # AS => [] + + # extract the digest + exec.native::state_to_digest + # OS => [DIGEST, end_ptr', STORAGE_COMMITMENT] + + # drop end_ptr + movup.4 drop + # OS => [DIGEST, STORAGE_COMMITMENT] + + # verify hashed account storage slots match account storage commitment + assert_eqw.err=ERR_ACCT_STORAGE_COMMITMENT_MISMATCH + # OS => [] +end + +#! Saves account procedure data into memory and validates that the code commitment matches the +#! sequential procedure hash. +#! +#! Inputs: +#! Operand stack: [CODE_COMMITMENT] +#! Advice map: { +#! CODE_COMMITMENT: [num_procs, [ACCOUNT_PROCEDURE_DATA]], +#! } +#! Outputs: +#! Operand stack: [] +#! +#! Where: +#! - CODE_COMMITMENT is the commitment of the foreign account's code. +#! - num_procs is the number of foreign account's procedures. +#! - ACCOUNT_PROCEDURE_DATA is the information about account procedure which is constructed as +#! follows: [PROCEDURE_MAST_ROOT, storage_offset, 0, 0, 0] +#! +#! Panics if: +#! - the number of account procedures exceeded the maximum limit of 256 +#! - 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_mapval push.15161 drop # TODO: remove line, see miden-vm/#1122 + # OS => [CODE_COMMITMENT] + # AS => [num_procs, [ACCOUNT_PROCEDURE_DATA]] + + # push the number of procedures onto the operand stack before storing it in memory + adv_push.1 + # OS => [num_procs, CODE_COMMITMENT] + # AS => [[ACCOUNT_PROCEDURE_DATA]] + + # assert that account does not exceed allowed maximum number of procedures + dup exec.get_max_num_procedures lte assert.err=ERR_ACCT_TOO_MANY_PROCEDURES + # OS => [num_procs, CODE_COMMITMENT] + # AS => [[ACCOUNT_PROCEDURE_DATA]] + + # store number of procedures in memory + dup exec.memory::set_num_account_procedures + # OS => [num_procs, CODE_COMMITMENT] + # AS => [[ACCOUNT_PROCEDURE_DATA]] + + # setup acct_proc_offset and end_ptr for reading from advice stack + mul.2 exec.memory::get_acct_procedures_section_ptr dup movdn.2 add swap + # OS => [acct_proc_offset, end_ptr, CODE_COMMITMENT] + # AS => [[ACCOUNT_PROCEDURE_DATA]] + + # pad stack before reading from advice stack + padw padw padw + # OS => [PAD, PAD, PAD, acct_proc_offset, end_ptr, CODE_COMMITMENT] + # AS => [[ACCOUNT_PROCEDURE_DATA]] + + # read the data from advice stack to memory and hash + exec.mem::pipe_double_words_to_memory + # OS => [PERM, PERM, PERM, end_ptr', CODE_COMMITMENT] + # AS => [] + + # extract the digest + exec.native::state_to_digest + # OS => [DIGEST, end_ptr', CODE_COMMITMENT] + + # drop end_ptr + movup.4 drop + # OS => [DIGEST, CODE_COMMITMENT] + + # verify hashed account procedures match account code commitment + assert_eqw.err=ERR_ACCT_CODE_COMMITMENT_MISMATCH + # OS => [] +end + # HELPER PROCEDURES # ================================================================================================= @@ -732,3 +895,77 @@ proc.get_procedure_storage_offset mem_load # => [storage_offset] end + +#! Returns the pointer to the next vacant memory slot if the account was not loaded before, and the +#! pointer to the account data otherwise. +#! +#! Stack: [foreign_account_id] +#! Output: [was_loaded, ptr, foreign_account_id] +#! +#! Where: +#! - foreign_account_id is the ID of the foreign account whose procedure is going to be executed. +#! - was_loaded is the binary flag indicating whether the foreign account was already loaded to the +#! memory. +#! - ptr is the memory pointer to the next empty memory slot or the memory pointer to the account +#! data, depending on the value of the was_loaded flag. +#! +#! Panics if: +#! - the ID of the provided foreign account equals zero. +#! - the maximum allowed number of foreign account to be loaded (64) was exceeded. +export.get_foreign_account_ptr + # check that foreign account id is not equal zero + dup neq.0 assert.err=ERR_FOREIGN_ACCOUNT_ID_IS_ZERO + # => [foreign_account_id] + + # check that foreign account id is not equal to the native account id + dup exec.memory::get_native_account_id neq assert.err=ERR_FOREIGN_ACCT_ID_EQUALS_NATIVE_ACCT_ID + + # get the initial account data pointer + exec.memory::get_native_account_data_ptr + # => [curr_account_ptr, foreign_account_id] + + # push the flag to enter the loop + push.1 + + while.true + # drop the flag left from the previous loop + movup.2 drop + # => [curr_account_ptr, foreign_account_id] + + # move the current account pointer to the next account data block + exec.memory::get_account_data_length add + # => [curr_account_ptr', foreign_account_id] + + # load the first data word at the current account pointer + padw dup.4 mem_loadw + # => [FIRST_DATA_WORD, curr_account_ptr', foreign_account_id] + + # check whether the first data words is an empty word, preserve the last value in this word + # (account id) + dup.3 movdn.4 padw eqw movdn.8 dropw dropw + # => [is_empty_word, last_data_value, curr_account_ptr', foreign_account_id] + + # check whether the current id matches the foreign id + swap dup.3 eq + # => [is_equal_id, is_empty_word, curr_account_ptr', foreign_account_id] + + # get the sum of the flags to obtain the loop flag + dup movdn.4 add + # => [flags_sum, curr_account_ptr', foreign_account_id, is_equal_id] + + # get the loop flag + # it equals 0 if both `is_equal_id` and `is_empty_word` flags equal 0, so we should continue + # iterating + eq.0 + # => [loop_flag, curr_account_ptr', foreign_account_id, is_equal_id] + end + + # check that the loading of one more account won't exceed the maximum number of the foreign + # accounts which can be loaded. + dup exec.memory::get_max_foreign_account_ptr lte assert.err=ERR_MAX_NUM_FOREIGN_ACCOUNTS_EXCEEDED + # => [curr_account_ptr, foreign_account_id, is_equal_id] + + # the resulting `was_loaded` flag is essentially equal to the `is_equal_id` flag + movup.2 + # => [was_loaded, curr_account_ptr, foreign_account_id] +end \ No newline at end of file diff --git a/miden-lib/asm/kernels/transaction/lib/memory.masm b/miden-lib/asm/kernels/transaction/lib/memory.masm index 83e3e7255..7acb877b9 100644 --- a/miden-lib/asm/kernels/transaction/lib/memory.masm +++ b/miden-lib/asm/kernels/transaction/lib/memory.masm @@ -1,4 +1,3 @@ -use.std::mem use.std::crypto::hashes::native use.kernel::account @@ -6,17 +5,6 @@ use.kernel::constants # ERRORS # ================================================================================================= -# Computed account code commitment does not match recorded account code commitment -const.ERR_ACCT_CODE_COMMITMENT_MISMATCH=0x0002004C - -# Number of account procedures exceeded the maximum limit of 256 -const.ERR_ACCT_TOO_MANY_PROCEDURES=0x0002004D - -# Number of account storage slots exceeded the maximum limit of 255 -const.ERR_ACCT_TOO_MANY_STORAGE_SLOTS=0x0002004F - -# Computed account storage commitment does not match recorded account storage commitment -const.ERR_ACCT_STORAGE_COMMITMENT_MISMATCH=0x00020050 # Number of assets exceeds the maximum allowed number of assets per note. const.ERR_NOTE_TOO_MANY_ASSETS=0x0002002A @@ -24,12 +12,6 @@ const.ERR_NOTE_TOO_MANY_ASSETS=0x0002002A # Current account data pointer is not equal to native account data pointer (2048). const.ERR_CURRENT_ACCOUNT_IS_NOT_NATIVE=0x00020054 -# ID of the provided foreign account equals zero. -const.ERR_FOREIGN_ACCOUNT_ID_IS_ZERO=0x00020056 - -# Maximum allowed number of foreign account to be loaded (64) was exceeded. -const.ERR_MAX_NUM_FOREIGN_ACCOUNTS_EXCEEDED=0x00020057 - # MEMORY ADDRESS CONSTANTS # ================================================================================================= @@ -638,75 +620,31 @@ end # ACCOUNT DATA # ------------------------------------------------------------------------------------------------- -#! Returns the pointer to the next vacant memory slot if the account was not loaded before, and the -#! pointer to the account data otherwise. -#! -#! Stack: [foreign_account_id] -#! Output: [was_loaded, ptr, foreign_account_id] +#! Returns the memory pointer at which the native account data is stored. #! -#! Where: -#! - foreign_account_id is the ID of the foreign account whose procedure is going to be executed. -#! - was_loaded is the binary flag indicating whether the foreign account was already loaded to the -#! memory. -#! - ptr is the memory pointer to the next empty memory slot or the memory pointer to the account -#! data, depending on the value of the was_loaded flag. +#! Stack: [] +#! Output: [ptr] #! -#! Panics if: -#! - the ID of the provided foreign account equals zero. -#! - the maximum allowed number of foreign account to be loaded (64) was exceeded. -export.get_foreign_account_ptr - # check that foreign account id is not equal zero - dup neq.0 assert.err=ERR_FOREIGN_ACCOUNT_ID_IS_ZERO - # => [foreign_account_id] - - # push the initial account data pointer +#! Where: +#! - ptr is the memory address at which the native account data is stored. +export.get_native_account_data_ptr push.NATIVE_ACCOUNT_DATA_PTR - # => [curr_account_ptr, foreign_account_id] - - # push the flag to enter the loop - push.1 - - while.true - # drop the flag left from the previous loop - movup.2 drop - # => [curr_account_ptr, foreign_account_id] - - # move the current account pointer to the next account data block - push.ACCOUNT_DATA_LENGTH add - # => [curr_account_ptr', foreign_account_id] - - # load the first data word at the current account pointer - padw dup.4 mem_loadw - # => [FIRST_DATA_WORD, curr_account_ptr', foreign_account_id] - - # check whether the first data words is an empty word, preserve the last value in this word - # (account id) - dup.3 movdn.4 padw eqw movdn.8 dropw dropw - # => [is_empty_word, last_data_value, curr_account_ptr', foreign_account_id] - - # check whether the current id matches the foreign id - swap dup.3 eq - # => [is_equal_id, is_empty_word, curr_account_ptr', foreign_account_id] - - # get the sum of the flags to obtain the loop flag - dup movdn.4 add - # => [flags_sum, curr_account_ptr', foreign_account_id, is_equal_id] - - # get the loop flag - # it equals 0 if both `is_equal_id` and `is_empty_word` flags equal 0, so we should continue - # iterating - eq.0 - # => [loop_flag, curr_account_ptr', foreign_account_id, is_equal_id] - end +end - # check that the loading of one more account won't exceed the maximum number of the foreign - # accounts which can be loaded. - dup push.MAX_FOREIGN_ACCOUNT_PTR lte assert.err=ERR_MAX_NUM_FOREIGN_ACCOUNTS_EXCEEDED - # => [curr_account_ptr, foreign_account_id, is_equal_id] +#! Returns the length of the memory interval that the account data occupies. +#! +#! Stack: [] +#! Output: [acct_data_length] +export.get_account_data_length + push.ACCOUNT_DATA_LENGTH +end - # the resulting `was_loaded` flag is essentially equal to the `is_equal_id` flag - movup.2 - # => [was_loaded, curr_account_ptr, foreign_account_id] +#! Returns the largest memory address which can be used to load the foreign account data. +#! +#! Stack: [] +#! Output: [max_foreign_acct_ptr] +export.get_max_foreign_account_ptr + push.MAX_FOREIGN_ACCOUNT_PTR end #! Sets the memory pointer of the current account data to the native account (2048). @@ -1452,144 +1390,3 @@ end export.get_kernel_procedures_ptr push.KERNEL_PROCEDURES_PTR end - -# ACCOUNT DATA LOADERS -# ================================================================================================= - -#! Saves storage slots data into memory and validates that the storage commitment matches the -#! sequential storage hash. -#! -#! Inputs: -#! Operand stack: [STORAGE_COMMITMENT] -#! Advice map: { -#! STORAGE_COMMITMENT: [num_storage_slots, [STORAGE_SLOT_DATA]], -#! } -#! Outputs: -#! Operand stack: [] -#! -#! Where: -#! - STORAGE_COMMITMENT is the commitment of the foreign account's storage. -#! - num_storage_slots is the number of foreign account's storage slots. -#! - STORAGE_SLOT_DATA is the data contained in the storage slot which is constructed as follows: -#! [SLOT_VALUE, slot_type, 0, 0, 0] -#! -#! Panics if: -#! - the number of account storage slots exceeded the maximum limit of 255. -#! - 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_mapval push.15160 drop # TODO: remove line, see miden-vm/#1122 - # OS => [STORAGE_COMMITMENT] - # AS => [num_storage_slots, [STORAGE_SLOT_DATA]] - - # push the number of storage slots onto the operand stack before storing it into memory - adv_push.1 - # OS => [num_storage_slots, STORAGE_COMMITMENT] - # AS => [[STORAGE_SLOT_DATA]] - - # assert that account does not exceed allowed maximum number of storage slots - dup exec.account::get_max_num_storage_slots lte assert.err=ERR_ACCT_TOO_MANY_STORAGE_SLOTS - # OS => [num_storage_slots, STORAGE_COMMITMENT] - # AS => [[STORAGE_SLOT_DATA]] - - # store number of storage slots in memory - dup exec.set_num_storage_slots - # OS => [num_storage_slots, STORAGE_COMMITMENT] - # AS => [[STORAGE_SLOT_DATA]] - - # setup acct_storage_slots_offset and end_ptr for reading from advice stack - mul.2 exec.get_acct_storage_slots_section_ptr dup movdn.2 add swap - # OS => [acct_storage_slots_offset, end_ptr, STORAGE_COMMITMENT] - # AS => [[STORAGE_SLOT_DATA]] - - # pad stack before reading from advice stack - padw padw padw - # OS => [PAD, PAD, PAD, acct_proc_offset, end_ptr, STORAGE_COMMITMENT] - # AS => [[STORAGE_SLOT_DATA]] - - # read the data from advice stack to memory and hash - exec.mem::pipe_double_words_to_memory - # OS => [PERM, PERM, PERM, end_ptr', STORAGE_COMMITMENT] - # AS => [] - - # extract the digest - exec.native::state_to_digest - # OS => [DIGEST, end_ptr', STORAGE_COMMITMENT] - - # drop end_ptr - movup.4 drop - # OS => [DIGEST, STORAGE_COMMITMENT] - - # verify hashed account storage slots match account storage commitment - assert_eqw.err=ERR_ACCT_STORAGE_COMMITMENT_MISMATCH - # OS => [] -end - -#! Saves account procedure data into memory and validates that the code commitment matches the -#! sequential procedure hash. -#! -#! Inputs: -#! Operand stack: [CODE_COMMITMENT] -#! Advice map: { -#! CODE_COMMITMENT: [num_procs, [ACCOUNT_PROCEDURE_DATA]], -#! } -#! Outputs: -#! Operand stack: [] -#! -#! Where: -#! - CODE_COMMITMENT is the commitment of the foreign account's code. -#! - num_procs is the number of foreign account's procedures. -#! - ACCOUNT_PROCEDURE_DATA is the information about account procedure which is constructed as -#! follows: [PROCEDURE_MAST_ROOT, storage_offset, 0, 0, 0] -#! -#! Panics if: -#! - the number of account procedures exceeded the maximum limit of 256 -#! - 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_mapval push.15161 drop # TODO: remove line, see miden-vm/#1122 - # OS => [CODE_COMMITMENT] - # AS => [num_procs, [ACCOUNT_PROCEDURE_DATA]] - - # push the number of procedures onto the operand stack before storing it in memory - adv_push.1 - # OS => [num_procs, CODE_COMMITMENT] - # AS => [[ACCOUNT_PROCEDURE_DATA]] - - # assert that account does not exceed allowed maximum number of procedures - dup exec.account::get_max_num_procedures lte assert.err=ERR_ACCT_TOO_MANY_PROCEDURES - # OS => [num_procs, CODE_COMMITMENT] - # AS => [[ACCOUNT_PROCEDURE_DATA]] - - # store number of procedures in memory - dup exec.set_num_account_procedures - # OS => [num_procs, CODE_COMMITMENT] - # AS => [[ACCOUNT_PROCEDURE_DATA]] - - # setup acct_proc_offset and end_ptr for reading from advice stack - mul.2 exec.get_acct_procedures_section_ptr dup movdn.2 add swap - # OS => [acct_proc_offset, end_ptr, CODE_COMMITMENT] - # AS => [[ACCOUNT_PROCEDURE_DATA]] - - # pad stack before reading from advice stack - padw padw padw - # OS => [PAD, PAD, PAD, acct_proc_offset, end_ptr, CODE_COMMITMENT] - # AS => [[ACCOUNT_PROCEDURE_DATA]] - - # read the data from advice stack to memory and hash - exec.mem::pipe_double_words_to_memory - # OS => [PERM, PERM, PERM, end_ptr', CODE_COMMITMENT] - # AS => [] - - # extract the digest - exec.native::state_to_digest - # OS => [DIGEST, end_ptr', CODE_COMMITMENT] - - # drop end_ptr - movup.4 drop - # OS => [DIGEST, CODE_COMMITMENT] - - # verify hashed account procedures match account code commitment - assert_eqw.err=ERR_ACCT_CODE_COMMITMENT_MISMATCH - # OS => [] -end \ No newline at end of file diff --git a/miden-lib/asm/kernels/transaction/lib/prologue.masm b/miden-lib/asm/kernels/transaction/lib/prologue.masm index e63204ee8..521c2721f 100644 --- a/miden-lib/asm/kernels/transaction/lib/prologue.masm +++ b/miden-lib/asm/kernels/transaction/lib/prologue.masm @@ -455,7 +455,7 @@ proc.process_account_data # validates and stores account storage slots in memory. exec.memory::get_acct_storage_commitment - exec.memory::save_account_storage_data + exec.account::save_account_storage_data # => [ACCT_HASH] # set the new account code commitment to the initial account code root @@ -465,7 +465,7 @@ proc.process_account_data # => [ACCOUNT_CODE_COMMITMENT, ACCT_HASH] # validates and stores account procedures in memory. - exec.memory::save_account_procedure_data + exec.account::save_account_procedure_data # => [ACCT_HASH] # copy the initial account vault hash to the input vault hash to support transaction asset diff --git a/miden-lib/src/transaction/inputs.rs b/miden-lib/src/transaction/inputs.rs index 91d749c7a..c70c0e791 100644 --- a/miden-lib/src/transaction/inputs.rs +++ b/miden-lib/src/transaction/inputs.rs @@ -168,7 +168,7 @@ fn add_account_to_advice_inputs( } // extend advice map with storage commitment |-> length, storage slots and types vector - let mut storage_slots: Vec = vec![(storage.slots().len() as u8).into()]; + let mut storage_slots = Vec::::new(); storage_slots.append(&mut storage.as_elements()); inputs.extend_map([(storage.commitment(), storage_slots)]); diff --git a/miden-lib/src/transaction/procedures/kernel_v0.rs b/miden-lib/src/transaction/procedures/kernel_v0.rs index 4eae36b9d..aeb0683fe 100644 --- a/miden-lib/src/transaction/procedures/kernel_v0.rs +++ b/miden-lib/src/transaction/procedures/kernel_v0.rs @@ -68,7 +68,7 @@ pub const KERNEL0_PROCEDURES: [Digest; 34] = [ // get_block_number digest!(0xd483c8edceb956d, 0xf9f8d62043fcf072, 0xb917fc68b6e01ad1, 0x3ef8d736e7331692), // start_foreign_context - digest!(0xab1819477203527a, 0x5a91109f6791d2d9, 0x60ac7e49d3f3e35c, 0x70deab90343c8a12), + digest!(0xf2eab0ab8d99cc68, 0x6476574ac16fc557, 0x8e83b55df2cc1f24, 0xce7d5430d40197fa), // end_foreign_context digest!(0x3770db711ce9aaf1, 0xb6f3c929151a5d52, 0x3ed145ec5dbee85f, 0xf979d975d7951bf6), // update_expiration_block_num diff --git a/miden-tx/src/errors/tx_kernel_errors.rs b/miden-tx/src/errors/tx_kernel_errors.rs index 373592cb7..7956e0ae6 100644 --- a/miden-tx/src/errors/tx_kernel_errors.rs +++ b/miden-tx/src/errors/tx_kernel_errors.rs @@ -89,8 +89,10 @@ pub const ERR_CURRENT_ACCOUNT_IS_NOT_NATIVE: u32 = 131156; pub const ERR_INVALID_TX_EXPIRATION_DELTA: u32 = 131157; pub const ERR_FOREIGN_ACCOUNT_ID_IS_ZERO: u32 = 131158; pub const ERR_MAX_NUM_FOREIGN_ACCOUNTS_EXCEEDED: u32 = 131159; +pub const ERR_ACCT_TOO_MANY_STORAGE_SLOTS: u32 = 131160; +pub const ERR_FOREIGN_ACCT_ID_EQUALS_NATIVE_ACCT_ID: u32 = 131161; -pub const KERNEL_ERRORS: [(u32, &str); 88] = [ +pub const KERNEL_ERRORS: [(u32, &str); 90] = [ (ERR_FAUCET_RESERVED_DATA_SLOT, "For faucets, storage slot 254 is reserved and can not be used with set_account_item procedure"), (ERR_ACCT_MUST_BE_A_FAUCET, "Procedure can only be called from faucet accounts"), (ERR_P2ID_WRONG_NUMBER_OF_INPUTS, "P2ID scripts expect exactly 1 note input"), @@ -179,4 +181,6 @@ pub const KERNEL_ERRORS: [(u32, &str); 88] = [ (ERR_INVALID_TX_EXPIRATION_DELTA, "Invalid transaction expiration block delta was set."), (ERR_FOREIGN_ACCOUNT_ID_IS_ZERO, "Provided ID of the foreign account equals zero"), (ERR_MAX_NUM_FOREIGN_ACCOUNTS_EXCEEDED, "Maximum number of the foreign accounts (64) was exceeded"), + (ERR_ACCT_TOO_MANY_STORAGE_SLOTS, "Number of account storage slots exceeded the maximum limit of 255"), + (ERR_FOREIGN_ACCT_ID_EQUALS_NATIVE_ACCT_ID, "Provided foreign account ID is equal to the native account ID") ]; diff --git a/miden-tx/src/tests/kernel_tests/test_tx.rs b/miden-tx/src/tests/kernel_tests/test_tx.rs index 0e8ce1f73..7cb4ff2cc 100644 --- a/miden-tx/src/tests/kernel_tests/test_tx.rs +++ b/miden-tx/src/tests/kernel_tests/test_tx.rs @@ -678,7 +678,7 @@ fn test_load_foreign_account_basic() { # push the index of desired storage item push.2 - # get the hash of the `get_item_foreign` account procedure + # get the hash of the `get_map_item_foreign` account procedure procref.account::get_map_item_foreign # push the foreign account id @@ -803,15 +803,8 @@ fn get_mock_advice_inputs(foreign_account: &Account) -> AdviceInputs { ] .concat(), ), - // STORAGE_ROOT |-> [num_storage_slots, [STORAGE_SLOT_DATA]] - ( - foreign_storage_root, - [ - vec![Felt::try_from(foreign_account.storage().slots().len()).unwrap()], - foreign_account.storage().as_elements(), - ] - .concat(), - ), + // STORAGE_ROOT |-> [[STORAGE_SLOT_DATA]] + (foreign_storage_root, foreign_account.storage().as_elements()), // CODE_ROOT |-> [num_procs, [ACCOUNT_PROCEDURE_DATA]] ( foreign_code_root,