Skip to content

Commit

Permalink
refactor: make memory setters consistent (#795)
Browse files Browse the repository at this point in the history
  • Loading branch information
Fumuran authored Jul 13, 2024
1 parent 9de838a commit 19df86c
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 46 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- [BREAKING] Renamed `NoteType::OffChain` into `NoteType::Private`.
- [BREAKING] Renamed public accessors of the `Block` struct to match the updated fields (#791).
- [BREAKING] Changed the `TransactionArgs` to use `AdviceInputs` (#793).
- Setters in `memory` module don't drop the setting `Word` anymore (#795).

## 0.4.0 (2024-07-03)

Expand Down
4 changes: 2 additions & 2 deletions miden-lib/asm/miden/kernels/tx/account.masm
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ export.set_code
# => [CODE_ROOT]

# set the code root
exec.memory::set_new_acct_code_root
exec.memory::set_new_acct_code_root dropw
# => []
end

Expand Down Expand Up @@ -370,7 +370,7 @@ proc.set_item_raw
# => [OLD_VALUE, NEW_ROOT]

# set the new storage root
swapw exec.memory::set_acct_storage_root
swapw exec.memory::set_acct_storage_root dropw
# => [OLD_VALUE]
end

Expand Down
4 changes: 2 additions & 2 deletions miden-lib/asm/miden/kernels/tx/epilogue.masm
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ end
#! Output: []
proc.build_output_vault
# copy final account vault root to output account vault root
exec.memory::get_acct_vault_root exec.memory::set_output_vault_root
exec.memory::get_acct_vault_root exec.memory::set_output_vault_root dropw
# => []

# get the number of output notes from memory
Expand Down Expand Up @@ -157,7 +157,7 @@ proc.update_account_code
# => [NEW_ACCT_CODE_ROOT]

# set the account code root to the new account code root (may not have changed)
exec.memory::set_acct_code_root
exec.memory::set_acct_code_root dropw
# => []
end

Expand Down
76 changes: 45 additions & 31 deletions miden-lib/asm/miden/kernels/tx/memory.masm
Original file line number Diff line number Diff line change
Expand Up @@ -227,12 +227,13 @@ end
#! Sets the input vault root.
#!
#! Stack: [INPUT_VAULT_ROOT]
#! Output: []
#! Output: [INPUT_VAULT_ROOT]
#!
#! Where:
#! - INPUT_VAULT_ROOT is the input vault root.
export.set_input_vault_root
push.INPUT_VAULT_ROOT_PTR mem_storew dropw
push.INPUT_VAULT_ROOT_PTR
mem_storew
end

#! Returns a pointer to the memory address at which the output vault root is stored.
Expand Down Expand Up @@ -260,12 +261,13 @@ end
#! Sets the output vault root.
#!
#! Stack: [OUTPUT_VAULT_ROOT]
#! Output: []
#! Output: [OUTPUT_VAULT_ROOT]
#!
#! Where:
#! - OUTPUT_VAULT_ROOT is the output vault root.
export.set_output_vault_root
push.OUTPUT_VAULT_ROOT_PTR mem_storew dropw
push.OUTPUT_VAULT_ROOT_PTR
mem_storew
end


Expand All @@ -275,12 +277,13 @@ end
#! Saves the hash of the reference block to memory.
#!
#! Stack: [BLOCK_HASH]
#! Output: []
#! Output: [BLOCK_HASH]
#!
#! Where:
#! - BLOCK_HASH, reference block for the transaction execution.
export.set_block_hash
push.BLK_HASH_PTR mem_storew dropw
push.BLK_HASH_PTR
mem_storew
end

#! Returns the block hash of the reference block.
Expand Down Expand Up @@ -318,12 +321,13 @@ end
#! Sets the initial account hash.
#!
#! Stack: [INIT_ACCT_HASH]
#! Output: []
#! Output: [INIT_ACCT_HASH]
#!
#! Where:
#! - INIT_ACCT_HASH is the initial account hash.
export.set_init_acct_hash
push.INIT_ACCT_HASH_PTR mem_storew dropw
push.INIT_ACCT_HASH_PTR
mem_storew
end

#! Returns the initial account hash.
Expand Down Expand Up @@ -353,12 +357,13 @@ end
#! Sets the input notes' commitment.
#!
#! Stack: [INPUT_NOTES_COMMITMENT]
#! Output: []
#! Output: [INPUT_NOTES_COMMITMENT]
#!
#! Where:
#! - INPUT_NOTES_COMMITMENT is the notes' commitment.
export.set_nullifier_commitment
push.INPUT_NOTES_COMMITMENT_PTR mem_storew dropw
push.INPUT_NOTES_COMMITMENT_PTR
mem_storew
end

#! Returns the initial account nonce.
Expand Down Expand Up @@ -397,12 +402,13 @@ end
#! Sets the transaction script root.
#!
#! Stack: [TX_SCRIPT_ROOT]
#! Output: []
#! Output: [TX_SCRIPT_ROOT]
#!
#! Where:
#! - TX_SCRIPT_ROOT is the transaction script root.
export.set_tx_script_root
push.TX_SCRIPT_ROOT_PTR mem_storew dropw
push.TX_SCRIPT_ROOT_PTR
mem_storew
end

# BLOCK DATA
Expand Down Expand Up @@ -533,12 +539,13 @@ end
#! Sets the note root of the last known block.
#!
#! Stack: [NOTE_ROOT]
#! Output: []
#! Output: [NOTE_ROOT]
#!
#! Where:
#! - NOTE_ROOT is the note root of the last known block.
export.set_note_root
push.NOTE_ROOT_PTR mem_storew dropw
push.NOTE_ROOT_PTR
mem_storew
end

# CHAIN DATA
Expand Down Expand Up @@ -640,12 +647,13 @@ end
#! Sets the code root of the account.
#!
#! Stack: [CODE_ROOT]
#! Output: []
#! Output: [CODE_ROOT]
#!
#! Where:
#! - CODE_ROOT is the code root to be set.
export.set_acct_code_root
push.ACCT_CODE_ROOT_PTR mem_storew dropw
push.ACCT_CODE_ROOT_PTR
mem_storew
end

#! Returns the code root of the account.
Expand All @@ -662,12 +670,13 @@ end
#! Stores the new account code root in memory.
#!
#! Stack: [CODE_ROOT]
#! Output: []
#! Output: [CODE_ROOT]
#!
#! Where:
#! - CODE_ROOT is the new account code root.
export.set_new_acct_code_root
push.ACCT_NEW_CODE_ROOT_PTR mem_storew dropw
push.ACCT_NEW_CODE_ROOT_PTR
mem_storew
end

#! Returns the new account code root.
Expand Down Expand Up @@ -695,12 +704,13 @@ end
#! Sets the account storage root.
#!
#! Stack: [STORAGE_ROOT]
#! Output: []
#! Output: [STORAGE_ROOT]
#!
#! Where:
#! - STORAGE_ROOT is the account storage root.
export.set_acct_storage_root
push.ACCT_STORAGE_ROOT_PTR mem_storew dropw
push.ACCT_STORAGE_ROOT_PTR
mem_storew
end

#! Returns a pointer to the memory address at which the account vault root is stored.
Expand Down Expand Up @@ -728,12 +738,13 @@ end
#! Sets the account vault root.
#!
#! Stack: [ACCT_VAULT_ROOT]
#! Output: []
#! Output: [ACCT_VAULT_ROOT]
#!
#! Where:
#! - ACCT_VAULT_ROOT is the account vault root to be set.
export.set_acct_vault_root
push.ACCT_VAULT_ROOT_PTR mem_storew dropw
push.ACCT_VAULT_ROOT_PTR
mem_storew
end

#! Returns a pointer to the memory address at which the account storage slot type data begins.
Expand Down Expand Up @@ -946,14 +957,14 @@ end
#! Sets the note args for a input note located at the specified memory address.
#!
#! Stack: [note_ptr, NOTE_ARGS]
#! Output: []
#! Output: [NOTE_ARGS]
#!
#! Where:
#! - note_ptr is the memory address at which the input note data begins.
#! - NOTE_ARGS are optional note args of the input note.
export.set_input_note_args
push.INPUT_NOTE_ARGS_OFFSET add
mem_storew dropw
mem_storew
end

#! Returns the number of assets in the input note located at the specified memory address.
Expand Down Expand Up @@ -1085,25 +1096,27 @@ end
#! Sets the output note's recipient
#!
#! Stack: [note_ptr, RECIPIENT]
#! Output: []
#! Output: [RECIPIENT]
#!
#! Where:
#! - recipient is the recipient of the note
#! - note_ptr is the memory address at which the output note data begins.
export.set_output_note_recipient
push.OUTPUT_NOTE_RECIPIENT_OFFSET add mem_storew dropw
push.OUTPUT_NOTE_RECIPIENT_OFFSET add
mem_storew
end

#! Sets the output note's metadata
#!
#! Stack: [note_ptr, METADATA]
#! Output: []
#! Output: [METADATA]
#!
#! Where:
#! - METADATA is the note metadata
#! - note_ptr is the memory address at which the output note data begins.
export.set_output_note_metadata
push.OUTPUT_NOTE_METADATA_OFFSET add mem_storew dropw
push.OUTPUT_NOTE_METADATA_OFFSET add
mem_storew
end

#! Returns the number of assets in the output note
Expand Down Expand Up @@ -1153,11 +1166,12 @@ end
#! Sets the output note assets hash.
#!
#! Stack: [output_note_data_ptr, ASSET_HASH]
#! Output: []
#! Output: [ASSET_HASH]
#!
#! Where:
#! - output_note_data_ptr is the memory address at which the output note data begins.
#! - ASSET_HASH, sequential hash of the padded assets of a output note.
#! - ASSET_HASH, sequential hash of the padded assets of an output note.
export.set_output_note_assets_hash
push.OUTPUT_NOTE_ASSETS_HASH_OFFSET add mem_storew
push.OUTPUT_NOTE_ASSETS_HASH_OFFSET add
mem_storew
end
18 changes: 9 additions & 9 deletions miden-lib/asm/miden/kernels/tx/prologue.masm
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@ const.ERR_PROLOGUE_INPUT_NOTES_COMMITMENT_MISMATCH=0x0002001F
#! - INITIAL_ACCOUNT_HASH, account state prior to the transaction, EMPTY_WORD for new accounts.
#! - INPUT_NOTES_COMMITMENT, see `transaction::api::get_input_notes_commitment`.
proc.process_global_inputs
exec.memory::set_block_hash
exec.memory::set_block_hash dropw
exec.memory::set_global_acct_id
exec.memory::set_init_acct_hash
exec.memory::set_nullifier_commitment
exec.memory::set_init_acct_hash dropw
exec.memory::set_nullifier_commitment dropw
end

# BLOCK DATA
Expand Down Expand Up @@ -136,7 +136,7 @@ proc.process_block_data

# store the note root in memory
padw adv_loadw
dupw exec.memory::set_note_root
dupw exec.memory::set_note_root dropw
# => [NOTE_ROOT, DIG, block_data_ptr']

# merge the note root with the block data digest
Expand Down Expand Up @@ -440,7 +440,7 @@ proc.process_account_data
# process conditional logic depending on whether the account is new or existing
if.true
# set the initial account hash
exec.memory::set_init_acct_hash
exec.memory::set_init_acct_hash dropw
# => []

# validate the new account
Expand Down Expand Up @@ -475,12 +475,12 @@ proc.process_account_data
# set the new account code root to the initial account code root this is used for managing
# code root updates
exec.memory::get_acct_code_root
exec.memory::set_new_acct_code_root
exec.memory::set_new_acct_code_root dropw
# => []

# copy the initial account vault hash to the input vault hash to support transaction asset
# invariant checking
exec.memory::get_acct_vault_root exec.memory::set_input_vault_root
exec.memory::get_acct_vault_root exec.memory::set_input_vault_root dropw
# => []
end

Expand Down Expand Up @@ -615,7 +615,7 @@ end
#! - NOTE_ARGS, user arguments passed to the note.
#! - NOTE_METADATA, note's metadata.
proc.process_note_args_and_metadata
padw adv_loadw dup.4 exec.memory::set_input_note_args
padw adv_loadw dup.4 exec.memory::set_input_note_args dropw
# => [note_ptr]

padw adv_loadw movup.4 exec.memory::set_input_note_metadata
Expand Down Expand Up @@ -1008,7 +1008,7 @@ proc.process_tx_script_root
# => [TX_SCRIPT_ROOT]

# store the transaction script root in memory
exec.memory::set_tx_script_root
exec.memory::set_tx_script_root dropw
# => []
end

Expand Down
4 changes: 2 additions & 2 deletions miden-lib/asm/miden/kernels/tx/tx.masm
Original file line number Diff line number Diff line change
Expand Up @@ -303,11 +303,11 @@ export.create_note
emit.NOTE_AFTER_CREATED_EVENT

# set the metadata for the output note
dup.4 exec.memory::set_output_note_metadata
dup.4 exec.memory::set_output_note_metadata dropw
# => [note_ptr, RECIPIENT, note_idx]

# set the RECIPIENT for the output note
exec.memory::set_output_note_recipient
exec.memory::set_output_note_recipient dropw
# => [note_idx]
end

Expand Down

0 comments on commit 19df86c

Please sign in to comment.