Skip to content

Commit

Permalink
Update names used for input/output notes (#791)
Browse files Browse the repository at this point in the history
* refactor: update notes naming, rename offchain note type

* chore: minor wording and naming fixes

* chore: update changelog

---------

Co-authored-by: Bobbin Threadbare <bobbinth@protonmail.com>
  • Loading branch information
Fumuran and bobbinth authored Jul 10, 2024
1 parent da10ea7 commit 5482077
Show file tree
Hide file tree
Showing 40 changed files with 588 additions and 584 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
- Created `get_serial_number` procedure to get the serial num of the currently processed note (#760).
- [BREAKING] Added support for conversion from `Nullifier` to `InputNoteCommitment`, commitment header return reference (#774).
- Added `compute_inputs_hash` procedure for hash computation of the arbitrary number of note inputs (#750).
- Notion of "consumed" and "created" notes changed to "input" and "output" respectively (#791).
- [BREAKING] "OffChain" variant of `NoteType` was renamed to "Private", public accessors of the `Block` struct were renamed to match the updated fields (#791).

## 0.3.1 (2024-06-12)

Expand Down
2 changes: 1 addition & 1 deletion docs/architecture/transactions/execution.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ The data store defines the interface that transaction objects use to fetch the d

- `Account` data which includes the [AccountID](../accounts.md#account-id) and the [AccountCode](../accounts.md#code) that is executed during the transaction.
- A `BlockHeader` which contains metadata about the block, commitments to the current state of the chain, and the hash of the proof that attests to the integrity of the chain.
- A `ChainMmr` which authenticates consumed notes during transaction execution. Authentication is achieved by providing an inclusion-proof for the transaction's consumed notes against the `ChainMmr`-root associated with the latest block known at the time of transaction execution.
- A `ChainMmr` which authenticates input notes during transaction execution. Authentication is achieved by providing an inclusion proof for the transaction's input notes against the `ChainMmr`-root associated with the latest block known at the time of transaction execution.
- `InputNotes` consumed by the transaction that include the corresponding note data, e.g. the [note script](../notes.md#the-note-script) and serial number.

!!! note
Expand Down
10 changes: 5 additions & 5 deletions docs/architecture/transactions/kernel.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ The kernel has a well-defined structure which does the following:
1. The [prologue](#prologue) prepares the transaction for processing by parsing the transaction data and setting up the root context.
2. Note processing executes the note processing loop which consumes each `InputNote` and invokes the note script of each note.
3. Transaction script processing executes the optional transaction script.
4. The [epilogue](#epilogue) finalizes the transaction by computing the created notes commitment, the final account hash, asserting asset invariant conditions, and asserting the nonce rules are upheld.
4. The [epilogue](#epilogue) finalizes the transaction by computing the output notes commitment, the final account hash, asserting asset invariant conditions, and asserting the nonce rules are upheld.

<center>
![Transaction program](../../img/architecture/transaction/transaction-program.png)
Expand Down Expand Up @@ -76,11 +76,11 @@ As the account data is read from the advice provider, the account hash is comput

Input note processing involves the kernel reading the data from each note and storing it at the appropriate memory addresses. All the data (note, account, and blockchain data) comes from the advice provider and global inputs.

Next to the total number of consumed notes, input note data consists of a serial number, the roots of the script, the inputs and asset vault, its metadata, and all its assets.
Next to the total number of input notes, input note data consists of a serial number, the roots of the script, the inputs and asset vault, its metadata, and all its assets.

As each note is consumed, its hash and nullifier are computed.

The transaction nullifier commitment is computed via a sequential hash of `(nullifier, ZERO)` pairs for all consumed notes. This step involves authentication such that the input note data provided via the advice provider is consistent with the chain history.
The transaction nullifier commitment is computed via a sequential hash of `(nullifier, ZERO)` pairs for all input notes. This step involves authentication such that the input note data provided via the advice provider is consistent with the chain history.

!!! info
- Note data is required for computing the nullifier, e.g. the [note script](../notes.md#main-script) and the serial number.
Expand Down Expand Up @@ -111,7 +111,7 @@ For every note, the [MAST root](https://0xpolygonmiden.github.io/miden-vm/design
# => []
# check if we have more notes to consume and should loop again
exec.note::increment_current_consumed_note_ptr
exec.note::increment_current_input_note_ptr
loc_load.0
neq
# => [should_loop]
Expand Down Expand Up @@ -147,7 +147,7 @@ The epilogue finalizes the transaction. It does the following:

1. Computes the final account hash.
2. If the account has changed, it asserts that the final account nonce is greater than the initial account nonce.
3. Computes the created notes commitment.
3. Computes the output notes commitment.
4. Asserts that the input and output vault roots are equal.

There is an exception for special accounts, called faucets, which can mint or burn assets. In these cases, input and output vault roots are not equal.
Expand Down
18 changes: 9 additions & 9 deletions miden-lib/asm/kernels/transaction/api.masm
Original file line number Diff line number Diff line change
Expand Up @@ -389,22 +389,22 @@ export.account_vault_remove_asset
# => [ASSET]
end

#! Returns the number of assets and vault hash of the note currently being processed. Panics if a
#! note is not being processed.
#! Returns the number of assets and the assets hash of the note currently being processed. Panics
#! if a note is not being processed.
#!
#! Inputs: [0, 0, 0, 0, 0]
#! Outputs: [VAULT_HASH, num_assets]
#! Outputs: [ASSETS_HASH, num_assets]
#!
#! - num_assets is the number of assets in the note currently being processed.
#! - VAULT_HASH is the vault hash of the note currently being processed.
export.get_note_vault_info
# get the vault info
exec.note::get_vault_info
# => [VAULT_HASH, num_assets, 0, 0, 0, 0, 0]
#! - ASSETS_HASH is the assets hash of the note currently being processed.
export.get_note_assets_info
# get the assets info
exec.note::get_assets_info
# => [ASSETS_HASH, num_assets, 0, 0, 0, 0, 0]

# organize the stack for return
movup.5 drop movup.5 drop movup.5 drop movup.5 drop movup.5 drop
# => [VAULT_HASH, num_assets]
# => [ASSETS_HASH, num_assets]
end

#! Returns the current note's inputs hash.
Expand Down
20 changes: 10 additions & 10 deletions miden-lib/asm/kernels/transaction/main.masm
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@ const.EPILOGUE_END=131081
#! advice provider.
#!
#! Stack: [BLOCK_HASH, account_id, INITIAL_ACCOUNT_HASH, INPUT_NOTES_COMMITMENT]
#! Output: [CREATED_NOTES_COMMITMENT, FINAL_ACCOUNT_HASH]
#! Output: [OUTPUT_NOTES_COMMITMENT, FINAL_ACCOUNT_HASH]
#!
#! Where:
#! - BLOCK_HASH, reference block for the transaction execution.
#! - account_id, the account that the transaction is being executed against.
#! - INITIAL_ACCOUNT_HASH, account state prior to the transaction, EMPTY_WORD for new accounts.
#! - INPUT_NOTES_COMMITMENT, see `transaction::api::get_input_notes_commitment`.
#! - CREATED_NOTES_COMMITMENT, commitment to the notes created by the transaction.
#! - OUTPUT_NOTES_COMMITMENT, commitment to the notes created by the transaction.
#! - FINAL_ACCOUNT_HASH, account's hash after execution the transaction.
proc.main.1
# Prologue
Expand All @@ -77,12 +77,12 @@ proc.main.1
push.0 drop # TODO: remove line, see miden-vm/#1122
trace.NOTES_PROCESSING_START

exec.memory::get_total_num_consumed_notes
# => [num_consumed_notes]
exec.memory::get_num_input_notes
# => [num_input_notes]

# compute the memory location after all input notes, i.e. the exit condition
dup exec.memory::get_consumed_note_ptr loc_store.0
# => [num_consumed_notes]
dup exec.memory::get_input_note_ptr loc_store.0
# => [num_input_notes]

eq.0 not
# => [should_loop]
Expand All @@ -103,8 +103,8 @@ proc.main.1
dropw dropw dropw dropw
# => []

exec.note::increment_current_consumed_note_ptr
# => [current_consumed_note_ptr]
exec.note::increment_current_input_note_ptr
# => [current_input_note_ptr]

# loop condition, exit when the memory ptr is after all input notes
loc_load.0 neq
Expand Down Expand Up @@ -158,11 +158,11 @@ proc.main.1

# execute the transaction epilogue
exec.epilogue::finalize_transaction
# => [CREATED_NOTES_COMMITMENT, FINAL_ACCOUNT_HASH]
# => [OUTPUT_NOTES_COMMITMENT, FINAL_ACCOUNT_HASH]

push.0 drop # TODO: remove line, see miden-vm/#1122
trace.EPILOGUE_END
# => [CREATED_NOTES_COMMITMENT, FINAL_ACCOUNT_HASH]
# => [OUTPUT_NOTES_COMMITMENT, FINAL_ACCOUNT_HASH]
end

begin
Expand Down
2 changes: 1 addition & 1 deletion miden-lib/asm/miden/contracts/auth/basic.masm
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const.PUBLIC_KEY_SLOT=0
#! Output: []
#!
export.auth_tx_rpo_falcon512
# Get commitments to created notes
# Get commitments to output notes
exec.tx::get_output_notes_hash
# => [OUTPUT_NOTES_HASH, ...]

Expand Down
4 changes: 2 additions & 2 deletions miden-lib/asm/miden/contracts/faucets/basic_fungible.masm
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use.miden::contracts::auth::basic

# CONSTANTS
# =================================================================================================
const.OFFCHAIN_NOTE=2
const.PRIVATE_NOTE=2

# ERRORS
# =================================================================================================
Expand All @@ -42,7 +42,7 @@ export.basic::auth_tx_rpo_falcon512
#! - note_type is the type of the note that holds the asset.
#! - RECIPIENT is the recipient of the asset, i.e.,
#! hash(hash(hash(serial_num, [0; 4]), script_hash), input_hash).
#! - note_idx is the index of the created note.
#! - note_idx is the index of the output note.
#! This cannot directly be accessed from another context.
#!
#! FAILS if:
Expand Down
2 changes: 1 addition & 1 deletion miden-lib/asm/miden/contracts/wallets/basic.masm
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ end
#! - note_type is the note's storage type
#! - RECIPIENT is the recipient of the note, i.e.,
#! hash(hash(hash(serial_num, [0; 4]), script_hash), input_hash)
#! - note_idx is the index of the created note.
#! - note_idx is the index of the output note.
#! This cannot directly be accessed from another context.
#!
#! Panics:
Expand Down
16 changes: 8 additions & 8 deletions miden-lib/asm/miden/kernels/tx/constants.masm
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,13 @@ export.get_max_assets_per_note
push.MAX_ASSETS_PER_NOTE
end

#! Returns the max allow number of consumed notes.
#! Returns the maximum number of notes that can be consumed in a single transaction.
#!
#! Stack: []
#! Output: [max_num_consumed_notes]
#! Output: [max_num_input_notes]
#!
#! - max_num_consumed_notes is the max number of consumed notes.
export.get_max_num_consumed_notes
#! - max_num_input_notes is the max number of input notes.
export.get_max_num_input_notes
push.MAX_INPUT_NOTES_PER_TX
end

Expand All @@ -101,13 +101,13 @@ export.get_note_tree_depth
push.NOTE_TREE_DEPTH
end

#! Returns the max number of notes that can be created in a single transaction.
#! Returns the maximum number of notes that can be created in a single transaction.
#!
#! Stack: []
#! Output: [max_num_created_notes]
#! Output: [max_num_output_notes]
#!
#! - max_num_created_notes is the max number of notes that can be created in a single transaction.
export.get_max_num_created_notes
#! - max_num_output_notes is the max number of notes that can be created in a single transaction.
export.get_max_num_output_notes
push.MAX_OUTPUT_NOTES_PER_TX
end

Expand Down
Loading

0 comments on commit 5482077

Please sign in to comment.