-
Notifications
You must be signed in to change notification settings - Fork 163
feat(protocol): bound note storage loading in the OwnerConfig and FaucetPolicyConfig scripts #3563
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
Changes from 3 commits
f9e5fc9
c699dab
d7de31e
d556555
2b68505
fd25ea4
29f0cdc
6a0ccad
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,6 +14,9 @@ const ERR_NOTE_DATA_DOES_NOT_MATCH_COMMITMENT = "note data does not match the co | |
| const ERR_NOTE_INVALID_NUMBER_OF_STORAGE_ITEMS = | ||
| "the specified number of note storage items does not match the actual number" | ||
|
|
||
| const ERR_NOTE_TOO_MANY_STORAGE_ITEMS = | ||
| "the number of note storage items exceeds the maximum accepted by the note script" | ||
|
|
||
| # ACTIVE NOTE PROCEDURES | ||
| # ================================================================================================= | ||
| # | ||
|
|
@@ -275,6 +278,74 @@ pub proc get_storage(dest_ptr: MemoryAddress) -> u16 | |
| # => [num_storage_items] | ||
| end | ||
|
|
||
| #! Returns the storage commitment and the number of storage items of the active note. | ||
| #! | ||
| #! Inputs: [] | ||
| #! Outputs: [NOTE_STORAGE_COMMITMENT, num_storage_items] | ||
| #! | ||
| #! Where: | ||
| #! - NOTE_STORAGE_COMMITMENT is the commitment to the note's storage. | ||
| #! - num_storage_items is the number of storage items the active note was created with. | ||
| #! | ||
| #! Panics if: | ||
| #! - no note is currently active. | ||
| #! | ||
| #! Invocation: exec | ||
| pub proc get_storage_info() -> (word, u16) | ||
| # push a placeholder note_index (ignored when is_active_note = 1) and the active note flag | ||
| push.0.1 | ||
| # => [is_active_note = 1, note_index = 0] | ||
|
|
||
| exec.input_note_internal::get_storage_info_raw | ||
| # => [NOTE_STORAGE_COMMITMENT, num_storage_items] | ||
| end | ||
|
|
||
| #! Writes the active note's storage to memory starting at the specified address, provided the note | ||
| #! carries at most `max_num_storage_items` items. | ||
| #! | ||
| #! Inputs: | ||
| #! Stack: [dest_ptr, max_num_storage_items] | ||
| #! Advice Map: { NOTE_STORAGE_COMMITMENT: [STORAGE] } | ||
| #! Outputs: | ||
| #! Stack: [num_storage_items] | ||
| #! | ||
| #! Where: | ||
| #! - dest_ptr is the memory address to write the note storage. | ||
| #! - max_num_storage_items is the largest number of storage items the caller accepts. | ||
| #! - NOTE_STORAGE_COMMITMENT is the commitment to the note's storage. | ||
| #! - STORAGE is the data corresponding to the note's storage. | ||
| #! - num_storage_items is the number of storage items the active note was created with. | ||
| #! | ||
| #! Panics if: | ||
| #! - no note is currently active. | ||
| #! - num_storage_items is greater than max_num_storage_items. | ||
| #! | ||
| #! Invocation: exec | ||
| pub proc get_bounded_storage(dest_ptr: MemoryAddress, max_num_storage_items: u16) -> u16 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably not a good idea, but I wonder if we should just change the |
||
| # push a placeholder note_index (ignored when is_active_note = 1) and the active note flag | ||
| push.0.1 | ||
| # => [is_active_note = 1, note_index = 0, dest_ptr, max_num_storage_items] | ||
|
|
||
| exec.input_note_internal::get_storage_info_raw | ||
| # => [NOTE_STORAGE_COMMITMENT, num_storage_items, dest_ptr, max_num_storage_items] | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is the same as |
||
|
|
||
| # reject an oversized note before its storage preimage is loaded and hashed | ||
| dup.4 dup.7 lte assert.err=ERR_NOTE_TOO_MANY_STORAGE_ITEMS | ||
| # => [NOTE_STORAGE_COMMITMENT, num_storage_items, dest_ptr, max_num_storage_items] | ||
|
bobbinth marked this conversation as resolved.
Outdated
|
||
|
|
||
| # the bound is no longer needed | ||
| movup.6 drop | ||
| # => [NOTE_STORAGE_COMMITMENT, num_storage_items, dest_ptr] | ||
|
|
||
| # save num_storage_items for the return value | ||
| dup.4 movdn.6 | ||
| # => [NOTE_STORAGE_COMMITMENT, num_storage_items, dest_ptr, num_storage_items] | ||
|
|
||
| # write the inputs to the provided destination pointer | ||
| exec.write_storage_to_memory | ||
| # => [num_storage_items] | ||
| end | ||
|
|
||
| #! Returns the metadata of the active note. | ||
| #! | ||
| #! Inputs: [] | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,6 +24,9 @@ const NUM_ITEMS_TRANSFER_OWNERSHIP = 3 | |
| const NUM_ITEMS_ACCEPT_OWNERSHIP = 1 | ||
| const NUM_ITEMS_RENOUNCE_OWNERSHIP = 1 | ||
|
|
||
| # Largest storage item count any action uses | ||
| const MAX_NUM_ITEMS = NUM_ITEMS_TRANSFER_OWNERSHIP | ||
|
|
||
| # ERRORS | ||
| # ================================================================================================= | ||
|
|
||
|
|
@@ -58,6 +61,7 @@ const ERR_OWNER_CONFIG_UNEXPECTED_NUMBER_OF_STORAGE_ITEMS = "owner config note s | |
| #! | ||
| #! Panics if: | ||
| #! - the consuming account is not the note's target account, or the target attachment is missing. | ||
| #! - the number of storage items exceeds MAX_NUM_ITEMS. | ||
| #! - the selector is not a known action. | ||
| #! - the number of storage items does not match the selected action. | ||
| #! - the note sender is not authorized for the selected action (per the `Ownable2Step` procedures). | ||
|
|
@@ -73,7 +77,7 @@ pub proc main | |
| # => [pad(16)] | ||
|
|
||
| # write the note storage to memory starting at STORAGE_PTR | ||
| push.STORAGE_PTR exec.active_note::get_storage | ||
| push.MAX_NUM_ITEMS push.STORAGE_PTR exec.active_note::get_bounded_storage | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we propagate this everywhere (maybe in a different PR)? Basically, I'm not sure there should be much usage of |
||
| # => [num_storage_items] | ||
|
|
||
| mem_load.SELECTOR_PTR | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.