Skip to content

Commit

Permalink
refactor: update ABI for miden lib, small format fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Fumuran committed Nov 14, 2024
1 parent 0607a4d commit 10c46e1
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 61 deletions.
10 changes: 5 additions & 5 deletions miden-lib/asm/kernels/transaction/lib/account.masm
Original file line number Diff line number Diff line change
Expand Up @@ -552,8 +552,8 @@ end
#! Note:
#! - We assume that index has been validated and is within bounds.
#!
#! Inputs: [index, KEY, NEW_VALUE, OLD_ROOT, ...]
#! Outputs: [OLD_VALUE, NEW_ROOT, ...]
#! Inputs: [index, KEY, NEW_VALUE, OLD_ROOT]
#! Outputs: [OLD_VALUE, NEW_ROOT]
#!
#! Where:
#! - OLD_ROOT is the root of the map to set the KEY NEW_VALUE pair.
Expand Down Expand Up @@ -614,8 +614,8 @@ end

#! Returns the type of the requested storage slot.
#!
#! Inputs: [index, ...]
#! Outputs: [slot_type, ...]
#! Inputs: [index]
#! Outputs: [slot_type]
#!
#! Where:
#! - index is the location in memory of the storage slot.
Expand All @@ -639,7 +639,7 @@ end

#! Returns the procedure information.
#!
#! Inputs: [index, ...]
#! Inputs: [index]
#! Outputs: [PROC_ROOT, storage_offset, storage_size]
#!
#! Where:
Expand Down
14 changes: 7 additions & 7 deletions miden-lib/asm/kernels/transaction/lib/epilogue.masm
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ const.ERR_EPILOGUE_TOTAL_NUMBER_OF_ASSETS_MUST_STAY_THE_SAME=0x00020029
#! Copies output note data to the advice map. If no notes were created by a transaction, nothing
#! is copied to the advice map.
#!
#! Inputs: [OUTPUT_NOTES_COMMITMENT, ...]
#! Outputs: [OUTPUT_NOTES_COMMITMENT, ...]
#! Inputs: [OUTPUT_NOTES_COMMITMENT]
#! Outputs: [OUTPUT_NOTES_COMMITMENT]
#!
#! Where:
#! - OUTPUT_NOTES_COMMITMENT is the note commitment computed from note's id and metadata.
proc.copy_output_notes_to_advice_map
# get the number of notes created by the transaction
exec.memory::get_num_output_notes
# => [num_notes, OUTPUT_NOTES_COMMITMENT, ...]
# => [num_notes, OUTPUT_NOTES_COMMITMENT]

# if there are output notes, add them to the advice map
dup eq.0
Expand All @@ -40,20 +40,20 @@ proc.copy_output_notes_to_advice_map
else
# compute the end boundary of the output notes section
exec.memory::get_output_note_ptr movdn.4
# => [OUTPUT_NOTES_COMMITMENT, output_notes_end_ptr, ...]
# => [OUTPUT_NOTES_COMMITMENT, output_notes_end_ptr]

# compute the start boundary of the output notes section
exec.memory::get_output_note_data_offset movdn.4
# => [OUTPUT_NOTES_COMMITMENT, output_note_ptr, output_notes_end_ptr, ...]
# => [OUTPUT_NOTES_COMMITMENT, output_note_ptr, output_notes_end_ptr]

# insert created data into the advice map
adv.insert_mem push.15511 drop # TODO: remove line, see miden-vm/#1122
# => [OUTPUT_NOTES_COMMITMENT, output_note_ptr, output_notes_end_ptr, ...]
# => [OUTPUT_NOTES_COMMITMENT, output_note_ptr, output_notes_end_ptr]

# drop output note pointers
movup.4 drop movup.4 drop
end
# => [OUTPUT_NOTES_COMMITMENT, ...]
# => [OUTPUT_NOTES_COMMITMENT]
end

# BUILD OUTPUT VAULT
Expand Down
8 changes: 4 additions & 4 deletions miden-lib/asm/kernels/transaction/lib/prologue.masm
Original file line number Diff line number Diff line change
Expand Up @@ -845,9 +845,9 @@ end
#! ASSET_0, ..., ASSET_N,
#! is_authenticated,
#! (
#! block_num,
#! BLOCK_SUB_HASH,
#! NOTE_ROOT,
#! block_num,
#! BLOCK_SUB_HASH,
#! NOTE_ROOT,
#! )?
#! ]
#! Outputs:
Expand Down Expand Up @@ -1042,7 +1042,7 @@ proc.process_input_notes_data
# => [idx+1, num_notes]

drop drop
# => [...]
# => []
end

# TRANSACTION SCRIPT
Expand Down
8 changes: 4 additions & 4 deletions miden-lib/asm/kernels/transaction/lib/tx.masm
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,8 @@ end
#! limit at which the transaction will be considered valid (not expired).
#! This value can be later decreased, but not increased.
#!
#! Inputs: [block_height_delta, ...]
#! Outputs: [...]
#! Inputs: [block_height_delta]
#! Outputs: []
#!
#! Where:
#! - block_height_delta is the desired expiration time delta (1 to 0xFFFF).
Expand Down Expand Up @@ -240,8 +240,8 @@ end

#! Gets the transaction expiration delta.
#!
#! Inputs: [...]
#! Outputs: [block_height_delta, ...]
#! Inputs: []
#! Outputs: [block_height_delta]
#!
#! Where:
#! - block_height_delta is the stored expiration time delta (1 to 0xFFFF).
Expand Down
30 changes: 15 additions & 15 deletions miden-lib/asm/miden/tx.masm
Original file line number Diff line number Diff line change
Expand Up @@ -105,18 +105,18 @@ end

#! Creates a new note and returns the index of the note.
#!
#! Inputs: [tag, aux, note_type, execution_hint, RECIPIENT, ...]
#! Outputs: [note_idx, ...]
#! Inputs: [tag, aux, note_type, execution_hint, RECIPIENT]
#! Outputs: [note_idx]
#!
#! Where:
#! - tag is the tag to be included in the note.
#! - aux is the auxiliary metadata to be included in the note.
#! - note_type is the storage type of the note
#! - execution_hint is the note's execution hint
#! - note_type is the storage type of the note.
#! - execution_hint is the note's execution hint.
#! - RECIPIENT is the recipient of the note.
#! - note_idx is the index of the crated note.
#!
#! Annotation hint: is used with both `exec` and `call`
#! Annotation hint: is used only with `exec`
export.create_note
# pad the stack before the syscall to prevent accidental modification of the deeper stack
# elements
Expand All @@ -136,14 +136,14 @@ end

#! Adds the ASSET to the note specified by the index.
#!
#! Inputs: [ASSET, note_idx, ...]
#! Outputs: [ASSET, note_idx, ...]
#! Inputs: [ASSET, note_idx]
#! Outputs: [ASSET, note_idx]
#!
#! Where:
#! - note_idx is the index of the note to which the asset is added.
#! - ASSET can be a fungible or non-fungible asset.
#!
#! Annotation hint: is used with both `exec` and `call`
#! Annotation hint: is used only with `exec`
export.add_asset_to_note
movup.4 exec.kernel_proc_offsets::add_asset_to_note_offset
# => [offset, note_idx, ASSET]
Expand All @@ -163,25 +163,25 @@ end

#! Returns the RECIPIENT for a specified SERIAL_NUM, SCRIPT_HASH, and inputs hash
#!
#! Inputs: [SERIAL_NUM, SCRIPT_HASH, INPUT_HASH, pad(4)]
#! Outputs: [RECIPIENT, pad(12)]
#! Inputs: [SERIAL_NUM, SCRIPT_HASH, INPUT_HASH]
#! Outputs: [RECIPIENT]
#!
#! Where:
#! - SERIAL_NUM is the serial number of the recipient.
#! - SCRIPT_HASH is the commitment of the note script.
#! - INPUT_HASH is the commitment of the note inputs.
#! - RECIPIENT is the recipient of the note.
#!
#! Annotation hint: is used only with `call`
#! Annotation hint: is used only with `exec`
export.build_recipient_hash
padw hmerge
# => [SERIAL_NUM_HASH, SCRIPT_HASH, INPUT_HASH, pad(4)]
# => [SERIAL_NUM_HASH, SCRIPT_HASH, INPUT_HASH]

swapw hmerge
# => [MERGE_SCRIPT, INPUT_HASH, pad(8)]
# => [MERGE_SCRIPT, INPUT_HASH]

swapw hmerge
# [RECIPIENT, pad(12)]
# [RECIPIENT]
end

#! Executes the provided procedure against the foreign account.
Expand All @@ -195,7 +195,7 @@ end
#!
#! 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 - mem_addr_size - foreign_inputs_len)
#! moment of the foreign procedure execution (n = 16 - mem_addr_size - foreign_inputs_len).
#!
#! Annotation hint: is used only with `exec`
export.execute_foreign_procedure.1
Expand Down
7 changes: 5 additions & 2 deletions miden-tx/src/tests/kernel_tests/test_asset_vault.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,10 +262,13 @@ fn test_remove_fungible_asset_success_no_balance_remaining() {

let code = format!(
"
use.kernel::prologue
use.test::account
begin
exec.::kernel::prologue::prepare_transaction
exec.prologue::prepare_transaction
push.{FUNGIBLE_ASSET}
call.::miden::account::remove_asset
call.account::remove_asset
# truncate the stack
swapw dropw
Expand Down
Loading

0 comments on commit 10c46e1

Please sign in to comment.