Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### Changes

- [BREAKING] Removed redundant outputs from kernel procedures: `note::write_assets_to_memory`, `active_note::get_assets`, `input_note::get_assets`, `output_note::get_assets`, `active_note::get_storage`, and `faucet::mint` no longer return values identical to their inputs ([#2523](https://github.com/0xMiden/protocol/issues/2523)).
- [BREAKING] Renamed `ProvenBatch::new` to `new_unchecked` ([#2687](https://github.com/0xMiden/miden-base/issues/2687)).
- Added shared `ProcedurePolicy` for AuthMultisig ([#2670](https://github.com/0xMiden/protocol/pull/2670)).
- [BREAKING] Changed `NoteType` encoding from 2 bits to 1 and makes `NoteType::Private` the default ([#2691](https://github.com/0xMiden/miden-base/issues/2691)).
Expand Down
12 changes: 6 additions & 6 deletions crates/miden-agglayer/asm/note_scripts/B2AGG.masm
Original file line number Diff line number Diff line change
Expand Up @@ -76,26 +76,26 @@ begin

# Store note storage -> mem[8..14]
push.B2AGG_NOTE_STORAGE_PTR exec.active_note::get_storage
# => [num_storage_items, storage_ptr, pad(16)]
# => [num_storage_items, pad(16)]

# Validate the number of storage items
push.B2AGG_NOTE_NUM_STORAGE_ITEMS assert_eq.err=ERR_B2AGG_UNEXPECTED_NUMBER_OF_STORAGE_ITEMS
# => [storage_ptr, pad(16)]
# => [pad(16)]

# load the 6 B2AGG felts from B2AGG_NOTE_STORAGE_PTR as two words
add.4 mem_loadw_le swapw mem_loadw_le.B2AGG_NOTE_STORAGE_PTR
push.B2AGG_NOTE_STORAGE_PTR add.4 mem_loadw_le swapw mem_loadw_le.B2AGG_NOTE_STORAGE_PTR
# => [dest_network, dest_address(5), pad(10)]

# Store note assets -> mem[0..8]
push.B2AGG_NOTE_ASSETS_PTR exec.active_note::get_assets
# => [num_assets, assets_ptr, dest_network, dest_address(5), pad(10)]
# => [num_assets, dest_network, dest_address(5), pad(10)]

# Must be exactly 1 asset
push.B2AGG_NOTE_NUM_ASSETS assert_eq.err=ERR_B2AGG_WRONG_NUMBER_OF_ASSETS
# => [assets_ptr, dest_network, dest_address(5), pad(10)]
# => [dest_network, dest_address(5), pad(10)]

# Load asset onto the stack from B2AGG_NOTE_ASSETS_PTR
exec.asset::load
push.B2AGG_NOTE_ASSETS_PTR exec.asset::load
# => [ASSET_KEY, ASSET_VALUE, dest_network, dest_address(5), pad(10)]

call.bridge_out::bridge_out
Expand Down
2 changes: 1 addition & 1 deletion crates/miden-agglayer/asm/note_scripts/CLAIM.masm
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ begin
# => [pad(16)]

# Load CLAIM note storage into memory, starting at address 0
push.CLAIM_NOTE_STORAGE_PTR exec.active_note::get_storage drop drop
push.CLAIM_NOTE_STORAGE_PTR exec.active_note::get_storage drop
# => [pad(16)]

exec.write_claim_data_into_advice_map_by_key
Expand Down
4 changes: 2 additions & 2 deletions crates/miden-agglayer/asm/note_scripts/CONFIG_AGG_BRIDGE.masm
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ begin

# Load note storage to memory
push.STORAGE_START_PTR exec.active_note::get_storage
# => [num_storage_items, dest_ptr, pad(16)]
# => [num_storage_items, pad(16)]

# Validate the number of storage items
push.CONFIG_AGG_BRIDGE_NUM_STORAGE_ITEMS assert_eq.err=ERR_CONFIG_AGG_BRIDGE_UNEXPECTED_STORAGE_ITEMS drop
push.CONFIG_AGG_BRIDGE_NUM_STORAGE_ITEMS assert_eq.err=ERR_CONFIG_AGG_BRIDGE_UNEXPECTED_STORAGE_ITEMS
# => [pad(16)]

# Load origin_token_addr(5) and faucet_id from memory
Expand Down
4 changes: 2 additions & 2 deletions crates/miden-agglayer/asm/note_scripts/UPDATE_GER.masm
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ begin

# Load note storage to memory
push.STORAGE_PTR_GER_LOWER exec.active_note::get_storage
# => [num_storage_items, dest_ptr, pad(16)]
# => [num_storage_items, pad(16)]

# Validate the number of storage items
push.UPDATE_GER_NOTE_NUM_STORAGE_ITEMS assert_eq.err=ERR_UPDATE_GER_UNEXPECTED_NUMBER_OF_STORAGE_ITEMS drop
push.UPDATE_GER_NOTE_NUM_STORAGE_ITEMS assert_eq.err=ERR_UPDATE_GER_UNEXPECTED_NUMBER_OF_STORAGE_ITEMS
# => [pad(16)]

# Load GER_LOWER and GER_UPPER from note storage
Expand Down
9 changes: 3 additions & 6 deletions crates/miden-protocol/asm/kernels/transaction/api.masm
Original file line number Diff line number Diff line change
Expand Up @@ -741,14 +741,11 @@ end
#! Mint an asset from the faucet the transaction is being executed against.
#!
#! Inputs: [ASSET_KEY, ASSET_VALUE, pad(8)]
#! Outputs: [NEW_ASSET_VALUE, pad(12)]
#! Outputs: [pad(16)]
#!
#! Where:
#! - ASSET_KEY is the vault key of the asset to mint.
#! - ASSET_VALUE is the value of the asset that was minted.
#! - NEW_ASSET_VALUE is:
#! - For fungible assets: the ASSET_VALUE merged with the existing vault asset value, if any.
#! - For non-fungible assets: identical to ASSET_VALUE.
#! - ASSET_VALUE is the value of the asset to mint.
#!
#! Panics if:
#! - the transaction is not being executed against a faucet.
Expand All @@ -773,7 +770,7 @@ pub proc faucet_mint_asset

# mint the asset
exec.faucet::mint
# => [NEW_ASSET_VALUE, pad(12)]
# => [pad(16)]
end

#! Burn an asset from the faucet the transaction is being executed against.
Expand Down
14 changes: 11 additions & 3 deletions crates/miden-protocol/asm/protocol/active_note.masm
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const ERR_NOTE_INVALID_NUMBER_OF_STORAGE_ITEMS="the specified number of note sto
#! Writes the assets of the active note into memory starting at the specified address.
#!
#! Inputs: [dest_ptr]
#! Outputs: [num_assets, dest_ptr]
#! Outputs: [num_assets]
#!
#! Where:
#! - dest_ptr is the memory address to write the assets.
Expand Down Expand Up @@ -54,9 +54,13 @@ pub proc get_assets
swapdw dropw dropw movup.7 movup.7 movup.7 drop drop drop
# => [ASSETS_COMMITMENT, num_assets, dest_ptr]

# save num_assets for the return value
dup.4 movdn.6
# => [ASSETS_COMMITMENT, num_assets, dest_ptr, num_assets]

# write the assets from the advice map into memory
exec.note::write_assets_to_memory
# => [num_assets, dest_ptr]
# => [num_assets]
end

#! Returns the recipient of the active note.
Expand Down Expand Up @@ -97,7 +101,7 @@ end
#! Stack: [dest_ptr]
#! Advice Map: { NOTE_STORAGE_COMMITMENT: [STORAGE] }
#! Outputs:
#! Stack: [num_storage_items, dest_ptr]
#! Stack: [num_storage_items]
#!
#! Where:
#! - dest_ptr is the memory address to write the note storage.
Expand Down Expand Up @@ -131,6 +135,10 @@ pub proc get_storage
# write the inputs to the memory using the provided destination pointer
exec.write_storage_to_memory
# => [num_storage_items, dest_ptr]

# drop dest_ptr as it is identical to the input
swap drop
# => [num_storage_items]
end

#! Returns the metadata of the active note.
Expand Down
9 changes: 3 additions & 6 deletions crates/miden-protocol/asm/protocol/faucet.masm
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,11 @@ end
#! Mint an asset from the faucet the transaction is being executed against.
#!
#! Inputs: [ASSET_KEY, ASSET_VALUE]
#! Outputs: [NEW_ASSET_VALUE]
#! Outputs: []
#!
#! Where:
#! - ASSET_KEY is the vault key of the asset to mint.
#! - ASSET_VALUE is the value of the asset that was minted.
#! - NEW_ASSET_VALUE is:
#! - For fungible assets: the ASSET_VALUE merged with the existing vault asset value, if any.
#! - For non-fungible assets: identical to ASSET_VALUE.
#!
#! Panics if:
#! - the transaction is not being executed against a faucet.
Expand All @@ -94,8 +91,8 @@ pub proc mint
# => [ASSET_VALUE, pad(12)]

# clean the stack
swapdw dropw dropw swapw dropw
# => [ASSET_VALUE]
dropw dropw dropw dropw
# => []
end

#! Burn an asset from the faucet the transaction is being executed against.
Expand Down
11 changes: 9 additions & 2 deletions crates/miden-protocol/asm/protocol/input_note.masm
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ end
#! information about the layout of each asset see the description of the `Asset` Rust type.
#!
#! Inputs: [dest_ptr, note_index]
#! Outputs: [num_assets, dest_ptr, note_index]
#! Outputs: [num_assets]
#!
#! Where:
#! - dest_ptr is the memory address to write the assets.
Expand All @@ -81,9 +81,16 @@ pub proc get_assets
dup.1 exec.get_assets_info
# => [ASSETS_COMMITMENT, num_assets, dest_ptr, note_index]

# save num_assets for the return value and drop note_index
dup.4 movdn.7
# => [ASSETS_COMMITMENT, num_assets, dest_ptr, note_index, num_assets]

movup.6 drop
# => [ASSETS_COMMITMENT, num_assets, dest_ptr, num_assets]

# write the assets stored in the advice map to the specified memory pointer
exec.note::write_assets_to_memory
# => [num_assets, dest_ptr, note_index]
# => [num_assets]
end

#! Returns the recipient of the input note with the specified index.
Expand Down
6 changes: 5 additions & 1 deletion crates/miden-protocol/asm/protocol/note.masm
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ end
#! ASSETS_COMMITMENT: [[ASSETS_DATA]]
#! }
#! Outputs:
#! Operand stack: [num_assets, dest_ptr]
#! Operand stack: []
pub proc write_assets_to_memory
# load the asset data from the advice map to the advice stack
adv.push_mapval
Expand All @@ -75,6 +75,10 @@ pub proc write_assets_to_memory
exec.mem::pipe_double_words_preimage_to_memory drop
# OS => [num_assets, dest_ptr]
# AS => []

# drop num_assets and dest_ptr as these are identical to the inputs
drop drop
# OS => []
end

#! Builds the recipient hash from note storage, script root, and serial number.
Expand Down
11 changes: 9 additions & 2 deletions crates/miden-protocol/asm/protocol/output_note.masm
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ end
#! information about the layout of each asset see the description of the `Asset` Rust type.
#!
#! Inputs: [dest_ptr, note_index]
#! Outputs: [num_assets, dest_ptr, note_index]
#! Outputs: [num_assets]
#!
#! Where:
#! - dest_ptr is the memory address to write the assets.
Expand All @@ -121,9 +121,16 @@ pub proc get_assets
dup.1 exec.get_assets_info
# => [ASSETS_COMMITMENT, num_assets, dest_ptr, note_index]

# save num_assets for the return value and drop note_index
dup.4 movdn.7
# => [ASSETS_COMMITMENT, num_assets, dest_ptr, note_index, num_assets]

movup.6 drop
# => [ASSETS_COMMITMENT, num_assets, dest_ptr, num_assets]

# write the assets stored in the advice map to the specified memory pointer
exec.note::write_assets_to_memory
# => [num_assets, dest_ptr, note_index]
# => [num_assets]
end

#! Adds the asset to the note specified by the index.
Expand Down
7 changes: 3 additions & 4 deletions crates/miden-standards/asm/standards/faucets/mod.masm
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ pub proc mint_and_send
# this ensures that the asset's faucet ID matches the native account's ID.
# this is ensured because create_fungible_asset creates the asset with the native account's ID
exec.faucet::mint
dropw
# => [ASSET_KEY, ASSET_VALUE, note_idx, note_idx]

# Add the asset to the note.
Expand Down Expand Up @@ -179,13 +178,13 @@ pub proc burn

# this will fail if not called from a note context.
push.ASSET_PTR exec.active_note::get_assets
# => [num_assets, dest_ptr, pad(16)]
# => [num_assets, pad(16)]

# Verify we have exactly one asset
assert.err=ERR_BASIC_FUNGIBLE_BURN_WRONG_NUMBER_OF_ASSETS
# => [dest_ptr, pad(16)]
# => [pad(16)]

exec.asset::load
push.ASSET_PTR exec.asset::load
# => [ASSET_KEY, ASSET_VALUE, pad(16)]

# Burn the asset from the transaction vault
Expand Down
15 changes: 6 additions & 9 deletions crates/miden-standards/asm/standards/notes/mint.masm
Original file line number Diff line number Diff line change
Expand Up @@ -65,20 +65,20 @@ pub proc main
# => [pad(16)]
# Load note storage into memory starting at address 0
push.0 exec.active_note::get_storage
# => [num_storage_items, storage_ptr, pad(16)]
# => [num_storage_items, pad(16)]

dup
# => [num_storage_items, num_storage_items, storage_ptr, pad(16)]
# => [num_storage_items, num_storage_items, pad(16)]

u32assert2.err=ERR_MINT_UNEXPECTED_NUMBER_OF_STORAGE_ITEMS
u32gte.MINT_NOTE_MIN_NUM_STORAGE_ITEMS_PUBLIC
# => [is_public_output_note, num_storage_items, storage_ptr, pad(16)]
# => [is_public_output_note, num_storage_items, pad(16)]

if.true
# public output note creation
# => [num_storage_items, storage_ptr, pad(16)]
# => [num_storage_items, pad(16)]

movdn.9 drop
movdn.8
# => [EMPTY_WORD, EMPTY_WORD, num_storage_items, pad(8)]

mem_loadw_le.8
Expand All @@ -104,10 +104,7 @@ pub proc main
else
# private output note creation

eq.MINT_NOTE_NUM_STORAGE_ITEMS_PRIVATE assert.err=ERR_MINT_UNEXPECTED_NUMBER_OF_STORAGE_ITEMS drop
# => [storage_ptr, pad(16)]

drop
eq.MINT_NOTE_NUM_STORAGE_ITEMS_PRIVATE assert.err=ERR_MINT_UNEXPECTED_NUMBER_OF_STORAGE_ITEMS
# => [pad(16)]

mem_loadw_le.8
Expand Down
5 changes: 2 additions & 3 deletions crates/miden-standards/asm/standards/notes/p2id.masm
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,13 @@ const TARGET_ACCOUNT_ID_PREFIX_PTR = STORAGE_PTR + 1
pub proc main
# store the note storage to memory starting at address 0
push.STORAGE_PTR exec.active_note::get_storage
# => [num_storage_items, storage_ptr]
# => [num_storage_items]

# make sure the number of storage items is 2
eq.2 assert.err=ERR_P2ID_UNEXPECTED_NUMBER_OF_STORAGE_ITEMS
# => [storage_ptr]
# => []

# read the target account ID from the note storage
drop
mem_load.TARGET_ACCOUNT_ID_PREFIX_PTR
mem_load.TARGET_ACCOUNT_ID_SUFFIX_PTR
# => [target_account_id_suffix, target_account_id_prefix]
Expand Down
6 changes: 3 additions & 3 deletions crates/miden-standards/asm/standards/notes/p2ide.masm
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,14 @@ end
pub proc main
# store the note storage to memory starting at address 0
push.0 exec.active_note::get_storage
# => [num_storage_items, storage_ptr]
# => [num_storage_items]

# make sure the number of storage items is 4
eq.4 assert.err=ERR_P2IDE_UNEXPECTED_NUMBER_OF_STORAGE_ITEMS
# => [storage_ptr]
# => []

# read the target account ID, reclaim block height, and timelock_block_height from the note storage
mem_loadw_le
push.0 mem_loadw_le
# => [target_account_id_suffix, target_account_id_prefix, reclaim_block_height, timelock_block_height]

movup.3
Expand Down
9 changes: 4 additions & 5 deletions crates/miden-standards/asm/standards/notes/swap.masm
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,10 @@ pub proc main

# store note storage into memory starting at address 0
push.0 exec.active_note::get_storage
# => [num_storage_items, storage_ptr]
# => [num_storage_items]

# check number of storage items
eq.SWAP_NOTE_NUM_STORAGE_ITEMS assert.err=ERR_SWAP_UNEXPECTED_NUMBER_OF_STORAGE_ITEMS
drop
# => []

padw mem_loadw_le.PAYBACK_RECIPIENT_PTR
Expand Down Expand Up @@ -107,14 +106,14 @@ pub proc main

# store the number of note assets to memory starting at address ASSET_PTR
push.ASSET_PTR exec.active_note::get_assets
# => [num_assets, asset_ptr, pad(8)]
# => [num_assets, pad(8)]

# make sure the number of assets is 1
assert.err=ERR_SWAP_WRONG_NUMBER_OF_ASSETS
# => [asset_ptr, pad(8)]
# => [pad(8)]

# load asset
exec.asset::load
push.ASSET_PTR exec.asset::load
# => [ASSET_KEY, ASSET_VALUE, pad(8)]

# add the asset to the account
Expand Down
4 changes: 2 additions & 2 deletions crates/miden-standards/asm/standards/wallets/basic.masm
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ pub proc add_assets_to_account
# we have allocated ASSET_SIZE * MAX_ASSETS_PER_NOTE number of locals so all assets should fit
# since the asset memory will be overwritten, we don't have to initialize the locals to zero
locaddr.0 exec.active_note::get_assets
# => [num_of_assets, ptr = 0]
# => [num_of_assets]

# compute the pointer at which we should stop iterating
mul.ASSET_SIZE dup.1 add
mul.ASSET_SIZE locaddr.0 dup movdn.2 add
# => [end_ptr, ptr]

# pad the stack and move the pointer to the top
Expand Down
Loading
Loading