From a78a6d861c8bb0a86459bcf90e98e0fbd0567684 Mon Sep 17 00:00:00 2001 From: Bobbin Threadbare Date: Thu, 4 Jul 2024 00:51:40 -0700 Subject: [PATCH 01/47] chore: update crate versions to 0.5.0 --- CHANGELOG.md | 2 ++ Cargo.lock | 6 +++--- README.md | 2 +- bench-tx/Cargo.toml | 6 +++--- docs/index.md | 2 +- miden-lib/Cargo.toml | 6 +++--- miden-tx/Cargo.toml | 6 +++--- objects/Cargo.toml | 2 +- 8 files changed, 17 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4a9f8973d..459268684 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # Changelog +## 0.5.0 (TBD) + ## 0.4.0 (2024-07-03) ### Features diff --git a/Cargo.lock b/Cargo.lock index 8731013c5..fde50a771 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -473,7 +473,7 @@ dependencies = [ [[package]] name = "miden-lib" -version = "0.4.0" +version = "0.5.0" dependencies = [ "miden-assembly", "miden-objects", @@ -483,7 +483,7 @@ dependencies = [ [[package]] name = "miden-objects" -version = "0.4.0" +version = "0.5.0" dependencies = [ "criterion", "log", @@ -534,7 +534,7 @@ dependencies = [ [[package]] name = "miden-tx" -version = "0.4.0" +version = "0.5.0" dependencies = [ "miden-lib", "miden-objects", diff --git a/README.md b/README.md index f7f467a9f..e82839407 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ If you want to join the technical discussion or learn more about the project, pl ## Status and features -Polygon Miden is currently on release v0.4. This is an early version of the protocol and its components. We expect to keep making changes (including breaking changes) to all components. +Polygon Miden is currently on release v0.5. This is an early version of the protocol and its components. We expect to keep making changes (including breaking changes) to all components. ### Feature highlights diff --git a/bench-tx/Cargo.toml b/bench-tx/Cargo.toml index 8274a21f8..307fa2ac5 100644 --- a/bench-tx/Cargo.toml +++ b/bench-tx/Cargo.toml @@ -14,9 +14,9 @@ name = "bench-tx" path = "src/main.rs" [dependencies] -miden-lib = { path = "../miden-lib", version = "0.4" } -miden-objects = { path = "../objects", version = "0.4" } -miden-tx = { path = "../miden-tx", version = "0.4", features = ["testing"] } +miden-lib = { path = "../miden-lib", version = "0.5" } +miden-objects = { path = "../objects", version = "0.5" } +miden-tx = { path = "../miden-tx", version = "0.5", features = ["testing"] } rand = { workspace = true } serde = { package = "serde", version = "1.0", features = ["derive"]} serde_json = { package = "serde_json", version = "1.0", features = ["preserve_order"] } diff --git a/docs/index.md b/docs/index.md index 140f8217c..471acfc3b 100644 --- a/docs/index.md +++ b/docs/index.md @@ -20,7 +20,7 @@ If you want to join the technical discussion, please check out the following: ## Status and features -Polygon Miden is currently on release v0.4. This is an early version of the protocol and its components. +Polygon Miden is currently on release v0.5. This is an early version of the protocol and its components. !!! important We expect breaking changes on all components. diff --git a/miden-lib/Cargo.toml b/miden-lib/Cargo.toml index b12c92095..c3533194d 100644 --- a/miden-lib/Cargo.toml +++ b/miden-lib/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "miden-lib" -version = "0.4.0" +version = "0.5.0" description = "Standard library of the Miden rollup" readme = "README.md" categories = ["no-std"] @@ -22,11 +22,11 @@ std = ["assembly/std", "miden-objects/std", "miden-stdlib/std", "vm-processor/st testing = ["miden-objects/testing"] [dependencies] -miden-objects = { path = "../objects", version = "0.4", default-features = false } +miden-objects = { path = "../objects", version = "0.5", default-features = false } miden-stdlib = { workspace = true } [dev-dependencies] -miden-objects = { path = "../objects", version = "0.4", default-features = false, features = ["testing"] } +miden-objects = { path = "../objects", version = "0.5", default-features = false, features = ["testing"] } vm-processor = { workspace = true, features = ["internals"] } [build-dependencies] diff --git a/miden-tx/Cargo.toml b/miden-tx/Cargo.toml index c7d60d3e3..02e43c893 100644 --- a/miden-tx/Cargo.toml +++ b/miden-tx/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "miden-tx" -version = "0.4.0" +version = "0.5.0" description = "Miden rollup transaction compiler, executor, and prover" readme = "README.md" categories = ["no-std"] @@ -24,8 +24,8 @@ std = ["miden-lib/std", "miden-objects/std", "miden-prover/std", "miden-verifier testing = ["miden-objects/testing", "miden-lib/testing", "vm-processor/internals", "dep:rand_chacha"] [dependencies] -miden-lib = { path = "../miden-lib", version = "0.4", default-features = false } -miden-objects = { path = "../objects", version = "0.4", default-features = false } +miden-lib = { path = "../miden-lib", version = "0.5", default-features = false } +miden-objects = { path = "../objects", version = "0.5", default-features = false } miden-prover = { workspace = true } miden-verifier = { workspace = true } rand = { workspace = true } diff --git a/objects/Cargo.toml b/objects/Cargo.toml index 7e740003e..285456623 100644 --- a/objects/Cargo.toml +++ b/objects/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "miden-objects" -version = "0.4.0" +version = "0.5.0" description = "Core components of the Miden rollup" readme = "README.md" categories = ["no-std"] From da10ea76d98f9ea750ae451843ab77db89457cc4 Mon Sep 17 00:00:00 2001 From: polydez <155382956+polydez@users.noreply.github.com> Date: Wed, 10 Jul 2024 11:39:52 +0500 Subject: [PATCH 02/47] fix: remove useless inclusion proof from `NoteBuilder` (#792) --- objects/src/testing/notes.rs | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/objects/src/testing/notes.rs b/objects/src/testing/notes.rs index 6ae1f9d0a..d7c2e9ac3 100644 --- a/objects/src/testing/notes.rs +++ b/objects/src/testing/notes.rs @@ -11,8 +11,7 @@ use crate::{ assembly::ProgramAst, assets::Asset, notes::{ - Note, NoteAssets, NoteInclusionProof, NoteInputs, NoteMetadata, NoteRecipient, NoteScript, - NoteTag, NoteType, + Note, NoteAssets, NoteInputs, NoteMetadata, NoteRecipient, NoteScript, NoteTag, NoteType, }, Felt, NoteError, Word, ZERO, }; @@ -31,7 +30,6 @@ pub struct NoteBuilder { serial_num: Word, tag: NoteTag, code: String, - proof: Option, aux: Felt, } @@ -52,7 +50,6 @@ impl NoteBuilder { serial_num, tag: 0.into(), code: DEFAULT_NOTE_CODE.to_string(), - proof: None, aux: ZERO, } } @@ -84,11 +81,6 @@ impl NoteBuilder { self } - pub fn proof(mut self, proof: NoteInclusionProof) -> Self { - self.proof = Some(proof); - self - } - pub fn aux(mut self, aux: Felt) -> Self { self.aux = aux; self From 5482077b865340d0819ad19a18e32ddb7cc1eed1 Mon Sep 17 00:00:00 2001 From: Andrey Khmuro Date: Wed, 10 Jul 2024 17:37:54 +0300 Subject: [PATCH 03/47] Update names used for input/output notes (#791) * refactor: update notes naming, rename offchain note type * chore: minor wording and naming fixes * chore: update changelog --------- Co-authored-by: Bobbin Threadbare --- CHANGELOG.md | 2 + docs/architecture/transactions/execution.md | 2 +- docs/architecture/transactions/kernel.md | 10 +- miden-lib/asm/kernels/transaction/api.masm | 18 +- miden-lib/asm/kernels/transaction/main.masm | 20 +- miden-lib/asm/miden/contracts/auth/basic.masm | 2 +- .../contracts/faucets/basic_fungible.masm | 4 +- .../asm/miden/contracts/wallets/basic.masm | 2 +- miden-lib/asm/miden/kernels/tx/constants.masm | 16 +- miden-lib/asm/miden/kernels/tx/epilogue.masm | 92 ++--- miden-lib/asm/miden/kernels/tx/memory.masm | 366 +++++++++--------- miden-lib/asm/miden/kernels/tx/note.masm | 90 ++--- miden-lib/asm/miden/kernels/tx/prologue.masm | 56 +-- miden-lib/asm/miden/kernels/tx/tx.masm | 46 +-- miden-lib/asm/miden/note.masm | 14 +- miden-lib/asm/note_scripts/SWAP.masm | 4 +- miden-lib/src/tests/mod.rs | 2 +- miden-lib/src/transaction/memory.rs | 62 +-- miden-tx/src/compiler/tests.rs | 9 +- miden-tx/src/host/mod.rs | 4 +- miden-tx/src/host/note_builder.rs | 2 +- miden-tx/src/prover/mod.rs | 2 +- miden-tx/src/testing/utils.rs | 4 +- miden-tx/src/tests/kernel_tests/mod.rs | 33 +- .../src/tests/kernel_tests/test_epilogue.rs | 8 +- miden-tx/src/tests/kernel_tests/test_note.rs | 38 +- .../src/tests/kernel_tests/test_prologue.rs | 50 +-- miden-tx/src/tests/kernel_tests/test_tx.rs | 42 +- miden-tx/src/tests/mod.rs | 22 +- miden-tx/tests/integration/assets/test.masm | 8 +- miden-tx/tests/integration/scripts/faucet.rs | 12 +- miden-tx/tests/integration/scripts/swap.rs | 9 +- miden-tx/tests/integration/wallet/mod.rs | 2 +- objects/src/block/mod.rs | 45 +-- objects/src/constants.rs | 4 +- objects/src/notes/metadata.rs | 6 +- objects/src/notes/note_tag.rs | 26 +- objects/src/notes/note_type.rs | 8 +- objects/src/testing/block.rs | 28 +- objects/src/transaction/outputs.rs | 2 +- 40 files changed, 588 insertions(+), 584 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 459268684..76d5a82ae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/docs/architecture/transactions/execution.md b/docs/architecture/transactions/execution.md index 4db815c78..0b22c732e 100644 --- a/docs/architecture/transactions/execution.md +++ b/docs/architecture/transactions/execution.md @@ -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 diff --git a/docs/architecture/transactions/kernel.md b/docs/architecture/transactions/kernel.md index 8c8578bc7..cc6dcda35 100644 --- a/docs/architecture/transactions/kernel.md +++ b/docs/architecture/transactions/kernel.md @@ -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.
![Transaction program](../../img/architecture/transaction/transaction-program.png) @@ -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. @@ -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] @@ -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. diff --git a/miden-lib/asm/kernels/transaction/api.masm b/miden-lib/asm/kernels/transaction/api.masm index ab6a89e9c..ad69fab4e 100644 --- a/miden-lib/asm/kernels/transaction/api.masm +++ b/miden-lib/asm/kernels/transaction/api.masm @@ -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. diff --git a/miden-lib/asm/kernels/transaction/main.masm b/miden-lib/asm/kernels/transaction/main.masm index c9b9e2698..037130114 100644 --- a/miden-lib/asm/kernels/transaction/main.masm +++ b/miden-lib/asm/kernels/transaction/main.masm @@ -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 @@ -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] @@ -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 @@ -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 diff --git a/miden-lib/asm/miden/contracts/auth/basic.masm b/miden-lib/asm/miden/contracts/auth/basic.masm index 40d8356a3..337f238c0 100644 --- a/miden-lib/asm/miden/contracts/auth/basic.masm +++ b/miden-lib/asm/miden/contracts/auth/basic.masm @@ -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, ...] diff --git a/miden-lib/asm/miden/contracts/faucets/basic_fungible.masm b/miden-lib/asm/miden/contracts/faucets/basic_fungible.masm index e97f9a7ef..4f133aa47 100644 --- a/miden-lib/asm/miden/contracts/faucets/basic_fungible.masm +++ b/miden-lib/asm/miden/contracts/faucets/basic_fungible.masm @@ -15,7 +15,7 @@ use.miden::contracts::auth::basic # CONSTANTS # ================================================================================================= -const.OFFCHAIN_NOTE=2 +const.PRIVATE_NOTE=2 # ERRORS # ================================================================================================= @@ -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: diff --git a/miden-lib/asm/miden/contracts/wallets/basic.masm b/miden-lib/asm/miden/contracts/wallets/basic.masm index 033313e37..9c967f846 100644 --- a/miden-lib/asm/miden/contracts/wallets/basic.masm +++ b/miden-lib/asm/miden/contracts/wallets/basic.masm @@ -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: diff --git a/miden-lib/asm/miden/kernels/tx/constants.masm b/miden-lib/asm/miden/kernels/tx/constants.masm index 508517e5c..c830d5aef 100644 --- a/miden-lib/asm/miden/kernels/tx/constants.masm +++ b/miden-lib/asm/miden/kernels/tx/constants.masm @@ -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 @@ -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 diff --git a/miden-lib/asm/miden/kernels/tx/epilogue.masm b/miden-lib/asm/miden/kernels/tx/epilogue.masm index e291a1730..7be513768 100644 --- a/miden-lib/asm/miden/kernels/tx/epilogue.masm +++ b/miden-lib/asm/miden/kernels/tx/epilogue.masm @@ -23,28 +23,28 @@ const.ERR_EPILOGUE_ASSETS_DONT_ADD_UP=0x0002000A #! Output: [OUTPUT_NOTES_COMMITMENT, ...] proc.copy_output_notes_to_advice_map # get the number of notes created by the transaction - exec.memory::get_num_created_notes + exec.memory::get_num_output_notes # => [num_notes, OUTPUT_NOTES_COMMITMENT, ...] - # if there are created notes, add them to the advice map + # if there are output notes, add them to the advice map dup eq.0 if.true # drop num_notes drop else - # compute the end boundary of the created notes section - exec.memory::get_created_note_ptr movdn.4 - # => [OUTPUT_NOTES_COMMITMENT, created_notes_end_ptr, ...] + # compute the end boundary of the output notes section + exec.memory::get_output_note_ptr movdn.4 + # => [OUTPUT_NOTES_COMMITMENT, output_notes_end_ptr, ...] - # compute the start boundary of the created notes section - exec.memory::get_created_note_data_offset movdn.4 - # => [OUTPUT_NOTES_COMMITMENT, created_note_ptr, created_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, ...] # insert created data into the advice map adv.insert_mem - # => [OUTPUT_NOTES_COMMITMENT, created_note_ptr, created_notes_end_ptr, ...] + # => [OUTPUT_NOTES_COMMITMENT, output_note_ptr, output_notes_end_ptr, ...] - # drop created note pointers + # drop output note pointers movup.4 drop movup.4 drop end # => [OUTPUT_NOTES_COMMITMENT, ...] @@ -54,11 +54,11 @@ end # ================================================================================================= #! Builds the output vault which is combination of the assets in the account vault at the end of -#! the transaction and all the assets from the created notes. +#! the transaction and all the assets in the output notes. #! #! The output vault is built as follows: #! - we first copy the account vault root to the output vault root. -#! - we then loop over the created notes and insert the assets into the output vault. +#! - we then loop over the output notes and insert their assets into the output vault. #! #! Stack: [] #! Output: [] @@ -67,73 +67,73 @@ proc.build_output_vault exec.memory::get_acct_vault_root exec.memory::set_output_vault_root # => [] - # get the number of created notes from memory - exec.memory::get_num_created_notes - # => [num_created_notes] + # get the number of output notes from memory + exec.memory::get_num_output_notes + # => [num_output_notes] # calculate the address at which we should stop looping - exec.memory::get_created_note_ptr - # => [created_notes_end_ptr] + exec.memory::get_output_note_ptr + # => [output_notes_end_ptr] - # compute pointer for the first created note - push.0 exec.memory::get_created_note_ptr - # => [created_note_ptr, created_notes_end_ptr] + # compute pointer for the first output note + push.0 exec.memory::get_output_note_ptr + # => [output_note_ptr, output_notes_end_ptr] - # check if the number of created notes is greater then 0. Conditional for the while loop. + # check if the number of output notes is greater then 0. Conditional for the while loop. dup.1 dup.1 neq - # => [should_loop, created_note_ptr, created_notes_end_ptr] + # => [should_loop, output_note_ptr, output_notes_end_ptr] - # loop over created notes and add assets to output vault + # loop over output notes and add assets to output vault while.true - # get the number of assets for the created note from memory - dup exec.memory::get_created_note_num_assets - # => [num_assets, note_data_ptr, created_notes_end_ptr] + # get the number of assets for the output note from memory + dup exec.memory::get_output_note_num_assets + # => [num_assets, note_data_ptr, output_notes_end_ptr] - # prepare stack for reading created note assets - exec.memory::get_output_vault_root_ptr dup.2 exec.memory::get_created_note_asset_data_ptr dup - # => [assets_start_ptr, assets_start_ptr, output_vault_root_ptr, num_assets, note_data_ptr. - # created_notes_end_ptr] + # prepare stack for reading output note assets + exec.memory::get_output_vault_root_ptr dup.2 exec.memory::get_output_note_asset_data_ptr dup + # => [assets_start_ptr, assets_start_ptr, output_vault_root_ptr, num_assets, note_data_ptr, + # output_notes_end_ptr] - # compute the end pointer for created note asset looping + # compute the end pointer for output note asset looping dup.3 add swap # => [assets_start_ptr, assets_end_ptr, output_vault_root_ptr, num_assets, note_data_ptr, - # created_notes_end_ptr] + # output_notes_end_ptr] # assess if we should loop dup.1 dup.1 neq # => [should_loop, assets_start_ptr, assets_end_ptr, output_vault_root_ptr, num_assets, - # note_data_ptr, created_notes_end_ptr] + # note_data_ptr, output_notes_end_ptr] - # loop over created note assets and insert them into the output vault + # loop over output note assets and insert them into the output vault while.true # duplicate output_vault_root_ptr dup.2 # => [output_vault_root_ptr, assets_start_ptr, assets_end_ptr, output_vault_root_ptr, - # num_assets, note_data_ptr, created_notes_end_ptr] + # num_assets, note_data_ptr, output_notes_end_ptr] - # read the created note asset from memory + # read the output note asset from memory padw dup.5 mem_loadw # => [ASSET, output_vault_root_ptr, assets_start_ptr, assets_end_ptr, output_vault_root_ptr, - # num_assets, note_data_ptr, created_notes_end_ptr] + # num_assets, note_data_ptr, output_notes_end_ptr] - # insert created note asset into output vault + # insert output note asset into output vault exec.asset_vault::add_asset dropw # => [assets_start_ptr, assets_end_ptr, output_vault_root_ptr, num_assets, note_data_ptr, - # created_notes_end_ptr] + # output_notes_end_ptr] # increment assets_start_ptr and asses if we should loop again add.1 dup.1 dup.1 neq # => [should_loop, assets_start_ptr, assets_end_ptr, output_vault_root_ptr, num_assets, - # note_data_ptr, created_notes_end_ptr] + # note_data_ptr, output_notes_end_ptr] end # clean stack drop drop drop drop - # => [note_data_ptr, created_note_end_ptr] + # => [note_data_ptr, output_note_end_ptr] - # increment created note pointer and check if we should loop again + # increment output note pointer and check if we should loop again exec.constants::get_note_mem_size add dup.1 dup.1 neq - # => [should_loop, created_note_ptr, created_notes_end_ptr] + # => [should_loop, output_note_ptr, output_notes_end_ptr] end # clean stack @@ -168,13 +168,13 @@ end #! - computes the final account hash #! - if the account has changed, assert that the final account nonce is greater than the initial #! account nonce -#! - computes the created notes commitment +#! - computes the output notes commitment #! - asserts that the input and output vault roots are equal #! #! Stack: [] #! Output: [OUTPUT_NOTES_COMMITMENT, FINAL_ACCOUNT_HASH] #! -#! - OUTPUT_NOTES_COMMITMENT is the commitment of the created notes +#! - OUTPUT_NOTES_COMMITMENT is the commitment of the output notes #! - FINAL_ACCOUNT_HASH is the final account hash export.finalize_transaction # update account code @@ -232,7 +232,7 @@ export.finalize_transaction exec.build_output_vault # => [FINAL_ACCOUNT_HASH] - # compute created note hash + # compute output notes commitment exec.note::compute_output_notes_commitment # => [OUTPUT_NOTES_COMMITMENT, FINAL_ACCOUNT_HASH] diff --git a/miden-lib/asm/miden/kernels/tx/memory.masm b/miden-lib/asm/miden/kernels/tx/memory.masm index 2019d7a68..511d55e7c 100644 --- a/miden-lib/asm/miden/kernels/tx/memory.masm +++ b/miden-lib/asm/miden/kernels/tx/memory.masm @@ -13,11 +13,11 @@ const.ERR_NOTE_TOO_MANY_ASSETS=0x0002002A # The memory address at which the transaction vault root is stored const.TX_VAULT_ROOT_PTR=0 -# The memory address at which a pointer to the consumed note being executed is stored. -const.CURRENT_CONSUMED_NOTE_PTR=1 +# The memory address at which a pointer to the input note being executed is stored. +const.CURRENT_INPUT_NOTE_PTR=1 -# The memory address at which the number of created notes is stored. -const.NUM_CREATED_NOTES_PTR=2 +# The memory address at which the number of output notes is stored. +const.NUM_OUTPUT_NOTES_PTR=2 # The memory address at which the input vault root is stored const.INPUT_VAULT_ROOT_PTR=3 @@ -120,43 +120,43 @@ const.ACCT_CORE_DATA_SECTION_END_OFFSET=404 # The memory address at which the account storage slot type data beings const.ACCT_STORAGE_SLOT_TYPE_DATA_OFFSET=405 -# CONSUMED NOTES DATA +# INPUT NOTES DATA # ------------------------------------------------------------------------------------------------- -# The memory address at which the consumed note section begins. -const.CONSUMED_NOTE_SECTION_OFFSET=1048576 +# The memory address at which the input note section begins. +const.INPUT_NOTE_SECTION_OFFSET=1048576 -# The memory address at which the consumed note data section begins. -const.CONSUMED_NOTE_DATA_SECTION_OFFSET=1064960 +# The memory address at which the input note data section begins. +const.INPUT_NOTE_DATA_SECTION_OFFSET=1064960 -# The memory address at which the number of consumed notes is stored. -const.CONSUMED_NOTE_NUM_PTR=1048576 +# The memory address at which the number of input notes is stored. +const.NUM_INPUT_NOTES_PTR=1048576 -# The offsets at which data of a consumed note is stored relative to the start of its data segment -const.CONSUMED_NOTE_ID_OFFSET=0 -const.CONSUMED_NOTE_CORE_DATA_OFFSET=1 -const.CONSUMED_NOTE_SERIAL_NUM_OFFSET=1 -const.CONSUMED_NOTE_SCRIPT_ROOT_OFFSET=2 -const.CONSUMED_NOTE_INPUTS_HASH_OFFSET=3 -const.CONSUMED_NOTE_ASSETS_HASH_OFFSET=4 -const.CONSUMED_NOTE_METADATA_OFFSET=5 -const.CONSUMED_NOTE_ARGS_OFFSET=6 -const.CONSUMED_NOTE_NUM_ASSETS_OFFSET=7 -const.CONSUMED_NOTE_ASSETS_OFFSET=8 +# The offsets at which data of a input note is stored relative to the start of its data segment +const.INPUT_NOTE_ID_OFFSET=0 +const.INPUT_NOTE_CORE_DATA_OFFSET=1 +const.INPUT_NOTE_SERIAL_NUM_OFFSET=1 +const.INPUT_NOTE_SCRIPT_ROOT_OFFSET=2 +const.INPUT_NOTE_INPUTS_HASH_OFFSET=3 +const.INPUT_NOTE_ASSETS_HASH_OFFSET=4 +const.INPUT_NOTE_METADATA_OFFSET=5 +const.INPUT_NOTE_ARGS_OFFSET=6 +const.INPUT_NOTE_NUM_ASSETS_OFFSET=7 +const.INPUT_NOTE_ASSETS_OFFSET=8 -# CREATED NOTES +# OUTPUT NOTES # ------------------------------------------------------------------------------------------------- -# The memory address at which the created notes section begins. -const.CREATED_NOTE_SECTION_OFFSET=4194304 +# The memory address at which the output notes section begins. +const.OUTPUT_NOTE_SECTION_OFFSET=4194304 -# The offsets at which data of a created note is stored relative to the start of its data segment. -const.CREATED_NOTE_ID_OFFSET=0 -const.CREATED_NOTE_METADATA_OFFSET=1 -const.CREATED_NOTE_RECIPIENT_OFFSET=2 -const.CREATED_NOTE_ASSETS_HASH_OFFSET=3 -const.CREATED_NOTE_NUM_ASSETS_OFFSET=4 -const.CREATED_NOTE_ASSETS_OFFSET=5 +# The offsets at which data of a output note is stored relative to the start of its data segment. +const.OUTPUT_NOTE_ID_OFFSET=0 +const.OUTPUT_NOTE_METADATA_OFFSET=1 +const.OUTPUT_NOTE_RECIPIENT_OFFSET=2 +const.OUTPUT_NOTE_ASSETS_HASH_OFFSET=3 +const.OUTPUT_NOTE_NUM_ASSETS_OFFSET=4 +const.OUTPUT_NOTE_ASSETS_OFFSET=5 # MEMORY PROCEDURES # ================================================================================================= @@ -164,42 +164,42 @@ const.CREATED_NOTE_ASSETS_OFFSET=5 # BOOK KEEPING # ------------------------------------------------------------------------------------------------- -#! Returns the number of created notes. +#! Returns the number of output notes. #! #! Stack: [] -#! Output: [num_created_notes] -export.get_num_created_notes - push.NUM_CREATED_NOTES_PTR mem_load +#! Output: [num_output_notes] +export.get_num_output_notes + push.NUM_OUTPUT_NOTES_PTR mem_load end -#! Sets the number of created notes. +#! Sets the number of output notes. #! -#! Stack: [num_created_notes] +#! Stack: [num_output_notes] #! Output: [] -export.set_num_created_notes - push.NUM_CREATED_NOTES_PTR mem_store +export.set_num_output_notes + push.NUM_OUTPUT_NOTES_PTR mem_store end -#! Returns a pointer to the consumed note being executed. +#! Returns a pointer to the input note being executed. #! #! Stack: [] #! Output: [note_ptr] #! #! Where: -#! - note_ptr, the memory address of the data segment for the current consumed note. -export.get_current_consumed_note_ptr - push.CURRENT_CONSUMED_NOTE_PTR mem_load +#! - note_ptr, the memory address of the data segment for the current input note. +export.get_current_input_note_ptr + push.CURRENT_INPUT_NOTE_PTR mem_load end -#! Sets the current consumed note pointer to the consumed note being executed. +#! Sets the current input note pointer to the input note being executed. #! #! Stack: [note_ptr] #! Output: [] #! #! Where: -#! - note_ptr, the new memory address of the data segment for the consumed note. -export.set_current_consumed_note_ptr - push.CURRENT_CONSUMED_NOTE_PTR mem_store +#! - note_ptr, the new memory address of the data segment for the input note. +export.set_current_input_note_ptr + push.CURRENT_INPUT_NOTE_PTR mem_store end #! Returns a pointer to the memory address at which the input vault root is stored @@ -786,53 +786,53 @@ export.get_acct_storage_slot_type_data # => [slot_type_info] end -# CONSUMED NOTES +# INPUT NOTES # ------------------------------------------------------------------------------------------------- -#! Gets the total number of consumed notes in the transaction. +#! Gets the total number of input notes in the transaction. #! #! Stack: [] -#! Output: [num_consumed_notes] +#! Output: [num_input_notes] #! #! Where: -#! - num_consumed_notes is the total number of consumed notes in the transaction. -export.get_total_num_consumed_notes - push.CONSUMED_NOTE_NUM_PTR mem_load +#! - num_input_notes is the total number of input notes in the transaction. +export.get_num_input_notes + push.NUM_INPUT_NOTES_PTR mem_load end -#! Sets the total number of consumed notes in the transaction. +#! Sets the total number of input notes in the transaction. #! -#! Stack: [num_consumed_notes] +#! Stack: [num_input_notes] #! Output: [] #! #! Where: -#! - num_consumed_notes is the total number of consumed notes in the transaction. -export.set_total_num_consumed_notes - push.CONSUMED_NOTE_NUM_PTR mem_store +#! - num_input_notes is the total number of input notes in the transaction. +export.set_num_input_notes + push.NUM_INPUT_NOTES_PTR mem_store end -#! Computes a pointer to the memory address at which the data associated with a consumed note with +#! Computes a pointer to the memory address at which the data associated with a input note with #! index `idx` is stored. #! #! Stack: [idx] #! Output: [note_ptr] #! #! Where: -#! - idx, the index of the consumed note. -#! - note_ptr, the memory address of the data segment for the consumed note with idx. -export.get_consumed_note_ptr - exec.constants::get_note_mem_size mul push.CONSUMED_NOTE_DATA_SECTION_OFFSET add +#! - idx, the index of the input note. +#! - note_ptr, the memory address of the data segment for the input note with `idx`. +export.get_input_note_ptr + exec.constants::get_note_mem_size mul push.INPUT_NOTE_DATA_SECTION_OFFSET add end -#! Set the note id of the consumed note. +#! Set the note id of the input note. #! #! Stack: [note_ptr, NOTE_ID] #! Output: [NOTE_ID] #! #! Where: -#! - note_ptr, the consumed note's the memory address. +#! - note_ptr, the input note's the memory address. #! - NOTE_ID, the note's id. -export.set_consumed_note_id +export.set_input_note_id mem_storew end @@ -843,89 +843,89 @@ end #! Output: [nullifier_ptr] #! #! Where: -#! - idx, the index of the consumed note. +#! - idx, the index of the input note. #! - nullifier_ptr, the memory address of the nullifier for note idx. -export.get_consumed_note_nullifier_ptr - push.CONSUMED_NOTE_SECTION_OFFSET.1 add add +export.get_input_note_nullifier_ptr + push.INPUT_NOTE_SECTION_OFFSET.1 add add end -#! Returns the nullifier of a consumed note with `idx`. +#! Returns the nullifier of a input note with `idx`. #! #! Stack: [idx] #! Output: [nullifier] #! #! Where: -#! - idx, the index of the consumed note. -#! - nullifier, the nullifier of the consumed note. -export.get_consumed_note_nullifier - padw movup.4 push.CONSUMED_NOTE_SECTION_OFFSET.1 add add mem_loadw +#! - idx, the index of the input note. +#! - nullifier, the nullifier of the input note. +export.get_input_note_nullifier + padw movup.4 push.INPUT_NOTE_SECTION_OFFSET.1 add add mem_loadw end -#! Returns a pointer to the start of the consumed note core data segment for the note located at +#! Returns a pointer to the start of the input note core data segment for the note located at #! the specified memory address. #! #! Stack: [note_ptr] #! Output: [note_data_ptr] #! #! Where: -#! - note_ptr, the memory address at which the consumed note data begins. -#! - note_data_ptr, the memory address at which the consumed note core data begins. -export.get_consumed_note_core_ptr - push.CONSUMED_NOTE_CORE_DATA_OFFSET add +#! - note_ptr, the memory address at which the input note data begins. +#! - note_data_ptr, the memory address at which the input note core data begins. +export.get_input_note_core_ptr + push.INPUT_NOTE_CORE_DATA_OFFSET add end -#! Returns the script root of a consumed note located at the specified memory address. +#! Returns the script root of a input note located at the specified memory address. #! #! Stack: [note_ptr] #! Output: [SCRIPT_HASH] #! #! Where: -#! - note_ptr, the memory address at which the consumed note data begins. -#! - SCRIPT_HASH, the script root of the consumed note. -export.get_consumed_note_script_root +#! - note_ptr, the memory address at which the input note data begins. +#! - SCRIPT_HASH, the script root of the input note. +export.get_input_note_script_root padw - movup.4 push.CONSUMED_NOTE_SCRIPT_ROOT_OFFSET add + movup.4 push.INPUT_NOTE_SCRIPT_ROOT_OFFSET add mem_loadw end -#! Returns the inputs hash of a consumed note located at the specified memory address. +#! Returns the inputs hash of a input note located at the specified memory address. #! #! Stack: [note_ptr] #! Output: [INPUTS_HASH] #! #! Where: -#! - note_ptr, the memory address at which the consumed note data begins. -#! - INPUTS_HASH, the inputs hash of the consumed note. -export.get_consumed_note_inputs_hash +#! - note_ptr, the memory address at which the input note data begins. +#! - INPUTS_HASH, the inputs hash of the input note. +export.get_input_note_inputs_hash padw - movup.4 push.CONSUMED_NOTE_INPUTS_HASH_OFFSET add + movup.4 push.INPUT_NOTE_INPUTS_HASH_OFFSET add mem_loadw end -#! Returns the metadata of a consumed note located at the specified memory address. +#! Returns the metadata of a input note located at the specified memory address. #! #! Stack: [note_ptr] #! Output: [METADATA] #! #! Where: -#! - note_ptr, the memory address at which the consumed note data begins. -#! - METADATA, the metadata of the consumed note. -export.get_consumed_note_metadata +#! - note_ptr, the memory address at which the input note data begins. +#! - METADATA, the metadata of the input note. +export.get_input_note_metadata padw - movup.4 push.CONSUMED_NOTE_METADATA_OFFSET add + movup.4 push.INPUT_NOTE_METADATA_OFFSET add mem_loadw end -#! Sets the metadata for a consumed note located at the specified memory address. +#! Sets the metadata for a input note located at the specified memory address. #! #! Stack: [note_ptr, NOTE_METADATA] #! Output: [NOTE_METADATA] #! #! Where: -#! - note_ptr, the memory address at which the consumed note data begins. -#! - NOTE_METADATA, the metadata of the consumed note. -export.set_consumed_note_metadata - push.CONSUMED_NOTE_METADATA_OFFSET add +#! - note_ptr, the memory address at which the input note data begins. +#! - NOTE_METADATA, the metadata of the input note. +export.set_input_note_metadata + push.INPUT_NOTE_METADATA_OFFSET add mem_storew end @@ -937,103 +937,103 @@ end #! Where: #! - note_ptr, the start memory address of the note. #! - NOTE_ARGS, the note's args. -export.get_consumed_note_args +export.get_input_note_args padw - movup.4 push.CONSUMED_NOTE_ARGS_OFFSET add + movup.4 push.INPUT_NOTE_ARGS_OFFSET add mem_loadw end -#! Sets the note args for a consumed note located at the specified memory address. +#! Sets the note args for a input note located at the specified memory address. #! #! Stack: [note_ptr, NOTE_ARGS] #! Output: [] #! #! Where: -#! - note_ptr is the memory address at which the consumed note data begins. -#! - NOTE_ARGS are optional note args of the consumed note. -export.set_consumed_note_args - push.CONSUMED_NOTE_ARGS_OFFSET add +#! - 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 end -#! Returns the number of assets in the consumed note located at the specified memory address. +#! Returns the number of assets in the input note located at the specified memory address. #! #! Stack: [note_ptr] #! Output: [num_assets] #! #! Where: -#! - note_ptr is the memory address at which the consumed note data begins. -#! - num_assets is the number of assets in the consumed note. -export.get_consumed_note_num_assets - push.CONSUMED_NOTE_NUM_ASSETS_OFFSET add +#! - note_ptr is the memory address at which the input note data begins. +#! - num_assets is the number of assets in the input note. +export.get_input_note_num_assets + push.INPUT_NOTE_NUM_ASSETS_OFFSET add mem_load end -#! Sets the number of assets for a consumed note located at the specified memory address. +#! Sets the number of assets for a input note located at the specified memory address. #! #! Stack: [note_ptr, num_assets] #! Output: [] #! #! Where: -#! - note_ptr is the memory address at which the consumed note data begins. -#! - num_assets is the number of assets in the consumed note. -export.set_consumed_note_num_assets - push.CONSUMED_NOTE_NUM_ASSETS_OFFSET add +#! - note_ptr is the memory address at which the input note data begins. +#! - num_assets is the number of assets in the input note. +export.set_input_note_num_assets + push.INPUT_NOTE_NUM_ASSETS_OFFSET add mem_store end -#! Returns a pointer to the start of the assets segment for the consumed note located at +#! Returns a pointer to the start of the assets segment for the input note located at #! the specified memory address. #! #! Stack: [note_ptr] #! Output: [assets_ptr] #! #! Where: -#! - note_ptr is the memory address at which the consumed note data begins. -#! - assets_ptr is the memory address at which the assets segment for the consumed note begins. -export.get_consumed_note_assets_ptr - push.CONSUMED_NOTE_ASSETS_OFFSET add +#! - note_ptr is the memory address at which the input note data begins. +#! - assets_ptr is the memory address at which the assets segment for the input note begins. +export.get_input_note_assets_ptr + push.INPUT_NOTE_ASSETS_OFFSET add end -#! Returns the assets hash for the consumed note located at the specified memory address. +#! Returns the assets hash for the input note located at the specified memory address. #! #! Stack: [note_ptr] #! Output: [ASSET_HASH] #! #! Where: -#! - note_ptr is the memory address at which the consumed note data begins. -#! - ASSET_HASH, sequential hash of the padded assets of a consumed note. -export.get_consumed_note_assets_hash +#! - note_ptr is the memory address at which the input note data begins. +#! - ASSET_HASH, sequential hash of the padded assets of a input note. +export.get_input_note_assets_hash padw - movup.4 push.CONSUMED_NOTE_ASSETS_HASH_OFFSET add + movup.4 push.INPUT_NOTE_ASSETS_HASH_OFFSET add mem_loadw end -#! Returns the serial number for the consumed note located at the specified memory address. +#! Returns the serial number for the input note located at the specified memory address. #! #! Stack: [note_ptr] #! Output: [SERIAL_NUMBER] #! #! Where: -#! - note_ptr is the memory address at which the consumed note data begins. +#! - note_ptr is the memory address at which the input note data begins. #! - SERIAL_NUMBER, the input note's serial number. -export.get_consumed_note_serial_num +export.get_input_note_serial_num padw - movup.4 push.CONSUMED_NOTE_SERIAL_NUM_OFFSET add + movup.4 push.INPUT_NOTE_SERIAL_NUM_OFFSET add mem_loadw end -#! Returns the sender for the consumed note located at the specified memory address. +#! Returns the sender for the input note located at the specified memory address. #! #! Stack: [note_ptr] #! Output: [sender] #! #! Where: -#! - note_ptr is the memory address at which the consumed note data begins. -#! - sender is the sender for the consumed note. -export.get_consumed_note_sender +#! - note_ptr is the memory address at which the input note data begins. +#! - sender is the sender for the input note. +export.get_input_note_sender padw - movup.4 push.CONSUMED_NOTE_METADATA_OFFSET add + movup.4 push.INPUT_NOTE_METADATA_OFFSET add mem_loadw # => [0, 0, sender, tag] @@ -1041,84 +1041,84 @@ export.get_consumed_note_sender # => [sender] end -# CREATED NOTES +# OUTPUT NOTES # ------------------------------------------------------------------------------------------------- -#! Returns the offset of the created note data segment. +#! Returns the offset of the output note data segment. #! #! Stack: [] #! Output: [offset] #! #! Where: -#! - offset is the offset of the created note data segment. -export.get_created_note_data_offset - push.CREATED_NOTE_SECTION_OFFSET +#! - offset is the offset of the output note data segment. +export.get_output_note_data_offset + push.OUTPUT_NOTE_SECTION_OFFSET end -#! Computes a pointer to the memory address at which the data associated with a created note with -#! index i is stored. +#! Computes a pointer to the memory address at which the data associated with a output note with +#! index `i` is stored. #! #! Stack: [i] #! Output: [ptr] #! #! Where: -#! - i is the index of the created note. -#! - ptr is the memory address of the data segment for created note i. -export.get_created_note_ptr - exec.constants::get_note_mem_size mul push.CREATED_NOTE_SECTION_OFFSET add +#! - i is the index of the output note. +#! - ptr is the memory address of the data segment for output note i. +export.get_output_note_ptr + exec.constants::get_note_mem_size mul push.OUTPUT_NOTE_SECTION_OFFSET add end -#! Returns the created note recipient +#! Returns the output note recipient #! -#! Stack: [created_note_data_ptr] +#! Stack: [output_note_data_ptr] #! Output: [R] #! #! Where: -#! - created_note_data_ptr is the memory address at which the created note data begins. -#! - R is the recipient of the created note. -export.get_created_note_recipient +#! - output_note_data_ptr is the memory address at which the output note data begins. +#! - R is the recipient of the output note. +export.get_output_note_recipient padw - movup.4 push.CREATED_NOTE_RECIPIENT_OFFSET add + movup.4 push.OUTPUT_NOTE_RECIPIENT_OFFSET add mem_loadw end -#! Sets the created note's recipient +#! Sets the output note's recipient #! #! Stack: [note_ptr, RECIPIENT] #! Output: [] #! #! Where: #! - recipient is the recipient of the note -#! - note_ptr is the memory address at which the created note data begins. -export.set_created_note_recipient - push.CREATED_NOTE_RECIPIENT_OFFSET add mem_storew dropw +#! - 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 end -#! Sets the created note's metadata +#! Sets the output note's metadata #! #! Stack: [note_ptr, METADATA] #! Output: [] #! #! Where: #! - METADATA is the note metadata -#! - note_ptr is the memory address at which the created note data begins. -export.set_created_note_metadata - push.CREATED_NOTE_METADATA_OFFSET add mem_storew dropw +#! - 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 end -#! Returns the number of assets in the created note +#! Returns the number of assets in the output note #! #! Stack: [note_ptr] #! Output: [num_assets] #! #! Where: -#! - note_ptr is a pointer to the memory address at which the created note is stored. -#! - num_assets is the number of assets in the created note. -export.get_created_note_num_assets - push.CREATED_NOTE_NUM_ASSETS_OFFSET add mem_load +#! - note_ptr is a pointer to the memory address at which the output note is stored. +#! - num_assets is the number of assets in the output note. +export.get_output_note_num_assets + push.OUTPUT_NOTE_NUM_ASSETS_OFFSET add mem_load end -#! Sets the number of assets in the created note +#! Sets the number of assets in the output note #! #! Stack: [note_ptr, num_assets] #! Output: [] @@ -1126,10 +1126,10 @@ end #! Panics: if the number of assets exceeds the maximum allowed number of assets per note. #! #! Where: -#! - note_ptr is the memory address at which the created note data begins. -#! - num_assets is the number of assets in the created note. -export.set_created_note_num_assets - push.CREATED_NOTE_NUM_ASSETS_OFFSET add +#! - note_ptr is the memory address at which the output note data begins. +#! - num_assets is the number of assets in the output note. +export.set_output_note_num_assets + push.OUTPUT_NOTE_NUM_ASSETS_OFFSET add # => [note_ptr + offset, num_assets] # check note number of assets limit @@ -1138,26 +1138,26 @@ export.set_created_note_num_assets mem_store end -#! Returns a pointer to the created note asset data +#! Returns a pointer to the output note asset data #! -#! Stack: [created_note_data_ptr] +#! Stack: [output_note_data_ptr] #! Output: [asset_data_ptr] #! #! Where: -#! - created_note_data_ptr is the memory address at which the created note data begins. -#! - asset_data_ptr is the memory address at which the created note asset data begins. -export.get_created_note_asset_data_ptr - push.CREATED_NOTE_ASSETS_OFFSET add +#! - output_note_data_ptr is the memory address at which the output note data begins. +#! - asset_data_ptr is the memory address at which the output note asset data begins. +export.get_output_note_asset_data_ptr + push.OUTPUT_NOTE_ASSETS_OFFSET add end -#! Sets the created note assets hash. +#! Sets the output note assets hash. #! -#! Stack: [created_note_data_ptr, ASSET_HASH] +#! Stack: [output_note_data_ptr, ASSET_HASH] #! Output: [] #! #! Where: -#! - created_note_data_ptr is the memory address at which the created note data begins. -#! - ASSET_HASH, sequential hash of the padded assets of a created note. -export.set_created_note_assets_hash - push.CREATED_NOTE_ASSETS_HASH_OFFSET add mem_storew +#! - 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. +export.set_output_note_assets_hash + push.OUTPUT_NOTE_ASSETS_HASH_OFFSET add mem_storew end diff --git a/miden-lib/asm/miden/kernels/tx/note.masm b/miden-lib/asm/miden/kernels/tx/note.masm index 52caffdea..67bade673 100644 --- a/miden-lib/asm/miden/kernels/tx/note.masm +++ b/miden-lib/asm/miden/kernels/tx/note.masm @@ -36,8 +36,8 @@ const.OUTPUT_NOTE_HASHING_MEM_DIFF=510 #! #! - sender is the sender of the note currently being processed. export.get_sender - # get the current consumed note pointer - exec.memory::get_current_consumed_note_ptr + # get the current input note pointer + exec.memory::get_current_input_note_ptr # => [ptr] # assert the pointer is not zero - this would suggest the procedure has been called from an @@ -46,21 +46,21 @@ export.get_sender # => [ptr] # get the sender from the note pointer - exec.memory::get_consumed_note_sender + exec.memory::get_input_note_sender # => [sender] 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: [] -#! 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_vault_info - # get the current consumed note pointer - exec.memory::get_current_consumed_note_ptr +#! - ASSETS_HASH is the vault hash of the note currently being processed. +export.get_assets_info + # get the current input note pointer + exec.memory::get_current_input_note_ptr # => [ptr] # assert the pointer is not zero - this would suggest the procedure has been called from an @@ -69,12 +69,12 @@ export.get_vault_info # => [ptr] # get the number of assets in the note - dup exec.memory::get_consumed_note_num_assets + dup exec.memory::get_input_note_num_assets # => [num_assets, ptr] - # get the vault hash from the note pointer - swap exec.memory::get_consumed_note_assets_hash - # => [VAULT_HASH, num_assets] + # get the assets hash from the note pointer + swap exec.memory::get_input_note_assets_hash + # => [ASSETS_HASH, num_assets] end #! Returns the commitment to the note's inputs. @@ -87,7 +87,7 @@ end #! Where: #! - NOTE_INPUTS_HASH is the note inputs hash of the note currently being processed. export.get_note_inputs_hash - exec.memory::get_current_consumed_note_ptr + exec.memory::get_current_input_note_ptr # => [ptr] # The kernel memory is initialized by prologue::process_input_notes_data, and reset by @@ -96,39 +96,39 @@ export.get_note_inputs_hash dup neq.0 assert.err=ERR_NOTE_INVALID_INPUTS # => [ptr] - exec.memory::get_consumed_note_inputs_hash + exec.memory::get_input_note_inputs_hash # => [NOTE_INPUTS_HASH] end -#! Increment current consumed note pointer to the next note and returns the pointer value. +#! Move the current input note pointer to the next note and returns the pointer value. #! #! Inputs: [] -#! Outputs: [current_consumed_note_ptr] +#! Outputs: [current_input_note_ptr] #! #! Where: -#! - current_consumed_note_ptr is the pointer to the next note to be processed. -export.increment_current_consumed_note_ptr - # get the current consumed note pointer - exec.memory::get_current_consumed_note_ptr - # => [orig_consumed_note_ptr] +#! - current_input_note_ptr is the pointer to the next note to be processed. +export.increment_current_input_note_ptr + # get the current input note pointer + exec.memory::get_current_input_note_ptr + # => [orig_input_note_ptr] # increment the pointer exec.constants::get_note_mem_size add - # => [current_consumed_note_ptr] + # => [current_input_note_ptr] - # set the current consumed note pointer to the incremented value - dup exec.memory::set_current_consumed_note_ptr - # => [current_consumed_note_ptr] + # set the current input note pointer to the incremented value + dup exec.memory::set_current_input_note_ptr + # => [current_input_note_ptr] end -#! Sets the current consumed note pointer to 0. This should be called after all consumed notes have +#! Sets the current input note pointer to 0. This should be called after all input notes have #! been processed. #! #! Inputs: [] #! Outputs: [] export.note_processing_teardown - # set the current consumed note pointer to 0 - push.0 exec.memory::set_current_consumed_note_ptr + # set the current input note pointer to 0 + push.0 exec.memory::set_current_input_note_ptr # => [] end @@ -143,13 +143,13 @@ end #! - NOTE_SCRIPT_ROOT, the note's script root. #! - NOTE_ARGS, the note's arguments. export.prepare_note - exec.memory::get_current_consumed_note_ptr + exec.memory::get_current_input_note_ptr # => [note_ptr] - dup exec.memory::get_consumed_note_args movup.4 + dup exec.memory::get_input_note_args movup.4 # => [note_ptr, NOTE_ARGS] - exec.memory::get_consumed_note_script_root + exec.memory::get_input_note_script_root # => [NOTE_SCRIPT_ROOT, NOTE_ARGS] end @@ -169,7 +169,7 @@ end #! - ASSETS_HASH is the hash of the assets of the output note located at note_data_ptr. proc.compute_output_note_assets_hash # duplicate note pointer and fetch num_assets - dup dup exec.memory::get_created_note_num_assets + dup dup exec.memory::get_output_note_num_assets # => [num_assets, note_data_ptr, note_data_ptr] # calculate the number of pairs of assets (takes ceiling if we have an odd number) @@ -183,7 +183,7 @@ proc.compute_output_note_assets_hash # => [asset_counter, num_asset_pairs, note_data_ptr, note_data_ptr] # prepare address and stack for reading assets - movup.2 exec.memory::get_created_note_asset_data_ptr padw padw padw + movup.2 exec.memory::get_output_note_asset_data_ptr padw padw padw # => [PAD, PAD, PAD, asset_data_ptr, asset_counter, num_asset_pairs, note_data_ptr] # check if we should loop @@ -215,7 +215,7 @@ proc.compute_output_note_assets_hash # => [ASSETS_HASH, note_data_ptr] # save vault hash to memory - movup.4 exec.memory::set_created_note_assets_hash + movup.4 exec.memory::set_output_note_assets_hash # => [] end @@ -237,15 +237,15 @@ proc.compute_output_note_id padw # insert output note recipient into the first four elements of the hasher rate - dup.4 exec.memory::get_created_note_recipient + dup.4 exec.memory::get_output_note_recipient # populate the last four elements of the hasher rate with the output note's asset hash dup.8 exec.compute_output_note_assets_hash - # compute output note hash and extract digest + # compute output note commitment and extract digest hperm exec.native::state_to_digest - # save output note hash to memory + # save the output notes commitment to memory movup.4 mem_storew end @@ -255,18 +255,18 @@ end #! Stack: [] #! Output: [OUTPUT_NOTES_COMMITMENT] #! -#! - OUTPUT_NOTES_COMMITMENT is the commitment to the notes created by the transaction. +#! - OUTPUT_NOTES_COMMITMENT is the commitment to the notes output by the transaction. export.compute_output_notes_commitment # get the number of output notes from memory - exec.memory::get_num_created_notes + exec.memory::get_num_output_notes # => [num_notes, ...] # calculate the address at which we should stop looping - exec.memory::get_created_note_ptr + exec.memory::get_output_note_ptr # => [end_ptr, ...] # compute pointer for first address - push.0 exec.memory::get_created_note_ptr + push.0 exec.memory::get_output_note_ptr # => [first_note_ptr, end_ptr, ...] # prepare stack for hashing @@ -318,9 +318,9 @@ end #! #! - SERIAL_NUMBER is the serial number of the note currently being processed. export.get_serial_number - exec.memory::get_current_consumed_note_ptr + exec.memory::get_current_input_note_ptr # => [note_ptr, ...] - exec.memory::get_consumed_note_serial_num + exec.memory::get_input_note_serial_num # => [SERIAL_NUMBER, ...] end diff --git a/miden-lib/asm/miden/kernels/tx/prologue.masm b/miden-lib/asm/miden/kernels/tx/prologue.masm index 0851a68d3..dc216ae2c 100644 --- a/miden-lib/asm/miden/kernels/tx/prologue.masm +++ b/miden-lib/asm/miden/kernels/tx/prologue.masm @@ -113,14 +113,14 @@ end #! Where: #! - PREVIOUS_BLOCK_HASH, hash of the previous block. #! - CHAIN_MMR_HASH, sequential hash of the reference MMR. -#! - ACCOUNT_ROOT, rollup tree with latest account states. -#! - NULLIFIER_ROOT, epoch tree with the nullifiers of consumed notes. +#! - ACCOUNT_ROOT, root of the tree with latest account states for all accounts. +#! - NULLIFIER_ROOT, root of the tree with nullifiers of all notes that have ever been consumed. #! - TX_HASH, commitment to a set of IDs of transactions which affected accounts in the block. #! - PROOF_HASH, hash of the block's stark proof. #! - block_num, the reference block number. #! - version, current protocol version. #! - timestamp, current timestamp. -#! - NOTE_ROOT, epoch tree with created notes. +#! - NOTE_ROOT, root of the tree with all notes created in the block. proc.process_block_data exec.memory::get_block_data_ptr # => [block_data_ptr] @@ -578,7 +578,7 @@ end #! - ASSETS_HASH, sequential hash of the padded note's assets. #! - NULLIFIER result of `hash(SERIAL_NUMBER || SCRIPT_ROOT || INPUTS_HASH || ASSETS_HASH)`. proc.process_input_note_details - exec.memory::get_consumed_note_core_ptr + exec.memory::get_input_note_core_ptr # => [note_data_ptr] # read input note's data and compute its digest. See `Advice stack` above for details. @@ -615,10 +615,10 @@ 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_consumed_note_args + padw adv_loadw dup.4 exec.memory::set_input_note_args # => [note_ptr] - padw adv_loadw movup.4 exec.memory::set_consumed_note_metadata + padw adv_loadw movup.4 exec.memory::set_input_note_metadata # => [NOTE_METADATA] end @@ -645,7 +645,7 @@ proc.process_note_assets dup exec.constants::get_max_assets_per_note lte assert.err=ERR_PROLOGUE_NOTE_TOO_MANY_ASSETS # => [assets_count, note_ptr] - dup dup.2 exec.memory::set_consumed_note_num_assets + dup dup.2 exec.memory::set_input_note_num_assets # => [assets_count, note_ptr] # round up the number of assets, to the its padded length @@ -667,7 +667,7 @@ proc.process_note_assets push.0 movup.2 # => [note_ptr, counter, rounded_num_assets] - dup exec.memory::get_consumed_note_assets_ptr + dup exec.memory::get_input_note_assets_ptr # => [assets_ptr, note_ptr, counter, rounded_num_assets] padw padw padw @@ -700,7 +700,7 @@ proc.process_note_assets # => [note_ptr, ASSET_HASH_COMPUTED] # VERIFY: computed ASSET_HASH matches the provided hash - exec.memory::get_consumed_note_assets_hash + exec.memory::get_input_note_assets_hash assert_eqw.err=ERR_PROLOGUE_NOTE_CONSUMED_ASSETS_MISMATCH # => [] end @@ -719,10 +719,10 @@ proc.add_input_note_assets_to_vault exec.memory::get_input_vault_root_ptr # => [input_vault_root_ptr, note_ptr] - dup.1 exec.memory::get_consumed_note_assets_ptr + dup.1 exec.memory::get_input_note_assets_ptr # => [assets_start_ptr, input_vault_root_ptr, note_ptr] - dup movup.3 exec.memory::get_consumed_note_num_assets add swap + dup movup.3 exec.memory::get_input_note_num_assets add swap # => [assets_start_ptr, assets_end_ptr, input_vault_root_ptr] # add input note's assets to input vault @@ -754,7 +754,7 @@ proc.add_input_note_assets_to_vault # => [] end -#! Computes the inpute note's id. +#! Computes an input note's id. #! #! Stack: [note_ptr] #! Output: [NOTE_ID] @@ -762,21 +762,21 @@ end #! Where: #! - note_ptr, memory location for the input note. #! - NOTE_ID, the note's id, i.e. `hash(RECIPIENT || ASSET_HASH)`. -proc.compute_note_id +proc.compute_input_note_id # compute SERIAL_HASH: hash(SERIAL_NUMBER || EMPTY_WORD) - dup exec.memory::get_consumed_note_serial_num padw hmerge + dup exec.memory::get_input_note_serial_num padw hmerge # => [SERIAL_HASH, note_ptr] # compute MERGE_SCRIPT: hash(SERIAL_HASH || SCRIPT_HASH) - dup.4 exec.memory::get_consumed_note_script_root hmerge + dup.4 exec.memory::get_input_note_script_root hmerge # => [MERGE_SCRIPT, note_ptr] # compute RECIPIENT: hash(MERGE_SCRIPT || INPUT_HASH) - dup.4 exec.memory::get_consumed_note_inputs_hash hmerge + dup.4 exec.memory::get_input_note_inputs_hash hmerge # => [RECIPIENT, note_ptr] # compute NOTE_ID: hash(RECIPIENT || ASSET_HASH) - movup.4 exec.memory::get_consumed_note_assets_hash hmerge + movup.4 exec.memory::get_input_note_assets_hash hmerge # => [NOTE_ID] end @@ -829,14 +829,14 @@ proc.process_input_note # note details # --------------------------------------------------------------------------------------------- - dup exec.memory::get_consumed_note_ptr dup + dup exec.memory::get_input_note_ptr dup # => [note_ptr, note_ptr, idx, HASHER_CAPACITY] exec.process_input_note_details # => [NULLIFIER, note_ptr, idx, HASHER_CAPACITY] # save NULLIFIER to memory - movup.5 exec.memory::get_consumed_note_nullifier_ptr mem_storew + movup.5 exec.memory::get_input_note_nullifier_ptr mem_storew # => [NULLIFIER, note_ptr, HASHER_CAPACITY] # note metadata & args @@ -861,11 +861,11 @@ proc.process_input_note # note id # --------------------------------------------------------------------------------------------- - dup exec.compute_note_id + dup exec.compute_input_note_id # => [NOTE_ID, note_ptr, NOTE_METADATA, NULLIFIER, HASHER_CAPACITY] # save note id to memory - movup.4 exec.memory::set_consumed_note_id + movup.4 exec.memory::set_input_note_id # => [NOTE_ID, NOTE_METADATA, NULLIFIER, HASHER_CAPACITY] # note authentication @@ -917,7 +917,7 @@ proc.process_input_notes_data # assert the number of input notes is within limits; since max number of input notes is # expected to be smaller than 2^32, we can use a more efficient u32 comparison dup - exec.constants::get_max_num_consumed_notes u32assert2.err=ERR_PROLOGUE_TOO_MANY_INPUT_NOTES + exec.constants::get_max_num_input_notes u32assert2.err=ERR_PROLOGUE_TOO_MANY_INPUT_NOTES u32lte assert.err=ERR_PROLOGUE_TOO_MANY_INPUT_NOTES # => [num_notes] @@ -929,7 +929,7 @@ proc.process_input_notes_data # => [num_notes] # store the number of input notes into kernel memory - dup exec.memory::set_total_num_consumed_notes + dup exec.memory::set_num_input_notes # => [num_notes] # loop over input notes and read data @@ -983,8 +983,8 @@ proc.process_input_notes_data # set the current input note ptr to the address of the first input note push.0 - exec.memory::get_consumed_note_ptr - exec.memory::set_current_consumed_note_ptr + exec.memory::get_input_note_ptr + exec.memory::set_current_input_note_ptr # => [idx+1, num_notes] drop drop @@ -1057,14 +1057,14 @@ end #! - INPUT_NOTES_COMMITMENT, see `transaction::api::get_input_notes_commitment`. #! - PREVIOUS_BLOCK_HASH, hash of the previous block. #! - CHAIN_MMR_HASH, sequential hash of the reference MMR. -#! - ACCOUNT_ROOT, tree with latest account states. -#! - NULLIFIER_ROOT, epoch tree with nullifiers of consumed notes. +#! - ACCOUNT_ROOT, root of the tree with latest account states for all accounts. +#! - NULLIFIER_ROOT, root of the tree with nullifiers of all notes that have ever been consumed. #! - TX_HASH, commitment to a set of IDs of transactions which affected accounts in the block. #! - PROOF_HASH, hash of the block's stark proof. #! - block_num, the reference block number. #! - version, the current protocol version. #! - timestamp, the current timestamp. -#! - NOTE_ROOT, tree with created notes. +#! - NOTE_ROOT, root of the tree with all notes created in the block. #! - account_nonce, account's nonce. #! - ACCOUNT_VAULT_ROOT, account's vault root. #! - ACCOUNT_STORAGE_ROOT, account's storage root. diff --git a/miden-lib/asm/miden/kernels/tx/tx.masm b/miden-lib/asm/miden/kernels/tx/tx.masm index 07227529e..dde241c69 100644 --- a/miden-lib/asm/miden/kernels/tx/tx.masm +++ b/miden-lib/asm/miden/kernels/tx/tx.masm @@ -9,7 +9,7 @@ use.miden::kernels::tx::note # Constants for different note types const.PUBLIC_NOTE=1 # 0b01 -const.OFFCHAIN_NOTE=2 # 0b10 +const.PRIVATE_NOTE=2 # 0b10 const.ENCRYPTED_NOTE=3 # 0b11 # ERRORS @@ -108,21 +108,21 @@ export.memory::get_input_notes_commitment #! COM is the output notes hash. export.note::compute_output_notes_commitment->get_output_notes_hash -#! Increments the number of created notes by one. Returns the index of the next note to be created. +#! Increments the number of output notes by one. Returns the index of the next note to be created. #! #! Inputs: [] #! Outputs: [note_idx] -proc.increment_num_created_notes - # get the current number of created notes - exec.memory::get_num_created_notes +proc.increment_num_output_notes + # get the current number of output notes + exec.memory::get_num_output_notes # => [note_idx] # assert that there is space for a new note - dup exec.constants::get_max_num_created_notes lt assert.err=ERR_TX_OUTPUT_NOTES_OVERFLOW + dup exec.constants::get_max_num_output_notes lt assert.err=ERR_TX_OUTPUT_NOTES_OVERFLOW # => [note_idx] - # increment the number of created notes - dup add.1 exec.memory::set_num_created_notes + # increment the number of output notes + dup add.1 exec.memory::set_num_output_notes # => [note_idx] end @@ -133,7 +133,7 @@ end #! Inputs: [ASSET, note_ptr, num_of_assets, note_idx] #! Outputs: [note_ptr, note_idx] proc.add_non_fungible_asset_to_note - dup.4 exec.memory::get_created_note_asset_data_ptr + dup.4 exec.memory::get_output_note_asset_data_ptr # => [asset_ptr, ASSET, note_ptr, num_of_assets, note_idx] # compute the pointer at which we should stop iterating @@ -171,7 +171,7 @@ proc.add_non_fungible_asset_to_note # => [note_ptr, num_of_assets, note_idx] # increase the number of assets in the note - swap add.1 dup.1 exec.memory::set_created_note_num_assets + swap add.1 dup.1 exec.memory::set_output_note_num_assets # => [note_ptr, note_idx] end @@ -184,7 +184,7 @@ end #! Inputs: [ASSET, note_ptr, num_of_assets, note_idx] #! Outputs: [note_ptr] proc.add_fungible_asset_to_note - dup.4 exec.memory::get_created_note_asset_data_ptr + dup.4 exec.memory::get_output_note_asset_data_ptr # => [asset_ptr, ASSET, note_ptr, num_of_assets, note_idx] # compute the pointer at which we should stop iterating @@ -247,7 +247,7 @@ proc.add_fungible_asset_to_note # => [note_ptr, num_of_assets, note_idx] # increase the number of assets in the note - swap add.1 dup.1 exec.memory::set_created_note_num_assets + swap add.1 dup.1 exec.memory::set_output_note_num_assets # => [note_ptr, note_idx] end @@ -266,14 +266,14 @@ end #! - the note_type is not valid. #! - the note_tag is not an u32. #! - if note_tag starts with anything but 0b11 and note_type is not public. -#! - the number of created notes exceeds the maximum limit of 4096. +#! - the number of output notes exceeds the maximum limit of 4096. export.create_note push.0 drop # TODO: remove line, see miden-vm/#1122 emit.NOTE_BEFORE_CREATED_EVENT # validate the note type # NOTE: encrypted notes are currently unsupported - dup.2 push.OFFCHAIN_NOTE eq dup.3 push.PUBLIC_NOTE eq or assert.err=ERR_INVALID_NOTE_TYPE + dup.2 push.PRIVATE_NOTE eq dup.3 push.PUBLIC_NOTE eq or assert.err=ERR_INVALID_NOTE_TYPE # => [tag, aux, note_type, RECIPIENT] # copy data to validate the tag @@ -288,11 +288,11 @@ export.create_note # => [tag, aux, note_type, RECIPIENT] # get the index for the next note to be created and increment counter - exec.increment_num_created_notes dup movdn.8 + exec.increment_num_output_notes dup movdn.8 # => [note_idx, tag, aux, note_type, RECIPIENT, note_idx] # get a pointer to the memory address at which the note will be stored - exec.memory::get_created_note_ptr + exec.memory::get_output_note_ptr # => [note_ptr, tag, aux, note_type, RECIPIENT, note_idx] # populate the metadata @@ -302,12 +302,12 @@ export.create_note # emit event to signal that a new note is created emit.NOTE_AFTER_CREATED_EVENT - # set the metadata for the created note - dup.4 exec.memory::set_created_note_metadata + # set the metadata for the output note + dup.4 exec.memory::set_output_note_metadata # => [note_ptr, RECIPIENT, note_idx] - # set the RECIPIENT for the created note - exec.memory::set_created_note_recipient + # set the RECIPIENT for the output note + exec.memory::set_output_note_recipient # => [note_idx] end @@ -326,15 +326,15 @@ end #! - the total number of ASSETs exceeds the maximum of 256. export.add_asset_to_note # check if the note exists, it must be within [0, num_of_notes] - dup exec.memory::get_num_created_notes lte assert.err=ERR_INVALID_NOTE_IDX + dup exec.memory::get_num_output_notes lte assert.err=ERR_INVALID_NOTE_IDX # => [note_idx, ASSET] # get a pointer to the memory address of the note at which the asset will be stored - dup movdn.5 exec.memory::get_created_note_ptr + dup movdn.5 exec.memory::get_output_note_ptr # => [note_ptr, ASSET, note_idx] # get current num of assets - dup exec.memory::get_created_note_num_assets movdn.5 + dup exec.memory::get_output_note_num_assets movdn.5 # => [note_ptr, ASSET, num_of_assets, note_idx] # validate the ASSET diff --git a/miden-lib/asm/miden/note.masm b/miden-lib/asm/miden/note.masm index 658e8cbf8..e19f449fe 100644 --- a/miden-lib/asm/miden/note.masm +++ b/miden-lib/asm/miden/note.masm @@ -49,21 +49,21 @@ export.get_assets padw push.0 # => [0, 0, 0, 0, 0, dest_ptr] - # get the current consumed note vault hash - syscall.get_note_vault_info - # => [VAULT_HASH, num_assets, dest_ptr] + # get the current input note assets info + syscall.get_note_assets_info + # => [ASSETS_HASH, num_assets, dest_ptr] - # load the vault data from the advice map to the advice stack + # load the asset data from the advice map to the advice stack adv.push_mapval - # => [VAULT_HASH, num_assets, dest_ptr] + # => [ASSETS_HASH, num_assets, dest_ptr] # calculate number of assets rounded up to an even number dup.4 dup is_odd add - # => [even_num_assets, VAULT_HASH, num_assets, dest_ptr] + # => [even_num_assets, ASSETS_HASH, num_assets, dest_ptr] # calculate the start and end pointer for reading to memory dup.6 add dup.6 - # => [start_ptr, end_ptr, VAULT_HASH, num_assets, dest_ptr] + # => [start_ptr, end_ptr, ASSETS_HASH, num_assets, dest_ptr] # write the data from the advice stack into memory exec.write_advice_data_to_memory diff --git a/miden-lib/asm/note_scripts/SWAP.masm b/miden-lib/asm/note_scripts/SWAP.masm index 460b2eadb..1d79e3d66 100644 --- a/miden-lib/asm/note_scripts/SWAP.masm +++ b/miden-lib/asm/note_scripts/SWAP.masm @@ -4,7 +4,7 @@ use.miden::contracts::wallets::basic->wallet # CONSTANTS # ================================================================================================= -const.OFFCHAIN_NOTE=2 +const.PRIVATE_NOTE=2 # ERRORS # ================================================================================================= @@ -68,7 +68,7 @@ begin drop drop drop movdn.4 # => [ASSET, tag, RECIPIENT] - push.OFFCHAIN_NOTE movdn.5 + push.PRIVATE_NOTE movdn.5 # => [ASSET, tag, note_type, RECIPIENT] # we add aux = 0 to the note assuming we don't need it for the second leg of the SWAP diff --git a/miden-lib/src/tests/mod.rs b/miden-lib/src/tests/mod.rs index 4dca226f5..e74c43e73 100644 --- a/miden-lib/src/tests/mod.rs +++ b/miden-lib/src/tests/mod.rs @@ -8,7 +8,7 @@ use miden_objects::assembly::Library; #[test] fn test_compile() { - let path = "miden::kernels::tx::memory::get_consumed_note_ptr"; + let path = "miden::kernels::tx::memory::get_input_note_ptr"; let miden = super::MidenLib::default(); let exists = miden.modules().any(|module| { module diff --git a/miden-lib/src/transaction/memory.rs b/miden-lib/src/transaction/memory.rs index d83c51526..3cf55a9b3 100644 --- a/miden-lib/src/transaction/memory.rs +++ b/miden-lib/src/transaction/memory.rs @@ -27,11 +27,11 @@ pub const SLOT_TYPES_COMMITMENT_STORAGE_SLOT: StorageSlot = 255; /// The memory address at which the transaction vault root is stored. pub const TX_VAULT_ROOT_PTR: MemoryAddress = 0; -/// The memory address at which a pointer to the consumed note being executed is stored. -pub const CURRENT_CONSUMED_NOTE_PTR: MemoryAddress = 1; +/// The memory address at which a pointer to the input note being executed is stored. +pub const CURRENT_INPUT_NOTE_PTR: MemoryAddress = 1; -/// The memory address at which the number of created notes is stored. -pub const NUM_CREATED_NOTES_PTR: MemoryAddress = 2; +/// The memory address at which the number of output notes is stored. +pub const NUM_OUTPUT_NOTES_PTR: MemoryAddress = 2; /// The memory address at which the input vault root is stored pub const INPUT_VAULT_ROOT_PTR: MemoryAddress = 3; @@ -203,25 +203,25 @@ pub const NOTE_MEM_SIZE: MemoryAddress = 512; // - INPUTS_HASH is the key to look up note inputs in the advice map. // - ASSETS_HASH is the key to look up note assets in the advice map. -/// The memory address at which the consumed note section begins. -pub const CONSUMED_NOTE_SECTION_OFFSET: MemoryOffset = 1_048_576; +/// The memory address at which the input note section begins. +pub const INPUT_NOTE_SECTION_OFFSET: MemoryOffset = 1_048_576; -/// The memory address at which the consumed note data section begins. -pub const CONSUMED_NOTE_DATA_SECTION_OFFSET: MemoryAddress = 1_064_960; +/// The memory address at which the input note data section begins. +pub const INPUT_NOTE_DATA_SECTION_OFFSET: MemoryAddress = 1_064_960; -/// The memory address at which the number of consumed notes is stored. -pub const CONSUMED_NOTE_NUM_PTR: MemoryAddress = CONSUMED_NOTE_SECTION_OFFSET; +/// The memory address at which the number of input notes is stored. +pub const NUM_INPUT_NOTES_PTR: MemoryAddress = INPUT_NOTE_SECTION_OFFSET; -/// The offsets at which data of a consumed note is stored relative to the start of its data segment. -pub const CONSUMED_NOTE_ID_OFFSET: MemoryOffset = 0; -pub const CONSUMED_NOTE_SERIAL_NUM_OFFSET: MemoryOffset = 1; -pub const CONSUMED_NOTE_SCRIPT_ROOT_OFFSET: MemoryOffset = 2; -pub const CONSUMED_NOTE_INPUTS_HASH_OFFSET: MemoryOffset = 3; -pub const CONSUMED_NOTE_ASSETS_HASH_OFFSET: MemoryOffset = 4; -pub const CONSUMED_NOTE_METADATA_OFFSET: MemoryOffset = 5; -pub const CONSUMED_NOTE_ARGS_OFFSET: MemoryOffset = 6; -pub const CONSUMED_NOTE_NUM_ASSETS_OFFSET: MemoryOffset = 7; -pub const CONSUMED_NOTE_ASSETS_OFFSET: MemoryOffset = 8; +/// The offsets at which data of a input note is stored relative to the start of its data segment. +pub const INPUT_NOTE_ID_OFFSET: MemoryOffset = 0; +pub const INPUT_NOTE_SERIAL_NUM_OFFSET: MemoryOffset = 1; +pub const INPUT_NOTE_SCRIPT_ROOT_OFFSET: MemoryOffset = 2; +pub const INPUT_NOTE_INPUTS_HASH_OFFSET: MemoryOffset = 3; +pub const INPUT_NOTE_ASSETS_HASH_OFFSET: MemoryOffset = 4; +pub const INPUT_NOTE_METADATA_OFFSET: MemoryOffset = 5; +pub const INPUT_NOTE_ARGS_OFFSET: MemoryOffset = 6; +pub const INPUT_NOTE_NUM_ASSETS_OFFSET: MemoryOffset = 7; +pub const INPUT_NOTE_ASSETS_OFFSET: MemoryOffset = 8; // OUTPUT NOTES DATA // ------------------------------------------------------------------------------------------------ @@ -244,16 +244,16 @@ pub const CONSUMED_NOTE_ASSETS_OFFSET: MemoryOffset = 8; // Even though NUM_ASSETS takes up a while word, the actual value of this variable is stored in the // first element of the word. -/// The memory address at which the created notes section begins. -pub const CREATED_NOTE_SECTION_OFFSET: MemoryOffset = 4_194_304; +/// The memory address at which the output notes section begins. +pub const OUTPUT_NOTE_SECTION_OFFSET: MemoryOffset = 4_194_304; -/// The size of the core created note data segment. -pub const CREATED_NOTE_CORE_DATA_SIZE: MemSize = 4; +/// The size of the core output note data segment. +pub const OUTPUT_NOTE_CORE_DATA_SIZE: MemSize = 4; -/// The offsets at which data of a created note is stored relative to the start of its data segment. -pub const CREATED_NOTE_ID_OFFSET: MemoryOffset = 0; -pub const CREATED_NOTE_METADATA_OFFSET: MemoryOffset = 1; -pub const CREATED_NOTE_RECIPIENT_OFFSET: MemoryOffset = 2; -pub const CREATED_NOTE_ASSET_HASH_OFFSET: MemoryOffset = 3; -pub const CREATED_NOTE_NUM_ASSETS_OFFSET: MemoryOffset = 4; -pub const CREATED_NOTE_ASSETS_OFFSET: MemoryOffset = 5; +/// The offsets at which data of a output note is stored relative to the start of its data segment. +pub const OUTPUT_NOTE_ID_OFFSET: MemoryOffset = 0; +pub const OUTPUT_NOTE_METADATA_OFFSET: MemoryOffset = 1; +pub const OUTPUT_NOTE_RECIPIENT_OFFSET: MemoryOffset = 2; +pub const OUTPUT_NOTE_ASSET_HASH_OFFSET: MemoryOffset = 3; +pub const OUTPUT_NOTE_NUM_ASSETS_OFFSET: MemoryOffset = 4; +pub const OUTPUT_NOTE_ASSETS_OFFSET: MemoryOffset = 5; diff --git a/miden-tx/src/compiler/tests.rs b/miden-tx/src/compiler/tests.rs index a11436ac3..4ddb782e0 100644 --- a/miden-tx/src/compiler/tests.rs +++ b/miden-tx/src/compiler/tests.rs @@ -135,10 +135,7 @@ fn test_compile_valid_note_script() { } } -fn mock_consumed_notes( - tx_compiler: &mut TransactionCompiler, - target_account: AccountId, -) -> Vec { +fn mock_input_notes(tx_compiler: &mut TransactionCompiler, target_account: AccountId) -> Vec { // Note Assets let faucet_id_1 = AccountId::try_from(ACCOUNT_ID_FUNGIBLE_FAUCET_ON_CHAIN).unwrap(); let faucet_id_2 = AccountId::try_from(ACCOUNT_ID_FUNGIBLE_FAUCET_ON_CHAIN_1).unwrap(); @@ -156,7 +153,7 @@ fn mock_consumed_notes( .compile_note_script(note_program_ast, vec![ScriptTarget::AccountId(target_account)]) .unwrap(); - // Consumed Notes + // Input Notes const SERIAL_NUM_1: Word = [Felt::new(1), Felt::new(2), Felt::new(3), Felt::new(4)]; let vault = NoteAssets::new(vec![fungible_asset_1, fungible_asset_2, fungible_asset_3]).unwrap(); @@ -184,7 +181,7 @@ fn test_transaction_compilation_succeeds() { let account_code_ast = ModuleAst::parse(ACCOUNT_CODE_MASM).unwrap(); let _account_code = tx_compiler.load_account(account_id, account_code_ast).unwrap(); - let notes = mock_consumed_notes(&mut tx_compiler, account_id); + let notes = mock_input_notes(&mut tx_compiler, account_id); let mock_inclusion_proof = NoteInclusionProof::new( Default::default(), Default::default(), diff --git a/miden-tx/src/host/mod.rs b/miden-tx/src/host/mod.rs index 6f20330f0..5b9ce99a8 100644 --- a/miden-tx/src/host/mod.rs +++ b/miden-tx/src/host/mod.rs @@ -1,7 +1,7 @@ use alloc::{collections::BTreeMap, rc::Rc, string::ToString, vec::Vec}; use miden_lib::transaction::{ - memory::CURRENT_CONSUMED_NOTE_PTR, TransactionEvent, TransactionKernelError, TransactionTrace, + memory::CURRENT_INPUT_NOTE_PTR, TransactionEvent, TransactionKernelError, TransactionTrace, }; use miden_objects::{ accounts::{AccountDelta, AccountId, AccountStorage, AccountStub}, @@ -351,7 +351,7 @@ impl TransactionHost { /// greater than `u32::MAX`). fn get_current_note_id(process: &S) -> Result, ExecutionError> { // get the word where note address is stored - let note_address_word = process.get_mem_value(process.ctx(), CURRENT_CONSUMED_NOTE_PTR); + let note_address_word = process.get_mem_value(process.ctx(), CURRENT_INPUT_NOTE_PTR); // get the note address in `Felt` from or return `None` if the address hasn't been accessed // previously. let note_address_felt = match note_address_word { diff --git a/miden-tx/src/host/note_builder.rs b/miden-tx/src/host/note_builder.rs index 15bef7185..8f66ad2aa 100644 --- a/miden-tx/src/host/note_builder.rs +++ b/miden-tx/src/host/note_builder.rs @@ -107,7 +107,7 @@ impl OutputNoteBuilder { let recipient = NoteRecipient::new(serial_num, script, inputs); Some(recipient) - } else if metadata.is_offchain() { + } else if metadata.is_private() { None } else { // if there are no recipient details and the note is not private, return an error diff --git a/miden-tx/src/prover/mod.rs b/miden-tx/src/prover/mod.rs index 030f1ac6c..c89a01652 100644 --- a/miden-tx/src/prover/mod.rs +++ b/miden-tx/src/prover/mod.rs @@ -33,7 +33,7 @@ impl TransactionProver { /// Proves the provided transaction and returns a [ProvenTransaction]. /// /// # Errors - /// - If the consumed note data in the transaction witness is corrupt. + /// - If the input note data in the transaction witness is corrupt. /// - If the transaction program cannot be proven. /// - If the transaction result is corrupt. pub fn prove_transaction>( diff --git a/miden-tx/src/testing/utils.rs b/miden-tx/src/testing/utils.rs index 90e49c09f..be8ce357f 100644 --- a/miden-tx/src/testing/utils.rs +++ b/miden-tx/src/testing/utils.rs @@ -3,6 +3,6 @@ use miden_lib::transaction::memory; // TEST HELPERS // ================================================================================================ -pub fn consumed_note_data_ptr(note_idx: u32) -> memory::MemoryAddress { - memory::CONSUMED_NOTE_DATA_SECTION_OFFSET + note_idx * memory::NOTE_MEM_SIZE +pub fn input_note_data_ptr(note_idx: u32) -> memory::MemoryAddress { + memory::INPUT_NOTE_DATA_SECTION_OFFSET + note_idx * memory::NOTE_MEM_SIZE } diff --git a/miden-tx/src/tests/kernel_tests/mod.rs b/miden-tx/src/tests/kernel_tests/mod.rs index 6b218f4a0..202c0b484 100644 --- a/miden-tx/src/tests/kernel_tests/mod.rs +++ b/miden-tx/src/tests/kernel_tests/mod.rs @@ -1,9 +1,8 @@ use alloc::string::String; use miden_lib::transaction::memory::{ - CREATED_NOTE_ASSETS_OFFSET, CREATED_NOTE_METADATA_OFFSET, CREATED_NOTE_NUM_ASSETS_OFFSET, - CREATED_NOTE_RECIPIENT_OFFSET, CREATED_NOTE_SECTION_OFFSET, NOTE_MEM_SIZE, - NUM_CREATED_NOTES_PTR, + NOTE_MEM_SIZE, NUM_OUTPUT_NOTES_PTR, OUTPUT_NOTE_ASSETS_OFFSET, OUTPUT_NOTE_METADATA_OFFSET, + OUTPUT_NOTE_NUM_ASSETS_OFFSET, OUTPUT_NOTE_RECIPIENT_OFFSET, OUTPUT_NOTE_SECTION_OFFSET, }; use miden_objects::{ notes::Note, @@ -56,45 +55,45 @@ pub fn output_notes_data_procedure(notes: &[Note]) -> String { # populate note 0 push.{note_0_metadata} - push.{CREATED_NOTE_SECTION_OFFSET}.{CREATED_NOTE_METADATA_OFFSET} add mem_storew dropw + push.{OUTPUT_NOTE_SECTION_OFFSET}.{OUTPUT_NOTE_METADATA_OFFSET} add mem_storew dropw push.{note_0_recipient} - push.{CREATED_NOTE_SECTION_OFFSET}.{CREATED_NOTE_RECIPIENT_OFFSET} add mem_storew dropw + push.{OUTPUT_NOTE_SECTION_OFFSET}.{OUTPUT_NOTE_RECIPIENT_OFFSET} add mem_storew dropw push.{note_0_num_assets} - push.{CREATED_NOTE_SECTION_OFFSET}.{CREATED_NOTE_NUM_ASSETS_OFFSET} add mem_store + push.{OUTPUT_NOTE_SECTION_OFFSET}.{OUTPUT_NOTE_NUM_ASSETS_OFFSET} add mem_store push.{} - push.{CREATED_NOTE_SECTION_OFFSET}.{CREATED_NOTE_ASSETS_OFFSET} add mem_storew dropw + push.{OUTPUT_NOTE_SECTION_OFFSET}.{OUTPUT_NOTE_ASSETS_OFFSET} add mem_storew dropw # populate note 1 push.{note_1_metadata} - push.{CREATED_NOTE_SECTION_OFFSET}.{NOTE_1_OFFSET}.{CREATED_NOTE_METADATA_OFFSET} add add mem_storew dropw + push.{OUTPUT_NOTE_SECTION_OFFSET}.{NOTE_1_OFFSET}.{OUTPUT_NOTE_METADATA_OFFSET} add add mem_storew dropw push.{note_1_recipient} - push.{CREATED_NOTE_SECTION_OFFSET}.{NOTE_1_OFFSET}.{CREATED_NOTE_RECIPIENT_OFFSET} add add mem_storew dropw + push.{OUTPUT_NOTE_SECTION_OFFSET}.{NOTE_1_OFFSET}.{OUTPUT_NOTE_RECIPIENT_OFFSET} add add mem_storew dropw push.{note_1_num_assets} - push.{CREATED_NOTE_SECTION_OFFSET}.{NOTE_1_OFFSET}.{CREATED_NOTE_NUM_ASSETS_OFFSET} add add mem_store + push.{OUTPUT_NOTE_SECTION_OFFSET}.{NOTE_1_OFFSET}.{OUTPUT_NOTE_NUM_ASSETS_OFFSET} add add mem_store push.{} - push.{CREATED_NOTE_SECTION_OFFSET}.{NOTE_1_OFFSET}.{CREATED_NOTE_ASSETS_OFFSET} add add mem_storew dropw + push.{OUTPUT_NOTE_SECTION_OFFSET}.{NOTE_1_OFFSET}.{OUTPUT_NOTE_ASSETS_OFFSET} add add mem_storew dropw # populate note 2 push.{note_2_metadata} - push.{CREATED_NOTE_SECTION_OFFSET}.{NOTE_2_OFFSET}.{CREATED_NOTE_METADATA_OFFSET} add add mem_storew dropw + push.{OUTPUT_NOTE_SECTION_OFFSET}.{NOTE_2_OFFSET}.{OUTPUT_NOTE_METADATA_OFFSET} add add mem_storew dropw push.{note_2_recipient} - push.{CREATED_NOTE_SECTION_OFFSET}.{NOTE_2_OFFSET}.{CREATED_NOTE_RECIPIENT_OFFSET} add add mem_storew dropw + push.{OUTPUT_NOTE_SECTION_OFFSET}.{NOTE_2_OFFSET}.{OUTPUT_NOTE_RECIPIENT_OFFSET} add add mem_storew dropw push.{note_2_num_assets} - push.{CREATED_NOTE_SECTION_OFFSET}.{NOTE_2_OFFSET}.{CREATED_NOTE_NUM_ASSETS_OFFSET} add add mem_store + push.{OUTPUT_NOTE_SECTION_OFFSET}.{NOTE_2_OFFSET}.{OUTPUT_NOTE_NUM_ASSETS_OFFSET} add add mem_store push.{} - push.{CREATED_NOTE_SECTION_OFFSET}.{NOTE_2_OFFSET}.{CREATED_NOTE_ASSETS_OFFSET} add add mem_storew dropw + push.{OUTPUT_NOTE_SECTION_OFFSET}.{NOTE_2_OFFSET}.{OUTPUT_NOTE_ASSETS_OFFSET} add add mem_storew dropw - # set num created notes - push.{}.{NUM_CREATED_NOTES_PTR} mem_store + # set num output notes + push.{}.{NUM_OUTPUT_NOTES_PTR} mem_store end ", note_0_assets[0], diff --git a/miden-tx/src/tests/kernel_tests/test_epilogue.rs b/miden-tx/src/tests/kernel_tests/test_epilogue.rs index 447cb94cd..c9f8fdf79 100644 --- a/miden-tx/src/tests/kernel_tests/test_epilogue.rs +++ b/miden-tx/src/tests/kernel_tests/test_epilogue.rs @@ -1,7 +1,7 @@ use alloc::vec::Vec; use miden_lib::transaction::memory::{ - CREATED_NOTE_ASSET_HASH_OFFSET, CREATED_NOTE_SECTION_OFFSET, NOTE_MEM_SIZE, + NOTE_MEM_SIZE, OUTPUT_NOTE_ASSET_HASH_OFFSET, OUTPUT_NOTE_SECTION_OFFSET, }; use miden_objects::{ accounts::{account_id::testing::ACCOUNT_ID_REGULAR_ACCOUNT_UPDATABLE_CODE_OFF_CHAIN, Account}, @@ -82,7 +82,7 @@ fn test_epilogue() { } #[test] -fn test_compute_created_note_id() { +fn test_compute_output_note_id() { let tx_context = TransactionContextBuilder::with_standard_account( ACCOUNT_ID_REGULAR_ACCOUNT_UPDATABLE_CODE_OFF_CHAIN, ONE, @@ -115,14 +115,14 @@ fn test_compute_created_note_id() { note.assets().commitment().as_elements(), read_root_mem_value( &process, - CREATED_NOTE_SECTION_OFFSET + i * NOTE_MEM_SIZE + CREATED_NOTE_ASSET_HASH_OFFSET + OUTPUT_NOTE_SECTION_OFFSET + i * NOTE_MEM_SIZE + OUTPUT_NOTE_ASSET_HASH_OFFSET ), "ASSET_HASH didn't match expected value", ); assert_eq!( note.id().as_elements(), - &read_root_mem_value(&process, CREATED_NOTE_SECTION_OFFSET + i * NOTE_MEM_SIZE), + &read_root_mem_value(&process, OUTPUT_NOTE_SECTION_OFFSET + i * NOTE_MEM_SIZE), "NOTE_ID didn't match expected value", ); } diff --git a/miden-tx/src/tests/kernel_tests/test_note.rs b/miden-tx/src/tests/kernel_tests/test_note.rs index 6b11cde0c..0a0823e3c 100644 --- a/miden-tx/src/tests/kernel_tests/test_note.rs +++ b/miden-tx/src/tests/kernel_tests/test_note.rs @@ -1,6 +1,6 @@ use alloc::{collections::BTreeMap, string::String}; -use miden_lib::transaction::memory::CURRENT_CONSUMED_NOTE_PTR; +use miden_lib::transaction::memory::CURRENT_INPUT_NOTE_PTR; use miden_objects::{ accounts::account_id::testing::ACCOUNT_ID_REGULAR_ACCOUNT_UPDATABLE_CODE_OFF_CHAIN, notes::Note, testing::prepare_word, transaction::TransactionArgs, Hasher, WORD_SIZE, @@ -10,7 +10,7 @@ use vm_processor::{ProcessState, EMPTY_WORD, ONE}; use super::{Felt, Process, ZERO}; use crate::{ testing::{ - utils::consumed_note_data_ptr, MockHost, TransactionContext, TransactionContextBuilder, + utils::input_note_data_ptr, MockHost, TransactionContext, TransactionContextBuilder, }, tests::kernel_tests::read_root_mem_value, }; @@ -31,8 +31,8 @@ fn test_get_sender_no_sender() { begin exec.prologue::prepare_transaction - # force the current consumed note pointer to 0 - push.0 exec.memory::set_current_consumed_note_ptr + # force the current input note pointer to 0 + push.0 exec.memory::set_current_input_note_ptr # get the sender exec.note::get_sender @@ -84,7 +84,7 @@ fn test_get_vault_data() { let notes = tx_context.input_notes(); - // calling get_vault_info should return vault info + // calling get_assets_info should return assets info let code = format!( " use.miden::kernels::tx::prologue @@ -96,23 +96,23 @@ fn test_get_vault_data() { # prepare note 0 exec.note::prepare_note - # get the vault data - exec.note::get_vault_info + # get the assets info + exec.note::get_assets_info - # assert the vault data is correct + # assert the assets data is correct push.{note_0_asset_hash} assert_eqw push.{note_0_num_assets} assert_eq - # increment current consumed note pointer - exec.note::increment_current_consumed_note_ptr + # increment current input note pointer + exec.note::increment_current_input_note_ptr # prepare note 1 exec.note::prepare_note - # get the vault data - exec.note::get_vault_info + # get the assets data + exec.note::get_assets_info - # assert the vault data is correct + # assert the assets data is correct push.{note_1_asset_hash} assert_eqw push.{note_1_num_assets} assert_eq end @@ -216,8 +216,8 @@ fn test_get_assets() { # process note 0 call.process_note_0 - # increment current consumed note pointer - exec.note_internal::increment_current_consumed_note_ptr + # increment current input note pointer + exec.note_internal::increment_current_input_note_ptr # prepare note 1 exec.note_internal::prepare_note @@ -355,9 +355,9 @@ fn test_note_script_and_note_args() { begin exec.prologue::prepare_transaction - exec.memory::get_total_num_consumed_notes push.2 assert_eq + exec.memory::get_num_input_notes push.2 assert_eq exec.note::prepare_note dropw - exec.note::increment_current_consumed_note_ptr drop + exec.note::increment_current_input_note_ptr drop exec.note::prepare_note dropw end "; @@ -393,8 +393,8 @@ fn note_setup_stack_assertions(process: &Process, inputs: &Transaction fn note_setup_memory_assertions(process: &Process) { // assert that the correct pointer is stored in bookkeeping memory assert_eq!( - read_root_mem_value(process, CURRENT_CONSUMED_NOTE_PTR)[0], - Felt::from(consumed_note_data_ptr(0)) + read_root_mem_value(process, CURRENT_INPUT_NOTE_PTR)[0], + Felt::from(input_note_data_ptr(0)) ); } diff --git a/miden-tx/src/tests/kernel_tests/test_prologue.rs b/miden-tx/src/tests/kernel_tests/test_prologue.rs index 436eda374..13d56868a 100644 --- a/miden-tx/src/tests/kernel_tests/test_prologue.rs +++ b/miden-tx/src/tests/kernel_tests/test_prologue.rs @@ -5,14 +5,13 @@ use miden_lib::transaction::{ MemoryOffset, ACCT_CODE_ROOT_PTR, ACCT_DB_ROOT_PTR, ACCT_ID_AND_NONCE_PTR, ACCT_ID_PTR, ACCT_STORAGE_ROOT_PTR, ACCT_STORAGE_SLOT_TYPE_DATA_OFFSET, ACCT_VAULT_ROOT_PTR, BLK_HASH_PTR, BLOCK_METADATA_PTR, BLOCK_NUMBER_IDX, CHAIN_MMR_NUM_LEAVES_PTR, - CHAIN_MMR_PEAKS_PTR, CHAIN_ROOT_PTR, CONSUMED_NOTE_ARGS_OFFSET, - CONSUMED_NOTE_ASSETS_HASH_OFFSET, CONSUMED_NOTE_ASSETS_OFFSET, CONSUMED_NOTE_ID_OFFSET, - CONSUMED_NOTE_INPUTS_HASH_OFFSET, CONSUMED_NOTE_METADATA_OFFSET, - CONSUMED_NOTE_NUM_ASSETS_OFFSET, CONSUMED_NOTE_SCRIPT_ROOT_OFFSET, - CONSUMED_NOTE_SECTION_OFFSET, CONSUMED_NOTE_SERIAL_NUM_OFFSET, INIT_ACCT_HASH_PTR, - INIT_NONCE_PTR, INPUT_NOTES_COMMITMENT_PTR, NOTE_ROOT_PTR, NULLIFIER_DB_ROOT_PTR, - PREV_BLOCK_HASH_PTR, PROOF_HASH_PTR, PROTOCOL_VERSION_IDX, TIMESTAMP_IDX, TX_HASH_PTR, - TX_SCRIPT_ROOT_PTR, + CHAIN_MMR_PEAKS_PTR, CHAIN_ROOT_PTR, INIT_ACCT_HASH_PTR, INIT_NONCE_PTR, + INPUT_NOTES_COMMITMENT_PTR, INPUT_NOTE_ARGS_OFFSET, INPUT_NOTE_ASSETS_HASH_OFFSET, + INPUT_NOTE_ASSETS_OFFSET, INPUT_NOTE_ID_OFFSET, INPUT_NOTE_INPUTS_HASH_OFFSET, + INPUT_NOTE_METADATA_OFFSET, INPUT_NOTE_NUM_ASSETS_OFFSET, INPUT_NOTE_SCRIPT_ROOT_OFFSET, + INPUT_NOTE_SECTION_OFFSET, INPUT_NOTE_SERIAL_NUM_OFFSET, NOTE_ROOT_PTR, + NULLIFIER_DB_ROOT_PTR, PREV_BLOCK_HASH_PTR, PROOF_HASH_PTR, PROTOCOL_VERSION_IDX, + TIMESTAMP_IDX, TX_HASH_PTR, TX_SCRIPT_ROOT_PTR, }, TransactionKernel, }; @@ -31,7 +30,7 @@ use vm_processor::{AdviceInputs, ONE}; use super::{Felt, Process, Word, ZERO}; use crate::{ testing::{ - utils::consumed_note_data_ptr, MockHost, TransactionContext, TransactionContextBuilder, + utils::input_note_data_ptr, MockHost, TransactionContext, TransactionContextBuilder, }, tests::kernel_tests::read_root_mem_value, }; @@ -91,7 +90,7 @@ fn test_transaction_prologue() { block_data_memory_assertions(&process, &tx_context); chain_mmr_memory_assertions(&process, &tx_context); account_data_memory_assertions(&process, &tx_context); - consumed_notes_memory_assertions(&process, &tx_context, ¬e_args); + input_notes_memory_assertions(&process, &tx_context, ¬e_args); } fn global_input_memory_assertions(process: &Process, inputs: &TransactionContext) { @@ -260,70 +259,70 @@ fn account_data_memory_assertions(process: &Process, inputs: &Transact } } -fn consumed_notes_memory_assertions( +fn input_notes_memory_assertions( process: &Process, inputs: &TransactionContext, note_args: &[[Felt; 4]], ) { assert_eq!( - read_root_mem_value(process, CONSUMED_NOTE_SECTION_OFFSET), + read_root_mem_value(process, INPUT_NOTE_SECTION_OFFSET), [Felt::new(inputs.input_notes().num_notes() as u64), ZERO, ZERO, ZERO], - "number of consumed notes should be stored at the CONSUMED_NOTES_OFFSET" + "number of input notes should be stored at the INPUT_NOTES_OFFSET" ); for (input_note, note_idx) in inputs.input_notes().iter().zip(0_u32..) { let note = input_note.note(); assert_eq!( - read_root_mem_value(process, CONSUMED_NOTE_SECTION_OFFSET + 1 + note_idx), + read_root_mem_value(process, INPUT_NOTE_SECTION_OFFSET + 1 + note_idx), note.nullifier().as_elements(), "note nullifier should be computer and stored at the correct offset" ); assert_eq!( - read_note_element(process, note_idx, CONSUMED_NOTE_ID_OFFSET), + read_note_element(process, note_idx, INPUT_NOTE_ID_OFFSET), note.id().as_elements(), "ID hash should be computed and stored at the correct offset" ); assert_eq!( - read_note_element(process, note_idx, CONSUMED_NOTE_SERIAL_NUM_OFFSET), + read_note_element(process, note_idx, INPUT_NOTE_SERIAL_NUM_OFFSET), note.serial_num(), "note serial num should be stored at the correct offset" ); assert_eq!( - read_note_element(process, note_idx, CONSUMED_NOTE_SCRIPT_ROOT_OFFSET), + read_note_element(process, note_idx, INPUT_NOTE_SCRIPT_ROOT_OFFSET), note.script().hash().as_elements(), "note script hash should be stored at the correct offset" ); assert_eq!( - read_note_element(process, note_idx, CONSUMED_NOTE_INPUTS_HASH_OFFSET), + read_note_element(process, note_idx, INPUT_NOTE_INPUTS_HASH_OFFSET), note.inputs().commitment().as_elements(), "note input hash should be stored at the correct offset" ); assert_eq!( - read_note_element(process, note_idx, CONSUMED_NOTE_ASSETS_HASH_OFFSET), + read_note_element(process, note_idx, INPUT_NOTE_ASSETS_HASH_OFFSET), note.assets().commitment().as_elements(), "note asset hash should be stored at the correct offset" ); assert_eq!( - read_note_element(process, note_idx, CONSUMED_NOTE_METADATA_OFFSET), + read_note_element(process, note_idx, INPUT_NOTE_METADATA_OFFSET), Word::from(note.metadata()), "note metadata should be stored at the correct offset" ); assert_eq!( - read_note_element(process, note_idx, CONSUMED_NOTE_ARGS_OFFSET), + read_note_element(process, note_idx, INPUT_NOTE_ARGS_OFFSET), Word::from(note_args[note_idx as usize]), "note args should be stored at the correct offset" ); assert_eq!( - read_note_element(process, note_idx, CONSUMED_NOTE_NUM_ASSETS_OFFSET), + read_note_element(process, note_idx, INPUT_NOTE_NUM_ASSETS_OFFSET), [Felt::from(note.assets().num_assets() as u32), ZERO, ZERO, ZERO], "number of assets should be stored at the correct offset" ); @@ -331,8 +330,9 @@ fn consumed_notes_memory_assertions( for (asset, asset_idx) in note.assets().iter().cloned().zip(0_u32..) { let word: Word = asset.into(); assert_eq!( - read_note_element(process, note_idx, CONSUMED_NOTE_ASSETS_OFFSET + asset_idx), - word, "assets should be stored at (CONSUMED_NOTES_OFFSET + (note_index + 1) * 1024 + 7..)" + read_note_element(process, note_idx, INPUT_NOTE_ASSETS_OFFSET + asset_idx), + word, + "assets should be stored at (INPUT_NOTES_OFFSET + (note_index + 1) * 1024 + 7..)" ); } } @@ -543,5 +543,5 @@ fn test_get_blk_timestamp() { // ================================================================================================ fn read_note_element(process: &Process, note_idx: u32, offset: MemoryOffset) -> Word { - read_root_mem_value(process, consumed_note_data_ptr(note_idx) + offset) + read_root_mem_value(process, input_note_data_ptr(note_idx) + offset) } diff --git a/miden-tx/src/tests/kernel_tests/test_tx.rs b/miden-tx/src/tests/kernel_tests/test_tx.rs index 7d8ad4730..8d8cbe6bb 100644 --- a/miden-tx/src/tests/kernel_tests/test_tx.rs +++ b/miden-tx/src/tests/kernel_tests/test_tx.rs @@ -1,8 +1,8 @@ use alloc::vec::Vec; use miden_lib::transaction::memory::{ - CREATED_NOTE_ASSETS_OFFSET, CREATED_NOTE_METADATA_OFFSET, CREATED_NOTE_RECIPIENT_OFFSET, - CREATED_NOTE_SECTION_OFFSET, NOTE_MEM_SIZE, NUM_CREATED_NOTES_PTR, + NOTE_MEM_SIZE, NUM_OUTPUT_NOTES_PTR, OUTPUT_NOTE_ASSETS_OFFSET, OUTPUT_NOTE_METADATA_OFFSET, + OUTPUT_NOTE_RECIPIENT_OFFSET, OUTPUT_NOTE_SECTION_OFFSET, }; use miden_objects::{ accounts::account_id::testing::{ @@ -59,19 +59,19 @@ fn test_create_note() { let process = tx_context.execute_code(&code).unwrap(); assert_eq!( - read_root_mem_value(&process, NUM_CREATED_NOTES_PTR), + read_root_mem_value(&process, NUM_OUTPUT_NOTES_PTR), [ONE, ZERO, ZERO, ZERO], - "number of created notes must increment by 1", + "number of output notes must increment by 1", ); assert_eq!( - read_root_mem_value(&process, CREATED_NOTE_SECTION_OFFSET + CREATED_NOTE_RECIPIENT_OFFSET), + read_root_mem_value(&process, OUTPUT_NOTE_SECTION_OFFSET + OUTPUT_NOTE_RECIPIENT_OFFSET), recipient, "recipient must be stored at the correct memory location", ); assert_eq!( - read_root_mem_value(&process, CREATED_NOTE_SECTION_OFFSET + CREATED_NOTE_METADATA_OFFSET), + read_root_mem_value(&process, OUTPUT_NOTE_SECTION_OFFSET + OUTPUT_NOTE_METADATA_OFFSET), [tag, Felt::from(account_id), NoteType::Public.into(), Felt::new(27)], "metadata must be stored at the correct memory location", ); @@ -79,7 +79,7 @@ fn test_create_note() { assert_eq!( process.stack.get(0), ZERO, - "top item on the stack is the index of the created note" + "top item on the stack is the index of the output note" ); } @@ -131,8 +131,8 @@ fn test_create_note_too_many_notes() { use.miden::tx begin - exec.constants::get_max_num_created_notes - exec.memory::set_num_created_notes + exec.constants::get_max_num_output_notes + exec.memory::set_num_output_notes push.{recipient} push.{PUBLIC_NOTE} @@ -267,14 +267,14 @@ fn test_get_output_notes_hash() { let process = tx_context.execute_code(&code).unwrap(); assert_eq!( - read_root_mem_value(&process, NUM_CREATED_NOTES_PTR), + read_root_mem_value(&process, NUM_OUTPUT_NOTES_PTR), [Felt::new(2), ZERO, ZERO, ZERO], "The test creates two notes", ); assert_eq!( NoteMetadata::try_from(read_root_mem_value( &process, - CREATED_NOTE_SECTION_OFFSET + CREATED_NOTE_METADATA_OFFSET + OUTPUT_NOTE_SECTION_OFFSET + OUTPUT_NOTE_METADATA_OFFSET )) .unwrap(), *output_note_1.metadata(), @@ -283,7 +283,7 @@ fn test_get_output_notes_hash() { assert_eq!( NoteMetadata::try_from(read_root_mem_value( &process, - CREATED_NOTE_SECTION_OFFSET + CREATED_NOTE_METADATA_OFFSET + NOTE_MEM_SIZE + OUTPUT_NOTE_SECTION_OFFSET + OUTPUT_NOTE_METADATA_OFFSET + NOTE_MEM_SIZE )) .unwrap(), *output_note_2.metadata(), @@ -337,7 +337,7 @@ fn test_create_note_and_add_asset() { let process = tx_context.execute_code(&code).unwrap(); assert_eq!( - read_root_mem_value(&process, CREATED_NOTE_SECTION_OFFSET + CREATED_NOTE_ASSETS_OFFSET), + read_root_mem_value(&process, OUTPUT_NOTE_SECTION_OFFSET + OUTPUT_NOTE_ASSETS_OFFSET), asset, "asset must be stored at the correct memory location", ); @@ -345,7 +345,7 @@ fn test_create_note_and_add_asset() { assert_eq!( process.stack.get(0), ZERO, - "top item on the stack is the index to the created note" + "top item on the stack is the index to the output note" ); } @@ -416,19 +416,19 @@ fn test_create_note_and_add_multiple_assets() { let process = tx_context.execute_code(&code).unwrap(); assert_eq!( - read_root_mem_value(&process, CREATED_NOTE_SECTION_OFFSET + CREATED_NOTE_ASSETS_OFFSET), + read_root_mem_value(&process, OUTPUT_NOTE_SECTION_OFFSET + OUTPUT_NOTE_ASSETS_OFFSET), asset, "asset must be stored at the correct memory location", ); assert_eq!( - read_root_mem_value(&process, CREATED_NOTE_SECTION_OFFSET + CREATED_NOTE_ASSETS_OFFSET + 1), + read_root_mem_value(&process, OUTPUT_NOTE_SECTION_OFFSET + OUTPUT_NOTE_ASSETS_OFFSET + 1), asset_2_and_3, "asset_2 and asset_3 must be stored at the same correct memory location", ); assert_eq!( - read_root_mem_value(&process, CREATED_NOTE_SECTION_OFFSET + CREATED_NOTE_ASSETS_OFFSET + 2), + read_root_mem_value(&process, OUTPUT_NOTE_SECTION_OFFSET + OUTPUT_NOTE_ASSETS_OFFSET + 2), Word::from(non_fungible_asset_encoded), "non_fungible_asset must be stored at the correct memory location", ); @@ -436,7 +436,7 @@ fn test_create_note_and_add_multiple_assets() { assert_eq!( process.stack.get(0), ZERO, - "top item on the stack is the index to the created note" + "top item on the stack is the index to the output note" ); } @@ -540,15 +540,15 @@ fn test_build_recipient_hash() { let process = tx_context.execute_code(&code).unwrap(); assert_eq!( - read_root_mem_value(&process, NUM_CREATED_NOTES_PTR), + read_root_mem_value(&process, NUM_OUTPUT_NOTES_PTR), [ONE, ZERO, ZERO, ZERO], - "number of created notes must increment by 1", + "number of output notes must increment by 1", ); let recipient_digest: Vec = recipient.clone().digest().to_vec(); assert_eq!( - read_root_mem_value(&process, CREATED_NOTE_SECTION_OFFSET + CREATED_NOTE_RECIPIENT_OFFSET), + read_root_mem_value(&process, OUTPUT_NOTE_SECTION_OFFSET + OUTPUT_NOTE_RECIPIENT_OFFSET), recipient_digest.as_slice(), "recipient hash not correct", ); diff --git a/miden-tx/src/tests/mod.rs b/miden-tx/src/tests/mod.rs index 1381bf70c..f5ae0d67d 100644 --- a/miden-tx/src/tests/mod.rs +++ b/miden-tx/src/tests/mod.rs @@ -156,9 +156,9 @@ fn executed_transaction_account_delta() { let aux2 = Felt::new(28); let aux3 = Felt::new(29); - let note_type1 = NoteType::OffChain; - let note_type2 = NoteType::OffChain; - let note_type3 = NoteType::OffChain; + let note_type1 = NoteType::Private; + let note_type2 = NoteType::Private; + let note_type3 = NoteType::Private; assert_eq!(tag1.validate(note_type1), Ok(tag1)); assert_eq!(tag2.validate(note_type2), Ok(tag2)); @@ -431,7 +431,7 @@ fn executed_transaction_output_notes() { let aux2 = Felt::new(28); let aux3 = Felt::new(29); - let note_type1 = NoteType::OffChain; + let note_type1 = NoteType::Private; let note_type2 = NoteType::Public; let note_type3 = NoteType::Public; @@ -593,22 +593,22 @@ fn executed_transaction_output_notes() { // NOTE: the mock state already contains 3 output notes assert_eq!(output_notes.num_notes(), 6); - let created_note_id_3 = executed_transaction.output_notes().get_note(3).id(); + let output_note_id_3 = executed_transaction.output_notes().get_note(3).id(); let recipient_3 = Digest::from([Felt::new(0), Felt::new(1), Felt::new(2), Felt::new(3)]); let note_assets_3 = NoteAssets::new(vec![combined_asset]).unwrap(); let expected_note_id_3 = NoteId::new(recipient_3, note_assets_3.commitment()); - assert_eq!(created_note_id_3, expected_note_id_3); + assert_eq!(output_note_id_3, expected_note_id_3); // assert that the expected output note 2 is present - let created_note = executed_transaction.output_notes().get_note(4); + let output_note = executed_transaction.output_notes().get_note(4); let note_id = expected_output_note_2.id(); let note_metadata = expected_output_note_2.metadata(); - assert_eq!(NoteHeader::from(created_note), NoteHeader::new(note_id, *note_metadata)); + assert_eq!(NoteHeader::from(output_note), NoteHeader::new(note_id, *note_metadata)); // assert that the expected output note 3 is present and has no assets - let created_note_3 = executed_transaction.output_notes().get_note(5); - assert_eq!(expected_output_note_3.id(), created_note_3.id()); - assert_eq!(expected_output_note_3.assets(), created_note_3.assets().unwrap()); + let output_note_3 = executed_transaction.output_notes().get_note(5); + assert_eq!(expected_output_note_3.id(), output_note_3.id()); + assert_eq!(expected_output_note_3.assets(), output_note_3.assets().unwrap()); } #[test] diff --git a/miden-tx/tests/integration/assets/test.masm b/miden-tx/tests/integration/assets/test.masm index dbeffc726..8e407b9c8 100644 --- a/miden-tx/tests/integration/assets/test.masm +++ b/miden-tx/tests/integration/assets/test.masm @@ -5,10 +5,10 @@ use.miden::kernels::utils # CONSTANTS # ================================================================================================= -const.CREATED_NOTES_OFFSET=10000 +const.OUTPUT_NOTES_OFFSET=10000 -# The memory address at the number of created notes is stored. -const.NUM_CREATED_NOTES_PTR=2 +# The memory address at which the number of output notes is stored. +const.NUM_OUTPUT_NOTES_PTR=2 # TEST UTILS # ================================================================================================= @@ -68,7 +68,7 @@ proc.create_mock_notes push.100.0.0.12033618204333965332 push.10000.2048.7 add add mem_storew dropw - # set num created notes + # set num output notes push.3.2 mem_store end diff --git a/miden-tx/tests/integration/scripts/faucet.rs b/miden-tx/tests/integration/scripts/faucet.rs index 7dd56230c..9d396e416 100644 --- a/miden-tx/tests/integration/scripts/faucet.rs +++ b/miden-tx/tests/integration/scripts/faucet.rs @@ -55,7 +55,7 @@ fn prove_faucet_contract_mint_fungible_asset_succeeds() { let recipient = [Felt::new(0), Felt::new(1), Felt::new(2), Felt::new(3)]; let tag = NoteTag::for_local_use_case(0, 0).unwrap(); let aux = Felt::new(27); - let note_type = NoteType::OffChain; + let note_type = NoteType::Private; let amount = Felt::new(100); assert_eq!(tag.validate(note_type), Ok(tag)); @@ -101,15 +101,15 @@ fn prove_faucet_contract_mint_fungible_asset_succeeds() { let fungible_asset: Asset = FungibleAsset::new(faucet_account.id(), amount.into()).unwrap().into(); - let created_note = executed_transaction.output_notes().get_note(0).clone(); + let output_note = executed_transaction.output_notes().get_note(0).clone(); let assets = NoteAssets::new(vec![fungible_asset]).unwrap(); let id = NoteId::new(recipient.into(), assets.commitment()); - assert_eq!(created_note.id(), id); + assert_eq!(output_note.id(), id); assert_eq!( - created_note.metadata(), - &NoteMetadata::new(faucet_account.id(), NoteType::OffChain, tag, aux).unwrap() + output_note.metadata(), + &NoteMetadata::new(faucet_account.id(), NoteType::Private, tag, aux).unwrap() ); } @@ -159,7 +159,7 @@ fn faucet_contract_mint_fungible_asset_fails_exceeds_max_supply() { end ", - note_type = NoteType::OffChain as u8, + note_type = NoteType::Private as u8, recipient = prepare_word(&recipient), ) .as_str(), diff --git a/miden-tx/tests/integration/scripts/swap.rs b/miden-tx/tests/integration/scripts/swap.rs index 1f569f35d..a6380676d 100644 --- a/miden-tx/tests/integration/scripts/swap.rs +++ b/miden-tx/tests/integration/scripts/swap.rs @@ -100,16 +100,15 @@ fn prove_swap_script() { // Check if only one `Note` has been created assert_eq!(executed_transaction.output_notes().num_notes(), 1); - // Check if the created `Note` is what we expect + // Check if the output `Note` is what we expect let recipient = payback_note.recipient().clone(); let tag = NoteTag::from_account_id(sender_account_id, NoteExecutionHint::Local).unwrap(); - let note_metadata = - NoteMetadata::new(target_account_id, NoteType::OffChain, tag, ZERO).unwrap(); + let note_metadata = NoteMetadata::new(target_account_id, NoteType::Private, tag, ZERO).unwrap(); let assets = NoteAssets::new(vec![requested_asset]).unwrap(); let note_id = NoteId::new(recipient.digest(), assets.commitment()); - let created_note = executed_transaction.output_notes().get_note(0); - assert_eq!(NoteHeader::from(created_note), NoteHeader::new(note_id, note_metadata)); + let output_note = executed_transaction.output_notes().get_note(0); + assert_eq!(NoteHeader::from(output_note), NoteHeader::new(note_id, note_metadata)); // Prove, serialize/deserialize and verify the transaction assert!(prove_and_verify_transaction(executed_transaction.clone()).is_ok()); diff --git a/miden-tx/tests/integration/wallet/mod.rs b/miden-tx/tests/integration/wallet/mod.rs index 7e4be695a..8a966bfd4 100644 --- a/miden-tx/tests/integration/wallet/mod.rs +++ b/miden-tx/tests/integration/wallet/mod.rs @@ -142,7 +142,7 @@ fn prove_send_asset_via_wallet() { let recipient = [ZERO, ONE, Felt::new(2), Felt::new(3)]; let aux = Felt::new(27); let tag = NoteTag::for_local_use_case(0, 0).unwrap(); - let note_type = NoteType::OffChain; + let note_type = NoteType::Private; assert_eq!(tag.validate(note_type), Ok(tag)); diff --git a/objects/src/block/mod.rs b/objects/src/block/mod.rs index f8fd559d9..9a50f05e7 100644 --- a/objects/src/block/mod.rs +++ b/objects/src/block/mod.rs @@ -44,11 +44,11 @@ pub struct Block { /// Account updates for the block. updated_accounts: Vec, - /// Note batches created in transactions in the block. - created_notes: Vec, + /// Note batches created by the transactions in this block. + output_note_batches: Vec, - /// Nullifiers produced in transactions in the block. - created_nullifiers: Vec, + /// Nullifiers produced by the transactions in this block. + nullifiers: Vec, // // TODO: add zk proof } @@ -60,14 +60,14 @@ impl Block { pub fn new( header: BlockHeader, updated_accounts: Vec, - created_notes: Vec, - created_nullifiers: Vec, + output_note_batches: Vec, + nullifiers: Vec, ) -> Result { let block = Self { header, updated_accounts, - created_notes, - created_nullifiers, + output_note_batches, + nullifiers, }; block.validate()?; @@ -91,16 +91,16 @@ impl Block { } /// Returns a set of note batches containing all notes created in this block. - pub fn created_notes(&self) -> &[NoteBatch] { - &self.created_notes + pub fn output_note_batches(&self) -> &[NoteBatch] { + &self.output_note_batches } /// Returns an iterator over all notes created in this block. /// /// Each note is accompanied by a corresponding index specifying where the note is located - /// in the blocks note tree. + /// in the block's note tree. pub fn notes(&self) -> impl Iterator { - self.created_notes.iter().enumerate().flat_map(|(batch_idx, notes)| { + self.output_note_batches.iter().enumerate().flat_map(|(batch_idx, notes)| { notes.iter().enumerate().map(move |(note_idx_in_batch, note)| { (BlockNoteIndex::new(batch_idx, note_idx_in_batch), note) }) @@ -118,11 +118,12 @@ impl Block { } /// Returns a set of nullifiers for all notes consumed in the block. - pub fn created_nullifiers(&self) -> &[Nullifier] { - &self.created_nullifiers + pub fn nullifiers(&self) -> &[Nullifier] { + &self.nullifiers } - /// Returns an iterator over all transactions which affected accounts in the block with corresponding account IDs. + /// Returns an iterator over all transactions which affected accounts in the block with + /// corresponding account IDs. pub fn transactions(&self) -> impl Iterator + '_ { self.updated_accounts.iter().flat_map(|update| { update @@ -141,19 +142,19 @@ impl Block { // -------------------------------------------------------------------------------------------- fn validate(&self) -> Result<(), BlockError> { - let batch_count = self.created_notes.len(); + let batch_count = self.output_note_batches.len(); if batch_count > MAX_BATCHES_PER_BLOCK { return Err(BlockError::TooManyTransactionBatches(batch_count)); } - for batch in self.created_notes.iter() { + for batch in self.output_note_batches.iter() { if batch.len() > MAX_NOTES_PER_BATCH { return Err(BlockError::TooManyNotesInBatch(batch.len())); } } let mut notes = BTreeSet::new(); - for batch in self.created_notes.iter() { + for batch in self.output_note_batches.iter() { for note in batch.iter() { if !notes.insert(note.id()) { return Err(BlockError::DuplicateNoteFound(note.id())); @@ -169,8 +170,8 @@ impl Serializable for Block { fn write_into(&self, target: &mut W) { self.header.write_into(target); self.updated_accounts.write_into(target); - self.created_notes.write_into(target); - self.created_nullifiers.write_into(target); + self.output_note_batches.write_into(target); + self.nullifiers.write_into(target); } } @@ -179,8 +180,8 @@ impl Deserializable for Block { let block = Self { header: BlockHeader::read_from(source)?, updated_accounts: >::read_from(source)?, - created_notes: >::read_from(source)?, - created_nullifiers: >::read_from(source)?, + output_note_batches: >::read_from(source)?, + nullifiers: >::read_from(source)?, }; block diff --git a/objects/src/constants.rs b/objects/src/constants.rs index bf2a8df5a..84bab520a 100644 --- a/objects/src/constants.rs +++ b/objects/src/constants.rs @@ -25,7 +25,7 @@ pub const MIN_PROOF_SECURITY_LEVEL: u32 = 96; // TRANSACTION BATCH // ================================================================================================ -/// The depth of the Sparse Merkle Tree used to store created notes in a single batch. +/// The depth of the Sparse Merkle Tree used to store output notes in a single batch. /// /// A single note uses two leaves in the tree. The even leaf is used to store the note's id, the /// odd leaf is used to store the note's metadata. @@ -47,7 +47,7 @@ pub const MAX_TRANSACTIONS_PER_BATCH: usize = MAX_NOTES_PER_BATCH / MAX_OUTPUT_N /// /// This value can be interpreted as: /// -/// - The depth of a tree with the leaves set to a batch created note tree root. +/// - The depth of a tree with the leaves set to a batch output note tree root. /// - The level at which the batches create note trees are merged, creating a new tree with this many /// additional new levels. pub const BLOCK_OUTPUT_NOTES_BATCH_TREE_DEPTH: u8 = 8; diff --git a/objects/src/notes/metadata.rs b/objects/src/notes/metadata.rs index 77e06859c..cda958bfe 100644 --- a/objects/src/notes/metadata.rs +++ b/objects/src/notes/metadata.rs @@ -67,9 +67,9 @@ impl NoteMetadata { self.aux } - /// Returns `true` if the note is off-chain. - pub fn is_offchain(&self) -> bool { - self.note_type == NoteType::OffChain + /// Returns `true` if the note is private. + pub fn is_private(&self) -> bool { + self.note_type == NoteType::Private } } diff --git a/objects/src/notes/note_tag.rs b/objects/src/notes/note_tag.rs index a5dbad0b8..d08443d9d 100644 --- a/objects/src/notes/note_tag.rs +++ b/objects/src/notes/note_tag.rs @@ -146,7 +146,7 @@ impl NoteTag { /// Returns a new [NoteTag] instantiated for a custom local use case. /// - /// The local use_case tag is the only tag type that allows for [NoteType::OffChain] notes. + /// The local use_case tag is the only tag type that allows for [NoteType::Private] notes. /// /// The two high bits are set to the `b11`, the next 14 bits are set to the `use_case_id`, and /// the low 16 bits are set to `payload`. @@ -350,8 +350,8 @@ mod tests { "Network execution requires public notes" ); assert_eq!( - tag.validate(NoteType::OffChain), - Err(NoteError::NetworkExecutionRequiresPublicNote(NoteType::OffChain)) + tag.validate(NoteType::Private), + Err(NoteError::NetworkExecutionRequiresPublicNote(NoteType::Private)) ); assert_eq!( tag.validate(NoteType::Encrypted), @@ -371,9 +371,9 @@ mod tests { "Local execution supports public notes" ); assert_eq!( - tag.validate(NoteType::OffChain), + tag.validate(NoteType::Private), Ok(tag), - "Local execution supports offchain notes" + "Local execution supports private notes" ); assert_eq!( tag.validate(NoteType::Encrypted), @@ -394,9 +394,9 @@ mod tests { "Local execution supports public notes" ); assert_eq!( - tag.validate(NoteType::OffChain), + tag.validate(NoteType::Private), Ok(tag), - "Local execution supports offchain notes" + "Local execution supports private notes" ); assert_eq!( tag.validate(NoteType::Encrypted), @@ -439,8 +439,8 @@ mod tests { let tag = tag.unwrap(); assert_eq!(tag.validate(NoteType::Public), Ok(tag)); assert_eq!( - tag.validate(NoteType::OffChain), - Err(NoteError::NetworkExecutionRequiresPublicNote(NoteType::OffChain)) + tag.validate(NoteType::Private), + Err(NoteError::NetworkExecutionRequiresPublicNote(NoteType::Private)) ); assert_eq!( tag.validate(NoteType::Encrypted), @@ -464,8 +464,8 @@ mod tests { let tag = tag.unwrap(); assert_eq!(tag.validate(NoteType::Public), Ok(tag)); assert_eq!( - tag.validate(NoteType::OffChain), - Err(NoteError::PublicUseCaseRequiresPublicNote(NoteType::OffChain)) + tag.validate(NoteType::Private), + Err(NoteError::PublicUseCaseRequiresPublicNote(NoteType::Private)) ); assert_eq!( tag.validate(NoteType::Encrypted), @@ -497,9 +497,9 @@ mod tests { "Local execution supports private notes" ); assert_eq!( - tag.validate(NoteType::OffChain), + tag.validate(NoteType::Private), Ok(tag), - "Local execution supports offchain notes" + "Local execution supports private notes" ); assert_eq!( tag.validate(NoteType::Encrypted), diff --git a/objects/src/notes/note_type.rs b/objects/src/notes/note_type.rs index 18eb48040..62cb4e845 100644 --- a/objects/src/notes/note_type.rs +++ b/objects/src/notes/note_type.rs @@ -8,7 +8,7 @@ use crate::{ // Keep these masks in sync with `miden-lib/asm/miden/kernels/tx/tx.masm` const PUBLIC: u8 = 0b01; -const OFF_CHAIN: u8 = 0b10; +const PRIVATE: u8 = 0b10; const ENCRYPTED: u8 = 0b11; // NOTE TYPE @@ -19,7 +19,7 @@ const ENCRYPTED: u8 = 0b11; #[repr(u8)] pub enum NoteType { /// Notes with this type have only their hash published to the network. - OffChain = OFF_CHAIN, + Private = PRIVATE, /// Notes with type are shared with the network encrypted. Encrypted = ENCRYPTED, @@ -45,7 +45,7 @@ impl TryFrom for NoteType { fn try_from(value: u8) -> Result { match value { - OFF_CHAIN => Ok(NoteType::OffChain), + PRIVATE => Ok(NoteType::Private), ENCRYPTED => Ok(NoteType::Encrypted), PUBLIC => Ok(NoteType::Public), _ => Err(NoteError::InvalidNoteTypeValue(value.into())), @@ -100,7 +100,7 @@ impl Deserializable for NoteType { let discriminat = u8::read_from(source)?; let note_type = match discriminat { - OFF_CHAIN => NoteType::OffChain, + PRIVATE => NoteType::Private, ENCRYPTED => NoteType::Encrypted, PUBLIC => NoteType::Public, v => { diff --git a/objects/src/testing/block.rs b/objects/src/testing/block.rs index ee2b7fdbc..d82de7c21 100644 --- a/objects/src/testing/block.rs +++ b/objects/src/testing/block.rs @@ -29,7 +29,7 @@ pub struct PendingObjects { updated_accounts: Vec, /// Note batches created in transactions in the block. - created_notes: Vec, + output_note_batches: Vec, /// Nullifiers produced in transactions in the block. created_nullifiers: Vec, @@ -42,7 +42,7 @@ impl PendingObjects { pub fn new() -> PendingObjects { PendingObjects { updated_accounts: vec![], - created_notes: vec![], + output_note_batches: vec![], created_nullifiers: vec![], transaction_ids: vec![], } @@ -54,11 +54,16 @@ impl PendingObjects { /// is not for all fields of the [Note] struct, but only for note metadata + core fields of /// a note (i.e., vault, inputs, script, and serial number). pub fn build_notes_tree(&self) -> BlockNoteTree { - let entries = self.created_notes.iter().enumerate().flat_map(|(batch_index, batch)| { - batch.iter().enumerate().map(move |(note_index, note)| { - (BlockNoteIndex::new(batch_index, note_index), note.id().into(), *note.metadata()) - }) - }); + let entries = + self.output_note_batches.iter().enumerate().flat_map(|(batch_index, batch)| { + batch.iter().enumerate().map(move |(note_index, note)| { + ( + BlockNoteIndex::new(batch_index, note_index), + note.id().into(), + *note.metadata(), + ) + }) + }); BlockNoteTree::with_entries(entries).unwrap() } @@ -156,13 +161,13 @@ impl MockChain { // TODO: check that notes are not duplicate let output_notes: Vec = transaction.output_notes().iter().cloned().collect(); - self.pending_objects.created_notes.push(output_notes); + self.pending_objects.output_note_batches.push(output_notes); } /// Add a public [Note] to the pending objects. /// A block has to be created to finalize the new entity. pub fn add_note(&mut self, note: Note) { - self.pending_objects.created_notes.push(vec![OutputNote::Full(note)]); + self.pending_objects.output_note_batches.push(vec![OutputNote::Full(note)]); } /// Mark a [Note] as consumed by inserting its nullifier into the block. @@ -271,12 +276,13 @@ impl MockChain { let block = Block::new( header, self.pending_objects.updated_accounts.clone(), - self.pending_objects.created_notes.clone(), + self.pending_objects.output_note_batches.clone(), self.pending_objects.created_nullifiers.clone(), ) .unwrap(); - for (batch_index, note_batch) in self.pending_objects.created_notes.iter().enumerate() { + for (batch_index, note_batch) in self.pending_objects.output_note_batches.iter().enumerate() + { for (note_index, note) in note_batch.iter().enumerate() { // All note details should be OutputNote::Full at this point match note { diff --git a/objects/src/transaction/outputs.rs b/objects/src/transaction/outputs.rs index 1e0c04ac8..6f988a614 100644 --- a/objects/src/transaction/outputs.rs +++ b/objects/src/transaction/outputs.rs @@ -197,7 +197,7 @@ impl OutputNote { /// - All partial notes are converted into note headers. pub fn shrink(&self) -> Self { match self { - OutputNote::Full(note) if note.metadata().is_offchain() => { + OutputNote::Full(note) if note.metadata().is_private() => { OutputNote::Header(*note.header()) }, OutputNote::Partial(note) => OutputNote::Header(note.into()), From be25e835a36cd2dbd7c10e438e7132b56eb70111 Mon Sep 17 00:00:00 2001 From: Tomas Rodriguez Dala <43424983+tomyrd@users.noreply.github.com> Date: Fri, 12 Jul 2024 20:27:57 -0300 Subject: [PATCH 04/47] feat: Change `TransactionArgs` to use `AdviceInputs` (#793) --- CHANGELOG.md | 2 + miden-lib/build.rs | 2 +- miden-lib/src/transaction/inputs.rs | 2 +- miden-tx/src/tests/kernel_tests/test_note.rs | 7 ++- .../src/tests/kernel_tests/test_prologue.rs | 2 +- miden-tx/src/tests/mod.rs | 21 +++++--- objects/src/transaction/tx_args.rs | 50 ++++++++++++------- 7 files changed, 56 insertions(+), 30 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 76d5a82ae..bdee3f6f5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## 0.5.0 (TBD) +- [BREAKING] Changed the `TransactionArgs` to use `AdviceInputs` (#793). + ## 0.4.0 (2024-07-03) ### Features diff --git a/miden-lib/build.rs b/miden-lib/build.rs index d07008735..5e4bc6b10 100644 --- a/miden-lib/build.rs +++ b/miden-lib/build.rs @@ -76,7 +76,7 @@ fn compile_miden_lib(source_dir: &Path, target_dir: &Path) -> io::Result<()> { for line in modified { write.write_all(line.unwrap().as_bytes()).unwrap(); - write.write_all(&[b'\n']).unwrap(); + write.write_all(b"\n").unwrap(); } write.flush().unwrap(); } diff --git a/miden-lib/src/transaction/inputs.rs b/miden-lib/src/transaction/inputs.rs index bf3ef565b..1fd6eb51e 100644 --- a/miden-lib/src/transaction/inputs.rs +++ b/miden-lib/src/transaction/inputs.rs @@ -93,7 +93,7 @@ fn extend_advice_inputs( add_chain_mmr_to_advice_inputs(tx_inputs.block_chain(), advice_inputs); add_account_to_advice_inputs(tx_inputs.account(), tx_inputs.account_seed(), advice_inputs); add_input_notes_to_advice_inputs(tx_inputs.input_notes(), tx_args, advice_inputs); - advice_inputs.extend_map(tx_args.advice_map().clone()); + advice_inputs.extend(tx_args.advice_inputs().clone()); } // ADVICE STACK BUILDER diff --git a/miden-tx/src/tests/kernel_tests/test_note.rs b/miden-tx/src/tests/kernel_tests/test_note.rs index 0a0823e3c..a065e26a7 100644 --- a/miden-tx/src/tests/kernel_tests/test_note.rs +++ b/miden-tx/src/tests/kernel_tests/test_note.rs @@ -367,8 +367,11 @@ fn test_note_script_and_note_args() { (tx_context.input_notes().get_note(1).note().id(), note_args[0]), ]); - let tx_args = - TransactionArgs::new(None, Some(note_args_map), tx_context.tx_args().advice_map().clone()); + let tx_args = TransactionArgs::new( + None, + Some(note_args_map), + tx_context.tx_args().advice_inputs().clone().map, + ); tx_context.set_tx_args(tx_args); let process = tx_context.execute_code(code).unwrap(); diff --git a/miden-tx/src/tests/kernel_tests/test_prologue.rs b/miden-tx/src/tests/kernel_tests/test_prologue.rs index 13d56868a..8104e1d28 100644 --- a/miden-tx/src/tests/kernel_tests/test_prologue.rs +++ b/miden-tx/src/tests/kernel_tests/test_prologue.rs @@ -80,7 +80,7 @@ fn test_transaction_prologue() { let tx_args = TransactionArgs::new( Some(tx_script), Some(note_args_map), - tx_context.tx_args().advice_map().clone(), + tx_context.tx_args().advice_inputs().clone().map, ); tx_context.set_tx_args(tx_args); diff --git a/miden-tx/src/tests/mod.rs b/miden-tx/src/tests/mod.rs index f5ae0d67d..4c2ad0e37 100644 --- a/miden-tx/src/tests/mod.rs +++ b/miden-tx/src/tests/mod.rs @@ -291,8 +291,11 @@ fn executed_transaction_account_delta() { ); let tx_script_code = ProgramAst::parse(&tx_script).unwrap(); let tx_script = executor.compile_tx_script(tx_script_code, vec![], vec![]).unwrap(); - let tx_args = - TransactionArgs::new(Some(tx_script), None, tx_context.tx_args().advice_map().clone()); + let tx_args = TransactionArgs::new( + Some(tx_script), + None, + tx_context.tx_args().advice_inputs().clone().map, + ); let block_ref = tx_context.tx_inputs().block_header().block_num(); let note_ids = tx_context @@ -566,8 +569,11 @@ fn executed_transaction_output_notes() { ); let tx_script_code = ProgramAst::parse(&tx_script).unwrap(); let tx_script = executor.compile_tx_script(tx_script_code, vec![], vec![]).unwrap(); - let mut tx_args = - TransactionArgs::new(Some(tx_script), None, tx_context.tx_args().advice_map().clone()); + let mut tx_args = TransactionArgs::new( + Some(tx_script), + None, + tx_context.tx_args().advice_inputs().clone().map, + ); tx_args.add_expected_output_note(&expected_output_note_2); tx_args.add_expected_output_note(&expected_output_note_3); @@ -701,8 +707,11 @@ fn test_tx_script() { vec![], ) .unwrap(); - let tx_args = - TransactionArgs::new(Some(tx_script), None, tx_context.tx_args().advice_map().clone()); + let tx_args = TransactionArgs::new( + Some(tx_script), + None, + tx_context.tx_args().advice_inputs().clone().map, + ); let executed_transaction = executor.execute_transaction(account_id, block_ref, ¬e_ids, tx_args); diff --git a/objects/src/transaction/tx_args.rs b/objects/src/transaction/tx_args.rs index 653a1fcc4..438ded634 100644 --- a/objects/src/transaction/tx_args.rs +++ b/objects/src/transaction/tx_args.rs @@ -1,7 +1,8 @@ use alloc::{collections::BTreeMap, vec::Vec}; use core::ops::Deref; -use vm_processor::AdviceMap; +use miden_crypto::merkle::InnerNodeInfo; +use vm_processor::{AdviceInputs, AdviceMap}; use super::{Digest, Felt, Word}; use crate::{ @@ -21,12 +22,12 @@ use crate::{ /// - Note arguments: data put onto the stack right before a note script is executed. These /// are different from note inputs, as the user executing the transaction can specify arbitrary /// note args. -/// - Advice map: Provides data needed by the runtime, like the details of a public output note. +/// - Advice inputs: Provides data needed by the runtime, like the details of a public output note. #[derive(Clone, Debug, Default)] pub struct TransactionArgs { tx_script: Option, note_args: BTreeMap, - advice_map: AdviceMap, + advice_inputs: AdviceInputs, } impl TransactionArgs { @@ -37,21 +38,23 @@ impl TransactionArgs { /// arguments. /// /// If tx_script is provided, this also adds all mappings from the transaction script inputs - /// to the advice map. + /// to the advice inputs' map. pub fn new( tx_script: Option, note_args: Option>, - mut advice_map: AdviceMap, + advice_map: AdviceMap, ) -> Self { - // add transaction script inputs to the advice map + let mut advice_inputs = AdviceInputs::default().with_map(advice_map); + // add transaction script inputs to the advice inputs' map if let Some(ref tx_script) = tx_script { - advice_map.extend(tx_script.inputs().iter().map(|(hash, input)| (*hash, input.clone()))) + advice_inputs + .extend_map(tx_script.inputs().iter().map(|(hash, input)| (*hash, input.clone()))) } Self { tx_script, note_args: note_args.unwrap_or_default(), - advice_map, + advice_inputs, } } @@ -78,9 +81,9 @@ impl TransactionArgs { self.note_args.get(¬e_id) } - /// Returns a reference to the args [AdviceMap]. - pub fn advice_map(&self) -> &AdviceMap { - &self.advice_map + /// Returns a reference to the args [AdviceInputs]. + pub fn advice_inputs(&self) -> &AdviceInputs { + &self.advice_inputs } // STATE MUTATORS @@ -88,7 +91,7 @@ impl TransactionArgs { /// Populates the advice inputs with the specified note details. /// - /// The advice map is extended with the following keys: + /// The advice inputs' map is extended with the following keys: /// /// - recipient |-> recipient details (inputs_hash, script_hash, serial_num). /// - inputs_key |-> inputs, where inputs_key is computed by taking note inputs commitment and @@ -100,14 +103,18 @@ impl TransactionArgs { let script = note.script(); let script_encoded: Vec = script.into(); - self.advice_map.insert(recipient.digest(), recipient.to_elements()); - self.advice_map.insert(inputs.commitment(), inputs.format_for_advice()); - self.advice_map.insert(script.hash(), script_encoded); + let new_elements = [ + (recipient.digest(), recipient.to_elements()), + (inputs.commitment(), inputs.format_for_advice()), + (script.hash(), script_encoded), + ]; + + self.advice_inputs.extend_map(new_elements); } /// Populates the advice inputs with the specified note details. /// - /// The advice map is extended with the following keys: + /// The advice inputs' map is extended with the following keys: /// /// - recipient |-> recipient details (inputs_hash, script_hash, serial_num) /// - inputs_key |-> inputs, where inputs_key is computed by taking note inputs commitment and @@ -123,9 +130,14 @@ impl TransactionArgs { } } - /// Extends the internal advice map with the provided key-value pairs. + /// Extends the internal advice inputs' map with the provided key-value pairs. pub fn extend_advice_map)>>(&mut self, iter: T) { - self.advice_map.extend(iter) + self.advice_inputs.extend_map(iter) + } + + /// Extends the internal advice inputs' merkle store with the provided nodes. + pub fn extend_merkle_store>(&mut self, iter: I) { + self.advice_inputs.extend_merkle_store(iter) } } @@ -141,7 +153,7 @@ impl TransactionArgs { /// - [code](TransactionScript::code): the transaction script source code. /// - [hash](TransactionScript::hash): the hash of the compiled transaction script. /// - [inputs](TransactionScript::inputs): a map of key, value inputs that are loaded into the -/// advice map such that the transaction script can access them. +/// advice inputs' map such that the transaction script can access them. #[derive(Clone, Debug)] pub struct TransactionScript { code: ProgramAst, From 9de838ab8a15bb89ad9219636f9944f5e1b0cbf1 Mon Sep 17 00:00:00 2001 From: Bobbin Threadbare Date: Fri, 12 Jul 2024 16:33:00 -0700 Subject: [PATCH 05/47] chore: update changelog --- CHANGELOG.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bdee3f6f5..231c19969 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ ## 0.5.0 (TBD) +- Renamed "consumed" and "created" notes into "input" and "output" respectively (#791). +- [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). ## 0.4.0 (2024-07-03) @@ -35,8 +38,6 @@ - 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) From 19df86c05dba35a9717cbe1ac7ca2d86af763966 Mon Sep 17 00:00:00 2001 From: Andrey Khmuro Date: Sat, 13 Jul 2024 03:02:28 +0300 Subject: [PATCH 06/47] refactor: make memory setters consistent (#795) --- CHANGELOG.md | 1 + miden-lib/asm/miden/kernels/tx/account.masm | 4 +- miden-lib/asm/miden/kernels/tx/epilogue.masm | 4 +- miden-lib/asm/miden/kernels/tx/memory.masm | 76 ++++++++++++-------- miden-lib/asm/miden/kernels/tx/prologue.masm | 18 ++--- miden-lib/asm/miden/kernels/tx/tx.masm | 4 +- 6 files changed, 61 insertions(+), 46 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 231c19969..6ad809e9b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/miden-lib/asm/miden/kernels/tx/account.masm b/miden-lib/asm/miden/kernels/tx/account.masm index e0eff818b..5e14d1291 100644 --- a/miden-lib/asm/miden/kernels/tx/account.masm +++ b/miden-lib/asm/miden/kernels/tx/account.masm @@ -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 @@ -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 diff --git a/miden-lib/asm/miden/kernels/tx/epilogue.masm b/miden-lib/asm/miden/kernels/tx/epilogue.masm index 7be513768..f41e43eab 100644 --- a/miden-lib/asm/miden/kernels/tx/epilogue.masm +++ b/miden-lib/asm/miden/kernels/tx/epilogue.masm @@ -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 @@ -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 diff --git a/miden-lib/asm/miden/kernels/tx/memory.masm b/miden-lib/asm/miden/kernels/tx/memory.masm index 511d55e7c..179482171 100644 --- a/miden-lib/asm/miden/kernels/tx/memory.masm +++ b/miden-lib/asm/miden/kernels/tx/memory.masm @@ -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. @@ -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 @@ -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. @@ -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. @@ -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. @@ -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 @@ -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 @@ -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. @@ -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. @@ -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. @@ -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. @@ -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. @@ -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 @@ -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 diff --git a/miden-lib/asm/miden/kernels/tx/prologue.masm b/miden-lib/asm/miden/kernels/tx/prologue.masm index dc216ae2c..f1f3e0a31 100644 --- a/miden-lib/asm/miden/kernels/tx/prologue.masm +++ b/miden-lib/asm/miden/kernels/tx/prologue.masm @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/miden-lib/asm/miden/kernels/tx/tx.masm b/miden-lib/asm/miden/kernels/tx/tx.masm index dde241c69..a88536f9f 100644 --- a/miden-lib/asm/miden/kernels/tx/tx.masm +++ b/miden-lib/asm/miden/kernels/tx/tx.masm @@ -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 From dd5b7b9da328da6d47abd18fc784f3c56a0f1585 Mon Sep 17 00:00:00 2001 From: Andrey Khmuro Date: Thu, 18 Jul 2024 12:13:38 +0300 Subject: [PATCH 07/47] Allow increasing an account's nonce without changing its state (#796) * refactor: remove nonce increase restriction * test: add nonce update with empty delta test * refactor: update tx script, update comment --- CHANGELOG.md | 1 + miden-tx/src/tests/mod.rs | 60 +++++++++++++++++++++++++++++++ objects/src/accounts/delta/mod.rs | 10 ++---- objects/src/accounts/mod.rs | 1 - 4 files changed, 63 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6ad809e9b..32abc400b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ - [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). +- [BREAKING] Increase of nonce does not require changes in account state any more (#789). ## 0.4.0 (2024-07-03) diff --git a/miden-tx/src/tests/mod.rs b/miden-tx/src/tests/mod.rs index 4c2ad0e37..3f374c832 100644 --- a/miden-tx/src/tests/mod.rs +++ b/miden-tx/src/tests/mod.rs @@ -377,6 +377,66 @@ fn executed_transaction_account_delta() { ); } +#[test] +fn test_empty_delta_nonce_update() { + let tx_context = TransactionContextBuilder::with_standard_account( + ACCOUNT_ID_REGULAR_ACCOUNT_UPDATABLE_CODE_OFF_CHAIN, + ONE, + ) + .build(); + + let mut executor: TransactionExecutor<_, ()> = + TransactionExecutor::new(tx_context.clone(), None); + let account_id = tx_context.tx_inputs().account().id(); + executor.load_account(account_id).unwrap(); + + let tx_script = format!( + "\ + begin + push.1 + + call.{ACCOUNT_INCR_NONCE_MAST_ROOT} + # => [0, 1] + + drop drop + # => [] + end + " + ); + let tx_script_code = ProgramAst::parse(&tx_script).unwrap(); + let tx_script = executor.compile_tx_script(tx_script_code, vec![], vec![]).unwrap(); + let tx_args = TransactionArgs::new( + Some(tx_script), + None, + tx_context.tx_args().advice_inputs().clone().map, + ); + + let block_ref = tx_context.tx_inputs().block_header().block_num(); + let note_ids = tx_context + .tx_inputs() + .input_notes() + .iter() + .map(|note| note.id()) + .collect::>(); + + // expected delta + // -------------------------------------------------------------------------------------------- + // execute the transaction and get the witness + let executed_transaction = + executor.execute_transaction(account_id, block_ref, ¬e_ids, tx_args).unwrap(); + + // nonce delta + // -------------------------------------------------------------------------------------------- + assert_eq!(executed_transaction.account_delta().nonce(), Some(Felt::new(2))); + + // storage delta + // -------------------------------------------------------------------------------------------- + // We expect one updated item and one updated map + assert_eq!(executed_transaction.account_delta().storage().updated_items.len(), 0); + + assert_eq!(executed_transaction.account_delta().storage().updated_maps.len(), 0); +} + #[test] fn executed_transaction_output_notes() { let tx_context = TransactionContextBuilder::with_standard_account( diff --git a/objects/src/accounts/delta/mod.rs b/objects/src/accounts/delta/mod.rs index c3b9e9739..8f0a11547 100644 --- a/objects/src/accounts/delta/mod.rs +++ b/objects/src/accounts/delta/mod.rs @@ -41,7 +41,6 @@ impl AccountDelta { /// # Errors /// Returns an error if: /// - Storage or vault deltas are invalid. - /// - Storage and vault deltas are empty, and the nonce was updated. /// - Storage or vault deltas are not empty, but nonce was not updated. pub fn new( storage: AccountStorageDelta, @@ -52,7 +51,7 @@ impl AccountDelta { storage.validate()?; vault.validate()?; - // nonce must be updated if and only if either account storage or vault were updated + // nonce must be updated if either account storage or vault were updated validate_nonce(nonce, &storage, &vault)?; Ok(Self { storage, vault, nonce }) @@ -169,7 +168,6 @@ impl Deserializable for AccountUpdateDetails { /// # Errors /// Returns an error if: /// - Storage or vault were updated, but the nonce was either not updated or set to 0. -/// - Storage and vault were not updated, but the nonce was updated. fn validate_nonce( nonce: Option, storage: &AccountStorageDelta, @@ -190,10 +188,6 @@ fn validate_nonce( )) }, } - } else if nonce.is_some() { - return Err(AccountDeltaError::InconsistentNonceUpdate( - "nonce updated for empty delta".to_string(), - )); } Ok(()) @@ -222,7 +216,7 @@ mod tests { }; assert!(AccountDelta::new(storage_delta.clone(), vault_delta.clone(), None).is_ok()); - assert!(AccountDelta::new(storage_delta.clone(), vault_delta.clone(), Some(ONE)).is_err()); + assert!(AccountDelta::new(storage_delta.clone(), vault_delta.clone(), Some(ONE)).is_ok()); // non-empty delta let storage_delta = AccountStorageDelta { diff --git a/objects/src/accounts/mod.rs b/objects/src/accounts/mod.rs index 731bcbe53..f751697c4 100644 --- a/objects/src/accounts/mod.rs +++ b/objects/src/accounts/mod.rs @@ -481,7 +481,6 @@ mod tests { } #[test] - #[should_panic] fn empty_account_delta_with_incremented_nonce() { // build account let init_nonce = Felt::new(1); From 911ffbec0d41e1a72b17daf9bf3712ba5478eba8 Mon Sep 17 00:00:00 2001 From: igamigo Date: Mon, 22 Jul 2024 08:35:05 -0300 Subject: [PATCH 08/47] test: Add test for executing transactions with new accounts (#801) * test: Add test for executing transactions with new accounts, and small refactor * test: Add proving and verification on test * chore: Fmt * chore: Lints after merge * chore: Fmt * Address reviews --- Cargo.lock | 33 ++++--- bench-tx/src/main.rs | 9 +- miden-tx/src/testing/tx_context.rs | 10 ++- .../src/tests/kernel_tests/test_account.rs | 63 +++----------- .../tests/kernel_tests/test_asset_vault.rs | 73 +++------------- .../src/tests/kernel_tests/test_epilogue.rs | 63 +++++--------- .../src/tests/kernel_tests/test_faucet.rs | 43 ++------- miden-tx/src/tests/kernel_tests/test_note.rs | 79 ++++++----------- .../src/tests/kernel_tests/test_prologue.rs | 49 ++++------- miden-tx/src/tests/kernel_tests/test_tx.rs | 49 +++-------- miden-tx/src/tests/mod.rs | 52 ++++------- miden-tx/tests/integration/scripts/p2id.rs | 87 ++++++++++++++++++- objects/src/testing/account.rs | 14 +-- objects/src/testing/account_id.rs | 11 ++- objects/src/testing/storage.rs | 4 +- 15 files changed, 252 insertions(+), 387 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index fde50a771..4a456f6ef 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -49,9 +49,9 @@ checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" [[package]] name = "blake3" -version = "1.5.1" +version = "1.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30cca6d3674597c30ddf2c587bf8d9d65c9a84d2326d941cc79c9842dfe0ef52" +checksum = "e9ec96fe9a81b5e365f9db71fe00edc4fe4ca2cc7dcb7861f0603012a7caa210" dependencies = [ "arrayref", "arrayvec", @@ -77,13 +77,12 @@ checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5" [[package]] name = "cc" -version = "1.0.104" +version = "1.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "74b6a57f98764a267ff415d50a25e6e166f3831a5071af4995296ea97d210490" +checksum = "324c74f2155653c90b04f25b2a47a8a631360cb908f92a772695f430c7e31052" dependencies = [ "jobserver", "libc", - "once_cell", ] [[package]] @@ -121,18 +120,18 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.8" +version = "4.5.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84b3edb18336f4df585bc9aa31dd99c036dfa5dc5e9a2939a722a188f3a8970d" +checksum = "64acc1846d54c1fe936a78dc189c34e28d3f5afc348403f28ecf53660b9b8462" dependencies = [ "clap_builder", ] [[package]] name = "clap_builder" -version = "4.5.8" +version = "4.5.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1c09dd5ada6c6c78075d6fd0da3f90d8080651e2d6cc8eb2f1aaa4034ced708" +checksum = "6fb8393d67ba2e7bfaf28a23458e4e2b543cc73a99595511eb207fdb8aede942" dependencies = [ "anstyle", "clap_lex", @@ -662,9 +661,9 @@ checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" [[package]] name = "oorandom" -version = "11.1.3" +version = "11.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ab1bc2a289d34bd04a330323ac98a1b4bc82c9d9fcb1e66b63caa84da26b575" +checksum = "b410bbe7e14ab526a0e86877eb47c6996a2bd7746f027ba551028c925390e4e9" [[package]] name = "pin-project-lite" @@ -814,18 +813,18 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.203" +version = "1.0.204" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7253ab4de971e72fb7be983802300c30b5a7f0c2e56fab8abfc6a214307c0094" +checksum = "bc76f558e0cbb2a839d37354c575f1dc3fdc6546b5be373ba43d95f231bf7c12" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.203" +version = "1.0.204" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "500cbc0ebeb6f46627f50f3f5811ccf6bf00643be300b4c3eabc0ef55dc5b5ba" +checksum = "e0cd7e117be63d3c3678776753929474f3b04a43a080c744d6b0ae2a8c28e222" dependencies = [ "proc-macro2", "quote", @@ -856,9 +855,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.68" +version = "2.0.71" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "901fa70d88b9d6c98022e23b4136f9f3e54e4662c3bc1bd1d84a42a9a0f0c1e9" +checksum = "b146dcf730474b4bcd16c311627b31ede9ab149045db4d6088b3becaea046462" dependencies = [ "proc-macro2", "quote", diff --git a/bench-tx/src/main.rs b/bench-tx/src/main.rs index 934ca9832..28c8ed256 100644 --- a/bench-tx/src/main.rs +++ b/bench-tx/src/main.rs @@ -66,12 +66,9 @@ fn main() -> Result<(), String> { /// Runs the default transaction with empty transaction script and two default notes. pub fn benchmark_default_tx() -> Result { - let tx_context = TransactionContextBuilder::with_standard_account( - ACCOUNT_ID_REGULAR_ACCOUNT_UPDATABLE_CODE_OFF_CHAIN, - ONE, - ) - .with_mock_notes_preserved() - .build(); + let tx_context = TransactionContextBuilder::with_standard_account(ONE) + .with_mock_notes_preserved() + .build(); let mut executor: TransactionExecutor<_, ()> = TransactionExecutor::new(tx_context.clone(), None).with_tracing(); diff --git a/miden-tx/src/testing/tx_context.rs b/miden-tx/src/testing/tx_context.rs index 010d8268c..69fc46137 100644 --- a/miden-tx/src/testing/tx_context.rs +++ b/miden-tx/src/testing/tx_context.rs @@ -6,9 +6,9 @@ use miden_objects::{ account_id::testing::{ ACCOUNT_ID_FUNGIBLE_FAUCET_ON_CHAIN_1, ACCOUNT_ID_FUNGIBLE_FAUCET_ON_CHAIN_2, ACCOUNT_ID_FUNGIBLE_FAUCET_ON_CHAIN_3, ACCOUNT_ID_NON_FUNGIBLE_FAUCET_ON_CHAIN, - ACCOUNT_ID_SENDER, + ACCOUNT_ID_REGULAR_ACCOUNT_UPDATABLE_CODE_ON_CHAIN, ACCOUNT_ID_SENDER, }, - Account, AccountCode, AccountId, + Account, AccountId, }, assembly::{Assembler, ModuleAst}, assets::{Asset, FungibleAsset}, @@ -129,6 +129,7 @@ pub struct TransactionContextBuilder { impl TransactionContextBuilder { pub fn new(account: Account) -> Self { let tx_args = TransactionArgs::default(); + Self { assembler: TransactionKernel::assembler().with_debug_mode(true), account, @@ -141,9 +142,10 @@ impl TransactionContextBuilder { } } - pub fn with_standard_account(account_id: u64, nonce: Felt) -> Self { + pub fn with_standard_account(nonce: Felt) -> Self { let assembler = TransactionKernel::assembler().with_debug_mode(true); - let account = Account::mock(account_id, nonce, AccountCode::mock_wallet(&assembler)); + let account = + Account::mock(ACCOUNT_ID_REGULAR_ACCOUNT_UPDATABLE_CODE_ON_CHAIN, nonce, &assembler); Self { assembler, diff --git a/miden-tx/src/tests/kernel_tests/test_account.rs b/miden-tx/src/tests/kernel_tests/test_account.rs index a378b29d1..dc3a47eee 100644 --- a/miden-tx/src/tests/kernel_tests/test_account.rs +++ b/miden-tx/src/tests/kernel_tests/test_account.rs @@ -25,11 +25,7 @@ use crate::{ #[test] pub fn test_set_code_is_not_immediate() { - let tx_context = TransactionContextBuilder::with_standard_account( - ACCOUNT_ID_REGULAR_ACCOUNT_UPDATABLE_CODE_OFF_CHAIN, - ONE, - ) - .build(); + let tx_context = TransactionContextBuilder::with_standard_account(ONE).build(); let code = " use.miden::kernels::tx::prologue use.miden::account @@ -57,12 +53,9 @@ pub fn test_set_code_is_not_immediate() { #[test] pub fn test_set_code_succeeds() { - let tx_context = TransactionContextBuilder::with_standard_account( - ACCOUNT_ID_REGULAR_ACCOUNT_UPDATABLE_CODE_OFF_CHAIN, - ONE, - ) - .with_mock_notes_preserved() - .build(); + let tx_context = TransactionContextBuilder::with_standard_account(ONE) + .with_mock_notes_preserved() + .build(); let output_notes_data_procedure = output_notes_data_procedure(tx_context.expected_output_notes()); @@ -222,11 +215,7 @@ fn test_is_faucet_procedure() { #[test] fn test_get_item() { for storage_item in [AccountStorage::mock_item_0(), AccountStorage::mock_item_1()] { - let tx_context = TransactionContextBuilder::with_standard_account( - ACCOUNT_ID_REGULAR_ACCOUNT_UPDATABLE_CODE_OFF_CHAIN, - ONE, - ) - .build(); + let tx_context = TransactionContextBuilder::with_standard_account(ONE).build(); let code = format!( " @@ -255,11 +244,7 @@ fn test_get_item() { #[test] fn test_set_item() { - let tx_context = TransactionContextBuilder::with_standard_account( - ACCOUNT_ID_REGULAR_ACCOUNT_UPDATABLE_CODE_OFF_CHAIN, - ONE, - ) - .build(); + let tx_context = TransactionContextBuilder::with_standard_account(ONE).build(); // copy the initial account slots (SMT) let mut account_smt = tx_context.account().storage().slots().clone(); @@ -309,11 +294,7 @@ fn test_get_storage_data_type() { AccountStorage::mock_item_1(), AccountStorage::mock_item_2(), ] { - let tx_context = TransactionContextBuilder::with_standard_account( - ACCOUNT_ID_REGULAR_ACCOUNT_UPDATABLE_CODE_OFF_CHAIN, - ONE, - ) - .build(); + let tx_context = TransactionContextBuilder::with_standard_account(ONE).build(); let code = format!( " @@ -361,11 +342,7 @@ fn test_get_storage_data_type() { #[test] fn test_get_map_item() { - let tx_context = TransactionContextBuilder::with_standard_account( - ACCOUNT_ID_REGULAR_ACCOUNT_UPDATABLE_CODE_OFF_CHAIN, - ONE, - ) - .build(); + let tx_context = TransactionContextBuilder::with_standard_account(ONE).build(); let storage_item = AccountStorage::mock_item_2(); for (key, value) in STORAGE_LEAVES_2 { @@ -418,11 +395,7 @@ fn test_set_map_item() { [Felt::new(9_u64), Felt::new(10_u64), Felt::new(11_u64), Felt::new(12_u64)], ); - let tx_context = TransactionContextBuilder::with_standard_account( - ACCOUNT_ID_REGULAR_ACCOUNT_UPDATABLE_CODE_OFF_CHAIN, - ONE, - ) - .build(); + let tx_context = TransactionContextBuilder::with_standard_account(ONE).build(); let storage_item = AccountStorage::mock_item_2(); @@ -472,11 +445,7 @@ fn test_set_map_item() { #[test] fn test_get_vault_commitment() { - let tx_context = TransactionContextBuilder::with_standard_account( - ACCOUNT_ID_REGULAR_ACCOUNT_UPDATABLE_CODE_OFF_CHAIN, - ONE, - ) - .build(); + let tx_context = TransactionContextBuilder::with_standard_account(ONE).build(); let account = tx_context.account(); let code = format!( @@ -504,11 +473,7 @@ fn test_get_vault_commitment() { #[test] fn test_authenticate_procedure() { - let tx_context = TransactionContextBuilder::with_standard_account( - ACCOUNT_ID_REGULAR_ACCOUNT_UPDATABLE_CODE_OFF_CHAIN, - ONE, - ) - .build(); + let tx_context = TransactionContextBuilder::with_standard_account(ONE).build(); let account = tx_context.tx_inputs().account(); let proc0_index = LeafIndex::new(0).unwrap(); @@ -521,11 +486,7 @@ fn test_authenticate_procedure() { ]; for (root, valid) in test_cases.into_iter() { - let tx_context = TransactionContextBuilder::with_standard_account( - ACCOUNT_ID_REGULAR_ACCOUNT_UPDATABLE_CODE_OFF_CHAIN, - ONE, - ) - .build(); + let tx_context = TransactionContextBuilder::with_standard_account(ONE).build(); let code = format!( " diff --git a/miden-tx/src/tests/kernel_tests/test_asset_vault.rs b/miden-tx/src/tests/kernel_tests/test_asset_vault.rs index 3cda16280..74b9bd2d9 100644 --- a/miden-tx/src/tests/kernel_tests/test_asset_vault.rs +++ b/miden-tx/src/tests/kernel_tests/test_asset_vault.rs @@ -4,7 +4,6 @@ use miden_objects::{ account_id::testing::{ ACCOUNT_ID_FUNGIBLE_FAUCET_ON_CHAIN, ACCOUNT_ID_NON_FUNGIBLE_FAUCET_ON_CHAIN, ACCOUNT_ID_NON_FUNGIBLE_FAUCET_ON_CHAIN_1, - ACCOUNT_ID_REGULAR_ACCOUNT_UPDATABLE_CODE_OFF_CHAIN, }, AccountId, }, @@ -21,11 +20,7 @@ use crate::{testing::TransactionContextBuilder, tests::kernel_tests::read_root_m #[test] fn test_get_balance() { - let tx_context = TransactionContextBuilder::with_standard_account( - ACCOUNT_ID_REGULAR_ACCOUNT_UPDATABLE_CODE_OFF_CHAIN, - ONE, - ) - .build(); + let tx_context = TransactionContextBuilder::with_standard_account(ONE).build(); let faucet_id: AccountId = ACCOUNT_ID_FUNGIBLE_FAUCET_ON_CHAIN.try_into().unwrap(); let code = format!( @@ -51,11 +46,7 @@ fn test_get_balance() { #[test] fn test_get_balance_non_fungible_fails() { - let tx_context = TransactionContextBuilder::with_standard_account( - ACCOUNT_ID_REGULAR_ACCOUNT_UPDATABLE_CODE_OFF_CHAIN, - ONE, - ) - .build(); + let tx_context = TransactionContextBuilder::with_standard_account(ONE).build(); let code = format!( " use.miden::kernels::tx::prologue @@ -76,11 +67,7 @@ fn test_get_balance_non_fungible_fails() { #[test] fn test_has_non_fungible_asset() { - let tx_context = TransactionContextBuilder::with_standard_account( - ACCOUNT_ID_REGULAR_ACCOUNT_UPDATABLE_CODE_OFF_CHAIN, - ONE, - ) - .build(); + let tx_context = TransactionContextBuilder::with_standard_account(ONE).build(); let non_fungible_asset = tx_context.account().vault().assets().next().unwrap(); let code = format!( @@ -104,11 +91,7 @@ fn test_has_non_fungible_asset() { #[test] fn test_add_fungible_asset_success() { - let tx_context = TransactionContextBuilder::with_standard_account( - ACCOUNT_ID_REGULAR_ACCOUNT_UPDATABLE_CODE_OFF_CHAIN, - ONE, - ) - .build(); + let tx_context = TransactionContextBuilder::with_standard_account(ONE).build(); let mut account_vault = tx_context.account().vault().clone(); let faucet_id: AccountId = ACCOUNT_ID_FUNGIBLE_FAUCET_ON_CHAIN.try_into().unwrap(); let amount = FungibleAsset::MAX_AMOUNT - FUNGIBLE_ASSET_AMOUNT; @@ -144,11 +127,7 @@ fn test_add_fungible_asset_success() { #[test] fn test_add_non_fungible_asset_fail_overflow() { - let tx_context = TransactionContextBuilder::with_standard_account( - ACCOUNT_ID_REGULAR_ACCOUNT_UPDATABLE_CODE_OFF_CHAIN, - ONE, - ) - .build(); + let tx_context = TransactionContextBuilder::with_standard_account(ONE).build(); let mut account_vault = tx_context.account().vault().clone(); let faucet_id: AccountId = ACCOUNT_ID_FUNGIBLE_FAUCET_ON_CHAIN.try_into().unwrap(); @@ -178,11 +157,7 @@ fn test_add_non_fungible_asset_fail_overflow() { #[test] fn test_add_non_fungible_asset_success() { - let tx_context = TransactionContextBuilder::with_standard_account( - ACCOUNT_ID_REGULAR_ACCOUNT_UPDATABLE_CODE_OFF_CHAIN, - ONE, - ) - .build(); + let tx_context = TransactionContextBuilder::with_standard_account(ONE).build(); let faucet_id: AccountId = ACCOUNT_ID_NON_FUNGIBLE_FAUCET_ON_CHAIN.try_into().unwrap(); let mut account_vault = tx_context.account().vault().clone(); let add_non_fungible_asset = Asset::NonFungible( @@ -221,11 +196,7 @@ fn test_add_non_fungible_asset_success() { #[test] fn test_add_non_fungible_asset_fail_duplicate() { - let tx_context = TransactionContextBuilder::with_standard_account( - ACCOUNT_ID_REGULAR_ACCOUNT_UPDATABLE_CODE_OFF_CHAIN, - ONE, - ) - .build(); + let tx_context = TransactionContextBuilder::with_standard_account(ONE).build(); let faucet_id: AccountId = ACCOUNT_ID_NON_FUNGIBLE_FAUCET_ON_CHAIN.try_into().unwrap(); let mut account_vault = tx_context.account().vault().clone(); let non_fungible_asset_details = @@ -255,11 +226,7 @@ fn test_add_non_fungible_asset_fail_duplicate() { #[test] fn test_remove_fungible_asset_success_no_balance_remaining() { - let tx_context = TransactionContextBuilder::with_standard_account( - ACCOUNT_ID_REGULAR_ACCOUNT_UPDATABLE_CODE_OFF_CHAIN, - ONE, - ) - .build(); + let tx_context = TransactionContextBuilder::with_standard_account(ONE).build(); let mut account_vault = tx_context.account().vault().clone(); let faucet_id: AccountId = ACCOUNT_ID_FUNGIBLE_FAUCET_ON_CHAIN.try_into().unwrap(); @@ -296,11 +263,7 @@ fn test_remove_fungible_asset_success_no_balance_remaining() { #[test] fn test_remove_fungible_asset_fail_remove_too_much() { - let tx_context = TransactionContextBuilder::with_standard_account( - ACCOUNT_ID_REGULAR_ACCOUNT_UPDATABLE_CODE_OFF_CHAIN, - ONE, - ) - .build(); + let tx_context = TransactionContextBuilder::with_standard_account(ONE).build(); let faucet_id: AccountId = ACCOUNT_ID_FUNGIBLE_FAUCET_ON_CHAIN.try_into().unwrap(); let amount = FUNGIBLE_ASSET_AMOUNT + 1; let remove_fungible_asset = @@ -327,11 +290,7 @@ fn test_remove_fungible_asset_fail_remove_too_much() { #[test] fn test_remove_fungible_asset_success_balance_remaining() { - let tx_context = TransactionContextBuilder::with_standard_account( - ACCOUNT_ID_REGULAR_ACCOUNT_UPDATABLE_CODE_OFF_CHAIN, - ONE, - ) - .build(); + let tx_context = TransactionContextBuilder::with_standard_account(ONE).build(); let mut account_vault = tx_context.account().vault().clone(); let faucet_id: AccountId = ACCOUNT_ID_FUNGIBLE_FAUCET_ON_CHAIN.try_into().unwrap(); @@ -368,11 +327,7 @@ fn test_remove_fungible_asset_success_balance_remaining() { #[test] fn test_remove_inexisting_non_fungible_asset_fails() { - let tx_context = TransactionContextBuilder::with_standard_account( - ACCOUNT_ID_REGULAR_ACCOUNT_UPDATABLE_CODE_OFF_CHAIN, - ONE, - ) - .build(); + let tx_context = TransactionContextBuilder::with_standard_account(ONE).build(); let faucet_id: AccountId = ACCOUNT_ID_NON_FUNGIBLE_FAUCET_ON_CHAIN_1.try_into().unwrap(); let mut account_vault = tx_context.account().vault().clone(); @@ -413,11 +368,7 @@ fn test_remove_inexisting_non_fungible_asset_fails() { #[test] fn test_remove_non_fungible_asset_success() { - let tx_context = TransactionContextBuilder::with_standard_account( - ACCOUNT_ID_REGULAR_ACCOUNT_UPDATABLE_CODE_OFF_CHAIN, - ONE, - ) - .build(); + let tx_context = TransactionContextBuilder::with_standard_account(ONE).build(); let faucet_id: AccountId = ACCOUNT_ID_NON_FUNGIBLE_FAUCET_ON_CHAIN.try_into().unwrap(); let mut account_vault = tx_context.account().vault().clone(); let non_fungible_asset_details = diff --git a/miden-tx/src/tests/kernel_tests/test_epilogue.rs b/miden-tx/src/tests/kernel_tests/test_epilogue.rs index c9f8fdf79..c8487b881 100644 --- a/miden-tx/src/tests/kernel_tests/test_epilogue.rs +++ b/miden-tx/src/tests/kernel_tests/test_epilogue.rs @@ -1,10 +1,11 @@ use alloc::vec::Vec; -use miden_lib::transaction::memory::{ - NOTE_MEM_SIZE, OUTPUT_NOTE_ASSET_HASH_OFFSET, OUTPUT_NOTE_SECTION_OFFSET, +use miden_lib::transaction::{ + memory::{NOTE_MEM_SIZE, OUTPUT_NOTE_ASSET_HASH_OFFSET, OUTPUT_NOTE_SECTION_OFFSET}, + TransactionKernel, }; use miden_objects::{ - accounts::{account_id::testing::ACCOUNT_ID_REGULAR_ACCOUNT_UPDATABLE_CODE_OFF_CHAIN, Account}, + accounts::Account, transaction::{OutputNote, OutputNotes}, }; use vm_processor::ONE; @@ -14,12 +15,9 @@ use crate::{testing::TransactionContextBuilder, tests::kernel_tests::read_root_m #[test] fn test_epilogue() { - let tx_context = TransactionContextBuilder::with_standard_account( - ACCOUNT_ID_REGULAR_ACCOUNT_UPDATABLE_CODE_OFF_CHAIN, - ONE, - ) - .with_mock_notes_preserved() - .build(); + let tx_context = TransactionContextBuilder::with_standard_account(ONE) + .with_mock_notes_preserved() + .build(); let output_notes_data_procedure = output_notes_data_procedure(tx_context.expected_output_notes()); @@ -50,7 +48,7 @@ fn test_epilogue() { let final_account = Account::mock( tx_context.account().id().into(), tx_context.account().nonce() + ONE, - tx_context.account().code().clone(), + &TransactionKernel::assembler(), ); let output_notes = OutputNotes::new( @@ -83,12 +81,9 @@ fn test_epilogue() { #[test] fn test_compute_output_note_id() { - let tx_context = TransactionContextBuilder::with_standard_account( - ACCOUNT_ID_REGULAR_ACCOUNT_UPDATABLE_CODE_OFF_CHAIN, - ONE, - ) - .with_mock_notes_preserved() - .build(); + let tx_context = TransactionContextBuilder::with_standard_account(ONE) + .with_mock_notes_preserved() + .build(); let output_notes_data_procedure = output_notes_data_procedure(tx_context.expected_output_notes()); @@ -130,12 +125,9 @@ fn test_compute_output_note_id() { #[test] fn test_epilogue_asset_preservation_violation_too_few_input() { - let tx_context = TransactionContextBuilder::with_standard_account( - ACCOUNT_ID_REGULAR_ACCOUNT_UPDATABLE_CODE_OFF_CHAIN, - ONE, - ) - .with_mock_notes_too_few_input() - .build(); + let tx_context = TransactionContextBuilder::with_standard_account(ONE) + .with_mock_notes_too_few_input() + .build(); let output_notes_data_procedure = output_notes_data_procedure(tx_context.expected_output_notes()); @@ -164,12 +156,9 @@ fn test_epilogue_asset_preservation_violation_too_few_input() { #[test] fn test_epilogue_asset_preservation_violation_too_many_fungible_input() { - let tx_context = TransactionContextBuilder::with_standard_account( - ACCOUNT_ID_REGULAR_ACCOUNT_UPDATABLE_CODE_OFF_CHAIN, - ONE, - ) - .with_mock_notes_too_many_fungible_input() - .build(); + let tx_context = TransactionContextBuilder::with_standard_account(ONE) + .with_mock_notes_too_many_fungible_input() + .build(); let output_notes_data_procedure = output_notes_data_procedure(tx_context.expected_output_notes()); @@ -198,12 +187,9 @@ fn test_epilogue_asset_preservation_violation_too_many_fungible_input() { #[test] fn test_epilogue_increment_nonce_success() { - let tx_context = TransactionContextBuilder::with_standard_account( - ACCOUNT_ID_REGULAR_ACCOUNT_UPDATABLE_CODE_OFF_CHAIN, - ONE, - ) - .with_mock_notes_preserved() - .build(); + let tx_context = TransactionContextBuilder::with_standard_account(ONE) + .with_mock_notes_preserved() + .build(); let output_notes_data_procedure = output_notes_data_procedure(tx_context.expected_output_notes()); @@ -240,12 +226,9 @@ fn test_epilogue_increment_nonce_success() { #[test] fn test_epilogue_increment_nonce_violation() { - let tx_context = TransactionContextBuilder::with_standard_account( - ACCOUNT_ID_REGULAR_ACCOUNT_UPDATABLE_CODE_OFF_CHAIN, - ONE, - ) - .with_mock_notes_preserved() - .build(); + let tx_context = TransactionContextBuilder::with_standard_account(ONE) + .with_mock_notes_preserved() + .build(); let output_notes_data_procedure = output_notes_data_procedure(tx_context.expected_output_notes()); diff --git a/miden-tx/src/tests/kernel_tests/test_faucet.rs b/miden-tx/src/tests/kernel_tests/test_faucet.rs index 97d0814a0..967075b02 100644 --- a/miden-tx/src/tests/kernel_tests/test_faucet.rs +++ b/miden-tx/src/tests/kernel_tests/test_faucet.rs @@ -2,7 +2,6 @@ use miden_objects::{ accounts::account_id::testing::{ ACCOUNT_ID_FUNGIBLE_FAUCET_ON_CHAIN, ACCOUNT_ID_FUNGIBLE_FAUCET_ON_CHAIN_1, ACCOUNT_ID_NON_FUNGIBLE_FAUCET_ON_CHAIN, ACCOUNT_ID_NON_FUNGIBLE_FAUCET_ON_CHAIN_1, - ACCOUNT_ID_REGULAR_ACCOUNT_UPDATABLE_CODE_OFF_CHAIN, }, assets::{Asset, FungibleAsset}, testing::{ @@ -70,11 +69,7 @@ fn test_mint_fungible_asset_succeeds() { #[test] fn test_mint_fungible_asset_fails_not_faucet_account() { - let tx_context = TransactionContextBuilder::with_standard_account( - ACCOUNT_ID_REGULAR_ACCOUNT_UPDATABLE_CODE_OFF_CHAIN, - ONE, - ) - .build(); + let tx_context = TransactionContextBuilder::with_standard_account(ONE).build(); let code = format!( " @@ -96,11 +91,7 @@ fn test_mint_fungible_asset_fails_not_faucet_account() { #[test] fn test_mint_fungible_asset_inconsistent_faucet_id() { - let tx_context = TransactionContextBuilder::with_standard_account( - ACCOUNT_ID_REGULAR_ACCOUNT_UPDATABLE_CODE_OFF_CHAIN, - ONE, - ) - .build(); + let tx_context = TransactionContextBuilder::with_standard_account(ONE).build(); let code = format!( " @@ -122,11 +113,7 @@ fn test_mint_fungible_asset_inconsistent_faucet_id() { #[test] fn test_mint_fungible_asset_fails_saturate_max_amount() { - let tx_context = TransactionContextBuilder::with_standard_account( - ACCOUNT_ID_REGULAR_ACCOUNT_UPDATABLE_CODE_OFF_CHAIN, - ONE, - ) - .build(); + let tx_context = TransactionContextBuilder::with_standard_account(ONE).build(); let code = format!( " @@ -207,11 +194,7 @@ fn test_mint_non_fungible_asset_succeeds() { #[test] fn test_mint_non_fungible_asset_fails_not_faucet_account() { - let tx_context = TransactionContextBuilder::with_standard_account( - ACCOUNT_ID_REGULAR_ACCOUNT_UPDATABLE_CODE_OFF_CHAIN, - ONE, - ) - .build(); + let tx_context = TransactionContextBuilder::with_standard_account(ONE).build(); let non_fungible_asset = Asset::mock_non_fungible(ACCOUNT_ID_NON_FUNGIBLE_FAUCET_ON_CHAIN, &[1, 2, 3, 4]); @@ -237,11 +220,7 @@ fn test_mint_non_fungible_asset_fails_not_faucet_account() { #[test] fn test_mint_non_fungible_asset_fails_inconsistent_faucet_id() { - let tx_context = TransactionContextBuilder::with_standard_account( - ACCOUNT_ID_REGULAR_ACCOUNT_UPDATABLE_CODE_OFF_CHAIN, - ONE, - ) - .build(); + let tx_context = TransactionContextBuilder::with_standard_account(ONE).build(); let non_fungible_asset = Asset::mock_non_fungible(ACCOUNT_ID_NON_FUNGIBLE_FAUCET_ON_CHAIN_1, &[1, 2, 3, 4]); @@ -351,11 +330,7 @@ fn test_burn_fungible_asset_succeeds() { #[test] fn test_burn_fungible_asset_fails_not_faucet_account() { - let tx_context = TransactionContextBuilder::with_standard_account( - ACCOUNT_ID_REGULAR_ACCOUNT_UPDATABLE_CODE_OFF_CHAIN, - ONE, - ) - .build(); + let tx_context = TransactionContextBuilder::with_standard_account(ONE).build(); let code = format!( " @@ -526,11 +501,7 @@ fn test_burn_non_fungible_asset_fails_does_not_exist() { #[test] fn test_burn_non_fungible_asset_fails_not_faucet_account() { - let tx_context = TransactionContextBuilder::with_standard_account( - ACCOUNT_ID_REGULAR_ACCOUNT_UPDATABLE_CODE_OFF_CHAIN, - ONE, - ) - .build(); + let tx_context = TransactionContextBuilder::with_standard_account(ONE).build(); let non_fungible_asset_burnt = Asset::mock_non_fungible(ACCOUNT_ID_NON_FUNGIBLE_FAUCET_ON_CHAIN, &[1, 2, 3]); diff --git a/miden-tx/src/tests/kernel_tests/test_note.rs b/miden-tx/src/tests/kernel_tests/test_note.rs index a065e26a7..63de03e3e 100644 --- a/miden-tx/src/tests/kernel_tests/test_note.rs +++ b/miden-tx/src/tests/kernel_tests/test_note.rs @@ -2,7 +2,6 @@ use alloc::{collections::BTreeMap, string::String}; use miden_lib::transaction::memory::CURRENT_INPUT_NOTE_PTR; use miden_objects::{ - accounts::account_id::testing::ACCOUNT_ID_REGULAR_ACCOUNT_UPDATABLE_CODE_OFF_CHAIN, notes::Note, testing::prepare_word, transaction::TransactionArgs, Hasher, WORD_SIZE, }; use vm_processor::{ProcessState, EMPTY_WORD, ONE}; @@ -17,11 +16,7 @@ use crate::{ #[test] fn test_get_sender_no_sender() { - let tx_context = TransactionContextBuilder::with_standard_account( - ACCOUNT_ID_REGULAR_ACCOUNT_UPDATABLE_CODE_OFF_CHAIN, - ONE, - ) - .build(); + let tx_context = TransactionContextBuilder::with_standard_account(ONE).build(); // calling get_sender should return sender let code = " use.miden::kernels::tx::memory @@ -46,12 +41,9 @@ fn test_get_sender_no_sender() { #[test] fn test_get_sender() { - let tx_context = TransactionContextBuilder::with_standard_account( - ACCOUNT_ID_REGULAR_ACCOUNT_UPDATABLE_CODE_OFF_CHAIN, - ONE, - ) - .with_mock_notes_preserved() - .build(); + let tx_context = TransactionContextBuilder::with_standard_account(ONE) + .with_mock_notes_preserved() + .build(); // calling get_sender should return sender let code = " @@ -75,12 +67,9 @@ fn test_get_sender() { #[test] fn test_get_vault_data() { - let tx_context = TransactionContextBuilder::with_standard_account( - ACCOUNT_ID_REGULAR_ACCOUNT_UPDATABLE_CODE_OFF_CHAIN, - ONE, - ) - .with_mock_notes_preserved() - .build(); + let tx_context = TransactionContextBuilder::with_standard_account(ONE) + .with_mock_notes_preserved() + .build(); let notes = tx_context.input_notes(); @@ -127,12 +116,9 @@ fn test_get_vault_data() { } #[test] fn test_get_assets() { - let tx_context = TransactionContextBuilder::with_standard_account( - ACCOUNT_ID_REGULAR_ACCOUNT_UPDATABLE_CODE_OFF_CHAIN, - ONE, - ) - .with_mock_notes_preserved() - .build(); + let tx_context = TransactionContextBuilder::with_standard_account(ONE) + .with_mock_notes_preserved() + .build(); let notes = tx_context.input_notes(); @@ -237,12 +223,9 @@ fn test_get_assets() { #[test] fn test_get_inputs() { - let tx_context = TransactionContextBuilder::with_standard_account( - ACCOUNT_ID_REGULAR_ACCOUNT_UPDATABLE_CODE_OFF_CHAIN, - ONE, - ) - .with_mock_notes_preserved() - .build(); + let tx_context = TransactionContextBuilder::with_standard_account(ONE) + .with_mock_notes_preserved() + .build(); let notes = tx_context.mock_chain().available_notes(); @@ -311,12 +294,9 @@ fn test_get_inputs() { #[test] fn test_note_setup() { - let tx_context = TransactionContextBuilder::with_standard_account( - ACCOUNT_ID_REGULAR_ACCOUNT_UPDATABLE_CODE_OFF_CHAIN, - ONE, - ) - .with_mock_notes_preserved() - .build(); + let tx_context = TransactionContextBuilder::with_standard_account(ONE) + .with_mock_notes_preserved() + .build(); let code = " use.miden::kernels::tx::prologue @@ -341,12 +321,9 @@ fn test_note_script_and_note_args() { [Felt::new(92), Felt::new(92), Felt::new(92), Felt::new(92)], ]; - let mut tx_context = TransactionContextBuilder::with_standard_account( - ACCOUNT_ID_REGULAR_ACCOUNT_UPDATABLE_CODE_OFF_CHAIN, - ONE, - ) - .with_mock_notes_preserved() - .build(); + let mut tx_context = TransactionContextBuilder::with_standard_account(ONE) + .with_mock_notes_preserved() + .build(); let code = " use.miden::kernels::tx::prologue @@ -403,12 +380,9 @@ fn note_setup_memory_assertions(process: &Process) { #[test] fn test_get_note_serial_number() { - let tx_context = TransactionContextBuilder::with_standard_account( - ACCOUNT_ID_REGULAR_ACCOUNT_UPDATABLE_CODE_OFF_CHAIN, - ONE, - ) - .with_mock_notes_preserved() - .build(); + let tx_context = TransactionContextBuilder::with_standard_account(ONE) + .with_mock_notes_preserved() + .build(); // calling get_serial_number should return the serial number of the note let code = " @@ -432,12 +406,9 @@ fn test_get_note_serial_number() { #[test] fn test_get_inputs_hash() { - let tx_context = TransactionContextBuilder::with_standard_account( - ACCOUNT_ID_REGULAR_ACCOUNT_UPDATABLE_CODE_OFF_CHAIN, - ONE, - ) - .with_mock_notes_preserved() - .build(); + let tx_context = TransactionContextBuilder::with_standard_account(ONE) + .with_mock_notes_preserved() + .build(); let code = " use.miden::note diff --git a/miden-tx/src/tests/kernel_tests/test_prologue.rs b/miden-tx/src/tests/kernel_tests/test_prologue.rs index 8104e1d28..bac951b87 100644 --- a/miden-tx/src/tests/kernel_tests/test_prologue.rs +++ b/miden-tx/src/tests/kernel_tests/test_prologue.rs @@ -16,15 +16,17 @@ use miden_lib::transaction::{ TransactionKernel, }; use miden_objects::{ - accounts::account_id::testing::ACCOUNT_ID_REGULAR_ACCOUNT_UPDATABLE_CODE_OFF_CHAIN, assembly::ProgramAst, testing::{ + account::AccountBuilder, constants::FUNGIBLE_FAUCET_INITIAL_BALANCE, storage::{generate_account_seed, AccountSeedType}, }, transaction::{TransactionArgs, TransactionScript}, Digest, FieldElement, }; +use rand::SeedableRng; +use rand_chacha::ChaCha20Rng; use vm_processor::{AdviceInputs, ONE}; use super::{Felt, Process, Word, ZERO}; @@ -37,12 +39,9 @@ use crate::{ #[test] fn test_transaction_prologue() { - let mut tx_context = TransactionContextBuilder::with_standard_account( - ACCOUNT_ID_REGULAR_ACCOUNT_UPDATABLE_CODE_OFF_CHAIN, - ONE, - ) - .with_mock_notes_preserved() - .build(); + let mut tx_context = TransactionContextBuilder::with_standard_account(ONE) + .with_mock_notes_preserved() + .build(); let code = " use.miden::kernels::tx::prologue @@ -341,13 +340,11 @@ fn input_notes_memory_assertions( #[cfg_attr(not(feature = "testing"), ignore)] #[test] pub fn test_prologue_create_account() { - let (acct_id, account_seed) = generate_account_seed( - AccountSeedType::RegularAccountUpdatableCodeOnChain, - &TransactionKernel::assembler().with_debug_mode(true), - ); - let tx_context = TransactionContextBuilder::with_standard_account(acct_id.into(), ZERO) - .account_seed(account_seed) - .build(); + let (account, seed) = AccountBuilder::new(ChaCha20Rng::from_entropy()) + .account_type(miden_objects::accounts::AccountType::RegularAccountUpdatableCode) + .build(&TransactionKernel::assembler()) + .unwrap(); + let tx_context = TransactionContextBuilder::new(account).account_seed(seed).build(); let code = " use.miden::kernels::tx::prologue @@ -468,10 +465,10 @@ pub fn test_prologue_create_account_invalid_non_fungible_faucet_reserved_slot() #[cfg_attr(not(feature = "testing"), ignore)] #[test] pub fn test_prologue_create_account_invalid_seed() { - let (acct_id, account_seed) = generate_account_seed( - AccountSeedType::RegularAccountUpdatableCodeOnChain, - &TransactionKernel::assembler().with_debug_mode(true), - ); + let (acct, account_seed) = AccountBuilder::new(ChaCha20Rng::from_entropy()) + .account_type(miden_objects::accounts::AccountType::RegularAccountUpdatableCode) + .build(&TransactionKernel::assembler()) + .unwrap(); let code = " use.miden::kernels::tx::prologue @@ -482,11 +479,11 @@ pub fn test_prologue_create_account_invalid_seed() { "; // override the seed with an invalid seed to ensure the kernel fails - let account_seed_key = [acct_id.into(), ZERO, ZERO, ZERO]; + let account_seed_key = [acct.id().into(), ZERO, ZERO, ZERO]; let adv_inputs = AdviceInputs::default().with_map([(Digest::from(account_seed_key), vec![ZERO; 4])]); - let tx_context = TransactionContextBuilder::with_standard_account(acct_id.into(), ZERO) + let tx_context = TransactionContextBuilder::new(acct) .account_seed(account_seed) .advice_inputs(adv_inputs) .build(); @@ -497,11 +494,7 @@ pub fn test_prologue_create_account_invalid_seed() { #[test] fn test_get_blk_version() { - let tx_context = TransactionContextBuilder::with_standard_account( - ACCOUNT_ID_REGULAR_ACCOUNT_UPDATABLE_CODE_OFF_CHAIN, - ONE, - ) - .build(); + let tx_context = TransactionContextBuilder::with_standard_account(ONE).build(); let code = " use.miden::kernels::tx::memory use.miden::kernels::tx::prologue @@ -519,11 +512,7 @@ fn test_get_blk_version() { #[test] fn test_get_blk_timestamp() { - let tx_context = TransactionContextBuilder::with_standard_account( - ACCOUNT_ID_REGULAR_ACCOUNT_UPDATABLE_CODE_OFF_CHAIN, - ONE, - ) - .build(); + let tx_context = TransactionContextBuilder::with_standard_account(ONE).build(); let code = " use.miden::kernels::tx::memory use.miden::kernels::tx::prologue diff --git a/miden-tx/src/tests/kernel_tests/test_tx.rs b/miden-tx/src/tests/kernel_tests/test_tx.rs index 8d8cbe6bb..e81d4db4d 100644 --- a/miden-tx/src/tests/kernel_tests/test_tx.rs +++ b/miden-tx/src/tests/kernel_tests/test_tx.rs @@ -8,7 +8,6 @@ use miden_objects::{ accounts::account_id::testing::{ ACCOUNT_ID_FUNGIBLE_FAUCET_ON_CHAIN, ACCOUNT_ID_FUNGIBLE_FAUCET_ON_CHAIN_2, ACCOUNT_ID_NON_FUNGIBLE_FAUCET_ON_CHAIN, - ACCOUNT_ID_REGULAR_ACCOUNT_UPDATABLE_CODE_OFF_CHAIN, }, assets::Asset, notes::{Note, NoteAssets, NoteInputs, NoteMetadata, NoteRecipient, NoteType}, @@ -24,11 +23,7 @@ use crate::{ #[test] fn test_create_note() { - let tx_context = TransactionContextBuilder::with_standard_account( - ACCOUNT_ID_REGULAR_ACCOUNT_UPDATABLE_CODE_OFF_CHAIN, - ONE, - ) - .build(); + let tx_context = TransactionContextBuilder::with_standard_account(ONE).build(); let account_id = tx_context.account().id(); let recipient = [ZERO, ONE, Felt::new(2), Felt::new(3)]; @@ -85,11 +80,7 @@ fn test_create_note() { #[test] fn test_create_note_with_invalid_tag() { - let tx_context = TransactionContextBuilder::with_standard_account( - ACCOUNT_ID_REGULAR_ACCOUNT_UPDATABLE_CODE_OFF_CHAIN, - ONE, - ) - .build(); + let tx_context = TransactionContextBuilder::with_standard_account(ONE).build(); let recipient = [ZERO, ONE, Felt::new(2), Felt::new(3)]; let tag = Felt::new((NoteType::Public as u64) << 62); @@ -154,12 +145,9 @@ fn test_create_note_too_many_notes() { #[test] fn test_get_output_notes_hash() { - let tx_context = TransactionContextBuilder::with_standard_account( - ACCOUNT_ID_REGULAR_ACCOUNT_UPDATABLE_CODE_OFF_CHAIN, - ONE, - ) - .with_mock_notes_preserved() - .build(); + let tx_context = TransactionContextBuilder::with_standard_account(ONE) + .with_mock_notes_preserved() + .build(); // extract input note data let input_note_1 = tx_context.tx_inputs().input_notes().get_note(0).note(); @@ -295,11 +283,7 @@ fn test_get_output_notes_hash() { #[test] fn test_create_note_and_add_asset() { - let tx_context = TransactionContextBuilder::with_standard_account( - ACCOUNT_ID_REGULAR_ACCOUNT_UPDATABLE_CODE_OFF_CHAIN, - ONE, - ) - .build(); + let tx_context = TransactionContextBuilder::with_standard_account(ONE).build(); let recipient = [ZERO, ONE, Felt::new(2), Felt::new(3)]; let aux = Felt::new(27); @@ -351,11 +335,7 @@ fn test_create_note_and_add_asset() { #[test] fn test_create_note_and_add_multiple_assets() { - let tx_context = TransactionContextBuilder::with_standard_account( - ACCOUNT_ID_REGULAR_ACCOUNT_UPDATABLE_CODE_OFF_CHAIN, - ONE, - ) - .build(); + let tx_context = TransactionContextBuilder::with_standard_account(ONE).build(); let recipient = [ZERO, ONE, Felt::new(2), Felt::new(3)]; let aux = Felt::new(27); @@ -442,11 +422,7 @@ fn test_create_note_and_add_multiple_assets() { #[test] fn test_create_note_and_add_same_nft_twice() { - let tx_context = TransactionContextBuilder::with_standard_account( - ACCOUNT_ID_REGULAR_ACCOUNT_UPDATABLE_CODE_OFF_CHAIN, - ONE, - ) - .build(); + let tx_context = TransactionContextBuilder::with_standard_account(ONE).build(); let recipient = [ZERO, ONE, Felt::new(2), Felt::new(3)]; let tag = Felt::new(4); @@ -491,12 +467,9 @@ fn test_create_note_and_add_same_nft_twice() { #[test] fn test_build_recipient_hash() { - let tx_context = TransactionContextBuilder::with_standard_account( - ACCOUNT_ID_REGULAR_ACCOUNT_UPDATABLE_CODE_OFF_CHAIN, - ONE, - ) - .with_mock_notes_preserved() - .build(); + let tx_context = TransactionContextBuilder::with_standard_account(ONE) + .with_mock_notes_preserved() + .build(); let input_note_1 = tx_context.tx_inputs().input_notes().get_note(0).note(); diff --git a/miden-tx/src/tests/mod.rs b/miden-tx/src/tests/mod.rs index 3f374c832..f05e0e1e4 100644 --- a/miden-tx/src/tests/mod.rs +++ b/miden-tx/src/tests/mod.rs @@ -7,7 +7,6 @@ use miden_objects::{ ACCOUNT_ID_FUNGIBLE_FAUCET_ON_CHAIN, ACCOUNT_ID_FUNGIBLE_FAUCET_ON_CHAIN_2, ACCOUNT_ID_NON_FUNGIBLE_FAUCET_ON_CHAIN, ACCOUNT_ID_REGULAR_ACCOUNT_IMMUTABLE_CODE_ON_CHAIN, - ACCOUNT_ID_REGULAR_ACCOUNT_UPDATABLE_CODE_OFF_CHAIN, }, AccountCode, }, @@ -47,12 +46,9 @@ mod kernel_tests; #[test] fn transaction_executor_witness() { - let tx_context = TransactionContextBuilder::with_standard_account( - ACCOUNT_ID_REGULAR_ACCOUNT_UPDATABLE_CODE_OFF_CHAIN, - ONE, - ) - .with_mock_notes_preserved() - .build(); + let tx_context = TransactionContextBuilder::with_standard_account(ONE) + .with_mock_notes_preserved() + .build(); let mut executor: TransactionExecutor<_, ()> = TransactionExecutor::new(tx_context.clone(), None); @@ -97,12 +93,9 @@ fn transaction_executor_witness() { #[test] fn executed_transaction_account_delta() { - let tx_context = TransactionContextBuilder::with_standard_account( - ACCOUNT_ID_REGULAR_ACCOUNT_UPDATABLE_CODE_OFF_CHAIN, - ONE, - ) - .with_mock_notes_preserved_with_account_vault_delta() - .build(); + let tx_context = TransactionContextBuilder::with_standard_account(ONE) + .with_mock_notes_preserved_with_account_vault_delta() + .build(); let mut executor: TransactionExecutor<_, ()> = TransactionExecutor::new(tx_context.clone(), None); @@ -379,11 +372,7 @@ fn executed_transaction_account_delta() { #[test] fn test_empty_delta_nonce_update() { - let tx_context = TransactionContextBuilder::with_standard_account( - ACCOUNT_ID_REGULAR_ACCOUNT_UPDATABLE_CODE_OFF_CHAIN, - ONE, - ) - .build(); + let tx_context = TransactionContextBuilder::with_standard_account(ONE).build(); let mut executor: TransactionExecutor<_, ()> = TransactionExecutor::new(tx_context.clone(), None); @@ -439,12 +428,9 @@ fn test_empty_delta_nonce_update() { #[test] fn executed_transaction_output_notes() { - let tx_context = TransactionContextBuilder::with_standard_account( - ACCOUNT_ID_REGULAR_ACCOUNT_UPDATABLE_CODE_OFF_CHAIN, - ONE, - ) - .with_mock_notes_preserved_with_account_vault_delta() - .build(); + let tx_context = TransactionContextBuilder::with_standard_account(ONE) + .with_mock_notes_preserved_with_account_vault_delta() + .build(); let mut executor: TransactionExecutor<_, ()> = TransactionExecutor::new(tx_context.clone(), None).with_debug_mode(true); @@ -679,12 +665,9 @@ fn executed_transaction_output_notes() { #[test] fn prove_witness_and_verify() { - let tx_context = TransactionContextBuilder::with_standard_account( - ACCOUNT_ID_REGULAR_ACCOUNT_UPDATABLE_CODE_OFF_CHAIN, - ONE, - ) - .with_mock_notes_preserved() - .build(); + let tx_context = TransactionContextBuilder::with_standard_account(ONE) + .with_mock_notes_preserved() + .build(); let mut executor: TransactionExecutor<_, ()> = TransactionExecutor::new(tx_context.clone(), None); @@ -721,12 +704,9 @@ fn prove_witness_and_verify() { #[test] fn test_tx_script() { - let tx_context = TransactionContextBuilder::with_standard_account( - ACCOUNT_ID_REGULAR_ACCOUNT_UPDATABLE_CODE_OFF_CHAIN, - ONE, - ) - .with_mock_notes_preserved() - .build(); + let tx_context = TransactionContextBuilder::with_standard_account(ONE) + .with_mock_notes_preserved() + .build(); let mut executor: TransactionExecutor<_, ()> = TransactionExecutor::new(tx_context.clone(), None); diff --git a/miden-tx/tests/integration/scripts/p2id.rs b/miden-tx/tests/integration/scripts/p2id.rs index 6474b59a7..b1d4543c4 100644 --- a/miden-tx/tests/integration/scripts/p2id.rs +++ b/miden-tx/tests/integration/scripts/p2id.rs @@ -1,3 +1,5 @@ +use std::rc::Rc; + use miden_lib::{notes::create_p2id_note, transaction::TransactionKernel}; use miden_objects::{ accounts::{ @@ -7,17 +9,22 @@ use miden_objects::{ ACCOUNT_ID_REGULAR_ACCOUNT_UPDATABLE_CODE_ON_CHAIN, ACCOUNT_ID_REGULAR_ACCOUNT_UPDATABLE_CODE_ON_CHAIN_2, ACCOUNT_ID_SENDER, }, - Account, AccountId, + Account, AccountId, AccountType, SlotItem, }, assembly::ProgramAst, assets::{Asset, AssetVault, FungibleAsset}, crypto::rand::RpoRandomCoin, notes::{NoteScript, NoteType}, - testing::{account_code::DEFAULT_AUTH_SCRIPT, notes::DEFAULT_NOTE_CODE}, + testing::{ + account::AccountBuilder, account_code::DEFAULT_AUTH_SCRIPT, notes::DEFAULT_NOTE_CODE, + }, transaction::TransactionArgs, - Felt, + Felt, FieldElement, }; -use miden_tx::{testing::TransactionContextBuilder, TransactionExecutor}; +use miden_tx::{auth::BasicAuthenticator, testing::TransactionContextBuilder, TransactionExecutor}; +use rand::{rngs::StdRng, SeedableRng}; +use rand_chacha::ChaCha20Rng; +use vm_processor::Word; use crate::{ get_account_with_default_account_code, get_new_pk_and_authenticator, @@ -244,6 +251,60 @@ fn p2id_script_multiple_assets() { assert!(executed_transaction_2.is_err()); } +/// Consumes an existing note with a new account +#[test] +fn test_execute_prove_new_account() { + let (mut target_account, seed, falcon_auth) = create_new_account(); + let faucet_id = AccountId::try_from(ACCOUNT_ID_FUNGIBLE_FAUCET_ON_CHAIN).unwrap(); + let fungible_asset_1: Asset = FungibleAsset::new(faucet_id, 123).unwrap().into(); + + // Create the note + let note = create_p2id_note( + ACCOUNT_ID_FUNGIBLE_FAUCET_ON_CHAIN.try_into().unwrap(), + target_account.id(), + vec![fungible_asset_1], + NoteType::Public, + Felt::new(0), + &mut RpoRandomCoin::new([Felt::new(1), Felt::new(2), Felt::new(3), Felt::new(4)]), + ) + .unwrap(); + + let tx_context = TransactionContextBuilder::new(target_account.clone()) + .account_seed(seed) + .input_notes(vec![note.clone()]) + .build(); + + assert!(target_account.is_new()); + + let mut executor = TransactionExecutor::new(tx_context.clone(), Some(falcon_auth)); + executor.load_account(target_account.id()).unwrap(); + + let block_ref = tx_context.tx_inputs().block_header().block_num(); + let note_ids = tx_context + .tx_inputs() + .input_notes() + .iter() + .map(|note| note.id()) + .collect::>(); + + let tx_script_code = ProgramAst::parse(DEFAULT_AUTH_SCRIPT).unwrap(); + let tx_script_target = + executor.compile_tx_script(tx_script_code.clone(), vec![], vec![]).unwrap(); + + let tx_args_target = TransactionArgs::with_tx_script(tx_script_target); + + // Execute the transaction and get the witness + let executed_transaction = executor + .execute_transaction(target_account.id(), block_ref, ¬e_ids, tx_args_target) + .unwrap(); + + // Account delta + target_account.apply_delta(executed_transaction.account_delta()).unwrap(); + assert!(!target_account.is_new()); + + prove_and_verify_transaction(executed_transaction).unwrap(); +} + #[test] fn test_note_script_to_from_felt() { let assembler = TransactionKernel::assembler().with_debug_mode(true); @@ -256,3 +317,21 @@ fn test_note_script_to_from_felt() { assert_eq!(note_script, decoded); } + +// HELPER FUNCTIONS +// =============================================================================================== + +fn create_new_account() -> (Account, Word, Rc>) { + let (pub_key, falcon_auth) = get_new_pk_and_authenticator(); + + let storage_item = SlotItem::new_value(0, 0, pub_key); + + let (account, seed) = AccountBuilder::new(ChaCha20Rng::from_entropy()) + .add_storage_item(storage_item) + .account_type(AccountType::RegularAccountUpdatableCode) + .nonce(Felt::ZERO) + .build(&TransactionKernel::assembler()) + .unwrap(); + + (account, seed, falcon_auth) +} diff --git a/objects/src/testing/account.rs b/objects/src/testing/account.rs index a28489663..8ee94b93a 100644 --- a/objects/src/testing/account.rs +++ b/objects/src/testing/account.rs @@ -93,15 +93,17 @@ impl AccountBuilder { self } - pub fn build(mut self, assembler: &Assembler) -> Result { + pub fn build(mut self, assembler: &Assembler) -> Result<(Account, Word), AccountBuilderError> { let vault = AssetVault::new(&self.assets).map_err(AccountBuilderError::AssetVaultError)?; let storage = self.storage_builder.build(); self.account_id_builder.code(&self.code); self.account_id_builder.storage_root(storage.root()); - let account_id = self.account_id_builder.build(assembler)?; + let (account_id, seed) = self.account_id_builder.build(assembler)?; let account_code = str_to_account_code(&self.code, assembler) .map_err(AccountBuilderError::AccountError)?; - Ok(Account::from_parts(account_id, vault, storage, account_code, self.nonce)) + + let account = Account::from_parts(account_id, vault, storage, account_code, self.nonce); + Ok((account, seed)) } /// Build an account using the provided `seed`. @@ -176,8 +178,8 @@ impl std::error::Error for AccountBuilderError {} // ================================================================================================ impl Account { - /// Creates a mock account with a defined number of assets and storage - pub fn mock(account_id: u64, nonce: Felt, account_code: AccountCode) -> Self { + /// Creates a non-new mock account with a defined number of assets and storage + pub fn mock(account_id: u64, nonce: Felt, assembler: &Assembler) -> Self { let account_storage = AccountStorage::mock(); let account_vault = if nonce == Felt::ZERO { @@ -186,6 +188,8 @@ impl Account { AssetVault::mock() }; + let account_code = AccountCode::mock_wallet(assembler); + let account_id = AccountId::try_from(account_id).unwrap(); Account::from_parts(account_id, account_vault, account_storage, account_code, nonce) } diff --git a/objects/src/testing/account_id.rs b/objects/src/testing/account_id.rs index 78b46769a..2534d1a6e 100644 --- a/objects/src/testing/account_id.rs +++ b/objects/src/testing/account_id.rs @@ -50,7 +50,10 @@ impl AccountIdBuilder { self } - pub fn build(&mut self, assembler: &Assembler) -> Result { + pub fn build( + &mut self, + assembler: &Assembler, + ) -> Result<(AccountId, Word), AccountBuilderError> { let (seed, code_root) = account_id_build_details( &mut self.rng, &self.code, @@ -60,8 +63,10 @@ impl AccountIdBuilder { assembler, )?; - AccountId::new(seed, code_root, self.storage_root) - .map_err(AccountBuilderError::AccountError) + let account_id = AccountId::new(seed, code_root, self.storage_root) + .map_err(AccountBuilderError::AccountError)?; + + Ok((account_id, seed)) } pub fn with_seed( diff --git a/objects/src/testing/storage.rs b/objects/src/testing/storage.rs index a20d8aabc..18302fbe7 100644 --- a/objects/src/testing/storage.rs +++ b/objects/src/testing/storage.rs @@ -184,7 +184,7 @@ pub fn generate_account_seed( Account::mock( ACCOUNT_ID_REGULAR_ACCOUNT_UPDATABLE_CODE_ON_CHAIN, Felt::ZERO, - AccountCode::mock_wallet(assembler), + assembler, ), AccountType::RegularAccountUpdatableCode, ), @@ -192,7 +192,7 @@ pub fn generate_account_seed( Account::mock( ACCOUNT_ID_REGULAR_ACCOUNT_UPDATABLE_CODE_OFF_CHAIN, Felt::ZERO, - AccountCode::mock_wallet(assembler), + assembler, ), AccountType::RegularAccountUpdatableCode, ), From 6abf53e3cda142fbef76292652665e757a4aefc0 Mon Sep 17 00:00:00 2001 From: Paul-Henry Kajfasz <42912740+phklive@users.noreply.github.com> Date: Mon, 22 Jul 2024 17:42:17 +0100 Subject: [PATCH 09/47] chore: add warning for `CHANGELOG.md` (#799) --- .github/workflows/changelog.yml | 23 +++++++++++++++++++++ .github/workflows/lint.yml | 36 ++++++++++++++++----------------- CHANGELOG.md | 9 +++++---- scripts/check-changelog.sh | 21 +++++++++++++++++++ 4 files changed, 67 insertions(+), 22 deletions(-) create mode 100644 .github/workflows/changelog.yml create mode 100755 scripts/check-changelog.sh diff --git a/.github/workflows/changelog.yml b/.github/workflows/changelog.yml new file mode 100644 index 000000000..5fde0d8d0 --- /dev/null +++ b/.github/workflows/changelog.yml @@ -0,0 +1,23 @@ +# Runs changelog related jobs. +# CI job heavily inspired by: https://github.com/tarides/changelog-check-action + +name: changelog + +on: + pull_request: + types: [opened, reopened, synchronize] + +jobs: + changelog: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@main + with: + fetch-depth: 0 + - name: Check for changes in changelog + env: + BASE_REF: ${{ github.event.pull_request.base.ref }} + NO_CHANGELOG_LABEL: ${{ contains(github.event.pull_request.labels.*.name, 'no changelog') }} + run: ./scripts/check-changelog.sh "${{ inputs.changelog }}" + shell: bash diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 7b7814184..b06425c54 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -9,16 +9,16 @@ on: types: [opened, reopened, synchronize] jobs: - version: - name: check rust version consistency + clippy: + name: clippy nightly on ubuntu-latest runs-on: ubuntu-latest steps: - uses: actions/checkout@main - with: - profile: minimal - override: true - - name: check rust versions - run: ./scripts/check-rust-version.sh + - name: Clippy + run: | + rustup update --no-self-update nightly + rustup +nightly component add clippy + make clippy rustfmt: name: rustfmt check nightly on ubuntu-latest @@ -31,17 +31,6 @@ jobs: rustup +nightly component add rustfmt make format-check - clippy: - name: clippy nightly on ubuntu-latest - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@main - - name: Clippy - run: | - rustup update --no-self-update nightly - rustup +nightly component add clippy - make clippy - doc: name: doc stable on ubuntu-latest runs-on: ubuntu-latest @@ -51,3 +40,14 @@ jobs: run: | rustup update --no-self-update make doc + + version: + name: check rust version consistency + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@main + with: + profile: minimal + override: true + - name: check rust versions + run: ./scripts/check-rust-version.sh diff --git a/CHANGELOG.md b/CHANGELOG.md index 32abc400b..b70ff9c69 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,12 +2,13 @@ ## 0.5.0 (TBD) +- [BREAKING] Increase of nonce does not require changes in account state any more (#789). - Renamed "consumed" and "created" notes into "input" and "output" respectively (#791). - [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). -- [BREAKING] Increase of nonce does not require changes in account state any more (#789). +- Added `CHANGELOG.md` warning message on CI (#799). ## 0.4.0 (2024-07-03) @@ -43,9 +44,9 @@ ## 0.3.1 (2024-06-12) -* Replaced `cargo-make` with just `make` for running tasks (#696). -* Made `DataStore` conditionally async using `winter-maybe-async` (#725) -* Fixed `StorageMap`s implementation and included into apply_delta (#745) +- Replaced `cargo-make` with just `make` for running tasks (#696). +- Made `DataStore` conditionally async using `winter-maybe-async` (#725) +- Fixed `StorageMap`s implementation and included into apply_delta (#745) ## 0.3.0 (2024-05-14) diff --git a/scripts/check-changelog.sh b/scripts/check-changelog.sh new file mode 100755 index 000000000..dbf14cdbb --- /dev/null +++ b/scripts/check-changelog.sh @@ -0,0 +1,21 @@ +#!/bin/bash +set -uo pipefail + +CHANGELOG_FILE="${1:-CHANGELOG.md}" + +if [ "${NO_CHANGELOG_LABEL}" = "true" ]; then + # 'no changelog' set, so finish successfully + echo "\"no changelog\" label has been set" + exit 0 +else + # a changelog check is required + # fail if the diff is empty + if git diff --exit-code "origin/${BASE_REF}" -- "${CHANGELOG_FILE}"; then + >&2 echo "Changes should come with an entry in the \"CHANGELOG.md\" file. This behavior +can be overridden by using the \"no changelog\" label, which is used for changes +that are trivial / explicitely stated not to require a changelog entry." + exit 1 + fi + + echo "The \"CHANGELOG.md\" file has been updated." +fi From 51e0656a595163ea3605f4d4fdd0a6aa7e8b20e8 Mon Sep 17 00:00:00 2001 From: Bobbin Threadbare Date: Mon, 22 Jul 2024 09:47:26 -0700 Subject: [PATCH 10/47] chore: refresh Cargo.lock --- Cargo.lock | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4a456f6ef..9a8523296 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -25,9 +25,9 @@ checksum = "038dfcf04a5feb68e9c60b21c9625a54c2c0616e79b72b0fd87075a056ae1d1b" [[package]] name = "arrayref" -version = "0.3.7" +version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b4930d2cb77ce62f89ee5d5289b4ac049559b1c45539271f5ed4fdc7db34545" +checksum = "9d151e35f61089500b617991b791fc8bfd237ae50cd5950803758a179b41e67a" [[package]] name = "arrayvec" @@ -77,9 +77,9 @@ checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5" [[package]] name = "cc" -version = "1.1.5" +version = "1.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "324c74f2155653c90b04f25b2a47a8a631360cb908f92a772695f430c7e31052" +checksum = "2aba8f4e9906c7ce3c73463f62a7f0c65183ada1a2d47e397cc8810827f9694f" dependencies = [ "jobserver", "libc", @@ -855,9 +855,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.71" +version = "2.0.72" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b146dcf730474b4bcd16c311627b31ede9ab149045db4d6088b3becaea046462" +checksum = "dc4b9b9bf2add8093d3f2c0204471e951b2285580335de42f9d2534f3ae7a8af" dependencies = [ "proc-macro2", "quote", From 2a34de3d7a5ea65acea381f8f5c55f5e473a638e Mon Sep 17 00:00:00 2001 From: Bobbin Threadbare Date: Mon, 22 Jul 2024 09:48:22 -0700 Subject: [PATCH 11/47] fix: typo in changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b70ff9c69..ae8450408 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,12 +2,12 @@ ## 0.5.0 (TBD) -- [BREAKING] Increase of nonce does not require changes in account state any more (#789). - Renamed "consumed" and "created" notes into "input" and "output" respectively (#791). - [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). +- [BREAKING] Increase of nonce does not require changes in account state any more (#796). - Added `CHANGELOG.md` warning message on CI (#799). ## 0.4.0 (2024-07-03) From 8af3e341f26701ab9b42a26d59e39121f33101b8 Mon Sep 17 00:00:00 2001 From: Bobbin Threadbare Date: Mon, 22 Jul 2024 09:52:35 -0700 Subject: [PATCH 12/47] chore: switch to rust-toolchain.toml --- rust-toolchain | 1 - rust-toolchain.toml | 5 +++++ scripts/check-rust-version.sh | 10 ++++++---- 3 files changed, 11 insertions(+), 5 deletions(-) delete mode 100644 rust-toolchain create mode 100644 rust-toolchain.toml diff --git a/rust-toolchain b/rust-toolchain deleted file mode 100644 index 8e95c75da..000000000 --- a/rust-toolchain +++ /dev/null @@ -1 +0,0 @@ -1.78 diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 000000000..f2b387867 --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,5 @@ +[toolchain] +channel = "1.78" +components = ["rustfmt", "rust-src", "clippy"] +targets = ["wasm32-unknown-unknown"] +profile = "minimal" diff --git a/scripts/check-rust-version.sh b/scripts/check-rust-version.sh index f84634cc3..1e795bc0e 100755 --- a/scripts/check-rust-version.sh +++ b/scripts/check-rust-version.sh @@ -1,10 +1,12 @@ #!/bin/bash -# Check rust-toolchain file -TOOLCHAIN_VERSION=$(cat rust-toolchain) +# Get rust-toolchain.toml file channel +TOOLCHAIN_VERSION=$(grep 'channel' rust-toolchain.toml | sed -E 's/.*"(.*)".*/\1/') -# Check workspace Cargo.toml file -CARGO_VERSION=$(cat Cargo.toml | grep "rust-version" | cut -d '"' -f 2) +# Get workspace Cargo.toml file rust-version +CARGO_VERSION=$(grep 'rust-version' Cargo.toml | sed -E 's/.*"(.*)".*/\1/') + +# Check version match if [ "$CARGO_VERSION" != "$TOOLCHAIN_VERSION" ]; then echo "Mismatch in Cargo.toml: Expected $TOOLCHAIN_VERSION, found $CARGO_VERSION" exit 1 From 5cb5047f67a4164ae875336d9beae75095242ea7 Mon Sep 17 00:00:00 2001 From: Mirko von Leipzig <48352201+Mirko-von-Leipzig@users.noreply.github.com> Date: Wed, 24 Jul 2024 13:18:55 +0200 Subject: [PATCH 13/47] feat: merge account updates details (#797) This includes implementing some form of merge for all its child components. --- CHANGELOG.md | 1 + Cargo.lock | 162 +++++++++++++++++++++ objects/Cargo.toml | 1 + objects/src/accounts/delta/mod.rs | 45 ++++++ objects/src/accounts/delta/storage.rs | 129 ++++++++++++++++- objects/src/accounts/delta/vault.rs | 196 +++++++++++++++++++++++++- objects/src/assets/nonfungible.rs | 13 ++ objects/src/errors.rs | 7 +- 8 files changed, 550 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ae8450408..00e35a5d0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ - Setters in `memory` module don't drop the setting `Word` anymore (#795). - [BREAKING] Increase of nonce does not require changes in account state any more (#796). - Added `CHANGELOG.md` warning message on CI (#799). +- Account deltas can now be merged (#797). ## 0.4.0 (2024-07-03) diff --git a/Cargo.lock b/Cargo.lock index 9a8523296..5ec9fab24 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -271,6 +271,101 @@ version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9fc0510504f03c51ada170672ac806f1f105a88aa97a5281117e1ddc3368e51a" +[[package]] +name = "futures" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" + +[[package]] +name = "futures-executor" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" + +[[package]] +name = "futures-macro" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "futures-sink" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" + +[[package]] +name = "futures-task" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" + +[[package]] +name = "futures-timer" +version = "3.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f288b0a4f20f9a56b5d1da57e2227c661b7b16168e2f72365f57b63326e29b24" + +[[package]] +name = "futures-util" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + [[package]] name = "generic-array" version = "0.14.7" @@ -493,6 +588,7 @@ dependencies = [ "miden-processor", "miden-verifier", "rand", + "rstest", "serde", "tempfile", "winter-rand-utils", @@ -671,6 +767,12 @@ version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + [[package]] name = "ppv-lite86" version = "0.2.17" @@ -783,6 +885,51 @@ version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b" +[[package]] +name = "relative-path" +version = "1.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba39f3699c378cd8970968dcbff9c43159ea4cfbd88d43c00b22f2ef10a435d2" + +[[package]] +name = "rstest" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9afd55a67069d6e434a95161415f5beeada95a01c7b815508a82dcb0e1593682" +dependencies = [ + "futures", + "futures-timer", + "rstest_macros", + "rustc_version", +] + +[[package]] +name = "rstest_macros" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4165dfae59a39dd41d8dec720d3cbfbc71f69744efb480a3920f5d4e0cc6798d" +dependencies = [ + "cfg-if", + "glob", + "proc-macro-crate", + "proc-macro2", + "quote", + "regex", + "relative-path", + "rustc_version", + "syn", + "unicode-ident", +] + +[[package]] +name = "rustc_version" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" +dependencies = [ + "semver", +] + [[package]] name = "rustix" version = "0.38.34" @@ -811,6 +958,12 @@ dependencies = [ "winapi-util", ] +[[package]] +name = "semver" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b" + [[package]] name = "serde" version = "1.0.204" @@ -853,6 +1006,15 @@ dependencies = [ "keccak", ] +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + [[package]] name = "syn" version = "2.0.72" diff --git a/objects/Cargo.toml b/objects/Cargo.toml index 285456623..a67137c5f 100644 --- a/objects/Cargo.toml +++ b/objects/Cargo.toml @@ -40,4 +40,5 @@ winter-rand-utils = { version = "0.8", optional = true } [dev-dependencies] criterion = { version = "0.5", default-features = false, features = ["html_reports"] } miden-objects = { path = ".", features = ["testing"] } +rstest = { version = "0.21" } tempfile = { version = "3.0" } diff --git a/objects/src/accounts/delta/mod.rs b/objects/src/accounts/delta/mod.rs index 8f0a11547..c1b0e50a8 100644 --- a/objects/src/accounts/delta/mod.rs +++ b/objects/src/accounts/delta/mod.rs @@ -57,6 +57,22 @@ impl AccountDelta { Ok(Self { storage, vault, nonce }) } + /// Merge another [AccountDelta] into this one. + pub fn merge(self, other: Self) -> Result { + let nonce = match (self.nonce, other.nonce) { + (Some(old), Some(new)) if new.as_int() <= old.as_int() => { + return Err(AccountDeltaError::InconsistentNonceUpdate(format!( + "New nonce {new} is not larger than the old nonce {old}" + ))) + }, + // Incoming nonce takes precedence. + (old, new) => new.or(old), + }; + let storage = self.storage.merge(other.storage)?; + let vault = self.vault.merge(other.vault)?; + Self::new(storage, vault, nonce) + } + // PUBLIC ACCESSORS // -------------------------------------------------------------------------------------------- @@ -103,6 +119,35 @@ impl AccountUpdateDetails { pub fn is_private(&self) -> bool { matches!(self, Self::Private) } + + /// Merges the `other` update into this one. + /// + /// This account update is assumed to come before the other. + pub fn merge(self, other: AccountUpdateDetails) -> Result { + let merged_update = match (self, other) { + (AccountUpdateDetails::Private, AccountUpdateDetails::Private) => { + AccountUpdateDetails::Private + }, + (AccountUpdateDetails::New(mut account), AccountUpdateDetails::Delta(delta)) => { + account.apply_delta(&delta).map_err(|_| { + AccountDeltaError::IncompatibleAccountUpdates( + AccountUpdateDetails::New(account.clone()), + AccountUpdateDetails::Delta(delta), + ) + })?; + + AccountUpdateDetails::New(account) + }, + (AccountUpdateDetails::Delta(initial), AccountUpdateDetails::Delta(new_delta)) => { + AccountUpdateDetails::Delta(initial.merge(new_delta)?) + }, + (left, right) => { + return Err(AccountDeltaError::IncompatibleAccountUpdates(left, right)) + }, + }; + + Ok(merged_update) + } } // SERIALIZATION diff --git a/objects/src/accounts/delta/storage.rs b/objects/src/accounts/delta/storage.rs index 4e43454aa..4378f0a27 100644 --- a/objects/src/accounts/delta/storage.rs +++ b/objects/src/accounts/delta/storage.rs @@ -1,9 +1,10 @@ -use alloc::{string::ToString, vec::Vec}; +use alloc::{collections::BTreeMap, string::ToString, vec::Vec}; use super::{ AccountDeltaError, ByteReader, ByteWriter, Deserializable, DeserializationError, Felt, Serializable, Word, }; +use crate::Digest; // CONSTANTS // ================================================================================================ @@ -40,6 +41,46 @@ impl AccountStorageDelta { } } + /// Merges another delta into this one, overwriting any existing values. + pub fn merge(self, other: Self) -> Result { + self.validate()?; + other.validate()?; + + let items = + self.cleared_items + .into_iter() + .map(|slot| (slot, None)) + .chain(self.updated_items.into_iter().map(|(slot, value)| (slot, Some(value)))) + .chain(other.cleared_items.into_iter().map(|slot| (slot, None)).chain( + other.updated_items.into_iter().map(|(slot, value)| (slot, Some(value))), + )) + .collect::>(); + + let cleared_items = items + .iter() + .filter_map(|(slot, value)| value.is_none().then_some(*slot)) + .collect(); + let updated_items = + items.iter().filter_map(|(slot, value)| value.map(|v| (*slot, v))).collect(); + + let mut updated_maps = BTreeMap::::new(); + for (slot, update) in self.updated_maps.into_iter().chain(other.updated_maps.into_iter()) { + let entry = updated_maps.entry(slot).or_default(); + *entry = entry.clone().merge(update); + } + + let updated_maps = updated_maps.into_iter().collect(); + + let result = Self { + cleared_items, + updated_items, + updated_maps, + }; + result.validate()?; + + Ok(result) + } + /// Checks whether this storage delta is valid. /// /// # Errors @@ -267,6 +308,30 @@ impl StorageMapDelta { pub fn is_empty(&self) -> bool { self.cleared_leaves.is_empty() && self.updated_leaves.is_empty() } + + /// Merge `other` into this delta, giving precedence to `other`. + pub fn merge(self, other: Self) -> Self { + // Aggregate the changes into a map such that `other` overwrites self. + let leaves = self.cleared_leaves.into_iter().map(|k| (k, None)); + let leaves = leaves + .chain(self.updated_leaves.into_iter().map(|(k, v)| (k, Some(v)))) + .chain(other.cleared_leaves.into_iter().map(|k| (k, None))) + .chain(other.updated_leaves.into_iter().map(|(k, v)| (k, Some(v)))) + .map(|(k, v)| (Digest::from(k), v.map(Digest::from))) + .collect::>(); + + let mut cleared = Vec::new(); + let mut updated = Vec::new(); + + for (key, value) in leaves { + match value { + Some(value) => updated.push((key.into(), value.into())), + None => cleared.push(key.into()), + } + } + + Self::from(cleared, updated) + } } impl Serializable for StorageMapDelta { @@ -289,8 +354,12 @@ impl Deserializable for StorageMapDelta { #[cfg(test)] mod tests { + use super::{AccountStorageDelta, Deserializable, Serializable}; - use crate::{accounts::StorageMapDelta, ONE, ZERO}; + use crate::{ + accounts::{delta::AccountStorageDeltaBuilder, StorageMapDelta}, + ONE, ZERO, + }; #[test] fn account_storage_delta_validation() { @@ -432,4 +501,60 @@ mod tests { let deserialized = StorageMapDelta::read_from_bytes(&serialized).unwrap(); assert_eq!(deserialized, storage_map_delta); } + + #[rstest::rstest] + #[case::some_some(Some(1), Some(2), Some(2))] + #[case::none_some(None, Some(2), Some(2))] + #[case::some_none(Some(1), None, None)] + #[test] + fn merge_items(#[case] x: Option, #[case] y: Option, #[case] expected: Option) { + /// Creates a delta containing the item as an update if Some, else with the item cleared. + fn create_delta(item: Option) -> AccountStorageDelta { + const SLOT: u8 = 123; + let item = item.map(|x| (SLOT, [vm_core::Felt::new(x), ZERO, ZERO, ZERO])); + + AccountStorageDeltaBuilder::new() + .add_cleared_items(item.is_none().then_some(SLOT)) + .add_updated_items(item) + .build() + .unwrap() + } + + let delta_x = create_delta(x); + let delta_y = create_delta(y); + let expected = create_delta(expected); + + let result = delta_x.merge(delta_y).unwrap(); + + assert_eq!(result, expected); + } + + #[rstest::rstest] + #[case::some_some(Some(1), Some(2), Some(2))] + #[case::none_some(None, Some(2), Some(2))] + #[case::some_none(Some(1), None, None)] + #[test] + fn merge_maps(#[case] x: Option, #[case] y: Option, #[case] expected: Option) { + fn create_delta(value: Option) -> StorageMapDelta { + let key = [vm_core::Felt::new(10), ZERO, ZERO, ZERO]; + match value { + Some(value) => StorageMapDelta { + updated_leaves: vec![(key, [vm_core::Felt::new(value), ZERO, ZERO, ZERO])], + ..Default::default() + }, + None => StorageMapDelta { + cleared_leaves: vec![key], + ..Default::default() + }, + } + } + + let delta_x = create_delta(x); + let delta_y = create_delta(y); + let expected = create_delta(expected); + + let result = delta_x.merge(delta_y); + + assert_eq!(result, expected); + } } diff --git a/objects/src/accounts/delta/vault.rs b/objects/src/accounts/delta/vault.rs index 6b50561d5..3c0a400dc 100644 --- a/objects/src/accounts/delta/vault.rs +++ b/objects/src/accounts/delta/vault.rs @@ -1,9 +1,13 @@ -use alloc::{string::ToString, vec::Vec}; +use alloc::{collections::BTreeMap, string::ToString, vec::Vec}; use super::{ AccountDeltaError, Asset, ByteReader, ByteWriter, Deserializable, DeserializationError, Serializable, }; +use crate::{ + accounts::AccountId, + assets::{FungibleAsset, NonFungibleAsset}, +}; // ACCOUNT VAULT DELTA // ================================================================================================ @@ -37,6 +41,99 @@ impl AccountVaultDelta { } } + /// Merges another delta into this one, overwriting any existing values. + /// + /// Inputs and the result are validated as part of the merge. + pub fn merge(self, other: Self) -> Result { + self.validate()?; + other.validate()?; + + // Merge fungible and non-fungible assets separately. The former can be summed while the + // latter is more of a boolean affair. + // + // Track fungible asset amounts - positive and negative. i64 is not lossy because fungible's are + // restricted to 2^63-1. Overflow is still possible but we check for that. + let mut fungibles = BTreeMap::::new(); + let mut non_fungibles = BTreeMap::::new(); + + let added = self.added_assets.into_iter().chain(other.added_assets); + let removed = self.removed_assets.into_iter().chain(other.removed_assets); + + let assets = added.map(|asset| (asset, true)).chain(removed.map(|asset| (asset, false))); + + for (asset, is_added) in assets { + match asset { + Asset::Fungible(fungible) => { + // Ensure overflow is not possible here. + const _: () = assert!(FungibleAsset::MAX_AMOUNT <= i64::MIN.unsigned_abs()); + const _: () = assert!(FungibleAsset::MAX_AMOUNT <= i64::MAX.unsigned_abs()); + let amount = i64::try_from(fungible.amount()).unwrap(); + + let entry = fungibles.entry(fungible.faucet_id()).or_default(); + *entry = if is_added { + entry.checked_add(amount) + } else { + entry.checked_sub(amount) + } + .ok_or_else(|| { + AccountDeltaError::AssetAmountTooBig( + entry.unsigned_abs() + amount.unsigned_abs(), + ) + })?; + }, + Asset::NonFungible(non_fungible) => { + let previous = non_fungibles.insert(non_fungible, is_added); + if let Some(previous) = previous { + if previous == is_added { + // Asset cannot be added nor removed twice. + return Err(AccountDeltaError::DuplicateVaultUpdate(asset)); + } else { + // Otherwise they cancel out. + non_fungibles.remove(&non_fungible); + } + } + }, + } + } + + let mut added = Vec::new(); + let mut removed = Vec::new(); + + for (faucet_id, amount) in fungibles { + let is_positive = amount.is_positive(); + let amount: u64 = amount.abs().try_into().expect("i64::abs() always fits in u64"); + + if amount == 0 { + continue; + } + + // We know that the faucet ID is valid since this comes from an existing asset, so the only + // possible error case is the amount overflowing. + let asset = FungibleAsset::new(faucet_id, amount) + .map_err(|_| AccountDeltaError::AssetAmountTooBig(amount))?; + + if is_positive { + added.push(Asset::Fungible(asset)); + } else { + removed.push(Asset::Fungible(asset)); + } + } + + for (non_fungible, is_added) in non_fungibles { + let asset = Asset::NonFungible(non_fungible); + if is_added { + added.push(asset); + } else { + removed.push(asset); + } + } + + let delta = Self::from_iterators(added, removed); + delta.validate()?; + + Ok(delta) + } + /// Checks whether this vault delta is valid. /// /// # Errors @@ -241,4 +338,101 @@ mod tests { assert!(!AccountVaultDelta::from_iterators([asset], []).is_empty()); assert!(!AccountVaultDelta::from_iterators([], [asset]).is_empty()); } + + #[rstest::rstest] + #[case::pos_pos(50, 50, Some(100))] + #[case::neg_neg(-50, -50, Some(-100))] + #[case::empty_pos(0, 50, Some(50))] + #[case::empty_neg(0, -50, Some(-50))] + #[case::nullify_pos_neg(100, -100, Some(0))] + #[case::nullify_neg_pos(-100, 100, Some(0))] + #[case::overflow(FungibleAsset::MAX_AMOUNT as i64, FungibleAsset::MAX_AMOUNT as i64, None)] + #[case::underflow(-(FungibleAsset::MAX_AMOUNT as i64), -(FungibleAsset::MAX_AMOUNT as i64), None)] + #[test] + fn merge_fungible_aggregation(#[case] x: i64, #[case] y: i64, #[case] expected: Option) { + /// Creates an [AccountVaultDelta] with a single [FungibleAsset] delta. This delta will + /// be added if `amount > 0`, removed if `amount < 0` or entirely missing if `amount == 0`. + fn create_delta_with_fungible(account_id: AccountId, amount: i64) -> AccountVaultDelta { + let asset = FungibleAsset::new(account_id, amount.unsigned_abs()).unwrap().into(); + match amount { + 0 => AccountVaultDelta::empty(), + x if x.is_positive() => AccountVaultDelta { + added_assets: vec![asset], + ..Default::default() + }, + _ => AccountVaultDelta { + removed_assets: vec![asset], + ..Default::default() + }, + } + } + + let account_id = AccountId::try_from(ACCOUNT_ID_FUNGIBLE_FAUCET_OFF_CHAIN).unwrap(); + + let delta_x = create_delta_with_fungible(account_id, x); + let delta_y = create_delta_with_fungible(account_id, y); + + let result = delta_x.merge(delta_y); + + // None is used to indicate an error is expected. + if let Some(expected) = expected { + let expected = create_delta_with_fungible(account_id, expected); + assert_eq!(result.unwrap(), expected); + } else { + assert!(result.is_err()); + } + } + + #[rstest::rstest] + #[case::empty_removed(None, Some(false), Ok(Some(false)))] + #[case::empty_added(None, Some(true), Ok(Some(true)))] + #[case::add_remove(Some(true), Some(false), Ok(None))] + #[case::remove_add(Some(false), Some(true), Ok(None))] + #[case::double_add(Some(true), Some(true), Err(()))] + #[case::double_remove(Some(false), Some(false), Err(()))] + #[test] + fn merge_non_fungible_aggregation( + #[case] x: Option, + #[case] y: Option, + #[case] expected: Result, ()>, + ) { + /// Creates an [AccountVaultDelta] with an optional [NonFungibleAsset] delta. This delta will + /// be added if `Some(true)`, removed for `Some(false)` and missing for `None`. + fn create_delta_with_non_fungible( + account_id: AccountId, + added: Option, + ) -> AccountVaultDelta { + let asset: Asset = NonFungibleAsset::new( + &NonFungibleAssetDetails::new(account_id, vec![1, 2, 3]).unwrap(), + ) + .unwrap() + .into(); + + match added { + Some(true) => AccountVaultDelta { + added_assets: vec![asset], + ..Default::default() + }, + Some(false) => AccountVaultDelta { + removed_assets: vec![asset], + ..Default::default() + }, + None => AccountVaultDelta::empty(), + } + } + + let account_id = AccountId::try_from(ACCOUNT_ID_NON_FUNGIBLE_FAUCET_OFF_CHAIN).unwrap(); + + let delta_x = create_delta_with_non_fungible(account_id, x); + let delta_y = create_delta_with_non_fungible(account_id, y); + + let result = delta_x.merge(delta_y); + + if let Ok(expected) = expected { + let expected = create_delta_with_non_fungible(account_id, expected); + assert_eq!(result.unwrap(), expected); + } else { + assert!(result.is_err()); + } + } } diff --git a/objects/src/assets/nonfungible.rs b/objects/src/assets/nonfungible.rs index bec6ac59b..1df4c0df1 100644 --- a/objects/src/assets/nonfungible.rs +++ b/objects/src/assets/nonfungible.rs @@ -5,6 +5,7 @@ use super::{ parse_word, AccountId, AccountType, Asset, AssetError, Felt, Hasher, Word, ACCOUNT_ISFAUCET_MASK, }; +use crate::Digest; /// Position of the faucet_id inside the [NonFungibleAsset] word. const FAUCET_ID_POS: usize = 1; @@ -26,6 +27,18 @@ const FAUCET_ID_POS: usize = 1; #[cfg_attr(feature = "serde", serde(transparent))] pub struct NonFungibleAsset(Word); +impl PartialOrd for NonFungibleAsset { + fn partial_cmp(&self, other: &Self) -> Option { + Some(self.cmp(other)) + } +} + +impl Ord for NonFungibleAsset { + fn cmp(&self, other: &Self) -> core::cmp::Ordering { + Digest::from(self.0).cmp(&Digest::from(other.0)) + } +} + impl NonFungibleAsset { // CONSTRUCTORS // -------------------------------------------------------------------------------------------- diff --git a/objects/src/errors.rs b/objects/src/errors.rs index 3f5621113..830bc1a51 100644 --- a/objects/src/errors.rs +++ b/objects/src/errors.rs @@ -11,7 +11,10 @@ use super::{ notes::NoteId, Digest, Word, MAX_BATCHES_PER_BLOCK, MAX_NOTES_PER_BATCH, }; -use crate::{accounts::AccountType, notes::NoteType}; +use crate::{ + accounts::{delta::AccountUpdateDetails, AccountType}, + notes::NoteType, +}; // ACCOUNT ERROR // ================================================================================================ @@ -63,6 +66,8 @@ pub enum AccountDeltaError { TooManyRemovedAssets { actual: usize, max: usize }, TooManyUpdatedStorageItems { actual: usize, max: usize }, DuplicateStorageMapLeaf { key: RpoDigest }, + AssetAmountTooBig(u64), + IncompatibleAccountUpdates(AccountUpdateDetails, AccountUpdateDetails), } #[cfg(feature = "std")] From 56516f3813ccf175b381ac943a746aee361a51ba Mon Sep 17 00:00:00 2001 From: Bobbin Threadbare Date: Mon, 29 Jul 2024 16:56:53 -0700 Subject: [PATCH 14/47] chore: add labeled and unlabeled triggers to changlog check task --- .github/workflows/changelog.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/changelog.yml b/.github/workflows/changelog.yml index 5fde0d8d0..c890c4c26 100644 --- a/.github/workflows/changelog.yml +++ b/.github/workflows/changelog.yml @@ -5,7 +5,7 @@ name: changelog on: pull_request: - types: [opened, reopened, synchronize] + types: [opened, reopened, synchronize, labeled, unlabeled] jobs: changelog: From a942c54bab7bfa1c08d89cb58fe5dd4c6afe05b0 Mon Sep 17 00:00:00 2001 From: omahs <73983677+omahs@users.noreply.github.com> Date: Tue, 30 Jul 2024 01:58:20 +0200 Subject: [PATCH 15/47] docs: fix typos (#805) --- docs/architecture/state.md | 4 ++-- docs/architecture/transactions/contexts.md | 4 ++-- docs/architecture/transactions/execution.md | 4 ++-- docs/architecture/transactions/kernel.md | 4 ++-- miden-tx/src/tests/kernel_tests/test_account.rs | 8 ++++---- objects/README.md | 2 +- objects/src/transaction/prepared_tx.rs | 2 +- 7 files changed, 14 insertions(+), 14 deletions(-) diff --git a/docs/architecture/state.md b/docs/architecture/state.md index bbb55217b..eb6fec7fa 100644 --- a/docs/architecture/state.md +++ b/docs/architecture/state.md @@ -85,9 +85,9 @@ Nullifiers are stored in a sparse Merkle tree, which maps [note nullifiers](note ![Architecture core concepts](../img/architecture/state/nullifier-db.png){ width="80%" }
-To prove that a note has not been consumed previously, the operator needs to provide a Merkle path to its node, and then show that the value in that node is `0`. In our case nullifiers are $32$ bytes each, and thus, the height of the Sparse Merkle Tree need to be $256$. +To prove that a note has not been consumed previously, the operator needs to provide a Merkle path to its node, and then show that the value in that node is `0`. In our case nullifiers are $32$ bytes each, and thus, the height of the Sparse Merkle Tree needs to be $256$. -To add new nullifiers to the database, operators needs to maintain the entire nullifier set. Otherwise, they would not be able to compute the new root of the tree. +To add new nullifiers to the database, operators need to maintain the entire nullifier set. Otherwise, they would not be able to compute the new root of the tree. !!! note Nullifiers as constructed in Miden break linkability of privately stored notes and the information about the note's consumption. To know the [note's nullifier](notes.md#note-nullifier-to-ensure-private-consumption) one must know the note's data. diff --git a/docs/architecture/transactions/contexts.md b/docs/architecture/transactions/contexts.md index aaf834c9d..2deca6b55 100644 --- a/docs/architecture/transactions/contexts.md +++ b/docs/architecture/transactions/contexts.md @@ -64,7 +64,7 @@ export.receive_asset end ``` -The [account API](https://github.com/0xPolygonMiden/miden-base/blob/main/miden-lib/asm/miden/account.masm#L162) exposes procedures to manage accounts. This particular procedure that was called by the wallet invokes a `syscall` to return back to the root context **(3)**, where the account vault is stored in memory (see prologue). `syscall` can incoke all procedures defined in the [Kernel API](https://github.com/0xPolygonMiden/miden-base/blob/main/miden-lib/asm/kernels/transaction/api.masm). +The [account API](https://github.com/0xPolygonMiden/miden-base/blob/main/miden-lib/asm/miden/account.masm#L162) exposes procedures to manage accounts. This particular procedure that was called by the wallet invokes a `syscall` to return back to the root context **(3)**, where the account vault is stored in memory (see prologue). `syscall` can invoke all procedures defined in the [Kernel API](https://github.com/0xPolygonMiden/miden-base/blob/main/miden-lib/asm/kernels/transaction/api.masm). ```arduino #! Add the specified asset to the vault. @@ -76,4 +76,4 @@ end Now, the asset can be safely added to the vault within the kernel context, and the note can be successfully processed. -
\ No newline at end of file +
diff --git a/docs/architecture/transactions/execution.md b/docs/architecture/transactions/execution.md index 0b22c732e..b3c11c277 100644 --- a/docs/architecture/transactions/execution.md +++ b/docs/architecture/transactions/execution.md @@ -4,7 +4,7 @@ comments: true The Miden transaction executor is the component that executes transactions. -Transaction execution consists of the following steps and results in a `ExecutedTransaction` object: +Transaction execution consists of the following steps and results in an `ExecutedTransaction` object: 1. Fetch the data required to execute a transaction from the data store. 2. Compile the transaction into an executable [MASM](https://0xpolygonmiden.github.io/miden-vm/user_docs/assembly/main.html) program using the transaction compiler. @@ -49,4 +49,4 @@ A successfully executed transaction results in a new account state which is a ve The transaction prover proves the inputted `ExecutedTransaction` and returns a `ProvenTransaction` object. The Miden node verifies the `ProvenTransaction` object using the transaction verifier and, if valid, updates the [state](../state.md) databases. -
\ No newline at end of file +
diff --git a/docs/architecture/transactions/kernel.md b/docs/architecture/transactions/kernel.md index cc6dcda35..f1ebbd602 100644 --- a/docs/architecture/transactions/kernel.md +++ b/docs/architecture/transactions/kernel.md @@ -28,7 +28,7 @@ The transaction kernel program receives two types of inputs, public inputs via t The operand stack holds the global inputs which serve as a commitment to the data being provided via the advice provider. -The advice provider holds data of the last known block, account and input note data. The details are layed out in the next paragraph. +The advice provider holds data of the last known block, account and input note data. The details are laid out in the next paragraph. ## Prologue @@ -156,4 +156,4 @@ There is an exception for special accounts, called faucets, which can mint or bu The transaction kernel program outputs the transaction script root, a commitment of all newly created outputs notes, and the account hash in its new state. -
\ No newline at end of file +
diff --git a/miden-tx/src/tests/kernel_tests/test_account.rs b/miden-tx/src/tests/kernel_tests/test_account.rs index dc3a47eee..bf384a98d 100644 --- a/miden-tx/src/tests/kernel_tests/test_account.rs +++ b/miden-tx/src/tests/kernel_tests/test_account.rs @@ -41,7 +41,7 @@ pub fn test_set_code_is_not_immediate() { assert_eq!( read_root_mem_value(&process, ACCT_CODE_ROOT_PTR), tx_context.account().code().root().as_elements(), - "the code root must not change immediatelly", + "the code root must not change immediately", ); assert_eq!( @@ -373,17 +373,17 @@ fn test_get_map_item() { assert_eq!( Word::default(), process.get_stack_word(1), - "The the rest of the stack must be cleared", + "The rest of the stack must be cleared", ); assert_eq!( Word::default(), process.get_stack_word(2), - "The the rest of the stack must be cleared", + "The rest of the stack must be cleared", ); assert_eq!( Word::default(), process.get_stack_word(3), - "The the rest of the stack must be cleared", + "The rest of the stack must be cleared", ); } } diff --git a/objects/README.md b/objects/README.md index 3959e5096..e1ac52e0c 100644 --- a/objects/README.md +++ b/objects/README.md @@ -22,7 +22,7 @@ Structures used to define fungible and non-fungible assets. Accounts own assets ### Block -Structures used to define a block. These objects contains authentication structures, merkle trees, used to represent the state of the rollup at a given point in time. +Structures used to define a block. These objects contain authentication structures, merkle trees, used to represent the state of the rollup at a given point in time. ### Notes diff --git a/objects/src/transaction/prepared_tx.rs b/objects/src/transaction/prepared_tx.rs index 80d20b9ac..b6e63e798 100644 --- a/objects/src/transaction/prepared_tx.rs +++ b/objects/src/transaction/prepared_tx.rs @@ -8,7 +8,7 @@ use super::{ /// A struct that contains all of the data required to execute a transaction. /// /// This includes: -/// - A an executable program which defines the transaction. +/// - An executable program which defines the transaction. /// - An optional transaction script. /// - A set of inputs against which the transaction program should be executed. #[derive(Debug)] From 194267b058bbec024251b36e95c23aba6a329e8a Mon Sep 17 00:00:00 2001 From: igamigo Date: Tue, 30 Jul 2024 16:39:37 -0300 Subject: [PATCH 16/47] test: Remove test subdir in favor of inline mod (#809) --- miden-lib/src/lib.rs | 27 ++++++++++++++++++++++++--- miden-lib/src/tests/mod.rs | 22 ---------------------- 2 files changed, 24 insertions(+), 25 deletions(-) delete mode 100644 miden-lib/src/tests/mod.rs diff --git a/miden-lib/src/lib.rs b/miden-lib/src/lib.rs index 0ef06ecb3..8095832cc 100644 --- a/miden-lib/src/lib.rs +++ b/miden-lib/src/lib.rs @@ -18,9 +18,6 @@ pub mod accounts; pub mod notes; pub mod transaction; -#[cfg(all(test, feature = "std"))] -mod tests; - // RE-EXPORTS // ================================================================================================ @@ -60,3 +57,27 @@ impl Library for MidenLib { self.contents.dependencies() } } + +// TESTS +// ================================================================================================ + +// NOTE: Most kernel-related tests can be found under /miden-tx/kernel_tests +#[cfg(all(test, feature = "std"))] +mod tests { + use miden_objects::assembly::Library; + + #[test] + fn test_compile() { + let path = "miden::kernels::tx::memory::get_input_note_ptr"; + let miden = super::MidenLib::default(); + let exists = miden.modules().any(|module| { + module + .ast + .procs() + .iter() + .any(|proc| module.path.append(&proc.name).unwrap().as_str() == path) + }); + + assert!(exists); + } +} diff --git a/miden-lib/src/tests/mod.rs b/miden-lib/src/tests/mod.rs deleted file mode 100644 index e74c43e73..000000000 --- a/miden-lib/src/tests/mod.rs +++ /dev/null @@ -1,22 +0,0 @@ -/// NOTE: Most kernel-related tests can be found under /miden-tx/kernel_tests -// CONSTANTS -// ================================================================================================ -use miden_objects::assembly::Library; - -// TESTS -// ================================================================================================ - -#[test] -fn test_compile() { - let path = "miden::kernels::tx::memory::get_input_note_ptr"; - let miden = super::MidenLib::default(); - let exists = miden.modules().any(|module| { - module - .ast - .procs() - .iter() - .any(|proc| module.path.append(&proc.name).unwrap().as_str() == path) - }); - - assert!(exists); -} From b2b66211865ea7b096eb090653bd74f3dc052ed5 Mon Sep 17 00:00:00 2001 From: Paul-Henry Kajfasz <42912740+phklive@users.noreply.github.com> Date: Tue, 30 Jul 2024 22:41:11 +0100 Subject: [PATCH 17/47] feat: `AccountCode` refactor from MerkleTree to sequential hash for offset based storage access (#763) --- CHANGELOG.md | 1 + bench-tx/src/main.rs | 6 +- docs/architecture/transactions/procedures.md | 89 +++++---- miden-lib/asm/kernels/transaction/api.masm | 15 +- miden-lib/asm/miden/account.masm | 4 +- miden-lib/asm/miden/kernels/tx/account.masm | 129 +++++++++---- miden-lib/asm/miden/kernels/tx/epilogue.masm | 18 +- miden-lib/asm/miden/kernels/tx/memory.masm | 117 ++++++++---- miden-lib/asm/miden/kernels/tx/prologue.masm | 79 +++++++- miden-lib/asm/miden/note.masm | 26 +-- miden-lib/src/accounts/faucets/mod.rs | 2 +- miden-lib/src/accounts/wallets/mod.rs | 2 +- miden-lib/src/transaction/inputs.rs | 16 +- miden-lib/src/transaction/memory.rs | 44 +++-- miden-lib/src/transaction/outputs.rs | 8 +- miden-tx/src/compiler/mod.rs | 5 +- miden-tx/src/compiler/tests.rs | 2 +- miden-tx/src/error.rs | 32 +++- miden-tx/src/executor/mod.rs | 3 +- miden-tx/src/host/account_procs.rs | 95 +++++++--- miden-tx/src/host/mod.rs | 21 ++- miden-tx/src/prover/mod.rs | 3 +- miden-tx/src/testing/account_procs.rs | 62 ------- miden-tx/src/testing/mock_host.rs | 7 +- miden-tx/src/testing/mod.rs | 1 - .../src/tests/kernel_tests/test_account.rs | 31 ++-- .../src/tests/kernel_tests/test_prologue.rs | 43 +++-- miden-tx/src/tests/mod.rs | 12 +- miden-tx/tests/integration/wallet/mod.rs | 6 +- objects/src/accounts/account_id.rs | 30 +-- objects/src/accounts/{code.rs => code/mod.rs} | 175 ++++++++++++------ objects/src/accounts/code/procedure.rs | 134 ++++++++++++++ objects/src/accounts/mod.rs | 17 +- objects/src/accounts/seed.rs | 20 +- objects/src/accounts/stub.rs | 20 +- objects/src/errors.rs | 2 + objects/src/testing/account_code.rs | 43 +++-- objects/src/testing/account_id.rs | 27 +-- objects/src/testing/storage.rs | 5 +- objects/src/transaction/inputs.rs | 5 +- 40 files changed, 892 insertions(+), 465 deletions(-) delete mode 100644 miden-tx/src/testing/account_procs.rs rename objects/src/accounts/{code.rs => code/mod.rs} (53%) create mode 100644 objects/src/accounts/code/procedure.rs diff --git a/CHANGELOG.md b/CHANGELOG.md index 00e35a5d0..32426bd63 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ - [BREAKING] Increase of nonce does not require changes in account state any more (#796). - Added `CHANGELOG.md` warning message on CI (#799). - Account deltas can now be merged (#797). +- Changed `AccountCode` procedures from merkle tree to sequential hash + added storage_offset support (#763). ## 0.4.0 (2024-07-03) diff --git a/bench-tx/src/main.rs b/bench-tx/src/main.rs index 28c8ed256..e0d3e9aea 100644 --- a/bench-tx/src/main.rs +++ b/bench-tx/src/main.rs @@ -90,7 +90,8 @@ pub fn benchmark_default_tx() -> Result { let (stack_inputs, advice_inputs) = transaction.get_kernel_inputs(); let advice_recorder: RecAdviceProvider = advice_inputs.into(); let mut host: TransactionHost<_, ()> = - TransactionHost::new(transaction.account().into(), advice_recorder, None); + TransactionHost::new(transaction.account().into(), advice_recorder, None) + .map_err(|e| format!("Failed to create transaction host: {}", e))?; vm_processor::execute( transaction.program(), @@ -174,7 +175,8 @@ pub fn benchmark_p2id() -> Result { )]); let authenticator = Some(Rc::new(authenticator)); let mut host = - TransactionHost::new(transaction.account().into(), advice_recorder, authenticator); + TransactionHost::new(transaction.account().into(), advice_recorder, authenticator) + .map_err(|e| format!("Failed to create transaction host: {}", e))?; vm_processor::execute( transaction.program(), diff --git a/docs/architecture/transactions/procedures.md b/docs/architecture/transactions/procedures.md index bde62bf0c..87f807e9c 100644 --- a/docs/architecture/transactions/procedures.md +++ b/docs/architecture/transactions/procedures.md @@ -8,73 +8,70 @@ There are user-facing procedures and kernel procedures. Users don't directly inv These procedures can be used to create smart contract/account code, note scripts, or account scripts. They basically serve as an API for the underlying kernel procedures. If a procedure can be called in the current context, an `exec` is sufficient. Otherwise the context procedures must be invoked by `call`. Users never need to invoke `syscall` procedures themselves. -!!! tip - - If capitalized, a variable representing a `word`, e.g., `ACCT_HASH` consists of four `felts`. If lowercase, the variable is represented by a single `felt`. +!!! tip - If capitalized, a variable representing a `word`, e.g., `ACCT_HASH` consists of four `felts`. If lowercase, the variable is represented by a single `felt`. ### Account -To import the account procedures, set `use.miden::account` at the beginning of the file. +To import the account procedures, set `use.miden::account` at the beginning of the file. Any procedure that changes the account state must be invoked in the account context and not by note or transaction scripts. All procedures invoke `syscall` to the kernel API and some are restricted by the kernel procedure `exec.authenticate_account_origin`, which fails if the parent context is not the executing account. -| Procedure name | Stack | Output | Context | Description | -|---------------------------|------------|--------------|---------|---------------------------------------------------------------------| -| `get_id` | `[]` | `[acct_id]` | account, note |
  • Returns the account id.
| -| `get_nonce` | `[]` | `[nonce]` | account, note |
  • Returns the account nonce.
| -| `get_initial_hash` | `[]` | `[H]` | account, note |
  • Returns the initial account hash.
| -| `get_current_hash` | `[]` | `[ACCT_HASH]`| account, note |
  • Computes and returns the account hash from account data stored in memory.
-| `incr_nonce` | `[value]` | `[]` | account |
  • Increments the account nonce by the provided `value` which can be at most `2^32 - 1` otherwise the procedure panics.
| -| `get_item` | `[index]` | `[VALUE]` | account, note |
  • Gets an item `VALUE` by `index` from the account storage.
  • Panics if the index is out of bounds.
| -| `set_item` | `[index, V']` | `[R', V]` | account |
  • Sets an index/value pair in the account storage.
  • Panics if the index is out of bounds. `R` is the new storage root.
| -| `set_code` | `[CODE_ROOT]`| `[]` | account |
  • Sets the code (`CODE_ROOT`) of the account the transaction is being executed against.
  • This procedure can only be executed on regular accounts with updatable code. Otherwise, the procedure fails.
| -| `get_balance` | `[faucet_id]`| `[balance]`| account, note |
  • Returns the `balance` of a fungible asset associated with a `faucet_id`.
  • Panics if the asset is not a fungible asset.
| -| `has_non_fungible_asset` | `[ASSET]` | `[has_asset]`| account, note |
  • Returns a boolean `has_asset` indicating whether the non-fungible asset is present in the vault.
  • Panics if the `ASSET` is a fungible asset.
| -| `add_asset` | `[ASSET]` | `[ASSET']` | account |
  • Adds the specified asset `ASSET` to the vault. Panics under various conditions.
  • If `ASSET` is a non-fungible asset, then `ASSET'` is the same as `ASSET`.
  • If `ASSET` is a fungible asset, then `ASSET'` is the total fungible asset in the account vault after `ASSET` was added to it.
| -| `remove_asset` | `[ASSET]` | `[ASSET]` | account |
  • Removes the specified `ASSET` from the vault.
  • Panics under various conditions.
| -| `get_vault_commitment` | `[]` | `[COM]` | account, note |
  • Returns a commitment `COM` to the account vault.
| +| Procedure name | Stack | Output | Context | Description | +| ------------------------ | ------------------- | ------------- | ------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `get_id` | `[]` | `[acct_id]` | account, note |
  • Returns the account id.
| +| `get_nonce` | `[]` | `[nonce]` | account, note |
  • Returns the account nonce.
| +| `get_initial_hash` | `[]` | `[H]` | account, note |
  • Returns the initial account hash.
| +| `get_current_hash` | `[]` | `[ACCT_HASH]` | account, note |
  • Computes and returns the account hash from account data stored in memory.
| +| `incr_nonce` | `[value]` | `[]` | account |
  • Increments the account nonce by the provided `value` which can be at most `2^32 - 1` otherwise the procedure panics.
| +| `get_item` | `[index]` | `[VALUE]` | account, note |
  • Gets an item `VALUE` by `index` from the account storage.
  • Panics if the index is out of bounds.
| +| `set_item` | `[index, V']` | `[R', V]` | account |
  • Sets an index/value pair in the account storage.
  • Panics if the index is out of bounds. `R` is the new storage root.
| +| `set_code` | `[CODE_COMMITMENT]` | `[]` | account |
  • Sets the code (`CODE_COMMITMENT`) of the account the transaction is being executed against.
  • This procedure can only be executed on regular accounts with updatable code. Otherwise, the procedure fails.
| +| `get_balance` | `[faucet_id]` | `[balance]` | account, note |
  • Returns the `balance` of a fungible asset associated with a `faucet_id`.
  • Panics if the asset is not a fungible asset.
| +| `has_non_fungible_asset` | `[ASSET]` | `[has_asset]` | account, note |
  • Returns a boolean `has_asset` indicating whether the non-fungible asset is present in the vault.
  • Panics if the `ASSET` is a fungible asset.
| +| `add_asset` | `[ASSET]` | `[ASSET']` | account |
  • Adds the specified asset `ASSET` to the vault. Panics under various conditions.
  • If `ASSET` is a non-fungible asset, then `ASSET'` is the same as `ASSET`.
  • If `ASSET` is a fungible asset, then `ASSET'` is the total fungible asset in the account vault after `ASSET` was added to it.
| +| `remove_asset` | `[ASSET]` | `[ASSET]` | account |
  • Removes the specified `ASSET` from the vault.
  • Panics under various conditions.
| +| `get_vault_commitment` | `[]` | `[COM]` | account, note |
  • Returns a commitment `COM` to the account vault.
| ### Note To import the note procedures, set `use.miden::note` at the beginning of the file. All procedures are restricted to the note context. -| Procedure name | Inputs | Outputs | Context | Description | -|--------------------------|---------------------|-----------------------|---------|-------------------------------------------------------------------------------------------------------------------------------------| -| `get_assets` | `[dest_ptr]` | `[num_assets, dest_ptr]` | note |
  • Writes the assets of the currently executing note into memory starting at the specified address `dest_ptr `.
  • `num_assets` is the number of assets in the currently executing note.
| -| `get_inputs` | `[dest_ptr]` | `[dest_ptr]` | note |
  • Writes the inputs of the currently executed note into memory starting at the specified address, `dest_ptr`.
| -| `get_sender` | `[]` | `[sender]` | note |
  • Returns the `sender` of the note currently being processed. Panics if a note is not being processed.
| -| `compute_inputs_hash` | `[inputs_ptr, num_inputs]` | `[HASH]` | note |
  • Computes hash of note inputs starting at the specified memory address.
| - +| Procedure name | Inputs | Outputs | Context | Description | +| --------------------- | -------------------------- | ------------------------ | ------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `get_assets` | `[dest_ptr]` | `[num_assets, dest_ptr]` | note |
  • Writes the assets of the currently executing note into memory starting at the specified address `dest_ptr `.
  • `num_assets` is the number of assets in the currently executing note.
| +| `get_inputs` | `[dest_ptr]` | `[dest_ptr]` | note |
  • Writes the inputs of the currently executed note into memory starting at the specified address, `dest_ptr`.
| +| `get_sender` | `[]` | `[sender]` | note |
  • Returns the `sender` of the note currently being processed. Panics if a note is not being processed.
| +| `compute_inputs_hash` | `[inputs_ptr, num_inputs]` | `[HASH]` | note |
  • Computes hash of note inputs starting at the specified memory address.
| ### Tx -To import the transaction procedures set `use.miden::tx` at the beginning of the file. Only the `create_note` procedure is restricted to the account context. -| Procedure name | Inputs | Outputs | Context | Description | -|--------------------------|------------------|-------------|---------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| `get_block_number` | `[]` | `[num]` | account, note |