Skip to content

Commit

Permalink
fix: decorator collision
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbinth committed Aug 14, 2024
1 parent 2987e69 commit 89e1f77
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 29 deletions.
4 changes: 3 additions & 1 deletion miden-lib/asm/kernels/transaction/lib/account.masm
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,9 @@ 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.memory::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 push.15263 drop # FIX: wrap the decorator to ensure MAST uniqueness
adv_loadw
# => [SEED, 0, 0, 0, 0]

# populate last four elements of the hasher rate with the code commitment
Expand Down
8 changes: 6 additions & 2 deletions miden-lib/asm/kernels/transaction/lib/asset_vault.masm
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,9 @@ export.add_fungible_asset
# get the asset vault root and read the vault asset value using the `push_smtpeek` decorator.
# To account for the edge case in which CUR_VAULT_VALUE is an EMPTY_WORD, we replace the most
# significant element with the faucet_id to construct the CUR_ASSET.
padw dup.10 mem_loadw swapw adv.push_smtpeek adv_loadw swapw dupw.1 drop movup.11
padw dup.10 mem_loadw swapw
adv.push_smtpeek push.15329 drop # FIX: wrap the decorator to ensure MAST uniqueness
adv_loadw swapw dupw.1 drop movup.11
# => [CUR_ASSET, VAULT_ROOT, CUR_VAULT_VALUE, amount, vault_root_ptr]

# arrange elements
Expand Down Expand Up @@ -238,7 +240,9 @@ export.remove_fungible_asset
# get the asset vault root and read the vault asset value using the `push_smtpeek` decorator
# To account for the edge case in which CUR_VAULT_VALUE is an EMPTY_WORD, we replace the most
# significant element with the faucet_id to construct the CUR_ASSET.
padw dup.14 mem_loadw swapw adv.push_smtpeek adv_loadw dupw movdnw.2 drop movup.11
padw dup.14 mem_loadw swapw
adv.push_smtpeek push.15413 drop # FIX: wrap the decorator to ensure MAST uniqueness
adv_loadw dupw movdnw.2 drop movup.11
# => [CUR_ASSET, VAULT_ROOT, CUR_VAULT_VALUE, amount, ASSET, vault_root_ptr]

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

# insert created data into the advice map
adv.insert_mem
adv.insert_mem push.15511 drop # FIX: wrap the decorator to ensure MAST uniqueness
# => [OUTPUT_NOTES_COMMITMENT, output_note_ptr, output_notes_end_ptr, ...]

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

# insert final account data into the advice map
adv.insert_mem
adv.insert_mem push.15619 drop # FIX: wrap the decorator to ensure MAST uniqueness
# => [FINAL_ACCOUNT_HASH, acct_data_ptr, acct_data_end_ptr, INIT_ACCT_HASH]

# drop account data section pointers
Expand Down
15 changes: 9 additions & 6 deletions miden-lib/asm/kernels/transaction/lib/prologue.masm
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,7 @@ proc.ingest_acct_storage_types
exec.account::get_slot_types_commitment_storage_slot exec.account::get_item
# => [TYPES_COM]

push.0 drop # TODO: remove line, see miden-vm/#1122
adv.push_mapval
adv.push_mapval push.15683 drop # FIX: wrap the decorator to ensure MAST uniqueness
# => [TYPES_COM]

# get the storage slot types data pointer
Expand Down Expand Up @@ -404,9 +403,11 @@ end
#! Stack: [CODE_COMMITMENT]
#! Output: []
proc.validate_account_procedures
# move procedure data from the advice map to the advice stack and then push the number of
# procedures onto the operand stack before storing it in memory
adv.push_mapval adv_push.1
# move procedure data from the advice map to the advice stack
adv.push_mapval push.15161 drop # FIX: wrap the decorator to ensure MAST uniqueness

# push the number of procedures onto the operand stack before storing it in memory
adv_push.1
# => [num_procs, CODE_COMMITMENT]

# assert that account does not exceed allowed maximum number of procedures
Expand Down Expand Up @@ -985,7 +986,9 @@ proc.process_input_notes_data
# if there are input notes, load input notes data from the advice map onto the advice stack
dup neq.0
if.true
exec.memory::get_input_notes_commitment adv.push_mapval dropw
exec.memory::get_input_notes_commitment
adv.push_mapval push.15787 drop # FIX: wrap the decorator to ensure MAST uniqueness
dropw
end
# => [num_notes]

Expand Down
4 changes: 2 additions & 2 deletions miden-lib/asm/miden/note.masm
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export.get_assets
# => [ASSETS_HASH, num_assets, dest_ptr]

# load the asset data from the advice map to the advice stack
adv.push_mapval
adv.push_mapval push.15887 drop # FIX: wrap the decorator to ensure MAST uniqueness
# => [ASSETS_HASH, num_assets, dest_ptr]

# calculate number of assets rounded up to an even number
Expand Down Expand Up @@ -87,7 +87,7 @@ export.get_inputs
# => [INPUTS_HASH, dest_ptr]

# load the inputs from the advice map to the advice stack
adv.push_mapval
adv.push_mapval push.15973 drop # FIX: wrap the decorator to ensure MAST uniqueness
# => [INPUTS_HASH, dest_ptr]

adv_push.1
Expand Down
2 changes: 1 addition & 1 deletion miden-lib/src/accounts/wallets/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ mod tests {
AccountType::RegularAccountImmutableCode,
AccountStorageType::OnChain,
);

wallet.unwrap_or_else(|err| {
panic!("{}", err);
});
Expand Down
9 changes: 4 additions & 5 deletions miden-lib/src/transaction/inputs.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use alloc::vec::Vec;

use miden_objects::{
accounts::{Account, AccountProcedureInfo},
accounts::Account,
transaction::{
ChainMmr, ExecutedTransaction, InputNote, PreparedTransaction, TransactionArgs,
TransactionInputs, TransactionScript, TransactionWitness,
Expand Down Expand Up @@ -245,10 +245,9 @@ fn add_account_to_advice_inputs(
let code = account.code();

// extend the advice_map with the account code data and number of procedures
let num_procs = code.as_elements().len() / AccountProcedureInfo::NUM_ELEMENTS_PER_PROC;
let mut procs = code.as_elements();
procs.insert(0, Felt::from(num_procs as u32));
inputs.extend_map([(code.commitment(), procs)]);
let mut proc_elements: Vec<Felt> = vec![(code.num_procedures() as u32).into()];
proc_elements.append(&mut code.as_elements());
inputs.extend_map([(code.commitment(), proc_elements)]);

// --- account seed -------------------------------------------------------
if let Some(account_seed) = account_seed {
Expand Down
3 changes: 2 additions & 1 deletion miden-tx/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -936,7 +936,8 @@ fn test_tx_script() {
push.{key}
# load the tx script input value from the map and read it onto the stack
adv.push_mapval adv_loadw
adv.push_mapval push.16073 drop # FIX: wrap the decorator to ensure MAST uniqueness
adv_loadw
# assert that the value is correct
push.{value} assert_eqw
Expand Down
13 changes: 4 additions & 9 deletions objects/src/testing/account_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,14 @@ pub const CODE: &str = "
// ================================================================================================

pub const DEFAULT_ACCOUNT_CODE: &str = "
use.miden::contracts::wallets::basic->basic_wallet
use.miden::contracts::auth::basic->basic_eoa
export.basic_wallet::receive_asset
export.basic_wallet::send_asset
export.basic_eoa::auth_tx_rpo_falcon512
export.::miden::contracts::wallets::basic::receive_asset
export.::miden::contracts::wallets::basic::send_asset
export.::miden::contracts::auth::basic::auth_tx_rpo_falcon512
";

pub const DEFAULT_AUTH_SCRIPT: &str = "
use.miden::contracts::auth::basic->auth_tx
begin
call.auth_tx::auth_tx_rpo_falcon512
call.::miden::contracts::auth::basic::auth_tx_rpo_falcon512
end
";

Expand Down

0 comments on commit 89e1f77

Please sign in to comment.