-
Notifications
You must be signed in to change notification settings - Fork 135
feat: add miden::standards::note_tag module
#2366
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
2848dcb
chore: use `ExecError` in `CodeExecutor`
PhilippGackstatter 5936732
feat: Implement `note_tag::create_account_target` MASM
PhilippGackstatter 3c9f4b1
chore: remove unused error; improve docs
PhilippGackstatter 1498788
chore: add changelog
PhilippGackstatter 56081c4
fix: docs and use constants instead of magic numbers
PhilippGackstatter 64899ba
Merge branch 'next' into pgackst-note-tag-followup
bobbinth 2fdcdad
chore: add note on meaning of tag length
PhilippGackstatter File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| use miden::core::math::u64 | ||
|
|
||
| # ERRORS | ||
| # ================================================================================================= | ||
|
|
||
| const ERR_NOTE_TAG_MAX_ACCOUNT_TARGET_LENGTH_EXCEEDED="note tag length can be at most 32" | ||
|
|
||
| # CONSTANTS | ||
| # ================================================================================================= | ||
|
|
||
| # The maximum account target tag length. | ||
| const MAX_ACCOUNT_TARGET_TAG_LENGTH = 32 | ||
|
|
||
| # The default account target tag length. | ||
| const DEFAULT_ACCOUNT_TARGET_TAG_LENGTH = 14 | ||
|
|
||
| # PROCEDURES | ||
| # ================================================================================================= | ||
|
|
||
| #! Constructs a note tag that targets the given account_id_prefix with the default tag_len of 14. | ||
| #! | ||
| #! The tag is a u32 constructed by taking the 14 most significant bits of the account ID prefix and | ||
| #! setting the remaining bits to zero. | ||
| #! | ||
| #! Inputs: [account_id_prefix] | ||
| #! Outputs: [note_tag] | ||
| #! | ||
| #! Where: | ||
| #! - account_id_prefix is the account id prefix to compute the note tag for. | ||
| #! - note_tag is the created note tag. | ||
| #! | ||
| #! Invocation: exec | ||
| pub proc create_account_target | ||
| push.DEFAULT_ACCOUNT_TARGET_TAG_LENGTH | ||
| exec.create_custom_account_target | ||
| # => [note_tag] | ||
| end | ||
|
|
||
| #! Constructs a note tag that targets the given account_id_prefix with the provided tag_len. | ||
| #! | ||
| #! The tag is a u32 constructed by taking the `tag_len` most significant bits of the account ID | ||
| #! prefix and setting the remaining bits to zero. | ||
| #! | ||
| #! See the Rust `NoteTag` documentation for what changing the tag length means. | ||
| #! | ||
| #! Inputs: [tag_len, account_id_prefix] | ||
| #! Outputs: [note_tag] | ||
| #! | ||
| #! Where: | ||
| #! - account_id_prefix is the account id prefix to compute the note tag for. | ||
| #! - note_tag is the created note tag. | ||
| #! - tag_len is the number of most significant bits from the account ID prefix that should be used | ||
| #! for the tag. | ||
| #! | ||
|
PhilippGackstatter marked this conversation as resolved.
|
||
| #! Panics if: | ||
| #! - the tag_len exceeds 32. | ||
| #! | ||
| #! Invocation: exec | ||
| pub proc create_custom_account_target | ||
| u32assert.err=ERR_NOTE_TAG_MAX_ACCOUNT_TARGET_LENGTH_EXCEEDED | ||
| # => [tag_len, account_id_prefix] | ||
|
|
||
| dup u32lte.MAX_ACCOUNT_TARGET_TAG_LENGTH | ||
| assert.err=ERR_NOTE_TAG_MAX_ACCOUNT_TARGET_LENGTH_EXCEEDED | ||
| # => [tag_len, account_id_prefix] | ||
|
|
||
| # create a bit mask that zeros out the lower (32 - tag_len) bits. | ||
| # since u32shl panics for a 32 shift, we need to use u64::shl in case tag_len is 0 | ||
|
|
||
| # push u32::MAX as a u64 | ||
| push.0 push.0xffffffff | ||
| # => [u32::MAX, 0, tag_len, account_id_prefix] | ||
|
|
||
| # compute "number of bits in u32" - tag_len | ||
| push.32 movup.3 sub | ||
| # => [shift_by, u32::MAX, 0, account_id_prefix] | ||
|
|
||
| exec.u64::shl | ||
| # => [bit_mask_hi, bit_mask_lo, account_id_prefix] | ||
|
|
||
| # discard the lo part | ||
| swap drop | ||
| # => [bit_mask, account_id_prefix] | ||
|
|
||
| swap u32split | ||
| # => [account_id_prefix_hi, account_id_prefix_lo, bit_mask] | ||
|
|
||
| # discard the lo part of the ID prefix | ||
| swap drop | ||
| # => [account_id_prefix_hi, bit_mask] | ||
|
|
||
| u32and | ||
| # => [note_tag] | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not directly related to this PR, but why do we need to set a tag for a
BURNnote? These are network notes and instead of a tag we should be setting an attachment for them, no?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll merge this PR as is - but cc @partylikeits1983 and @mmagician in case this is something we'd want to update in a different PR.