From 0a52bcbb02b81613351bbfd71d466bd3698aa10f Mon Sep 17 00:00:00 2001 From: Dominik Schmid Date: Tue, 28 May 2024 15:48:58 +0200 Subject: [PATCH 1/6] docs: adding note tags to note discovery --- docs/architecture/notes.md | 45 +++++++++++++++++++++++++++----------- 1 file changed, 32 insertions(+), 13 deletions(-) diff --git a/docs/architecture/notes.md b/docs/architecture/notes.md index 7f3b081d9..4eeee2b18 100644 --- a/docs/architecture/notes.md +++ b/docs/architecture/notes.md @@ -2,11 +2,11 @@ comments: true --- -Two of Miden's key goals are parallel transaction execution and privacy. +Two of Miden's key goals are parallel transaction execution and privacy. -Polygon Miden implements a hybrid UTXO and account-based [state model](state.md) which enforces these goals with notes. Notes interact with, and transfer assets between, accounts. They can be consumed and produced asynchronously and privately. +Polygon Miden implements a hybrid UTXO and account-based [state model](state.md) which enforces these goals with notes. Notes interact with, and transfer assets between, accounts. They can be consumed and produced asynchronously and privately. -The concept of notes is a key divergence from Ethereum’s account-based model. +The concept of notes is a key divergence from Ethereum’s account-based model. ## Note design @@ -23,11 +23,11 @@ The concept of notes is a key divergence from Ethereum’s account-based model. ## Note lifecycle -New notes are created by executing transactions. +New notes are created by executing transactions. -After verifying the transaction proof the operator adds either only the note hash (private notes) or the full note data (public notes) to the note database. +After verifying the transaction proof the operator adds either only the note hash (private notes) or the full note data (public notes) to the note database. -Notes can be produced and consumed locally by users in local transactions or by the operator in a network transaction. +Notes can be produced and consumed locally by users in local transactions or by the operator in a network transaction. Note consumption requires the transacting party to know the note data to compute the nullifier. After successful verification, the operator sets the corresponding entry in the nullifier database to "consumed". @@ -52,11 +52,10 @@ There are [standard note scripts](https://github.com/0xPolygonMiden/miden-base/t * P2ID and P2IDR scripts are used to send assets to a specific account ID. The scripts check at note consumption if the executing account ID equals the account ID that was set by the note creator as note inputs. The P2IDR script is reclaimable and thus after a certain block height can also be consumed by the sender itself. * SWAP script is a simple way to swap assets. It adds an asset from the note into the consumer's vault and creates a new note consumable by the first note's issuer containing the requested asset. -!!! info "Example note script pay to ID (P2ID)" - Want to know how to ensure a note can only be consumed by a specified account? Date: Wed, 29 May 2024 12:09:52 +0200 Subject: [PATCH 2/6] changing it slightly --- docs/architecture/notes.md | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/docs/architecture/notes.md b/docs/architecture/notes.md index 4eeee2b18..baec0ec18 100644 --- a/docs/architecture/notes.md +++ b/docs/architecture/notes.md @@ -195,13 +195,17 @@ hash(hash(hash(hash(serial_num, [0; 4]), script_hash), input_hash), vault_hash) !!! info To compute a note's hash, we do not need to know the note's `serial_num`. Knowing the hash of the `serial_num` (as well as `script_hash`, `input_hash` and `note_vault`) is also sufficient. We compute the hash of `serial_num` as `hash(serial_num, [0; 4])` to simplify processing within the VM._ -## Note discovery +## Note discovery (Note Tags) -Note discovery describes the process of Miden clients finding notes they want to consume. There are two ways to receive new relevant notes - getting notes via an off-chain channel or querying the Miden operator to request newly recorded relevant notes. +Note discovery describes the process of Miden clients finding notes they want to consume. Miden clients can query the Miden node for notes carrying a certain note tag. Note tag`s are best effort filters for notes registered with the network. They are light-weight values used to speed up queries. Clients can follow tags of a certain use case, e.g. swap scripts, or agree upon a group of users on certain tags for their specific use case. Tags are also used by the operator to identify notes intended for network execution including the corresponding information on how to execute. -The former is needed for private notes. The network doesn't have the note data necessary for consumption, in which case the sender needs to inform the receiver and send the data via an off-chain channel, e.g., an email or Signal. +```arduino +0b009f4adc47857e2f6 +``` + +This example note tag indicates that the network operator (Miden node) shall execute the note against the account with the ID `0x09f4adc47857e2f6`. In this case, the note and the account against it gets executed must be `public`. -The latter is done via note tags. Miden clients can query the Miden node for notes carrying a certain tag. Note tag`s are best effort filters for notes registered with the network. Tags are light-weight values used to speed up queries. The two most signification bits of the tags have the following interpretation: +The two most signification bits of the note tag have the following interpretation: | Prefix | Execution hint | Target | Allowed note type | | ------ | :------------: | :------: | :----------------:| @@ -216,9 +220,9 @@ Where: - Target describes how to further interpret the bits in the note tag. For tags with a specific target, the rest of the tag is interpreted as an `account_id`. For use case values, the meaning of the rest of the tag is not specified by the protocol and can be used by applications built on top of the rollup. - Note type describes the note's storage mode, either public or private. -The note type is the only value enforced by the protocol. The rationale is that any note intended to be consumed in a network transaction must be public to have all the details available. The public note for local execution is intended to allow users to search for notes that can be consumed right away, without requiring an off-chain communication channel. +The following 30 bits can represent anything, from Account IDs to use cases or any custom logic agreed upon. -Using note tags is a compromise between privacy and latency. A user doesn't need to download all the notes of a certain time period, but the Miden operator learns in which notes a specific user is interested in. +Using note tags is a compromise between privacy and latency. If a user would query the operator using the note ID, the operator would learn in which note a specific user is interested in. On the other side, if a user would always download all registered notes and filter locally, it would be quite inefficient. Using tags, users can decide their privacy parameters by narrowing or broadening their note tag schemes. ## Note consumption From 29d620f5dd971b5e9c9f17fcb019421b4fd888ba Mon Sep 17 00:00:00 2001 From: Dominik Schmid Date: Wed, 29 May 2024 14:20:04 +0200 Subject: [PATCH 3/6] after review --- docs/architecture/notes.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/docs/architecture/notes.md b/docs/architecture/notes.md index baec0ec18..2c23b7c58 100644 --- a/docs/architecture/notes.md +++ b/docs/architecture/notes.md @@ -195,15 +195,15 @@ hash(hash(hash(hash(serial_num, [0; 4]), script_hash), input_hash), vault_hash) !!! info To compute a note's hash, we do not need to know the note's `serial_num`. Knowing the hash of the `serial_num` (as well as `script_hash`, `input_hash` and `note_vault`) is also sufficient. We compute the hash of `serial_num` as `hash(serial_num, [0; 4])` to simplify processing within the VM._ -## Note discovery (Note Tags) +## Note discovery (note tags) -Note discovery describes the process of Miden clients finding notes they want to consume. Miden clients can query the Miden node for notes carrying a certain note tag. Note tag`s are best effort filters for notes registered with the network. They are light-weight values used to speed up queries. Clients can follow tags of a certain use case, e.g. swap scripts, or agree upon a group of users on certain tags for their specific use case. Tags are also used by the operator to identify notes intended for network execution including the corresponding information on how to execute. +Note discovery describes the process by which Miden clients find notes they want to consume. Miden clients can query the Miden node for notes carrying a certain note tag. Note tags are best-effort filters for notes registered on the network. They are lightweight values used to speed up queries. Clients can follow tags for specific use cases, such as swap scripts, or agree with a group of users on certain tags for their specific needs. Tags are also used by the operator to identify notes intended for network execution and include the corresponding information on how to execute them. ```arduino 0b009f4adc47857e2f6 ``` -This example note tag indicates that the network operator (Miden node) shall execute the note against the account with the ID `0x09f4adc47857e2f6`. In this case, the note and the account against it gets executed must be `public`. +The example note tag above indicates that the network operator (Miden node) executes the note against the account with the ID `0x09f4adc47857e2f6`. In this case, the note and the account against which it gets executed must be `public`. The two most signification bits of the note tag have the following interpretation: @@ -214,15 +214,15 @@ The two most signification bits of the note tag have the following interpretatio | `0b10` | Local | Any | NoteType::Public | | `0b11` | Local | Any | Any | -Where: +- Where: -- Execution hint is set to `Network` for network transactions. These notes will be further validated and if possible consumed in a network transaction. -- Target describes how to further interpret the bits in the note tag. For tags with a specific target, the rest of the tag is interpreted as an `account_id`. For use case values, the meaning of the rest of the tag is not specified by the protocol and can be used by applications built on top of the rollup. -- Note type describes the note's storage mode, either public or private. +- Execution Hint: Set to `Network` for network transactions. These notes will be further validated and, if possible, consumed in a network transaction. +- Target: Describes how to further interpret the bits in the note tag. For tags with a specific target, the rest of the tag is interpreted as an `account_id`. For use case values, the meaning of the rest of the tag is not specified by the protocol and can be used by applications built on top of the rollup. +- Note type describes the note's storage mode, either `public` or `private`. -The following 30 bits can represent anything, from Account IDs to use cases or any custom logic agreed upon. +The following 30 bits can represent anything—from Account IDs to use cases or any custom logic agreed upon. -Using note tags is a compromise between privacy and latency. If a user would query the operator using the note ID, the operator would learn in which note a specific user is interested in. On the other side, if a user would always download all registered notes and filter locally, it would be quite inefficient. Using tags, users can decide their privacy parameters by narrowing or broadening their note tag schemes. +Using note tags is a compromise between privacy and latency. If a user queries the operator using the note ID, the operator learns which note a specific user is interested in. Alternatively, if a user always downloads all registered notes and filters locally, it is quite inefficient. By using tags, users can customize privacy parameters by narrowing or broadening their note tag schemes. ## Note consumption From f077324fb6e5a51b17d04224e595a3f43d2ea8bb Mon Sep 17 00:00:00 2001 From: Dominik Schmid Date: Wed, 29 May 2024 19:35:25 +0200 Subject: [PATCH 4/6] after another review --- docs/architecture/notes.md | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/docs/architecture/notes.md b/docs/architecture/notes.md index 2c23b7c58..140d0bd54 100644 --- a/docs/architecture/notes.md +++ b/docs/architecture/notes.md @@ -214,13 +214,11 @@ The two most signification bits of the note tag have the following interpretatio | `0b10` | Local | Any | NoteType::Public | | `0b11` | Local | Any | Any | -- Where: +- Execution hint: Set to `Network` for network transactions. These notes will be validated and, if possible, consumed in a network transaction. +- Target: Describes how to interpret the bits in the note tag. For tags with a specific target, the rest of the tag is interpreted as an `account_id`. For use case values, the meaning of the rest of the tag is not specified by the protocol and can be used by applications built on top of the rollup. +- Note type: Describes the note's storage mode, either `public` or `private`. -- Execution Hint: Set to `Network` for network transactions. These notes will be further validated and, if possible, consumed in a network transaction. -- Target: Describes how to further interpret the bits in the note tag. For tags with a specific target, the rest of the tag is interpreted as an `account_id`. For use case values, the meaning of the rest of the tag is not specified by the protocol and can be used by applications built on top of the rollup. -- Note type describes the note's storage mode, either `public` or `private`. - -The following 30 bits can represent anything—from Account IDs to use cases or any custom logic agreed upon. +The following 30 bits can represent anything; from account IDs to use cases or any custom logic agreed upon. Using note tags is a compromise between privacy and latency. If a user queries the operator using the note ID, the operator learns which note a specific user is interested in. Alternatively, if a user always downloads all registered notes and filters locally, it is quite inefficient. By using tags, users can customize privacy parameters by narrowing or broadening their note tag schemes. From 7fc561817a5777498828f3d20bc153e819ba3575 Mon Sep 17 00:00:00 2001 From: Dominik Schmid Date: Thu, 30 May 2024 10:14:15 +0200 Subject: [PATCH 5/6] adding a P2ID example --- docs/architecture/notes.md | 27 +++++++++++++++++---------- objects/src/notes/note_tag.rs | 13 ++++--------- 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/docs/architecture/notes.md b/docs/architecture/notes.md index 140d0bd54..b20f1f315 100644 --- a/docs/architecture/notes.md +++ b/docs/architecture/notes.md @@ -35,11 +35,11 @@ Note consumption requires the transacting party to know the note data to compute ![Architecture core concepts](../img/architecture/note/note-life-cycle.png) -## Note creation +### Note creation Notes are created as the outputs (`OutputNotes`) of Miden transactions. Operators record the notes to the [note database](state.md#note-database). After successful verification of the underlying transactions, those notes can be consumed. -## The note script +### The note script Every note has a script which gets executed at note consumption. It is always executed in the context of a single account, and thus, may invoke zero or more of the [account's functions](accounts.md#code). The script allows for more than just asset transfers; actions which could be of arbitrary complexity thanks to the Turing completeness of the Miden VM. @@ -182,7 +182,7 @@ There are [standard note scripts](https://github.com/0xPolygonMiden/miden-base/t Lastly, the pointer gets incremented, and if there is a second asset, the loop continues (`movup.4 add.1 dup dup.6 neq`). Finally, when all assets were put into the account's vault, the stack is cleared (`drop dropw drop`). -## Note storage mode +### Note storage mode Similar to accounts, there are two storage modes for notes in Miden - private and public. Notes can be stored publicly in the [note database](https://0xpolygonmiden.github.io/miden-base/architecture/state.html#notes-database) with all data publicly visible for everyone. Alternatively, notes can be stored privately by committing only the note hash to the note database. @@ -195,15 +195,15 @@ hash(hash(hash(hash(serial_num, [0; 4]), script_hash), input_hash), vault_hash) !!! info To compute a note's hash, we do not need to know the note's `serial_num`. Knowing the hash of the `serial_num` (as well as `script_hash`, `input_hash` and `note_vault`) is also sufficient. We compute the hash of `serial_num` as `hash(serial_num, [0; 4])` to simplify processing within the VM._ -## Note discovery (note tags) +### Note discovery (note tags) -Note discovery describes the process by which Miden clients find notes they want to consume. Miden clients can query the Miden node for notes carrying a certain note tag. Note tags are best-effort filters for notes registered on the network. They are lightweight values used to speed up queries. Clients can follow tags for specific use cases, such as swap scripts, or agree with a group of users on certain tags for their specific needs. Tags are also used by the operator to identify notes intended for network execution and include the corresponding information on how to execute them. +Note discovery describes the process by which Miden clients find notes they want to consume. Miden clients can query the Miden node for notes carrying a certain note tag in their metadata. Note tags are best-effort filters for notes registered on the network. They are lightweight values (32-bit) used to speed up queries. Clients can follow tags for specific use cases, such as swap scripts, or user-created custom tags. Tags are also used by the operator to identify notes intended for network execution and include the corresponding information on how to execute them. ```arduino 0b009f4adc47857e2f6 ``` -The example note tag above indicates that the network operator (Miden node) executes the note against the account with the ID `0x09f4adc47857e2f6`. In this case, the note and the account against which it gets executed must be `public`. +The example note tag above indicates that the network operator (Miden node) executes the note against the account with ID `0x09f4adc47857e2f6`. In this case, the note and the account against which it gets executed must be `public`. The two most signification bits of the note tag have the following interpretation: @@ -214,15 +214,22 @@ The two most signification bits of the note tag have the following interpretatio | `0b10` | Local | Any | NoteType::Public | | `0b11` | Local | Any | Any | -- Execution hint: Set to `Network` for network transactions. These notes will be validated and, if possible, consumed in a network transaction. +- Execution hint: Set to `Network` for network transactions. These notes are validated and, if possible, consumed in a network transaction. - Target: Describes how to interpret the bits in the note tag. For tags with a specific target, the rest of the tag is interpreted as an `account_id`. For use case values, the meaning of the rest of the tag is not specified by the protocol and can be used by applications built on top of the rollup. -- Note type: Describes the note's storage mode, either `public` or `private`. +- Allowed note type: Describes the note's storage mode, either `public` or `private`. -The following 30 bits can represent anything; from account IDs to use cases or any custom logic agreed upon. +The following 30 bits can represent anything. In the above example note tag, it represents an account Id of a public account. As designed the first bit of a public account is always `0` which overlaps with the second most significant bit of the note tag. Using note tags is a compromise between privacy and latency. If a user queries the operator using the note ID, the operator learns which note a specific user is interested in. Alternatively, if a user always downloads all registered notes and filters locally, it is quite inefficient. By using tags, users can customize privacy parameters by narrowing or broadening their note tag schemes. -## Note consumption +??? note "Example note tag for P2ID" + P2ID scripts can only be consumed by the specified account Id (target Id). In the standard schema, the target Id is encoded into the note tag. + + In case the P2ID note is intended for network execution, the note tag looks like the above example `0b009f4adc47857e2f6`. Here the Miden operator knows exactly against which account it the transaction must be executed. + + In case the P2ID note is intended for local execution, the recipient needs to be able to discover that note. The recipient can query the Miden node for a specific tag, to see if there are new P2ID notes to be consumed. In that case the two most significant bits are set to `0b11`, which allows for any note type to be used (`private` or `public`), the following 14 bits are set to the 14 most significant bits of the account ID, and the remaining 16 bits are set to 0. + +### Note consumption As with creation, notes can only be consumed in Miden transactions. If a valid transaction consuming an `InputNote` gets verified by the Miden node, the note's unique nullifier gets added to the [nullifier database](https://0xpolygonmiden.github.io/miden-base/architecture/state.html#nullifier-database) and is therefore consumed. diff --git a/objects/src/notes/note_tag.rs b/objects/src/notes/note_tag.rs index a5dbad0b8..fe48a1191 100644 --- a/objects/src/notes/note_tag.rs +++ b/objects/src/notes/note_tag.rs @@ -289,19 +289,13 @@ impl Deserializable for NoteTag { #[cfg(test)] mod tests { + use std::println; + use super::{NoteExecutionHint, NoteTag}; use crate::{ accounts::{ account_id::testing::{ - ACCOUNT_ID_FUNGIBLE_FAUCET_OFF_CHAIN, ACCOUNT_ID_FUNGIBLE_FAUCET_ON_CHAIN, - 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_OFF_CHAIN, - ACCOUNT_ID_NON_FUNGIBLE_FAUCET_ON_CHAIN, ACCOUNT_ID_NON_FUNGIBLE_FAUCET_ON_CHAIN_1, - ACCOUNT_ID_OFF_CHAIN_SENDER, ACCOUNT_ID_REGULAR_ACCOUNT_IMMUTABLE_CODE_ON_CHAIN, - ACCOUNT_ID_REGULAR_ACCOUNT_IMMUTABLE_CODE_ON_CHAIN_2, - ACCOUNT_ID_REGULAR_ACCOUNT_UPDATABLE_CODE_OFF_CHAIN, - ACCOUNT_ID_REGULAR_ACCOUNT_UPDATABLE_CODE_ON_CHAIN, - ACCOUNT_ID_REGULAR_ACCOUNT_UPDATABLE_CODE_ON_CHAIN_2, ACCOUNT_ID_SENDER, + account_id, ACCOUNT_ID_FUNGIBLE_FAUCET_OFF_CHAIN, ACCOUNT_ID_FUNGIBLE_FAUCET_ON_CHAIN, 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_OFF_CHAIN, ACCOUNT_ID_NON_FUNGIBLE_FAUCET_ON_CHAIN, ACCOUNT_ID_NON_FUNGIBLE_FAUCET_ON_CHAIN_1, ACCOUNT_ID_OFF_CHAIN_SENDER, ACCOUNT_ID_REGULAR_ACCOUNT_IMMUTABLE_CODE_ON_CHAIN, ACCOUNT_ID_REGULAR_ACCOUNT_IMMUTABLE_CODE_ON_CHAIN_2, ACCOUNT_ID_REGULAR_ACCOUNT_UPDATABLE_CODE_OFF_CHAIN, ACCOUNT_ID_REGULAR_ACCOUNT_UPDATABLE_CODE_ON_CHAIN, ACCOUNT_ID_REGULAR_ACCOUNT_UPDATABLE_CODE_ON_CHAIN_2, ACCOUNT_ID_SENDER }, AccountId, }, @@ -417,6 +411,7 @@ mod tests { NoteTag::from_account_id(on_chain, NoteExecutionHint::Network), Ok(NoteTag(0b00000000_00000000_00000000_00000000)) ); + assert!(NoteTag::from_account_id(off_chain, NoteExecutionHint::Network).is_err()); assert_eq!( From 165406285952c3380f004cb9e094a9f417110940 Mon Sep 17 00:00:00 2001 From: Dominik Schmid Date: Thu, 30 May 2024 10:59:40 +0200 Subject: [PATCH 6/6] adding a P2ID example --- docs/architecture/notes.md | 24 +++++++++++++++--------- objects/src/notes/note_tag.rs | 13 +++++++++---- 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/docs/architecture/notes.md b/docs/architecture/notes.md index b20f1f315..38f93a535 100644 --- a/docs/architecture/notes.md +++ b/docs/architecture/notes.md @@ -199,12 +199,6 @@ hash(hash(hash(hash(serial_num, [0; 4]), script_hash), input_hash), vault_hash) Note discovery describes the process by which Miden clients find notes they want to consume. Miden clients can query the Miden node for notes carrying a certain note tag in their metadata. Note tags are best-effort filters for notes registered on the network. They are lightweight values (32-bit) used to speed up queries. Clients can follow tags for specific use cases, such as swap scripts, or user-created custom tags. Tags are also used by the operator to identify notes intended for network execution and include the corresponding information on how to execute them. -```arduino -0b009f4adc47857e2f6 -``` - -The example note tag above indicates that the network operator (Miden node) executes the note against the account with ID `0x09f4adc47857e2f6`. In this case, the note and the account against which it gets executed must be `public`. - The two most signification bits of the note tag have the following interpretation: | Prefix | Execution hint | Target | Allowed note type | @@ -220,14 +214,26 @@ The two most signification bits of the note tag have the following interpretatio The following 30 bits can represent anything. In the above example note tag, it represents an account Id of a public account. As designed the first bit of a public account is always `0` which overlaps with the second most significant bit of the note tag. +``` +0b00000100_11111010_01010110_11100010 +``` + +This example note tag indicates that the network operator (Miden node) executes the note against a specific account - `0x09f4adc47857e2f6`. Only the 30 most significant bits of the account id are represented in the note tag, since account Ids are 64-bit values but note tags only have 32-bits. Knowing a 30-bit prefix already narrows the set of potential target accounts down enough. + Using note tags is a compromise between privacy and latency. If a user queries the operator using the note ID, the operator learns which note a specific user is interested in. Alternatively, if a user always downloads all registered notes and filters locally, it is quite inefficient. By using tags, users can customize privacy parameters by narrowing or broadening their note tag schemes. ??? note "Example note tag for P2ID" - P2ID scripts can only be consumed by the specified account Id (target Id). In the standard schema, the target Id is encoded into the note tag. + P2ID scripts can only be consumed by the specified account ID (target ID). In the standard schema, the target ID is encoded into the note tag. + + For network execution of a P2ID note, the note tag is encoded as follows: 0b00000100_11111010_01010110_11100010. This encoding allows the Miden operator to quickly identify the account against which the transaction must be executed. - In case the P2ID note is intended for network execution, the note tag looks like the above example `0b009f4adc47857e2f6`. Here the Miden operator knows exactly against which account it the transaction must be executed. + For local execution of a P2ID note, the recipient needs to be able to discover the note. The recipient can query the Miden node for a specific tag to see if there are new P2ID notes to be consumed. In this case, the two most significant bits are set to 0b11, allowing any note type (private or public) to be used. The next 14 bits represent the 14 most significant bits of the account ID, and the remaining 16 bits are set to 0. - In case the P2ID note is intended for local execution, the recipient needs to be able to discover that note. The recipient can query the Miden node for a specific tag, to see if there are new P2ID notes to be consumed. In that case the two most significant bits are set to `0b11`, which allows for any note type to be used (`private` or `public`), the following 14 bits are set to the 14 most significant bits of the account ID, and the remaining 16 bits are set to 0. + Example for local execution: + ``` + 0b11000100_11111010_00000000_00000000 + ``` + This "fuzzy matching" approach balances privacy and efficiency. A note with this tag could be intended for any account sharing the same 16-bit prefix. ### Note consumption diff --git a/objects/src/notes/note_tag.rs b/objects/src/notes/note_tag.rs index fe48a1191..a5dbad0b8 100644 --- a/objects/src/notes/note_tag.rs +++ b/objects/src/notes/note_tag.rs @@ -289,13 +289,19 @@ impl Deserializable for NoteTag { #[cfg(test)] mod tests { - use std::println; - use super::{NoteExecutionHint, NoteTag}; use crate::{ accounts::{ account_id::testing::{ - account_id, ACCOUNT_ID_FUNGIBLE_FAUCET_OFF_CHAIN, ACCOUNT_ID_FUNGIBLE_FAUCET_ON_CHAIN, 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_OFF_CHAIN, ACCOUNT_ID_NON_FUNGIBLE_FAUCET_ON_CHAIN, ACCOUNT_ID_NON_FUNGIBLE_FAUCET_ON_CHAIN_1, ACCOUNT_ID_OFF_CHAIN_SENDER, ACCOUNT_ID_REGULAR_ACCOUNT_IMMUTABLE_CODE_ON_CHAIN, ACCOUNT_ID_REGULAR_ACCOUNT_IMMUTABLE_CODE_ON_CHAIN_2, ACCOUNT_ID_REGULAR_ACCOUNT_UPDATABLE_CODE_OFF_CHAIN, ACCOUNT_ID_REGULAR_ACCOUNT_UPDATABLE_CODE_ON_CHAIN, ACCOUNT_ID_REGULAR_ACCOUNT_UPDATABLE_CODE_ON_CHAIN_2, ACCOUNT_ID_SENDER + ACCOUNT_ID_FUNGIBLE_FAUCET_OFF_CHAIN, ACCOUNT_ID_FUNGIBLE_FAUCET_ON_CHAIN, + 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_OFF_CHAIN, + ACCOUNT_ID_NON_FUNGIBLE_FAUCET_ON_CHAIN, ACCOUNT_ID_NON_FUNGIBLE_FAUCET_ON_CHAIN_1, + ACCOUNT_ID_OFF_CHAIN_SENDER, ACCOUNT_ID_REGULAR_ACCOUNT_IMMUTABLE_CODE_ON_CHAIN, + ACCOUNT_ID_REGULAR_ACCOUNT_IMMUTABLE_CODE_ON_CHAIN_2, + ACCOUNT_ID_REGULAR_ACCOUNT_UPDATABLE_CODE_OFF_CHAIN, + ACCOUNT_ID_REGULAR_ACCOUNT_UPDATABLE_CODE_ON_CHAIN, + ACCOUNT_ID_REGULAR_ACCOUNT_UPDATABLE_CODE_ON_CHAIN_2, ACCOUNT_ID_SENDER, }, AccountId, }, @@ -411,7 +417,6 @@ mod tests { NoteTag::from_account_id(on_chain, NoteExecutionHint::Network), Ok(NoteTag(0b00000000_00000000_00000000_00000000)) ); - assert!(NoteTag::from_account_id(off_chain, NoteExecutionHint::Network).is_err()); assert_eq!(